Search in sources :

Example 1 with BoundingBox

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"));
}
Also used : BoundingBox(com.mapbox.geojson.BoundingBox) Test(org.junit.Test)

Example 2 with BoundingBox

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);
}
Also used : BoundingBox(com.mapbox.geojson.BoundingBox) Point(com.mapbox.geojson.Point) Test(org.junit.Test)

Example 3 with BoundingBox

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));
}
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 4 with BoundingBox

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);
}
Also used : BoundingBox(com.mapbox.geojson.BoundingBox) Test(org.junit.Test)

Example 5 with BoundingBox

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));
}
Also used : MultiPolygon(com.mapbox.geojson.MultiPolygon) BoundingBox(com.mapbox.geojson.BoundingBox) Polygon(com.mapbox.geojson.Polygon) MultiPolygon(com.mapbox.geojson.MultiPolygon) Feature(com.mapbox.geojson.Feature) 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