Search in sources :

Example 6 with BoundingBox

use of com.mapbox.geojson.BoundingBox in project mapbox-java by mapbox.

the class TurfMeasurementTest method bboxPolygonFromMultiPoint.

@Test
public void bboxPolygonFromMultiPoint() throws IOException, TurfException {
    // Create a MultiPoint
    MultiPoint multiPoint = MultiPoint.fromJson(loadJsonFixture(TURF_BBOX_POLYGON_MULTI_POINT));
    // Use the MultiPoint object to calculate its BoundingBox area
    double[] bbox = TurfMeasurement.bbox(multiPoint);
    // Use the BoundingBox coordinates to create an actual BoundingBox object
    BoundingBox boundingBox = BoundingBox.fromPoints(Point.fromLngLat(bbox[0], bbox[1]), Point.fromLngLat(bbox[2], bbox[3]));
    // Use the BoundingBox object in the TurfMeasurement.bboxPolygon() method.
    Feature featureRepresentingBoundingBox = TurfMeasurement.bboxPolygon(boundingBox);
    Polygon polygonRepresentingBoundingBox = (Polygon) featureRepresentingBoundingBox.geometry();
    assertNotNull(polygonRepresentingBoundingBox);
    assertEquals(0, polygonRepresentingBoundingBox.inner().size());
    assertEquals(5, polygonRepresentingBoundingBox.coordinates().get(0).size());
}
Also used : MultiPoint(com.mapbox.geojson.MultiPoint) BoundingBox(com.mapbox.geojson.BoundingBox) Polygon(com.mapbox.geojson.Polygon) MultiPolygon(com.mapbox.geojson.MultiPolygon) Feature(com.mapbox.geojson.Feature) Test(org.junit.Test)

Example 7 with BoundingBox

use of com.mapbox.geojson.BoundingBox 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 8 with BoundingBox

use of com.mapbox.geojson.BoundingBox in project mapbox-java by mapbox.

the class TurfMeasurementTest method bboxPolygonFromLineStringWithId.

@Test
public void bboxPolygonFromLineStringWithId() throws IOException, TurfException {
    // Create a LineString
    LineString lineString = LineString.fromJson(loadJsonFixture(TURF_BBOX_POLYGON_LINESTRING));
    // Use the LineString object to calculate its BoundingBox area
    double[] bbox = TurfMeasurement.bbox(lineString);
    // Use the BoundingBox coordinates to create an actual BoundingBox object
    BoundingBox boundingBox = BoundingBox.fromPoints(Point.fromLngLat(bbox[0], bbox[1]), Point.fromLngLat(bbox[2], bbox[3]));
    // Use the BoundingBox object in the TurfMeasurement.bboxPolygon() method.
    Feature featureRepresentingBoundingBox = TurfMeasurement.bboxPolygon(boundingBox, null, "TEST_ID");
    Polygon polygonRepresentingBoundingBox = (Polygon) featureRepresentingBoundingBox.geometry();
    assertNotNull(polygonRepresentingBoundingBox);
    assertEquals(0, polygonRepresentingBoundingBox.inner().size());
    assertEquals(5, polygonRepresentingBoundingBox.coordinates().get(0).size());
    assertEquals("TEST_ID", featureRepresentingBoundingBox.id());
    assertEquals(Point.fromLngLat(102.0, -10.0), polygonRepresentingBoundingBox.coordinates().get(0).get(0));
    assertEquals(Point.fromLngLat(130, -10.0), polygonRepresentingBoundingBox.coordinates().get(0).get(1));
    assertEquals(Point.fromLngLat(130.0, 4.0), polygonRepresentingBoundingBox.coordinates().get(0).get(2));
    assertEquals(Point.fromLngLat(102.0, 4.0), polygonRepresentingBoundingBox.coordinates().get(0).get(3));
    assertEquals(Point.fromLngLat(102.0, -10.0), polygonRepresentingBoundingBox.coordinates().get(0).get(4));
}
Also used : LineString(com.mapbox.geojson.LineString) MultiLineString(com.mapbox.geojson.MultiLineString) BoundingBox(com.mapbox.geojson.BoundingBox) Polygon(com.mapbox.geojson.Polygon) MultiPolygon(com.mapbox.geojson.MultiPolygon) Feature(com.mapbox.geojson.Feature) Test(org.junit.Test)

Example 9 with BoundingBox

use of com.mapbox.geojson.BoundingBox in project mapbox-java by mapbox.

the class ShifterTest method linestring_basic_shift_with_bbox.

@Test
public void linestring_basic_shift_with_bbox() {
    // set shifter
    CoordinateShifterManager.setCoordinateShifter(new TestCoordinateShifter());
    List<Point> points = new ArrayList<>();
    points.add(Point.fromLngLat(1.0, 1.0));
    points.add(Point.fromLngLat(2.0, 2.0));
    points.add(Point.fromLngLat(3.0, 3.0));
    BoundingBox bbox = BoundingBox.fromLngLats(1.0, 2.0, 3.0, 4.0);
    LineString lineString = LineString.fromLngLats(points, bbox);
    String jsonString = lineString.toJson();
    compareJson("{\"coordinates\":[[1,1],[2,2],[3,3]]," + "\"type\":\"LineString\",\"bbox\":[1.0,2.0,3.0,4.0]}", jsonString);
    CoordinateShifterManager.setCoordinateShifter(null);
}
Also used : LineString(com.mapbox.geojson.LineString) BoundingBox(com.mapbox.geojson.BoundingBox) ArrayList(java.util.ArrayList) Point(com.mapbox.geojson.Point) LineString(com.mapbox.geojson.LineString) Test(org.junit.Test)

Aggregations

BoundingBox (com.mapbox.geojson.BoundingBox)9 Test (org.junit.Test)9 Feature (com.mapbox.geojson.Feature)4 LineString (com.mapbox.geojson.LineString)4 MultiPolygon (com.mapbox.geojson.MultiPolygon)4 Polygon (com.mapbox.geojson.Polygon)4 Point (com.mapbox.geojson.Point)3 MultiLineString (com.mapbox.geojson.MultiLineString)2 ArrayList (java.util.ArrayList)2 FeatureCollection (com.mapbox.geojson.FeatureCollection)1 Geometry (com.mapbox.geojson.Geometry)1 GeometryCollection (com.mapbox.geojson.GeometryCollection)1 MultiPoint (com.mapbox.geojson.MultiPoint)1