@Test public void testGeoJson() { System.out.println(this.atlas.asGeoJson().toString()); }
@Test public void testPolygon() { final GeoJsonObject object = new GeoJsonBuilder() .create(new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6)); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]]}}", object.toString()); final Map<String, String> properties = new HashMap<>(); properties.put("property", "value"); properties.put("property2", "value2"); object.withNewProperties(properties); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]]},\"properties\":{\"property2\":\"value2\",\"property\":\"value\"}}", object.toString()); }
@Test public void testMultiLineString() { final List<PolyLine> polyLines = new ArrayList<>(); polyLines.add(new PolyLine(Location.TEST_5, Location.TEST_2)); polyLines.add(new PolyLine(Location.COLOSSEUM, Location.EIFFEL_TOWER)); final GeoJsonObject object = new GeoJsonBuilder().createMultiLineStrings(polyLines); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiLineString\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628]],[[12.49234,41.890224],[2.294495,48.858241]]]}}", object.toString()); }
@Test public void testLineString() { final GeoJsonObject object = new GeoJsonBuilder() .create(new PolyLine(Location.TEST_5, Location.TEST_2)); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[-122.031007,37.390535],[-122.028464,37.321628]]}}", object.toString()); final Map<String, String> properties = new HashMap<>(); properties.put("property", "value"); properties.put("property2", "value2"); object.withNewProperties(properties); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[-122.031007,37.390535],[-122.028464,37.321628]]},\"properties\":{\"property2\":\"value2\",\"property\":\"value\"}}", object.toString()); }
@Test public void testMultiPolygon() { final List<Polygon> polygons = new ArrayList<>(); polygons.add(new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6)); polygons.add(new Polygon(Location.COLOSSEUM, Location.EIFFEL_TOWER, Location.TEST_7)); final GeoJsonObject object = new GeoJsonBuilder().createMultiPolygons(polygons); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]],[[[12.49234,41.890224],[2.294495,48.858241],[-122.0304871,37.3314171],[12.49234,41.890224]]]]}}", object.toString()); }
@Test public void testMultiPoint() { final List<Location> locations = Arrays.asList(Location.EIFFEL_TOWER, Location.COLOSSEUM); final GeoJsonObject object = new GeoJsonBuilder().create(locations, GeoJsonType.MULTI_POINT); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiPoint\",\"coordinates\":[[2.294495,48.858241],[12.49234,41.890224]]}}", object.toString()); object.withNewProperty("property", "value"); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiPoint\",\"coordinates\":[[2.294495,48.858241],[12.49234,41.890224]]},\"properties\":{\"property\":\"value\"}}", object.toString()); object.withNewProperty("property2", "value2"); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiPoint\",\"coordinates\":[[2.294495,48.858241],[12.49234,41.890224]]},\"properties\":{\"property\":\"value\",\"property2\":\"value2\"}}", object.toString()); }
@Test public void testLocation() { final GeoJsonObject object = new GeoJsonBuilder().create(Location.TEST_5); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.031007,37.390535]}}", object.toString()); object.withNewProperty("property", "value"); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.031007,37.390535]},\"properties\":{\"property\":\"value\"}}", object.toString()); object.withNewProperty("property2", "value2"); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.031007,37.390535]},\"properties\":{\"property\":\"value\",\"property2\":\"value2\"}}", object.toString()); }
@Test public void testCreateFromGeometries() { final Map<String, Object> properties = new HashMap<>(); properties.put("property", "value"); properties.put("property2", "value2"); final List<GeometryWithProperties> items = new ArrayList<>(); items.add(new GeometryWithProperties(Location.TEST_1, properties)); items.add(new GeometryWithProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new GeometryWithProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().createFromGeometriesWithProperties(items); Assert.assertEquals( "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\"" + ":[-122.009566,37.33531]},\"properties\":{\"property2\":\"value2\",\"property\":\"value\"}},{\"type\":\"Feature\",\"geometry\"" + ":{\"type\":\"Polygon\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]]},\"properties\"" + ":{\"property2\":\"value2\",\"property\":\"value\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\"" + ":[[-122.031007,37.390535],[-122.028464,37.321628]]},\"properties\":{\"property2\":\"value2\",\"property\":\"value\"}}]}", object.toString()); }
@Test public void testGeometryCollectionFeatureSingularForm() { final Map<String, Object> properties = new HashMap<>(); final List<GeometryWithProperties> items = new ArrayList<>(); items.add(new GeometryWithProperties(Location.TEST_1, properties)); items.add(new GeometryWithProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new GeometryWithProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().createGeometryCollectionFeature(items); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[-122.009566,37.33531]},{\"type\":\"Polygon\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544]]]},{\"type\":\"LineString\",\"coordinates\":[[-122.031007,37.390535],[-122.028464,37.321628]]}]}}", object.toString()); }
@Test public void testGeometryCollectionSingularForm() { final Map<String, String> properties = new HashMap<>(); final List<LocationIterableProperties> items = new ArrayList<>(); items.add(new LocationIterableProperties(Location.TEST_1, properties)); items.add(new LocationIterableProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new LocationIterableProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().createGeometryCollection(items); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[-122.009566,37.33531]},{\"type\":\"Polygon\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544]]]},{\"type\":\"LineString\",\"coordinates\":[[-122.031007,37.390535],[-122.028464,37.321628]]}]}}", object.toString()); }
@Test public void testFeatureCollection() { final Map<String, String> properties = new HashMap<>(); properties.put("property", "value"); properties.put("property2", "value2"); final List<LocationIterableProperties> items = new ArrayList<>(); items.add(new LocationIterableProperties(Location.TEST_1, properties)); items.add(new LocationIterableProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new LocationIterableProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().create(items); Assert.assertEquals( "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\"" + ":[-122.009566,37.33531]},\"properties\":{\"property2\":\"value2\",\"property\":\"value\"}},{\"type\":\"Feature\",\"geometry\"" + ":{\"type\":\"Polygon\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]]},\"properties\"" + ":{\"property2\":\"value2\",\"property\":\"value\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\"" + ":[[-122.031007,37.390535],[-122.028464,37.321628]]},\"properties\":{\"property2\":\"value2\",\"property\":\"value\"}}]}", object.toString()); }
@Test public void testGeometryCollectionFeatureMultipleForm() { final Map<String, Object> properties = new HashMap<>(); final List<GeometryWithProperties> items = new ArrayList<>(); items.add(new GeometryWithProperties(Location.TEST_1, properties)); items.add(new GeometryWithProperties(Location.TEST_1, properties)); items.add(new GeometryWithProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new GeometryWithProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new GeometryWithProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); items.add(new GeometryWithProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().createGeometryCollectionFeature(items); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"MultiPoint\",\"coordinates\":[[-122.009566,37.33531],[-122.009566,37.33531]]},{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]],[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]]]},{\"type\":\"MultiLineString\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628]],[[-122.031007,37.390535],[-122.028464,37.321628]]]}]}}", object.toString()); }
@Test public void testGeometryCollectionFeature() { final Map<String, Object> properties = new HashMap<>(); final List<GeometryWithProperties> items = new ArrayList<>(); items.add(new GeometryWithProperties(Location.TEST_1, properties)); items.add(new GeometryWithProperties(Location.TEST_1, properties)); items.add(new GeometryWithProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new GeometryWithProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new GeometryWithProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); items.add(new GeometryWithProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().createGeometryCollectionFeature(items); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"MultiPoint\",\"coordinates\":[[-122.009566,37.33531],[-122.009566,37.33531]]},{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]],[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]]]},{\"type\":\"MultiLineString\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628]],[[-122.031007,37.390535],[-122.028464,37.321628]]]}]}}", object.toString()); }
@Test public void testGeometryCollectionMultipleForm() { final Map<String, String> properties = new HashMap<>(); final List<LocationIterableProperties> items = new ArrayList<>(); items.add(new LocationIterableProperties(Location.TEST_1, properties)); items.add(new LocationIterableProperties(Location.TEST_1, properties)); items.add(new LocationIterableProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new LocationIterableProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new LocationIterableProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); items.add(new LocationIterableProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().createGeometryCollection(items); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"MultiPoint\",\"coordinates\":[[-122.009566,37.33531],[-122.009566,37.33531]]},{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]],[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]]]},{\"type\":\"MultiLineString\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628]],[[-122.031007,37.390535],[-122.028464,37.321628]]]}]}}", object.toString()); }
@Test public void testConsistency() { final Polygon polygon = new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6); final GeoJsonObject object = new GeoJsonBuilder().create(polygon); final Map<String, String> properties = new HashMap<>(); properties.put("property", "value"); properties.put("property2", "value2"); object.withNewProperties(properties); // The GeoJsonReader reads Feature collections only object.makeFeatureCollection(); final GeoJsonReader reader = new GeoJsonReader(new StringResource(object.toString())); final PropertiesLocated item = reader.next(); Assert.assertEquals(polygon, item.getItem()); }
@Test public void testWrite() { final StringResource resource = new StringResource(); final JsonWriter writer = new JsonWriter(resource); final PolyLine polyLine = new PolyLine(Location.TEST_6, Location.TEST_2, Location.TEST_2); writer.write(polyLine.asGeoJson().jsonObject()); writer.close(); Assert.assertEquals(polyLine.asGeoJson().toString(), resource.writtenString()); } }
/** * Tests every polygon input form supported by the filter */ @Test public void testForms() { final Atlas testFormsAtlas = this.setup.getTestForm(); final String wktConfigurationStringFormat = "{\"filter.polygons\":{\"include.wkt\":[\"%s\"]}}"; final String wkbConfigurationStringFormat = "{\"filter.polygons\":{\"include.wkb\":[\"%s\"]}}"; final String atlasConfigurationStringFormat = "{\"filter.polygons\":{\"include.atlas\":[\"%s\"]}}"; final String geojsonConfigurationStringFormat = "{\"filter.polygons\":{\"include.geojson\":[\"%s\"]}}"; final Polygon includeBoundary = this.getPolygonWithName(testFormsAtlas, "include"); this.assertCounts(this.setup.getTestForm(), this.constructConfiguredFilter( wktConfigurationStringFormat, includeBoundary.toWkt()), 2, 2, 2, 0); this.assertCounts(this.setup.getTestForm(), this.constructConfiguredFilter(wkbConfigurationStringFormat, WKBWriter.toHex(new WkbPolygonConverter().convert(includeBoundary))), 2, 2, 2, 0); this.assertCounts(this.setup.getTestForm(), this.constructConfiguredFilter(atlasConfigurationStringFormat, new PolygonStringConverter().backwardConvert(includeBoundary)), 2, 2, 2, 0); this.assertCounts(this.setup.getTestForm(), this.constructConfiguredFilter(geojsonConfigurationStringFormat, includeBoundary.asGeoJson().toString().replaceAll("\"", "\\\\\"")), 2, 2, 2, 0); }
this.assertCounts(testMultiPolygonFormsAtlas, this.constructConfiguredFilter(geojsonConfigurationStringFormat, multiPolygon1 .asGeoJsonFeatureCollection().toString().replaceAll("\"", "\\\\\"")), 3, 1, -1, -1);