use of com.mapbox.geojson.GeometryCollection in project mapbox-java by mapbox.
the class TurfMetaTest method coordAllGeometryCollection.
@Test
public void coordAllGeometryCollection() throws TurfException {
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);
FeatureCollection featureCollection = FeatureCollection.fromFeature(Feature.fromGeometry(geometryCollection));
assertNotNull(featureCollection);
assertNotNull(TurfMeta.coordAll(featureCollection, true));
assertEquals(3, TurfMeta.coordAll(featureCollection, true).size());
assertEquals(1.0, TurfMeta.coordAll(featureCollection, true).get(0).longitude(), DELTA);
assertEquals(2.0, TurfMeta.coordAll(featureCollection, true).get(0).latitude(), DELTA);
}
use of com.mapbox.geojson.GeometryCollection in project mapbox-java by mapbox.
the class TurfConversionTest method explodeGeometryCollectionSingleFeature.
@Test
public void explodeGeometryCollectionSingleFeature() throws NullPointerException {
GeometryCollection geometryCollection = GeometryCollection.fromJson(loadJsonFixture(TURF_EXPLODE_GEOMETRY_COLLECTION));
assertEquals(3, TurfConversion.explode(Feature.fromGeometry(geometryCollection)).features().size());
}
use of com.mapbox.geojson.GeometryCollection in project mapbox-java by mapbox.
the class TurfMeasurement method bbox.
/**
* Takes an arbitrary {@link Geometry} and calculates a bounding box.
*
* @param geometry a {@link Geometry} 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(Geometry geometry) {
if (geometry instanceof Point) {
return bbox((Point) geometry);
} else if (geometry instanceof MultiPoint) {
return bbox((MultiPoint) geometry);
} else if (geometry instanceof LineString) {
return bbox((LineString) geometry);
} else if (geometry instanceof MultiLineString) {
return bbox((MultiLineString) geometry);
} else if (geometry instanceof Polygon) {
return bbox((Polygon) geometry);
} else if (geometry instanceof MultiPolygon) {
return bbox((MultiPolygon) geometry);
} else if (geometry instanceof GeometryCollection) {
List<Point> points = new ArrayList<>();
for (Geometry geo : ((GeometryCollection) geometry).geometries()) {
// recursive
double[] bbox = bbox(geo);
points.add(Point.fromLngLat(bbox[0], bbox[1]));
points.add(Point.fromLngLat(bbox[2], bbox[1]));
points.add(Point.fromLngLat(bbox[2], bbox[3]));
points.add(Point.fromLngLat(bbox[0], bbox[3]));
}
return TurfMeasurement.bbox(MultiPoint.fromLngLats(points));
} else {
throw new RuntimeException(("Unknown geometry class: " + geometry.getClass()));
}
}
Aggregations