TurfMeasurement { public static double[] bbox(@NonNull Point point) { List<Point> resultCoords = TurfMeta.coordAll(point); return bboxCalculator(resultCoords); } private  TurfMeasurement(); static double bearing(@NonNull Point point1, @NonNull Point point2); @NonNull static Point destination(@NonNull Point point, @FloatRange(from = 0) double distance,
                                  @FloatRange(from = -180, to = 180) double bearing,
                                  @NonNull @TurfConstants.TurfUnitCriteria String units); static double distance(@NonNull Point point1, @NonNull Point point2); static double distance(@NonNull Point point1, @NonNull Point point2,
                                @NonNull @TurfConstants.TurfUnitCriteria String units); static double length(@NonNull LineString lineString,
                              @NonNull @TurfConstants.TurfUnitCriteria String units); static double length(@NonNull MultiLineString multiLineString,
                              @NonNull @TurfConstants.TurfUnitCriteria String units); static double length(@NonNull Polygon polygon,
                              @NonNull @TurfConstants.TurfUnitCriteria String units); static double length(@NonNull MultiPolygon multiPolygon,
                              @NonNull @TurfConstants.TurfUnitCriteria String units); static double length(List<Point> coords, String units); static Point midpoint(@NonNull Point from, @NonNull Point to); static Point along(@NonNull LineString line, @FloatRange(from = 0) double distance,
                            @NonNull @TurfConstants.TurfUnitCriteria String units); static Point along(@NonNull List<Point> coords, @FloatRange(from = 0) double distance,
                            @NonNull @TurfConstants.TurfUnitCriteria String units); static double[] bbox(@NonNull Point point); static double[] bbox(@NonNull LineString lineString); static double[] bbox(@NonNull MultiPoint multiPoint); static double[] bbox(@NonNull Polygon polygon); static double[] bbox(@NonNull MultiLineString multiLineString); static double[] bbox(MultiPolygon multiPolygon); static double[] bbox(GeoJson geoJson); static double[] bbox(FeatureCollection featureCollection); static double[] bbox(Feature feature); static double[] bbox(Geometry geometry); static Feature bboxPolygon(@NonNull BoundingBox boundingBox); static Feature bboxPolygon(@NonNull BoundingBox boundingBox,
                                    @Nullable JsonObject properties,
                                    @Nullable String id); static Feature bboxPolygon(@NonNull double[] bbox); static Feature bboxPolygon(@NonNull double[] bbox,
                                    @Nullable JsonObject properties,
                                    @Nullable String id); static Polygon envelope(GeoJson geoJson); static BoundingBox square(@NonNull BoundingBox boundingBox); static double area(@NonNull Feature feature); static double area(@NonNull FeatureCollection featureCollection); static double area(@NonNull Geometry geometry); static Feature center(Feature feature,
                               @Nullable JsonObject properties,
                               @Nullable String id); static Feature center(Feature feature); static Feature center(FeatureCollection featureCollection,
                               @Nullable JsonObject properties,
                               @Nullable String id); static Feature center(FeatureCollection featureCollection); static double EARTH_RADIUS; }
@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 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 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 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 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 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 bboxFromGeometryCollection() throws IOException, TurfException { MultiPolygon multiPolygon = MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_MULTIPOLYGON)); assertArrayEquals(TurfMeasurement.bbox(multiPolygon), TurfMeasurement.bbox(GeometryCollection.fromGeometry(multiPolygon)), DELTA); 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); }