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());
}
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);
}
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));
}
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);
}
Aggregations