/** * Converts deprecated LocationIterableProperties to GeometryWithProperties. * * @param locationIterableProperties * LocationIterableProperties object * @return GeometryWithProperties object */ protected static final GeometryWithProperties toGeometryWithProperties( final LocationIterableProperties locationIterableProperties) { final Map<String, Object> propertiesObjects = new HashMap<>(); propertiesObjects.putAll(locationIterableProperties.getProperties()); return new GeometryWithProperties(locationIterableProperties.getLocations(), propertiesObjects); }
@Test public void testPropertiesObjects() { final List<Integer> list = Arrays.asList(new Integer[] { 1, 2, 3 }); final Map<String, Object> properties = new HashMap<>(); properties.put("prop1", 1); properties.put("prop2", list); properties.put("prop3", "mystring"); final GeometryWithProperties geometryWithProperties = new GeometryWithProperties( PolyLine.TEST_POLYLINE, properties); final JsonObject jsonObject = new GeoJsonBuilder().create(geometryWithProperties); Assert.assertEquals(1, jsonObject.get("properties").getAsJsonObject().get("prop1").getAsInt()); final List<Integer> resultList = new ArrayList<>(); for (final JsonElement element : jsonObject.get("properties").getAsJsonObject().get("prop2") .getAsJsonArray()) { resultList.add(element.getAsInt()); } Assert.assertEquals(list, resultList); Assert.assertEquals("mystring", jsonObject.get("properties").getAsJsonObject().get("prop3").getAsString()); }
@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 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 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()); }