Java Code Examples for com.mapbox.geojson.LineString#fromJson()

The following examples show how to use com.mapbox.geojson.LineString#fromJson() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TurfMeasurementTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@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));
}
 
Example 2
Source File: TurfMeasurementTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@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));
}
 
Example 3
Source File: TurfMeasurementTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void bboxFromLine() throws TurfException, IOException {
  LineString lineString = LineString.fromJson(loadJsonFixture(TURF_BBOX_LINESTRING));
  double[] bbox = TurfMeasurement.bbox(lineString);

  assertEquals(4, bbox.length);
  assertEquals(102, bbox[0], DELTA);
  assertEquals(-10, bbox[1], DELTA);
  assertEquals(130, bbox[2], DELTA);
  assertEquals(4, bbox[3], DELTA);
}
 
Example 4
Source File: TurfMetaTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void coordAllLineString() throws TurfException {
  String jsonLineString = "{type: 'LineString', coordinates: [[0, 0], [1, 1]]}";
  LineString lineStringGeometry = LineString.fromJson(jsonLineString);
  List<Point> resultList = TurfMeta.coordAll(lineStringGeometry);

  assertEquals(resultList.size(), 2, DELTA);
  assertEquals(resultList.get(0), Point.fromLngLat(0, 0));
  assertEquals(resultList.get(1), Point.fromLngLat(1, 1));
}
 
Example 5
Source File: MapboxStaticMapTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void geoJson_getsAddedToUrlCorrectly() throws Exception {
  LineString lineString
    = LineString.fromJson("{\"type\":\"LineString\",\"coordinates\":[[100,0],[101,1]]}");

  MapboxStaticMap staticMap = MapboxStaticMap.builder()
    .accessToken(ACCESS_TOKEN)
    .retina(true)
    .cameraAuto(true)
    .geoJson(lineString)
    .build();
  assertThat(staticMap.url().toString(),
    containsString("geojson(%7B%22type%22:%22LineString%22,%22coordinates%22:"
      + "[[100.0,0.0],[101.0,1.0]]%7D)"));
}
 
Example 6
Source File: TurfConversionTest.java    From mapbox-java with MIT License 4 votes vote down vote up
@Test
public void explodeLineStringSingleFeature() throws NullPointerException {
  LineString lineString = LineString.fromJson(loadJsonFixture(TURF_EXPLODE_LINESTRING));
  assertEquals(4, TurfConversion.explode(Feature.fromGeometry(lineString)).features().size());
}