Search in sources :

Example 1 with Geometry

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);
}
Also used : Geometry(com.mapbox.geojson.Geometry) ArrayList(java.util.ArrayList) Feature(com.mapbox.geojson.Feature)

Example 2 with Geometry

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);
}
Also used : Geometry(com.mapbox.geojson.Geometry) GeometryCollection(com.mapbox.geojson.GeometryCollection) LineString(com.mapbox.geojson.LineString) FeatureCollection(com.mapbox.geojson.FeatureCollection) BoundingBox(com.mapbox.geojson.BoundingBox) ArrayList(java.util.ArrayList) Point(com.mapbox.geojson.Point) Test(org.junit.Test)

Example 3 with Geometry

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()));
    }
}
Also used : MultiPoint(com.mapbox.geojson.MultiPoint) GeometryCollection(com.mapbox.geojson.GeometryCollection) Geometry(com.mapbox.geojson.Geometry) MultiLineString(com.mapbox.geojson.MultiLineString) LineString(com.mapbox.geojson.LineString) MultiLineString(com.mapbox.geojson.MultiLineString) MultiPolygon(com.mapbox.geojson.MultiPolygon) ArrayList(java.util.ArrayList) MultiPoint(com.mapbox.geojson.MultiPoint) Point(com.mapbox.geojson.Point) Polygon(com.mapbox.geojson.Polygon) MultiPolygon(com.mapbox.geojson.MultiPolygon)

Example 4 with Geometry

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;
}
Also used : Geometry(com.mapbox.geojson.Geometry) MoveDistancesObject(com.mapbox.android.gestures.MoveDistancesObject) PointF(android.graphics.PointF) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with Geometry

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);
}
Also used : Geometry(com.mapbox.geojson.Geometry) MultiPolygon(com.mapbox.geojson.MultiPolygon) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Geometry (com.mapbox.geojson.Geometry)8 ArrayList (java.util.ArrayList)7 LineString (com.mapbox.geojson.LineString)3 MultiPolygon (com.mapbox.geojson.MultiPolygon)3 Point (com.mapbox.geojson.Point)3 Test (org.junit.Test)3 Feature (com.mapbox.geojson.Feature)2 GeometryCollection (com.mapbox.geojson.GeometryCollection)2 MultiLineString (com.mapbox.geojson.MultiLineString)2 MultiPoint (com.mapbox.geojson.MultiPoint)2 Polygon (com.mapbox.geojson.Polygon)2 PointF (android.graphics.PointF)1 WritableArray (com.facebook.react.bridge.WritableArray)1 WritableMap (com.facebook.react.bridge.WritableMap)1 MoveDistancesObject (com.mapbox.android.gestures.MoveDistancesObject)1 TileRegion (com.mapbox.common.TileRegion)1 TileRegionError (com.mapbox.common.TileRegionError)1 TileRegionGeometryCallback (com.mapbox.common.TileRegionGeometryCallback)1 BoundingBox (com.mapbox.geojson.BoundingBox)1 FeatureCollection (com.mapbox.geojson.FeatureCollection)1