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

The following examples show how to use com.mapbox.geojson.FeatureCollection#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: BulkSymbolActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected FeatureCollection doInBackground(Void... params) {
  BulkSymbolActivity activity = this.activity.get();
  if (activity != null) {
    String json = null;
    try {
      json = GeoParseUtil.loadStringFromAssets(activity.getApplicationContext());
    } catch (IOException exception) {
      Timber.e(exception, "Could not add markers");
    }

    if (json != null) {
      return FeatureCollection.fromJson(json);
    }
  }
  return null;
}
 
Example 2
Source File: TurfClassificationTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void testLineDistanceWithGeometries() throws IOException, TurfException {
  Point pt = (Point) Feature.fromJson(loadJsonFixture(PT)).geometry();
  FeatureCollection pts = FeatureCollection.fromJson(loadJsonFixture(PTS));

  List<Point> pointList = new ArrayList<>();
  for (Feature feature : pts.features()) {
    pointList.add((Point) (feature.geometry()));
  }
  Point closestPt = TurfClassification.nearestPoint(pt, pointList);

  Assert.assertNotNull(closestPt);
  Assert.assertEquals(closestPt.type(), "Point");
  Assert.assertEquals(closestPt.longitude(), -75.33, DELTA);
  Assert.assertEquals(closestPt.latitude(), 39.44, DELTA);
}
 
Example 3
Source File: TurfMeasurementTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void envelope() throws IOException {
  FeatureCollection featureCollection = FeatureCollection.fromJson(loadJsonFixture(TURF_ENVELOPE_FEATURE_COLLECTION));
  Polygon polygon = TurfMeasurement.envelope(featureCollection);

  final List<Point> expectedPoints = new ArrayList<>();
  expectedPoints.add(Point.fromLngLat(20, -10));
  expectedPoints.add(Point.fromLngLat(130, -10));
  expectedPoints.add(Point.fromLngLat(130, 4));
  expectedPoints.add(Point.fromLngLat(20, 4));
  expectedPoints.add(Point.fromLngLat(20, -10));
  List<List<Point>> polygonPoints = new ArrayList<List<Point>>() {{
    add(expectedPoints);
  }};
  Polygon expected = Polygon.fromLngLats(polygonPoints);
  assertEquals("Polygon should match.", expected, polygon);
}
 
Example 4
Source File: TurfMeasurementTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void centerFeatureCollection() {
  FeatureCollection inputFeatureCollection = FeatureCollection.fromJson(loadJsonFixture(TURF_AREA_FEATURECOLLECTION_POLYGON_GEOJSON));
  Feature returnedCenterFeature = TurfMeasurement.center(inputFeatureCollection, null, null);
  Point returnedPoint = (Point) returnedCenterFeature.geometry();
  if (returnedPoint != null) {
    assertEquals(4.1748046875, returnedPoint.longitude(), DELTA);
    assertEquals(47.214224817196836, returnedPoint.latitude(), DELTA);
  }
}
 
Example 5
Source File: TurfTransformationTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
@Ignore
public void name() throws Exception {
  Feature feature = Feature.fromJson(loadJsonFixture(CIRCLE_IN));
  Polygon polygon = TurfTransformation.circle((Point) feature.geometry(),
    feature.getNumberProperty("radius").doubleValue());

  FeatureCollection featureCollection = FeatureCollection.fromJson(loadJsonFixture(CIRCLE_OUT));
  compareJson(featureCollection.features().get(1).geometry().toJson(), polygon.toJson());
}
 
Example 6
Source File: TurfConversionTest.java    From mapbox-java with MIT License 4 votes vote down vote up
@Test
public void polygonToLine_MultiPolygon() throws NullPointerException {
  Feature multiPolygon = Feature.fromJson(loadJsonFixture(TURF_POLYGON_TO_LINE_PATH_IN + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON));
  FeatureCollection expected = FeatureCollection.fromJson(loadJsonFixture(TURF_POLYGON_TO_LINE_PATH_OUT + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON));
  compareJson(expected.toJson(), TurfConversion.multiPolygonToLine(multiPolygon).toJson());
}
 
Example 7
Source File: TurfConversionTest.java    From mapbox-java with MIT License 4 votes vote down vote up
@Test
public void polygonToLine_MultiPolygonWithHoles() throws NullPointerException {
  Feature multiPolygon = Feature.fromJson(loadJsonFixture(TURF_POLYGON_TO_LINE_PATH_IN + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON_WITH_HOLES));
  FeatureCollection expected = FeatureCollection.fromJson(loadJsonFixture(TURF_POLYGON_TO_LINE_PATH_OUT + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON_WITH_HOLES));
  compareJson(expected.toJson(), TurfConversion.multiPolygonToLine(multiPolygon).toJson());
}
 
Example 8
Source File: TurfConversionTest.java    From mapbox-java with MIT License 4 votes vote down vote up
@Test
public void polygonToLine_MultiPolygonWithOuterDoughnut() throws NullPointerException {
  Feature multiPolygon = Feature.fromJson(loadJsonFixture(TURF_POLYGON_TO_LINE_PATH_IN + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON_OUTER_DOUGHNUT));
  FeatureCollection expected = FeatureCollection.fromJson(loadJsonFixture(TURF_POLYGON_TO_LINE_PATH_OUT + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON_OUTER_DOUGHNUT));
  compareJson(expected.toJson(), TurfConversion.multiPolygonToLine(multiPolygon).toJson());
}