@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 testLineDistanceMultiLineString() throws IOException, TurfException { Feature feature = Feature.fromJson(loadJsonFixture(LINE_DISTANCE_MULTILINESTRING)); assertEquals(4705d, Math.round(1000 * TurfMeasurement.length((MultiLineString) feature.geometry(), TurfConstants.UNIT_KILOMETERS)), DELTA); }
@Test public void testLineDistancePolygon() throws IOException, TurfException { Feature feature = Feature.fromJson(loadJsonFixture(LINE_DISTANCE_POLYGON)); assertEquals(5599, Math.round(1000 * TurfMeasurement.length((Polygon) feature.geometry(), TurfConstants.UNIT_KILOMETERS))); }
@Test public void testLineDistanceWithGeometries() throws IOException, TurfException { Feature route1 = Feature.fromJson(loadJsonFixture(LINE_DISTANCE_ROUTE_ONE)); Feature route2 = Feature.fromJson(loadJsonFixture(LINE_DISTANCE_ROUTE_TWO)); assertEquals(202, Math.round(TurfMeasurement.length((LineString) route1.geometry(), TurfConstants.UNIT_MILES))); Assert.assertEquals(741.7787396994203, TurfMeasurement.length((LineString) route2.geometry(), TurfConstants.UNIT_KILOMETERS), DELTA); }
@Test public void bboxFromMultiLineString() throws IOException, TurfException { MultiLineString multiLineString = MultiLineString.fromJson(loadJsonFixture(TURF_BBOX_MULTILINESTRING)); double[] bbox = TurfMeasurement.bbox(multiLineString); assertEquals(4, bbox.length); assertEquals(100, bbox[0], DELTA); assertEquals(0, bbox[1], DELTA); assertEquals(103, bbox[2], DELTA); assertEquals(3, bbox[3], DELTA); }
@Test public void bboxFromLine() throws TurfException, IOException { LineString lineString = LineString.fromJson(loadJsonFixture(TURF_BBOX_LINESTRING)); double[] bbox = TurfMeasurement.bbox(lineString); assertEquals(4, bbox.length); assertEquals(102, bbox[0], DELTA); assertEquals(-10, bbox[1], DELTA); assertEquals(130, bbox[2], DELTA); assertEquals(4, bbox[3], DELTA); }
@Test public void bboxFromGeometry() throws IOException, TurfException { Geometry geometry = MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_MULTIPOLYGON)); double[] bbox = TurfMeasurement.bbox(geometry); assertEquals(4, bbox.length); assertEquals(100, bbox[0], DELTA); assertEquals(0, bbox[1], DELTA); assertEquals(103, bbox[2], DELTA); assertEquals(3, bbox[3], DELTA); }
@Test public void bboxFromMultiPolygon() throws IOException, TurfException { MultiPolygon multiPolygon = MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_MULTIPOLYGON)); double[] bbox = TurfMeasurement.bbox(multiPolygon); assertEquals(4, bbox.length); assertEquals(100, bbox[0], DELTA); assertEquals(0, bbox[1], DELTA); assertEquals(103, bbox[2], DELTA); assertEquals(3, bbox[3], DELTA); }
@Test public void bboxFromPolygon() throws TurfException, IOException { Feature feature = Feature.fromJson(loadJsonFixture(TURF_BBOX_POLYGON)); double[] bbox = TurfMeasurement.bbox((Polygon) feature.geometry()); assertEquals(4, bbox.length); assertEquals(100, bbox[0], DELTA); assertEquals(0, bbox[1], DELTA); assertEquals(101, bbox[2], DELTA); assertEquals(1, bbox[3], DELTA); }
@Test public void bboxFromPoint() throws IOException, TurfException { Feature feature = Feature.fromJson(loadJsonFixture(TURF_BBOX_POINT)); double[] bbox = TurfMeasurement.bbox((Point) feature.geometry()); assertEquals(4, bbox.length); assertEquals(102, bbox[0], DELTA); assertEquals(0.5, bbox[1], DELTA); assertEquals(102, bbox[2], DELTA); assertEquals(0.5, bbox[3], DELTA); }
@Test public void testTurfAlong() throws IOException, TurfException { Feature feature = Feature.fromJson(loadJsonFixture(TURF_ALONG_DC_LINE)); LineString line = (LineString) feature.geometry();