@Test public void testGeoPointAsDoubleArray() { final double lat = rand.nextDouble() * 90 - 90; final double lon = rand.nextDouble() * 180 - 180; final Geometry geometry = parserUtil.createGeometry(Arrays.asList(new Double[] {lon, lat})); assertTrue(geometry.equals(geometryFactory.createPoint(new Coordinate(lon, lat)))); }
@Test public void testGeoShapeGeometryCollection() throws JsonParseException, JsonMappingException, IOException { rgb.setNumGeometries(5); GeometryCollection geom = rgb.createRandomGeometryCollection(); assertTrue(parserUtil.createGeometry(rgb.toMap(geom)).equalsExact(geom, 1e-9)); }
@Test public void testGeoPointPatternForFractions() { final double lat = rand.nextDouble() * 2 - 1; final double lon = rand.nextDouble() * 2 - 1; final String value = (lat + "," + lon).replace("0.", "."); final Geometry geom = parserUtil.createGeometry(value); assertTrue(geom.equals(geometryFactory.createPoint(new Coordinate(lon, lat)))); }
@Test public void testParseGeoPointPatternForNegatives() { final double lat = rand.nextDouble() * 90 - 90; final double lon = rand.nextDouble() * 180 - 180; final String value = lat + "," + lon; final Geometry geom = parserUtil.createGeometry(value); assertTrue(geom.equals(geometryFactory.createPoint(new Coordinate(lon, lat)))); }
@Test public void testGeoHash() { final double lat = rand.nextDouble() * 90 - 90; final double lon = rand.nextDouble() * 180 - 180; String geohash = GeoHashUtils.encode(lat, lon, 64); final Geometry expected = geometryFactory.createPoint(new Coordinate(lon, lat)); assertTrue(parserUtil.createGeometry(geohash).equals(expected)); }
@Test public void testGeoPointAsUnrecognizedProperties() { final double lat = rand.nextDouble() * 90 - 90; final double lon = rand.nextDouble() * 180 - 180; properties.put("latD", lat); properties.put("lonD", lon); final Geometry geometry = parserUtil.createGeometry(properties); assertTrue(geometry == null); }
@Test public void testGeoPointAsProperties() { final double lat = rand.nextDouble() * 90 - 90; final double lon = rand.nextDouble() * 180 - 180; properties.put("lat", lat); properties.put("lon", lon); final Geometry geometry = parserUtil.createGeometry(properties); assertTrue(geometry.equals(geometryFactory.createPoint(new Coordinate(lon, lat)))); }
@Test public void testGeoShapePointString() throws JsonParseException, JsonMappingException, IOException { Point geom = rgb.createRandomPoint(); final Map<String, Object> map = new HashMap<>(); final List<String> coords = new ArrayList<>(); coords.add(String.valueOf(geom.getX())); coords.add(String.valueOf(geom.getY())); map.put("coordinates", coords); map.put("type", "Point"); assertTrue(parserUtil.createGeometry(map).equalsExact(geom, 1e-9)); }
@Test public void testGeoPointPatternForWholeValues() { final Geometry geom = parserUtil.createGeometry("45,90"); assertTrue(geom.equals(geometryFactory.createPoint(new Coordinate(90, 45)))); }
@Test public void testUnrecognizedGeometry() { final Geometry geom = parserUtil.createGeometry(3.0); assertTrue(geom == null); }
@Test public void testGeoShapeEnvelope() throws JsonParseException, JsonMappingException, IOException { Envelope envelope = rgb.createRandomEnvelope(); Geometry expected = geometryFactory.toGeometry(envelope); assertTrue(parserUtil.createGeometry(rgb.toMap(envelope)).equalsExact(expected, 1e-9)); }
@Test public void testGeoShapeMultiPolygon() throws JsonParseException, JsonMappingException, IOException { MultiPolygon geom = rgb.createRandomMultiPolygon(); assertTrue(parserUtil.createGeometry(rgb.toMap(geom)).equalsExact(geom, 1e-9)); }
@Test public void testGeoShapeLineString() throws JsonParseException, JsonMappingException, IOException { LineString geom = rgb.createRandomLineString(); assertTrue(parserUtil.createGeometry(rgb.toMap(geom)).equalsExact(geom, 1e-9)); }
@Test public void testGeoPointAsInvalidArray() { final Geometry geometry = parserUtil.createGeometry(Arrays.asList(new Boolean[] {true, true})); assertTrue(geometry == null); }