/** * Creates a GeometryCollection type Feature containing geometries derived from a collection of * {@link LocationIterableProperties}. <strong>Note:</strong> feature parameters are not present * in the resulting GeometryCollection and must be handled separately to avoid data loss. * * @deprecated use {@link #createGeometryCollectionFeature(Iterable)} instead * @param objects * used to build each geometry * @return a GeoJson Feature */ @Deprecated public GeoJsonObject createGeometryCollection( final Iterable<LocationIterableProperties> objects) { return createGeometryCollectionFeature(toGeometriesWithProperties(objects)); }
@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 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 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()); }