/** * Takes a set of features, calculates the bbox of all input features, and returns a bounding box. * * @param multiPoint a {@link MultiPoint} object * @return a double array defining the bounding box in this order {@code [minX, minY, maxX, maxY]} * @since 2.0.0 */ public static double[] bbox(@NonNull MultiPoint multiPoint) { List<Point> resultCoords = TurfMeta.coordAll(multiPoint); return bboxCalculator(resultCoords); }
/** * Unwrap a coordinate {@link Point} from a Feature with a Point geometry. * * @param obj any value * @return a coordinate * @see <a href="http://turfjs.org/docs/#getcoord">Turf getCoord documentation</a> * @since 1.2.0 * @deprecated use {@link TurfMeta#getCoord(Feature)} */ @Deprecated public static Point getCoord(Feature obj) { return TurfMeta.getCoord(obj); }
/** * Takes a set of features, calculates the bbox of all input features, and returns a bounding box. * * @param lineString a {@link LineString} object * @return A double array defining the bounding box in this order {@code [minX, minY, maxX, maxY]} * @since 2.0.0 */ public static double[] bbox(@NonNull LineString lineString) { List<Point> resultCoords = TurfMeta.coordAll(lineString); return bboxCalculator(resultCoords); }
@Test public void testInvariantGetCoord() { String jsonFeature = "{type: 'Feature', geometry: {type: 'Point', coordinates: [1, 2]}}"; assertEquals(TurfMeta.getCoord(Feature.fromJson(jsonFeature)), Point.fromLngLat(1, 2)); } }
/** * Takes a set of features, calculates the bbox of all input features, and returns a bounding box. * * @param multiLineString a {@link MultiLineString} object * @return a double array defining the bounding box in this order {@code [minX, minY, maxX, maxY]} * @since 2.0.0 */ public static double[] bbox(@NonNull MultiLineString multiLineString) { List<Point> resultCoords = TurfMeta.coordAll(multiLineString); return bboxCalculator(resultCoords); }
/** * Takes a set of features, calculates the bbox of all input features, and returns a bounding box. * * @param point a {@link Point} object * @return A double array defining the bounding box in this order {@code [minX, minY, maxX, maxY]} * @since 2.0.0 */ public static double[] bbox(@NonNull Point point) { List<Point> resultCoords = TurfMeta.coordAll(point); return bboxCalculator(resultCoords); }
/** * Takes a set of features, calculates the bbox of all input features, and returns a bounding box. * * @param polygon a {@link Polygon} object * @return a double array defining the bounding box in this order {@code [minX, minY, maxX, maxY]} * @since 2.0.0 */ public static double[] bbox(@NonNull Polygon polygon) { List<Point> resultCoords = TurfMeta.coordAll(polygon, false); return bboxCalculator(resultCoords); }
/** * Takes a set of features, calculates the bbox of all input features, and returns a bounding box. * * @param multiPolygon a {@link MultiPolygon} object * @return a double array defining the bounding box in this order {@code [minX, minY, maxX, maxY]} * @since 2.0.0 */ public static double[] bbox(MultiPolygon multiPolygon) { List<Point> resultCoords = TurfMeta.coordAll(multiPolygon, false); return bboxCalculator(resultCoords); }
@Test public void coordAllPoint() throws TurfException { String jsonPoint = "{type: 'Point', coordinates: [0, 0]}"; Point pointGeometry = Point.fromJson(jsonPoint); List<Point> resultList = TurfMeta.coordAll(pointGeometry); assertEquals(resultList.size(), 1, DELTA); assertEquals(resultList.get(0), Point.fromLngLat(0, 0)); }
@Test public void coordAllLineString() throws TurfException { String jsonLineString = "{type: 'LineString', coordinates: [[0, 0], [1, 1]]}"; LineString lineStringGeometry = LineString.fromJson(jsonLineString); List<Point> resultList = TurfMeta.coordAll(lineStringGeometry); assertEquals(resultList.size(), 2, DELTA); assertEquals(resultList.get(0), Point.fromLngLat(0, 0)); assertEquals(resultList.get(1), Point.fromLngLat(1, 1)); }
@Test public void coordAllMultiPolygon() throws TurfException { String multipolygonString = "{type: 'MultiPolygon', coordinates: [[[[0, 0], [1, 1], [0, 1], [0, 0]]]]}"; MultiPolygon multiPolygonGeometry = MultiPolygon.fromJson(multipolygonString); List<Point> resultList = TurfMeta.coordAll(multiPolygonGeometry, false); assertEquals(resultList.size(), 4, DELTA); assertEquals(resultList.get(0), Point.fromLngLat(0, 0)); assertEquals(resultList.get(1), Point.fromLngLat(1, 1)); assertEquals(resultList.get(2), Point.fromLngLat(0, 1)); assertEquals(resultList.get(3), Point.fromLngLat(0, 0)); }
@Test public void coordAllPolygon() throws TurfException { String polygonString = "{type: 'Polygon', coordinates: [[[0, 0], [1, 1], [0, 1], [0, 0]]]}"; Polygon polygonGeometry = Polygon.fromJson(polygonString); List<Point> resultList = TurfMeta.coordAll(polygonGeometry, false); assertEquals(resultList.size(), 4, DELTA); assertEquals(resultList.get(0), Point.fromLngLat(0, 0)); assertEquals(resultList.get(1), Point.fromLngLat(1, 1)); assertEquals(resultList.get(2), Point.fromLngLat(0, 1)); assertEquals(resultList.get(3), Point.fromLngLat(0, 0)); }
@Test public void coordAllPolygonExcludeWrapCoord() throws TurfException { String polygonString = "{type: 'Polygon', coordinates: [[[0, 0], [1, 1], [0, 1], [0, 0]]]}"; Polygon polygonGeometry = Polygon.fromJson(polygonString); List<Point> resultList = TurfMeta.coordAll(polygonGeometry, true); assertEquals(resultList.size(), 3, DELTA); assertEquals(resultList.get(0), Point.fromLngLat(0, 0)); assertEquals(resultList.get(1), Point.fromLngLat(1, 1)); assertEquals(resultList.get(2), Point.fromLngLat(0, 1)); }