use of com.mapbox.geojson.BoundingBox in project mapbox-java by mapbox.
the class MapboxGeocodingTest method bbox_getsFormattedCorrectlyForUrl.
@Test
public void bbox_getsFormattedCorrectlyForUrl() {
BoundingBox bbox = BoundingBox.fromLngLats(-77.083056, 38.908611, -76.997778, 38.959167);
MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder().accessToken(ACCESS_TOKEN).baseUrl(mockUrl.toString()).bbox(bbox).query("1600 pennsylvania ave nw").build();
assertEquals("-77.083056,38.908611,-76.997778,38.959167", mapboxGeocoding.cloneCall().request().url().queryParameter("bbox"));
}
use of com.mapbox.geojson.BoundingBox in project mapbox-java by mapbox.
the class ShifterTest method bbox_basic_shift.
@Test
public void bbox_basic_shift() throws Exception {
Point southwest = Point.fromLngLat(2.0, 2.0);
Point northeast = Point.fromLngLat(4.0, 4.0);
CoordinateShifter shifter = new TestCoordinateShifter();
// Manually shifted
List<Double> shifted = shifter.shiftLonLat(southwest.longitude(), southwest.latitude());
Point southwestManualShifted = Point.fromLngLat(shifted.get(0), shifted.get(1));
shifted = shifter.shiftLonLat(northeast.longitude(), northeast.latitude());
Point northeastManualShifted = Point.fromLngLat(shifted.get(0), shifted.get(1));
CoordinateShifterManager.setCoordinateShifter(shifter);
BoundingBox boundingBoxFromDouble = BoundingBox.fromLngLats(2.0, 2.0, 4.0, 4.0);
BoundingBox boundingBoxFromPoints = BoundingBox.fromPoints(Point.fromLngLat(2.0, 2.0), Point.fromLngLat(4.0, 4.0));
assertEquals(boundingBoxFromDouble, boundingBoxFromPoints);
assertEquals(southwestManualShifted, boundingBoxFromPoints.southwest());
assertEquals(northeastManualShifted, boundingBoxFromPoints.northeast());
CoordinateShifterManager.setCoordinateShifter(null);
}
use of com.mapbox.geojson.BoundingBox in project mapbox-java by mapbox.
the class TurfMeasurementTest method bboxPolygonFromLineString.
@Test
public void bboxPolygonFromLineString() 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);
Polygon polygonRepresentingBoundingBox = (Polygon) featureRepresentingBoundingBox.geometry();
assertNotNull(polygonRepresentingBoundingBox);
assertEquals(0, polygonRepresentingBoundingBox.inner().size());
assertEquals(5, polygonRepresentingBoundingBox.coordinates().get(0).size());
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 TurfMeasurementTest method square.
@Test
public void square() {
BoundingBox bbox1 = BoundingBox.fromCoordinates(0, 0, 5, 10);
BoundingBox bbox2 = BoundingBox.fromCoordinates(0, 0, 10, 5);
BoundingBox sq1 = TurfMeasurement.square(bbox1);
BoundingBox sq2 = TurfMeasurement.square(bbox2);
assertEquals(BoundingBox.fromCoordinates(-2.5, 0, 7.5, 10), sq1);
assertEquals(BoundingBox.fromCoordinates(0, -2.5, 10, 7.5), sq2);
}
use of com.mapbox.geojson.BoundingBox in project mapbox-java by mapbox.
the class TurfMeasurementTest method bboxPolygonFromMultiPolygon.
@Test
public void bboxPolygonFromMultiPolygon() throws IOException, TurfException {
// Create a MultiPolygon
MultiPolygon multiPolygon = MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_POLYGON_MULTIPOLYGON));
// Use the MultiPolygon object to calculate its BoundingBox area
double[] bbox = TurfMeasurement.bbox(multiPolygon);
// 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());
assertEquals(Point.fromLngLat(100, 0.0), polygonRepresentingBoundingBox.coordinates().get(0).get(4));
}
Aggregations