com.mapbox.geojson.FeatureCollection Java Examples

The following examples show how to use com.mapbox.geojson.FeatureCollection. 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: TurfAssertions.java    From mapbox-java with 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 #2
Source File: AnnotationManager.java    From mapbox-plugins-android with 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 #3
Source File: MapUtils.java    From graphhopper-navigation-android with 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 #4
Source File: TurfConversionTest.java    From mapbox-java with 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 #5
Source File: MapboxTilequery.java    From mapbox-java with 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 #6
Source File: ProgramEventDetailRepositoryImpl.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #7
Source File: TurfConversionTest.java    From mapbox-java with 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 #8
Source File: TurfConversionTest.java    From mapbox-java with 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 #9
Source File: MapboxTilequeryTest.java    From mapbox-java with 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 #10
Source File: TurfMetaTest.java    From mapbox-java with 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 #11
Source File: MapboxIsochroneTest.java    From mapbox-java with 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 #12
Source File: TurfMetaTest.java    From mapbox-java with 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 #13
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 #14
Source File: TurfJoins.java    From mapbox-java with 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 #15
Source File: TurfMeasurement.java    From mapbox-java with 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 #16
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 #17
Source File: TurfConversionTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void combineEmptyFeatureCollectionThrowsException() throws Exception {
  thrown.expect(TurfException.class);
  thrown.expectMessage(startsWith("Your FeatureCollection doesn't have any Feature objects in it."));
  TurfConversion.combine(FeatureCollection.fromJson(
    "{\n" +
      "  \"type\": \"FeatureCollection\",\n" +
      "  \"features\": []\n" +
      "}"
  ));
}
 
Example #18
Source File: TurfAssertionsTest.java    From mapbox-java with 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 #19
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 #20
Source File: MapboxIsochroneTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void sanityPolygonsDeclared() throws ServicesException, IOException {
  MapboxIsochrone client = MapboxIsochrone.builder()
    .accessToken(ACCESS_TOKEN)
    .coordinates(testPoint)
    .addContoursMinutes(5,30,55)
    .profile(testProfile)
    .polygons(true)
    .baseUrl(mockUrl.toString())
    .build();
  Response<FeatureCollection> response = client.executeCall();
  assertEquals(200, response.code());
  assertNotNull(response.body());
  assertNotNull(response.body().features());
}
 
Example #21
Source File: MapboxIsochroneTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void sanityNoPolygonsDeclared() throws ServicesException, IOException {
  MapboxIsochrone client = MapboxIsochrone.builder()
    .accessToken(ACCESS_TOKEN)
    .coordinates(testPoint)
    .addContoursMinutes(5,30,55)
    .profile(testProfile)
    .polygons(false)
    .baseUrl(mockUrl.toString())
    .build();
  Response<FeatureCollection> response = client.executeCall();
  assertEquals(200, response.code());
  assertNotNull(response.body());
  assertNotNull(response.body().features());
}
 
Example #22
Source File: TurfConversionTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void explodeFeatureCollection() throws NullPointerException {
  FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[] {
    Feature.fromGeometry(MultiLineString.fromJson(loadJsonFixture(TURF_EXPLODE_MULTILINESTRING))),
    Feature.fromGeometry(MultiPolygon.fromJson(loadJsonFixture(TURF_EXPLODE_MULTIPOLYGON)))
  });
  assertEquals(16, TurfConversion.explode(featureCollection).features().size());
}
 
Example #23
Source File: TurfAssertionsTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void testInvariantCollectionOf3() throws TurfException {
  String json = "{type: 'FeatureCollection'}";
  thrown.expect(TurfException.class);
  thrown.expectMessage(startsWith("Invalid input to foo, FeatureCollection required"));
  TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Polygon", "foo");
}
 
Example #24
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 #25
Source File: GeoJsonAdapterFactory.java    From mapbox-java with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
  Class<?> rawType = type.getRawType();
  if (BoundingBox.class.isAssignableFrom(rawType)) {
    return (TypeAdapter<T>) BoundingBox.typeAdapter(gson);
  } else if (Feature.class.isAssignableFrom(rawType)) {
    return (TypeAdapter<T>) Feature.typeAdapter(gson);
  } else if (FeatureCollection.class.isAssignableFrom(rawType)) {
    return (TypeAdapter<T>) FeatureCollection.typeAdapter(gson);
  } else if (GeometryCollection.class.isAssignableFrom(rawType)) {
    return (TypeAdapter<T>) GeometryCollection.typeAdapter(gson);
  } else if (LineString.class.isAssignableFrom(rawType)) {
    return (TypeAdapter<T>) LineString.typeAdapter(gson);
  } else if (MultiLineString.class.isAssignableFrom(rawType)) {
    return (TypeAdapter<T>) MultiLineString.typeAdapter(gson);
  } else if (MultiPoint.class.isAssignableFrom(rawType)) {
    return (TypeAdapter<T>) MultiPoint.typeAdapter(gson);
  } else if (MultiPolygon.class.isAssignableFrom(rawType)) {
    return (TypeAdapter<T>) MultiPolygon.typeAdapter(gson);
  } else if (Polygon.class.isAssignableFrom(rawType)) {
    return (TypeAdapter<T>) Polygon.typeAdapter(gson);
  } else if (Point.class.isAssignableFrom(rawType)) {
    return (TypeAdapter<T>) Point.typeAdapter(gson);
  }
  return null;
}
 
Example #26
Source File: MapboxTilequery.java    From mapbox-java with MIT License 5 votes vote down vote up
@Override
protected Call<FeatureCollection> initializeCall() {
  return getService().getCall(
    tilesetIds(),
    query(),
    accessToken(),
    radius(),
    limit(),
    dedupe(),
    geometry(),
    layers());
}
 
Example #27
Source File: TurfMeasurementTest.java    From mapbox-java with 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 #28
Source File: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public void refreshSource(int contactId) {
    MapSource source = contactMapSources.get(contactId);
    LinkedList<Feature> collection = featureCollections.get(source.getMarkerFeatureCollection());
    GeoJsonSource pointSource = (GeoJsonSource) mapboxStyle.getSource(source.getMarkerSource());
    pointSource.setGeoJson(FeatureCollection.fromFeatures(collection));
    LinkedList<Feature> lineFeatures = featureCollections.get(source.getLineFeatureCollection());
    GeoJsonSource lineSource = (GeoJsonSource) mapboxStyle.getSource(source.getLineSource());
    lineSource.setGeoJson(FeatureCollection.fromFeatures(lineFeatures));
    GeoJsonSource lastPostionSource = (GeoJsonSource) mapboxStyle.getSource(LAST_POSITION_SOURCE);
    lastPostionSource.setGeoJson(FeatureCollection.fromFeatures(new LinkedList<>(lastPositions.values())));
}
 
Example #29
Source File: ProgramEventDetailActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #30
Source File: TurfMetaTest.java    From mapbox-java with 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);
}