@Test public void bbox_nullWhenNotSet() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); LineString lineString = LineString.fromLngLats(points); List<Geometry> geometries = new ArrayList<>(); geometries.add(points.get(0)); geometries.add(lineString); GeometryCollection geometryCollection = GeometryCollection.fromGeometries(geometries); assertNull(geometryCollection.bbox()); }
@Test public void passingInSingleGeometry_doesHandleCorrectly() throws Exception { Point geometry = Point.fromLngLat(1.0, 2.0); GeometryCollection collection = GeometryCollection.fromGeometry(geometry); assertNotNull(collection); assertEquals(1, collection.geometries().size()); assertEquals(2.0, ((Point) collection.geometries().get(0)).latitude(), DELTA); }
@Test public void fromJson() throws IOException { final String json = loadJsonFixture(SAMPLE_GEOMETRYCOLLECTION); GeometryCollection geo = GeometryCollection.fromJson(json); assertEquals(geo.type(), "GeometryCollection"); assertEquals(geo.geometries().get(0).type(), "Point"); assertEquals(geo.geometries().get(1).type(), "LineString"); }
@Test public void bboxFromGeometryCollection() throws IOException, TurfException { // Check that geometry collection and direct bbox are equal MultiPolygon multiPolygon = MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_MULTIPOLYGON)); assertArrayEquals(TurfMeasurement.bbox(multiPolygon), TurfMeasurement.bbox(GeometryCollection.fromGeometry(multiPolygon)), DELTA); // Check all geometry types List<Geometry> geometries = new ArrayList<>(); geometries.add(Feature.fromJson(loadJsonFixture(TURF_BBOX_POINT)).geometry()); geometries.add(MultiPoint.fromJson(loadJsonFixture(TURF_BBOX_MULTI_POINT))); geometries.add(LineString.fromJson(loadJsonFixture(TURF_BBOX_LINESTRING))); geometries.add(MultiLineString.fromJson(loadJsonFixture(TURF_BBOX_MULTILINESTRING))); geometries.add(Feature.fromJson(loadJsonFixture(TURF_BBOX_POLYGON)).geometry()); geometries.add(MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_MULTIPOLYGON))); geometries.add(GeometryCollection.fromGeometry(Point.fromLngLat(-1., -1.))); double[] bbox = TurfMeasurement.bbox(GeometryCollection.fromGeometries(geometries)); assertEquals(4, bbox.length); assertEquals(-1, bbox[0], DELTA); assertEquals(-10, bbox[1], DELTA); assertEquals(130, bbox[2], DELTA); assertEquals(4, bbox[3], DELTA); } }
@Test public void bbox_doesNotSerializeWhenNotPresent() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); LineString lineString = LineString.fromLngLats(points); List<Geometry> geometries = new ArrayList<>(); geometries.add(points.get(0)); geometries.add(lineString); GeometryCollection geometryCollection = GeometryCollection.fromGeometries(geometries); compareJson(geometryCollection.toJson(), "{\"type\":\"GeometryCollection\",\"geometries\":[" + "{\"type\":\"Point\"," + "\"coordinates\":[1.0,2.0]},{\"type\":\"LineString\",\"coordinates\":[[1,2],[2,3]]}]}"); }
@Test public void sanity() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); LineString lineString = LineString.fromLngLats(points); List<Geometry> geometries = new ArrayList<>(); geometries.add(points.get(0)); geometries.add(lineString); GeometryCollection geometryCollection = GeometryCollection.fromGeometries(geometries); assertNotNull(geometryCollection); }
} else if (geometry instanceof GeometryCollection) { List<Point> points = new ArrayList<>(); for (Geometry geo : ((GeometryCollection) geometry).geometries()) {
@Test public void bbox_doesSerializeWhenPresent() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); LineString lineString = LineString.fromLngLats(points); List<Geometry> geometries = new ArrayList<>(); geometries.add(points.get(0)); geometries.add(lineString); BoundingBox bbox = BoundingBox.fromLngLats(1.0, 2.0, 3.0, 4.0); GeometryCollection geometryCollection = GeometryCollection.fromGeometries(geometries, bbox); compareJson(geometryCollection.toJson(), "{\"type\":\"GeometryCollection\",\"bbox\":[1.0,2.0,3.0,4.0]," + "\"geometries\":[{\"type\":\"Point\",\"coordinates\":[1.0,2.0]}," + "{\"type\":\"LineString\",\"coordinates\":[[1,2],[2,3]]}]}"); }
@Test public void testSerializable() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); LineString lineString = LineString.fromLngLats(points); List<Geometry> geometries = new ArrayList<>(); geometries.add(points.get(0)); geometries.add(lineString); BoundingBox bbox = BoundingBox.fromLngLats(1.0, 2.0, 3.0, 4.0); GeometryCollection geometryCollection = GeometryCollection.fromGeometries(geometries, bbox); byte[] bytes = serialize(geometryCollection); assertEquals(geometryCollection, deserialize(bytes, GeometryCollection.class)); }
@Test public void bbox_returnsCorrectBbox() throws Exception { List<Point> points = new ArrayList<>(); points.add(Point.fromLngLat(1.0, 2.0)); points.add(Point.fromLngLat(2.0, 3.0)); LineString lineString = LineString.fromLngLats(points); List<Geometry> geometries = new ArrayList<>(); geometries.add(points.get(0)); geometries.add(lineString); BoundingBox bbox = BoundingBox.fromLngLats(1.0, 2.0, 3.0, 4.0); GeometryCollection geometryCollection = GeometryCollection.fromGeometries(geometries, bbox); assertNotNull(geometryCollection.bbox()); assertEquals(1.0, geometryCollection.bbox().west(), DELTA); assertEquals(2.0, geometryCollection.bbox().south(), DELTA); assertEquals(3.0, geometryCollection.bbox().east(), DELTA); assertEquals(4.0, geometryCollection.bbox().north(), DELTA); }