use of com.mapbox.geojson.MultiPoint in project mapbox-java by mapbox.
the class TurfConversionTest method explodeMultiPointSingleFeature.
@Test
public void explodeMultiPointSingleFeature() throws NullPointerException {
MultiPoint multiPoint = MultiPoint.fromJson(loadJsonFixture(TURF_EXPLODE_MULTI_POINT));
assertEquals(4, TurfConversion.explode(Feature.fromGeometry(multiPoint)).features().size());
}
use of com.mapbox.geojson.MultiPoint 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()));
}
}
use of com.mapbox.geojson.MultiPoint in project mapbox-java by mapbox.
the class TurfConversion method combine.
/**
* Combines a FeatureCollection of geometries and returns
* a {@link FeatureCollection} with "Multi-" geometries in it.
* If the original FeatureCollection parameter has {@link Point}(s)
* and/or {@link MultiPoint}s), the returned
* FeatureCollection will include a {@link MultiPoint} object.
*
* If the original FeatureCollection parameter has
* {@link LineString}(s) and/or {@link MultiLineString}s), the returned
* FeatureCollection will include a {@link MultiLineString} object.
*
* If the original FeatureCollection parameter has
* {@link Polygon}(s) and/or {@link MultiPolygon}s), the returned
* FeatureCollection will include a {@link MultiPolygon} object.
*
* @param originalFeatureCollection a {@link FeatureCollection}
*
* @return a {@link FeatureCollection} with a "Multi-" geometry
* or "Multi-" geometries.
*
* @since 4.10.0
*/
public static FeatureCollection combine(@NonNull FeatureCollection originalFeatureCollection) {
if (originalFeatureCollection.features() == null) {
throw new TurfException("Your FeatureCollection is null.");
} else if (originalFeatureCollection.features().size() == 0) {
throw new TurfException("Your FeatureCollection doesn't have any Feature objects in it.");
}
List<Point> pointList = new ArrayList<>(0);
List<LineString> lineStringList = new ArrayList<>(0);
List<Polygon> polygonList = new ArrayList<>(0);
for (Feature singleFeature : originalFeatureCollection.features()) {
Geometry singleFeatureGeometry = singleFeature.geometry();
if (singleFeatureGeometry instanceof Point || singleFeatureGeometry instanceof MultiPoint) {
if (singleFeatureGeometry instanceof Point) {
pointList.add((Point) singleFeatureGeometry);
} else {
pointList.addAll(((MultiPoint) singleFeatureGeometry).coordinates());
}
} else if (singleFeatureGeometry instanceof LineString || singleFeatureGeometry instanceof MultiLineString) {
if (singleFeatureGeometry instanceof LineString) {
lineStringList.add((LineString) singleFeatureGeometry);
} else {
lineStringList.addAll(((MultiLineString) singleFeatureGeometry).lineStrings());
}
} else if (singleFeatureGeometry instanceof Polygon || singleFeatureGeometry instanceof MultiPolygon) {
if (singleFeatureGeometry instanceof Polygon) {
polygonList.add((Polygon) singleFeatureGeometry);
} else {
polygonList.addAll(((MultiPolygon) singleFeatureGeometry).polygons());
}
}
}
List<Feature> finalFeatureList = new ArrayList<>(0);
if (!pointList.isEmpty()) {
finalFeatureList.add(Feature.fromGeometry(MultiPoint.fromLngLats(pointList)));
}
if (!lineStringList.isEmpty()) {
finalFeatureList.add(Feature.fromGeometry(MultiLineString.fromLineStrings(lineStringList)));
}
if (!polygonList.isEmpty()) {
finalFeatureList.add(Feature.fromGeometry(MultiPolygon.fromPolygons(polygonList)));
}
return finalFeatureList.isEmpty() ? originalFeatureCollection : FeatureCollection.fromFeatures(finalFeatureList);
}
use of com.mapbox.geojson.MultiPoint in project mapbox-java by mapbox.
the class TurfConversionTest method combinePointsToMultiPoint.
@Test
public void combinePointsToMultiPoint() throws Exception {
FeatureCollection pointFeatureCollection = FeatureCollection.fromFeatures(Arrays.asList(Feature.fromGeometry(Point.fromLngLat(-2.46, 27.6835)), Feature.fromGeometry(Point.fromLngLat(41.83, 7.3624))));
FeatureCollection featureCollectionWithNewMultiPointObject = TurfConversion.combine(pointFeatureCollection);
assertNotNull(featureCollectionWithNewMultiPointObject);
MultiPoint multiPoint = (MultiPoint) featureCollectionWithNewMultiPointObject.features().get(0).geometry();
assertNotNull(multiPoint);
assertEquals(-2.46, multiPoint.coordinates().get(0).longitude(), DELTA);
assertEquals(27.6835, multiPoint.coordinates().get(0).latitude(), DELTA);
assertEquals(41.83, multiPoint.coordinates().get(1).longitude(), DELTA);
assertEquals(7.3624, multiPoint.coordinates().get(1).latitude(), DELTA);
}
Aggregations