use of com.mapbox.geojson.Geometry in project maps by rnmapbox.
the class GeoJSONUtils method toGeometryCollection.
private static GeometryCollection toGeometryCollection(List<Feature> features) {
ArrayList<Geometry> geometries = new ArrayList<>();
geometries.ensureCapacity(features.size());
for (Feature feature : features) {
geometries.add(feature.geometry());
}
return GeometryCollection.fromGeometries(geometries);
}
use of com.mapbox.geojson.Geometry 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.Geometry 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.Geometry in project mapbox-plugins-android by mapbox.
the class DraggableAnnotationController method onMove.
boolean onMove(MoveGestureDetector detector) {
if (draggedAnnotation != null && (detector.getPointersCount() > 1 || !draggedAnnotation.isDraggable())) {
// Stopping the drag when we don't work with a simple, on-pointer move anymore
stopDragging(draggedAnnotation, draggedAnnotationManager);
return true;
}
// Updating symbol's position
if (draggedAnnotation != null) {
MoveDistancesObject moveObject = detector.getMoveObject(0);
float x = moveObject.getCurrentX() - touchAreaShiftX;
float y = moveObject.getCurrentY() - touchAreaShiftY;
PointF pointF = new PointF(x, y);
if (pointF.x < 0 || pointF.y < 0 || pointF.x > touchAreaMaxX || pointF.y > touchAreaMaxY) {
stopDragging(draggedAnnotation, draggedAnnotationManager);
return true;
}
Geometry shiftedGeometry = draggedAnnotation.getOffsetGeometry(mapboxMap.getProjection(), moveObject, touchAreaShiftX, touchAreaShiftY);
if (shiftedGeometry != null) {
draggedAnnotation.setGeometry(shiftedGeometry);
draggedAnnotationManager.internalUpdateSource();
for (OnAnnotationDragListener d : (List<OnAnnotationDragListener>) draggedAnnotationManager.getDragListeners()) {
d.onAnnotationDrag(draggedAnnotation);
}
return true;
}
}
return false;
}
use of com.mapbox.geojson.Geometry in project mapbox-java by mapbox.
the class TurfMeasurementTest method bboxFromGeometryCollection.
@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);
}
Aggregations