Java Code Examples for com.mapbox.geojson.FeatureCollection

The following examples show how to use com.mapbox.geojson.FeatureCollection. These examples are extracted from open source projects. 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
@NonNull
@Override
public Flowable<kotlin.Pair<FeatureCollection, BoundingBox>> filteredEventsForMap(
        List<DatePeriod> dateFilter, List<String> orgUnitFilter,
        List<CategoryOptionCombo> catOptCombList, List<EventStatus> eventStatus,
        List<State> states, boolean assignedToUser
) {
    EventCollectionRepository eventRepo = d2.eventModule().events().byProgramUid().eq(programUid).byDeleted().isFalse();
    if (!dateFilter.isEmpty())
        eventRepo = eventRepo.byEventDate().inDatePeriods(dateFilter);
    if (!orgUnitFilter.isEmpty())
        eventRepo = eventRepo.byOrganisationUnitUid().in(orgUnitFilter);
    if (!catOptCombList.isEmpty())
        eventRepo = eventRepo.byAttributeOptionComboUid().in(UidsHelper.getUids(catOptCombList));
    if (!eventStatus.isEmpty())
        eventRepo = eventRepo.byStatus().in(eventStatus);
    if (!states.isEmpty())
        eventRepo = eventRepo.byState().in(states);
    if (assignedToUser)
        eventRepo = eventRepo.byAssignedUser().eq(getCurrentUser());

    return eventRepo.byDeleted().isFalse().orderByEventDate(RepositoryScope.OrderByDirection.DESC).withTrackedEntityDataValues().get()
            .map(GeometryUtils.INSTANCE::getSourceFromEvent)
            .toFlowable();
}
 
Example #2
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Takes a {@link FeatureCollection} and creates a map GeoJson source using the sourceId also
 * provided.
 *
 * @param mapboxMap  that the current mapView is using
 * @param collection the feature collection to be added to the map style
 * @param sourceId   the source's id for identifying it when adding layers
 * @since 0.8.0
 */
public static void updateMapSourceFromFeatureCollection(@NonNull MapboxMap mapboxMap,
                                                        @Nullable FeatureCollection collection,
                                                        @NonNull String sourceId) {
  if (collection == null) {
    collection = FeatureCollection.fromFeatures(new Feature[] {});
  }

  GeoJsonSource source = mapboxMap.getSourceAs(sourceId);
  if (source == null) {
    GeoJsonOptions routeGeoJsonOptions = new GeoJsonOptions().withMaxZoom(16);
    GeoJsonSource routeSource = new GeoJsonSource(sourceId, collection, routeGeoJsonOptions);
    mapboxMap.addSource(routeSource);
  } else {
    source.setGeoJson(collection);
  }
}
 
Example #3
Source Project: mapbox-plugins-android   Author: mapbox   File: AnnotationManager.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
void internalUpdateSource() {
  if (!style.isFullyLoaded()) {
    // We are in progress of loading a new style
    return;
  }

  List<Feature> features = new ArrayList<>();
  T t;
  for (int i = 0; i < annotations.size(); i++) {
    t = annotations.valueAt(i);
    features.add(Feature.fromGeometry(t.getGeometry(), t.getFeature()));
    t.setUsedDataDrivenProperties();
  }

  geoJsonSource.setGeoJson(FeatureCollection.fromFeatures(features));
}
 
Example #4
Source Project: mapbox-java   Author: mapbox   File: MapboxTilequeryTest.java    License: MIT License 6 votes vote down vote up
@Test
public void executeCall_optionalParamLimitHonored() throws Exception {
  MapboxTilequery clientAppParams = MapboxTilequery.builder()
    .accessToken(ACCESS_TOKEN)
    .query("-122.42901,37.80633")
    .tilesetIds("mapbox.mapbox-streets-v7")
    .baseUrl(mockUrl.toString())
    .layers("poi_label")
    .geometry("point")
    .radius(500)
    .limit(2)
    .layers("poi_label")
    .build();

  Response<FeatureCollection> response = clientAppParams.executeCall();
  assertEquals(200, response.code());
  assertNotNull(response.body());

  FeatureCollection featureCollection = (FeatureCollection)response.body();
  assertEquals(2, featureCollection.features().size());
}
 
Example #5
Source Project: mapbox-java   Author: mapbox   File: MapboxIsochroneTest.java    License: MIT License 6 votes vote down vote up
@Test
public void build_optionalParameters() throws Exception {
  MapboxIsochrone client = MapboxIsochrone.builder()
    .accessToken(ACCESS_TOKEN)
    .coordinates(testPoint)
    .profile(testProfile)
    .addContoursMinutes(5,30,55)
    .baseUrl(mockUrl.toString())
    .build();

  assertNull(client.polygons());
  assertNull(client.contoursColors());
  assertNull(client.denoise());
  Response<FeatureCollection> response = client.executeCall();
  assertEquals(200, response.code());
  assertNotNull(response.body());
}
 
Example #6
Source Project: mapbox-java   Author: mapbox   File: TurfJoins.java    License: MIT License 6 votes vote down vote up
/**
 * Takes a {@link FeatureCollection} of {@link Point} and a {@link FeatureCollection} of
 * {@link Polygon} and returns the points that fall within the polygons.
 *
 * @param points   input points.
 * @param polygons input polygons.
 * @return points that land within at least one polygon.
 * @since 1.3.0
 */
public static FeatureCollection pointsWithinPolygon(FeatureCollection points,
                                                    FeatureCollection polygons) {
  ArrayList<Feature> features = new ArrayList<>();
  for (int i = 0; i < polygons.features().size(); i++) {
    for (int j = 0; j < points.features().size(); j++) {
      Point point = (Point) points.features().get(j).geometry();
      boolean isInside
        = TurfJoins.inside(point, (Polygon) polygons.features().get(i).geometry());
      if (isInside) {
        features.add(Feature.fromGeometry(point));
      }
    }
  }
  return FeatureCollection.fromFeatures(features);
}
 
Example #7
Source Project: mapbox-java   Author: mapbox   File: TurfMeasurement.java    License: MIT License 6 votes vote down vote up
/**
 * Takes a set of features, calculates the bbox of all input features, and returns a bounding box.
 *
 * @param geoJson a {@link GeoJson} object
 * @return a double array defining the bounding box in this order {@code [minX, minY, maxX, maxY]}
 * @since 4.8.0
 */
public static double[] bbox(GeoJson geoJson) {
  BoundingBox boundingBox = geoJson.bbox();
  if (boundingBox != null) {
    return new double[] {
      boundingBox.west(),
      boundingBox.south(),
      boundingBox.east(),
      boundingBox.north()
    };
  }

  if (geoJson instanceof Geometry) {
    return bbox((Geometry) geoJson);
  } else if (geoJson instanceof FeatureCollection) {
    return bbox((FeatureCollection) geoJson);
  } else if (geoJson instanceof Feature) {
    return bbox((Feature) geoJson);
  } else {
    throw new UnsupportedOperationException("bbox type not supported for GeoJson instance");
  }
}
 
Example #8
Source Project: mapbox-java   Author: mapbox   File: TurfAssertions.java    License: MIT License 6 votes vote down vote up
/**
 * Enforce expectations about types of {@link FeatureCollection} inputs for Turf. Internally
 * this uses {@link Feature#type()}} to judge geometry types.
 *
 * @param featureCollection for which features will be judged
 * @param type              expected GeoJson type
 * @param name              name of calling function
 * @see <a href="http://turfjs.org/docs/#collectionof">Turf collectionOf documentation</a>
 * @since 1.2.0
 */
public static void collectionOf(FeatureCollection featureCollection, String type, String name) {
  if (name == null || name.length() == 0) {
    throw new TurfException("collectionOf() requires a name");
  }
  if (featureCollection == null || !featureCollection.type().equals("FeatureCollection")
    || featureCollection.features() == null) {
    throw new TurfException(String.format(
      "Invalid input to %s, FeatureCollection required", name));
  }
  for (Feature feature : featureCollection.features()) {
    if (feature == null || !feature.type().equals("Feature") || feature.geometry() == null) {
      throw new TurfException(String.format(
        "Invalid input to %s, Feature with geometry required", name));
    }
    if (feature.geometry() == null || !feature.geometry().type().equals(type)) {
      throw new TurfException(String.format(
        "Invalid input to %s: must be a %s, given %s", name, type, feature.geometry().type()));
    }
  }
}
 
Example #9
Source Project: mapbox-java   Author: mapbox   File: TurfClassificationTest.java    License: 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 #10
Source Project: mapbox-java   Author: mapbox   File: TurfMeasurementTest.java    License: 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 #11
Source Project: mapbox-java   Author: mapbox   File: TurfMetaTest.java    License: MIT License 6 votes vote down vote up
@Test
public void coordAllFeatureCollection() throws TurfException {
  String multipolygonJson = "{type: 'MultiPolygon', coordinates: [[[[0, 0], [1, 1], [0, 1], [0, 0]]]]}";
  String lineStringJson = "{type: 'LineString', coordinates: [[0, 0], [1, 1]]}";
  FeatureCollection featureCollection = FeatureCollection.fromFeatures(
    new Feature[] {
      Feature.fromGeometry(MultiPolygon.fromJson(multipolygonJson)),
      Feature.fromGeometry(LineString.fromJson(lineStringJson))}
  );
  assertNotNull(featureCollection);
  assertEquals(5, TurfMeta.coordAll(featureCollection,true).size());
  assertEquals(0, TurfMeta.coordAll(featureCollection,true).get(0).latitude(), DELTA);
  assertEquals(0, TurfMeta.coordAll(featureCollection,true).get(0).longitude(), DELTA);
  assertEquals(1, TurfMeta.coordAll(featureCollection,true).get(4).latitude(), DELTA);
  assertEquals(1, TurfMeta.coordAll(featureCollection,true).get(4).longitude(), DELTA);
}
 
Example #12
Source Project: mapbox-java   Author: mapbox   File: TurfMetaTest.java    License: MIT License 6 votes vote down vote up
@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);
}
 
Example #13
Source Project: mapbox-java   Author: mapbox   File: TurfConversionTest.java    License: MIT License 6 votes vote down vote up
@Test
public void combinePointsToMultiPoint() throws Exception {
  FeatureCollection pointFeatureCollection =
    FeatureCollection.fromFeatures(
      Arrays.asList(
        Feature.fromGeometry(Point.fromLngLat(-2.46, 27.6835)),
        Feature.fromGeometry(Point.fromLngLat(41.83, 7.3624))
      ));

  FeatureCollection featureCollectionWithNewMultiPointObject = TurfConversion.combine(pointFeatureCollection);
  assertNotNull(featureCollectionWithNewMultiPointObject);

  MultiPoint multiPoint = (MultiPoint) featureCollectionWithNewMultiPointObject.features().get(0).geometry();
  assertNotNull(multiPoint);

  assertEquals(-2.46, multiPoint.coordinates().get(0).longitude(), DELTA);
  assertEquals(27.6835, multiPoint.coordinates().get(0).latitude(), DELTA);
  assertEquals(41.83, multiPoint.coordinates().get(1).longitude(), DELTA);
  assertEquals(7.3624, multiPoint.coordinates().get(1).latitude(), DELTA);
}
 
Example #14
Source Project: mapbox-java   Author: mapbox   File: TurfConversionTest.java    License: MIT License 6 votes vote down vote up
@Test
public void combinePointAndMultiPointToMultiPoint() throws Exception {
  FeatureCollection pointAndMultiPointFeatureCollection =
      FeatureCollection.fromFeatures(
          Arrays.asList(
              Feature.fromGeometry(Point.fromLngLat(-2.46, 27.6835)),
              Feature.fromGeometry(MultiPoint.fromLngLats(
                  Arrays.asList(Point.fromLngLat(41.83, 7.3624),
                      Point.fromLngLat(100, 101)))
              )));

  FeatureCollection combinedFeatureCollection =
      TurfConversion.combine(pointAndMultiPointFeatureCollection);

  assertNotNull(combinedFeatureCollection);

  MultiPoint multiPoint = (MultiPoint) combinedFeatureCollection.features().get(0).geometry();
  assertNotNull(multiPoint);

  assertEquals(-2.46, multiPoint.coordinates().get(0).longitude(), DELTA);
  assertEquals(27.6835, multiPoint.coordinates().get(0).latitude(), DELTA);
  assertEquals(41.83, multiPoint.coordinates().get(1).longitude(), DELTA);
  assertEquals(7.3624, multiPoint.coordinates().get(1).latitude(), DELTA);
  assertEquals(100, multiPoint.coordinates().get(2).longitude(), DELTA);
  assertEquals(101, multiPoint.coordinates().get(2).latitude(), DELTA);
}
 
Example #15
Source Project: mapbox-java   Author: mapbox   File: TurfConversionTest.java    License: MIT License 6 votes vote down vote up
@Test
public void combine_featureCollectionSizeCheck() throws Exception {
  FeatureCollection pointMultiPolygonAndLineStringFeatureCollection =
    FeatureCollection.fromFeatures(
      Arrays.asList(
        Feature.fromGeometry(Point.fromLngLat(-2.46, 27.6835)),
        Feature.fromGeometry(MultiPolygon.fromPolygons(Arrays.asList(
          Polygon.fromLngLats(Arrays.asList(Arrays.asList(
            Point.fromLngLat(11.42578125, 16.636191878397664),
            Point.fromLngLat(7.91015625, -9.102096738726443),
            Point.fromLngLat(31.113281249999996, 17.644022027872726),
            Point.fromLngLat(11.42578125, 16.636191878397664)
          )))))),
        Feature.fromGeometry(LineString.fromLngLats(
          Arrays.asList(Point.fromLngLat(-11.25, 55.7765),
            Point.fromLngLat(41.1328, 22.91792)))
        )));

  FeatureCollection combinedFeatureCollection = TurfConversion.combine(pointMultiPolygonAndLineStringFeatureCollection);
  assertNotNull(combinedFeatureCollection);
  assertEquals(3, combinedFeatureCollection.features().size());
}
 
Example #16
Source Project: mapbox-java   Author: mapbox   File: MapboxTilequery.java    License: MIT License 6 votes vote down vote up
private Call<List<FeatureCollection>> getBatchCall() {
  // No need to recreate it
  if (batchCall != null) {
    return batchCall;
  }

  batchCall = getService().getBatchCall(
    tilesetIds(),
    query(),
    accessToken(),
    radius(),
    limit(),
    dedupe(),
    geometry(),
    layers());

  return batchCall;
}
 
Example #17
@Override
public void setMap(FeatureCollection featureCollection, BoundingBox boundingBox) {
        if (map == null) {
            binding.mapView.getMapAsync(mapbox -> {
                map = mapbox;
                if (map.getStyle() == null){
                    map.setStyle(Style.MAPBOX_STREETS, style -> {
                        map.addOnMapClickListener(this);
                        style.addImage("ICON_ID", BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default));
                        setSource(style, featureCollection);
                        setLayer(style);

                        initCameraPosition(map,this,boundingBox);

                        markerViewManager = new MarkerViewManager(binding.mapView, map);
                        symbolManager = new SymbolManager(binding.mapView, map, style, null,
                                new GeoJsonOptions().withTolerance(0.4f));

                        symbolManager.setIconAllowOverlap(true);
                        symbolManager.setTextAllowOverlap(true);
                        symbolManager.create(featureCollection);

                    });
                }
                else {
                    ((GeoJsonSource) mapbox.getStyle().getSource("events")).setGeoJson(featureCollection);
                    initCameraPosition(map,this,boundingBox);
                }
            });
        } else {
            ((GeoJsonSource) map.getStyle().getSource("events")).setGeoJson(featureCollection);
            initCameraPosition(map,this, boundingBox);
        }
}
 
Example #18
Source Project: mapbox-java   Author: mapbox   File: MapboxIsochrone.java    License: MIT License 5 votes vote down vote up
@Override
protected Call<FeatureCollection> initializeCall() {
  return getService().getCall(
    user(),
    profile(),
    coordinates(),
    contoursMinutes(),
    accessToken(),
    contoursColors(),
    polygons(),
    denoise(),
    generalize()
  );
}
 
Example #19
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
/**
 * The routes also display an icon for each waypoint in the route, we use symbol layers for this.
 */
private FeatureCollection waypointFeatureCollection(DirectionsRoute route) {
  final List<Feature> waypointFeatures = new ArrayList<>();
  for (RouteLeg leg : route.legs()) {
    waypointFeatures.add(getPointFromLineString(leg, 0));
    waypointFeatures.add(getPointFromLineString(leg, leg.steps().size() - 1));
  }
  return FeatureCollection.fromFeatures(waypointFeatures);
}
 
Example #20
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
private void updateRoute() {
  // Update all route geometries to reflect their appropriate colors depending on if they are
  // alternative or primary.
  for (FeatureCollection featureCollection : featureCollections) {
    if (!(featureCollection.features().get(0).geometry() instanceof Point)) {
      int index = featureCollection.features().get(0).getNumberProperty(INDEX_KEY).intValue();
      updatePrimaryShieldRoute(String.format(Locale.US, ID_FORMAT, GENERIC_ROUTE_SHIELD_LAYER_ID,
        index), index);
      updatePrimaryRoute(String.format(Locale.US, ID_FORMAT, GENERIC_ROUTE_LAYER_ID,
        index), index);
    }
  }
}
 
Example #21
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
/**
 * If the {@link DirectionsRoute} request contains congestion information via annotations, breakup
 * the source into pieces so data-driven styling can be used to change the route colors
 * accordingly.
 */
private FeatureCollection addTrafficToSource(DirectionsRoute route, int index) {
  final List<Feature> features = new ArrayList<>();
  LineString originalGeometry = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  buildRouteFeatureFromGeometry(index, features, originalGeometry);
  routeLineStrings.put(originalGeometry, route);

  LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6);
  buildTrafficFeaturesFromRoute(route, index, features, lineString);
  return FeatureCollection.fromFeatures(features);
}
 
Example #22
Source Project: deltachat-android   Author: deltachat   File: MapDataManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
public boolean unselectMarker() {
    if (selectedFeature != null) {
        selectedFeature.addBooleanProperty(MARKER_SELECTED, false);
        refreshSource(selectedFeature.getNumberProperty(CONTACT_ID).intValue());
        selectedFeature = null;
        GeoJsonSource source = (GeoJsonSource) mapboxStyle.getSource(INFO_WINDOW_SRC);
        source.setGeoJson(FeatureCollection.fromFeatures(new ArrayList<>()));
        return true;
    }
    return false;
}
 
Example #23
Source Project: mapbox-plugins-android   Author: mapbox   File: BulkSymbolActivity.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void onLatLngListLoaded(FeatureCollection featureCollection, int amount) {
  if (progressDialog != null) {
    progressDialog.dismiss();
    progressDialog = null;
  }
  locations = featureCollection;
  showMarkers(amount);
}
 
Example #24
Source Project: mapbox-plugins-android   Author: mapbox   File: BulkSymbolActivity.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void onPostExecute(FeatureCollection locations) {
  super.onPostExecute(locations);
  BulkSymbolActivity activity = this.activity.get();
  if (activity != null) {
    activity.onLatLngListLoaded(locations, amount);
  }
}
 
Example #25
Source Project: mapbox-java   Author: mapbox   File: TurfMeasurement.java    License: MIT License 5 votes vote down vote up
/**
 * Takes one {@link FeatureCollection} and returns it's area in square meters.
 *
 * @param featureCollection input {@link FeatureCollection}
 * @return area in square meters
 * @since 4.10.0
 */
public static double area(@NonNull FeatureCollection featureCollection) {
  List<Feature> features = featureCollection.features();
  double total = 0.0f;
  if (features != null) {
    for (Feature feature : features) {
      total += area(feature);
    }
  }
  return total;
}
 
Example #26
Source Project: mapbox-java   Author: mapbox   File: TurfMeasurementTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testTurfAlong() throws IOException, TurfException {
  Feature feature = Feature.fromJson(loadJsonFixture(TURF_ALONG_DC_LINE));
  LineString line = (LineString) feature.geometry();

  Point pt1 = TurfMeasurement.along(line, 1, "miles");
  Point pt2 = TurfMeasurement.along(line, 1.2, "miles");
  Point pt3 = TurfMeasurement.along(line, 1.4, "miles");
  Point pt4 = TurfMeasurement.along(line, 1.6, "miles");
  Point pt5 = TurfMeasurement.along(line, 1.8, "miles");
  Point pt6 = TurfMeasurement.along(line, 2, "miles");
  Point pt7 = TurfMeasurement.along(line, 100, "miles");
  Point pt8 = TurfMeasurement.along(line, 0, "miles");
  FeatureCollection fc = FeatureCollection.fromFeatures(new Feature[] {
    Feature.fromGeometry(pt1),
    Feature.fromGeometry(pt2),
    Feature.fromGeometry(pt3),
    Feature.fromGeometry(pt4),
    Feature.fromGeometry(pt5),
    Feature.fromGeometry(pt6),
    Feature.fromGeometry(pt7),
    Feature.fromGeometry(pt8)
  });

  for (Feature f : fc.features()) {
    assertNotNull(f);
    assertEquals("Feature", f.type());
    assertEquals("Point", f.geometry().type());
  }

  assertEquals(8, fc.features().size());
  assertEquals(((Point) fc.features().get(7).geometry()).longitude(), pt8.longitude(), DELTA);
  assertEquals(((Point) fc.features().get(7).geometry()).latitude(), pt8.latitude(), DELTA);
}
 
Example #27
Source Project: mapbox-java   Author: mapbox   File: TurfMeasurementTest.java    License: 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 #28
Source Project: mapbox-java   Author: mapbox   File: TurfMetaTest.java    License: MIT License 5 votes vote down vote up
@Test
public void coordAllSingleFeature() throws TurfException {
  String lineStringJson = "{type: 'LineString', coordinates: [[0, 0], [1, 1]]}";
  FeatureCollection featureCollection = FeatureCollection.fromFeature(
    Feature.fromGeometry(LineString.fromJson(lineStringJson))
  );
  assertNotNull(featureCollection);
  assertEquals(2, TurfMeta.coordAll(featureCollection,true).size());
  assertEquals(0, TurfMeta.coordAll(featureCollection,true).get(0).latitude(), DELTA);
  assertEquals(0, TurfMeta.coordAll(featureCollection,true).get(0).longitude(), DELTA);
  assertEquals(1, TurfMeta.coordAll(featureCollection,true).get(1).latitude(), DELTA);
  assertEquals(1, TurfMeta.coordAll(featureCollection,true).get(1).longitude(), DELTA);
}
 
Example #29
Source Project: mapbox-java   Author: mapbox   File: TurfAssertionsTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testInvariantCollectionOf1() throws TurfException {
  String json = "{type: 'FeatureCollection', features: [{ type: 'Feature', geometry: { "
    + "type: 'Point', coordinates: [0, 0]}, properties: {}}]}";
  thrown.expect(TurfException.class);
  thrown.expectMessage(startsWith("Invalid input to myfn: must be a Polygon, given Point"));
  TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Polygon", "myfn");
}
 
Example #30
Source Project: mapbox-java   Author: mapbox   File: TurfAssertionsTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testInvariantCollectionOf2() throws TurfException {
  String json = "{type: 'FeatureCollection'}";
  thrown.expect(TurfException.class);
  thrown.expectMessage(startsWith("collectionOf() requires a name"));
  TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Polygon", null);
}