com.mapbox.geojson.Feature Java Examples
The following examples show how to use
com.mapbox.geojson.Feature.
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 |
private void showSymbols(int amount) { List<SymbolOptions> options = new ArrayList<>(); Random random = new Random(); int randomIndex; List<Feature> features = locations.features(); if (features == null) { return; } for (int i = 0; i < amount; i++) { randomIndex = random.nextInt(features.size()); Feature feature = features.get(randomIndex); options.add(new SymbolOptions() .withGeometry((Point) feature.geometry()) .withIconImage("fire-station-11") ); } symbols = symbolManager.create(options); }
Example #2
Source File: TurfConversionTest.java From mapbox-java with MIT License | 6 votes |
@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 #3
Source File: MapUtils.java From graphhopper-navigation-android with MIT License | 6 votes |
/** * 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: MapStyleController.java From AirMapSDK-Android with Apache License 2.0 | 6 votes |
public void highlight(Feature feature) { String id = feature.getStringProperty("id"); String type = feature.getStringProperty("category"); // remove old highlight unhighlight(); // add new highlight String sourceId = feature.getStringProperty("ruleset_id"); highlightLayerId = "airmap|highlight|line|" + sourceId; LineLayer highlightLayer = map.getMap().getStyle().getLayerAs(highlightLayerId); highlightLayer.setSourceLayer(sourceId + "_" + type); // feature's airspace_id can be an int or string (tile server bug), so match on either Expression filter; try { int airspaceId = Integer.parseInt(id); filter = Expression.any(Expression.eq(Expression.get("id"), id), Expression.eq(Expression.get("id"), airspaceId)); } catch (NumberFormatException e) { filter = Expression.any(Expression.eq(Expression.get("id"), id)); } highlightLayer.setFilter(filter); }
Example #5
Source File: TurfConversionTest.java From mapbox-java with MIT License | 6 votes |
@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 #6
Source File: TurfMiscTest.java From mapbox-java with MIT License | 6 votes |
@Test public void testTurfLineSliceVertical() throws IOException, TurfException { Point start = Point.fromLngLat(-121.25447809696198, 38.70582415504791); Point stop = Point.fromLngLat(-121.25447809696198, 38.70634324369764); Feature vertical = Feature.fromJson(loadJsonFixture(LINE_SLICE_VERTICAL)); LineString sliced = TurfMisc.lineSlice(start, stop, vertical); assertNotNull(sliced); // No duplicated coords assertEquals(2, sliced.coordinates().size()); // Vertical slice does not collapse to 1st coord assertNotEquals(sliced.coordinates().get(0), sliced.coordinates().get(1)); }
Example #7
Source File: MapWaynameTest.java From graphhopper-navigation-android with MIT License | 6 votes |
@Test public void onRoadsReturnedFromQuery_layoutProviderGeneratesBitmap() { String roadName = "roadName"; PointF point = mock(PointF.class); SymbolLayer waynameLayer = mock(SymbolLayer.class); List<Feature> roads = new ArrayList<>(); Feature road = mock(Feature.class); when(road.hasNonNullValueForProperty("name")).thenReturn(true); when(road.getStringProperty("name")).thenReturn(roadName); roads.add(road); WaynameLayoutProvider layoutProvider = mock(WaynameLayoutProvider.class); when(layoutProvider.generateLayoutBitmap(roadName)).thenReturn(mock(Bitmap.class)); MapWayname mapWayname = buildMapWayname(point, layoutProvider, waynameLayer, roads); mapWayname.updateWaynameVisibility(true, waynameLayer); mapWayname.updateWaynameWithPoint(point, waynameLayer); verify(layoutProvider).generateLayoutBitmap(roadName); }
Example #8
Source File: TurfConversionTest.java From mapbox-java with MIT License | 6 votes |
@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 #9
Source File: TurfMeasurement.java From mapbox-java with MIT License | 6 votes |
/** * 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 #10
Source File: MapActivity.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
private boolean handlePoiLongClick(LatLng point) { final PointF pixel = mapboxMap.getProjection().toScreenLocation(point); List<Feature> features = mapboxMap.queryRenderedFeatures(pixel, mapDataManager.getMarkerLayers()); for (Feature feature : features) { if (feature.getBooleanProperty(IS_POI)) { new AlertDialog.Builder(MapActivity.this) .setMessage(getString(R.string.menu_delete_location)) .setPositiveButton(R.string.yes, (dialog, which) -> { int messageId = feature.getNumberProperty(MESSAGE_ID).intValue(); int[] messages = new int[1]; messages[0] = messageId; ApplicationContext.getInstance(MapActivity.this).dcContext.deleteMsgs(messages); }) .setNegativeButton(R.string.no, null) .show(); return true; } } return false; }
Example #11
Source File: PolygonContainer.java From AirMapSDK-Android with Apache License 2.0 | 6 votes |
public boolean checkForIntersections() { List<LatLng> points = PointMath.findIntersections(path); if (points.isEmpty()) { return false; } List<Point> intersections = latLngsToPositions(points); if (map.getStyle().getLayer(INTERSECTION_LAYER) == null) { Source intersectionSource = new GeoJsonSource(INTERSECTION_SOURCE, Feature.fromGeometry(MultiPoint.fromLngLats(intersections))); map.getStyle().addSource(intersectionSource); Layer intersectionLayer = new SymbolLayer(INTERSECTION_LAYER, INTERSECTION_SOURCE) .withProperties(PropertyFactory.iconImage(INTERSECTION_IMAGE)); map.getStyle().addLayer(intersectionLayer); } else { GeoJsonSource intersectionsSource = map.getStyle().getSourceAs(INTERSECTION_SOURCE); intersectionsSource.setGeoJson(Feature.fromGeometry(MultiPoint.fromLngLats(intersections))); } return true; }
Example #12
Source File: TurfAssertions.java From mapbox-java with MIT License | 6 votes |
/** * 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 #13
Source File: TurfClassificationTest.java From mapbox-java with MIT License | 6 votes |
@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 #14
Source File: CircleContainer.java From AirMapSDK-Android with Apache License 2.0 | 6 votes |
public void move(LatLng center) { this.center = center; this.points = calculateCirclePoints(center, radius); List<Point> positions = latLngsToPositions(points); List<List<Point>> coordinates = new ArrayList<>(); coordinates.add(positions); List<Point> lineString = new ArrayList<>(positions); lineString.add(positions.get(0)); GeoJsonSource pointSource = map.getStyle().getSourceAs(POINT_SOURCE); pointSource.setGeoJson(Feature.fromGeometry(Point.fromLngLat(center.getLongitude(), center.getLatitude()))); GeoJsonSource polygonSource = map.getStyle().getSourceAs(POLYGON_SOURCE); polygonSource.setGeoJson(Feature.fromGeometry(Polygon.fromLngLats(coordinates))); FillLayer polygonFill = map.getStyle().getLayerAs(Container.POLYGON_LAYER); polygonFill.setProperties(PropertyFactory.fillColor(ContextCompat.getColor(context, R.color.colorAccent))); GeoJsonSource polylineSource = map.getStyle().getSourceAs(POLYLINE_SOURCE); polylineSource.setGeoJson(Feature.fromGeometry(LineString.fromLngLats(lineString))); }
Example #15
Source File: TurfMiscTest.java From mapbox-java with MIT License | 6 votes |
@Test public void testTurfPointOnLinePointsOnSidesOfLines() throws TurfException { List<Point> line = new ArrayList<>(); line.add(Point.fromLngLat(-122.45616137981413, 37.72125936929241)); line.add(Point.fromLngLat(-122.45717525482178, 37.718242366859215)); Point first = line.get(0); Point last = line.get(1); List<Point> pts = new ArrayList<>(); pts.add(Point.fromLngLat(-122.45702505111694, 37.71881098149625)); pts.add(Point.fromLngLat(-122.45733618736267, 37.719235317933844)); pts.add(Point.fromLngLat(-122.45686411857605, 37.72027068864082)); pts.add(Point.fromLngLat(-122.45652079582213, 37.72063561093274)); for (Point pt : pts) { Feature snappedFeature = TurfMisc.nearestPointOnLine(pt, line); Point snapped = (Point) snappedFeature.geometry(); // pt did not snap to first vertex assertNotEquals(snapped, first); // pt did not snap to last vertex assertNotEquals(snapped, last); } }
Example #16
Source File: TurfMiscTest.java From mapbox-java with MIT License | 6 votes |
@Test public void testTurfPointOnLinePointsInFrontOfLastPoint() throws TurfException { List<Point> line = new ArrayList<>(); line.add(Point.fromLngLat(-122.45616137981413, 37.72125936929241)); line.add(Point.fromLngLat(-122.45717525482178, 37.72003306385638)); line.add(Point.fromLngLat(-122.45717525482178, 37.718242366859215)); Point last = line.get(2); List<Point> pts = new ArrayList<>(); pts.add(Point.fromLngLat(-122.45696067810057, 37.7181405249708)); pts.add(Point.fromLngLat(-122.4573630094528, 37.71813203814049)); pts.add(Point.fromLngLat(-122.45730936527252, 37.71797927502795)); pts.add(Point.fromLngLat(-122.45718061923981, 37.71704571582896)); for (Point pt : pts) { Feature snappedFeature = TurfMisc.nearestPointOnLine(pt, line); Point snapped = (Point) snappedFeature.geometry(); // pt behind start moves to last vertex assertEquals(last, snapped); } }
Example #17
Source File: TurfMeasurementTest.java From mapbox-java with MIT License | 6 votes |
@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 #18
Source File: TurfMeasurementTest.java From mapbox-java with MIT License | 6 votes |
@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)); }
Example #19
Source File: MapDataController.java From AirMapSDK-Android with Apache License 2.0 | 5 votes |
protected Func1<AirMapPolygon, Observable<List<AirMapJurisdiction>>> getJurisdictions() { return polygon -> Observable.create((Observable.OnSubscribe<List<AirMapJurisdiction>>) subscriber -> { // query map for jurisdictions List<Feature> features = map.getMap().queryRenderedFeatures(new RectF(0, 0, map.getMeasuredWidth(), map.getMeasuredHeight()), "jurisdictions"); if (features.isEmpty()) { Timber.d("Features are empty"); hasJurisdictions = false; subscriber.onError(new Throwable("Features are empty")); } List<AirMapJurisdiction> jurisdictions = new ArrayList<>(); for (Feature feature : features) { try { JsonObject propertiesJSON = feature.properties(); JSONObject jurisdictionJSON = new JSONObject(propertiesJSON.get("jurisdiction").getAsString()); jurisdictions.add(new AirMapJurisdiction(jurisdictionJSON)); } catch (JSONException e) { Timber.e(e, "Unable to get jurisdiction json"); } } subscriber.onNext(jurisdictions); subscriber.onCompleted(); }) .retryWhen(new RetryWithDelay(4, 400), AndroidSchedulers.mainThread()) .onErrorReturn(throwable -> { Timber.v("Ran out of attempts to query jurisdictions"); return null; }); }
Example #20
Source File: TurfMetaTest.java From mapbox-java with MIT License | 5 votes |
@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 #21
Source File: TurfMeasurementTest.java From mapbox-java with MIT License | 5 votes |
@Test public void bboxFromPolygon() throws TurfException, IOException { Feature feature = Feature.fromJson(loadJsonFixture(TURF_BBOX_POLYGON)); double[] bbox = TurfMeasurement.bbox((Polygon) feature.geometry()); assertEquals(4, bbox.length); assertEquals(100, bbox[0], DELTA); assertEquals(0, bbox[1], DELTA); assertEquals(101, bbox[2], DELTA); assertEquals(1, bbox[3], DELTA); }
Example #22
Source File: TurfTransformationTest.java From mapbox-java with MIT License | 5 votes |
@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 #23
Source File: NavigationMapRoute.java From graphhopper-navigation-android with MIT License | 5 votes |
/** * 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 #24
Source File: MapDataManager.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
private void replaceSelectedMarker(String featureId) { Feature feature = getFeatureWithId(featureId); feature.addBooleanProperty(MARKER_SELECTED, true); selectedFeature.addBooleanProperty(MARKER_SELECTED, false); int lastContactId = selectedFeature.getNumberProperty(CONTACT_ID).intValue(); int currentContactId = feature.getNumberProperty(CONTACT_ID).intValue(); selectedFeature = feature; refreshSource(currentContactId); if (lastContactId != currentContactId) { refreshSource(lastContactId); } }
Example #25
Source File: TurfConversion.java From mapbox-java with MIT License | 5 votes |
@Nullable private static Feature coordsToLine(@NonNull List<List<Point>> coordinates, @Nullable JsonObject properties) { if (coordinates.size() > 1) { return Feature.fromGeometry(MultiLineString.fromLngLats(coordinates), properties); } else if (coordinates.size() == 1) { LineString lineString = LineString.fromLngLats(coordinates.get(0)); return Feature.fromGeometry(lineString, properties); } return null; }
Example #26
Source File: TurfMiscTest.java From mapbox-java with MIT License | 5 votes |
@Test public void testTurfPointOnLinePointsOnTopOfLine() throws TurfException { List<Point> line = new ArrayList<>(); line.add(Point.fromLngLat(-0.10919809341430663, 51.52204224896724)); line.add(Point.fromLngLat(-0.10923027992248535, 51.521942114455435)); line.add(Point.fromLngLat(-0.10916590690612793, 51.52186200668747)); line.add(Point.fromLngLat(-0.10904788970947266, 51.52177522311313)); line.add(Point.fromLngLat(-0.10886549949645996, 51.521601655468345)); line.add(Point.fromLngLat(-0.10874748229980469, 51.52138135712038)); line.add(Point.fromLngLat(-0.10855436325073242, 51.5206870765674)); line.add(Point.fromLngLat(-0.10843634605407713, 51.52027984939518)); line.add(Point.fromLngLat(-0.10839343070983887, 51.519952729849024)); line.add(Point.fromLngLat(-0.10817885398864746, 51.51957887606202)); line.add(Point.fromLngLat(-0.10814666748046874, 51.51928513164789)); line.add(Point.fromLngLat(-0.10789990425109863, 51.518624199789016)); line.add(Point.fromLngLat(-0.10759949684143065, 51.51778299991493)); double dist = TurfMeasurement.length(LineString.fromLngLats(line), TurfConstants.UNIT_MILES); double increment = dist / 10; for (int i = 0; i < 10; i++) { Point pt = TurfMeasurement.along( LineString.fromLngLats(line), increment * i, TurfConstants.UNIT_MILES); Feature snappedFeature = TurfMisc.nearestPointOnLine(pt, line); Point snapped = (Point) snappedFeature.geometry(); double shift = TurfMeasurement.distance(pt, snapped, TurfConstants.UNIT_MILES); // pt did not shift far assertTrue(shift < 0.000001); } }
Example #27
Source File: MapDataManager.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
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 #28
Source File: TurfMeasurement.java From mapbox-java with MIT License | 5 votes |
/** * Takes a bbox and uses its coordinates to create a {@link Polygon} geometry. * * @param bbox a double[] object to calculate with * @param properties a {@link JsonObject} containing the feature properties * @param id common identifier of this feature * @return a {@link Feature} object * @see <a href="http://turfjs.org/docs/#bboxPolygon">Turf BoundingBox Polygon documentation</a> * @since 4.9.0 */ public static Feature bboxPolygon(@NonNull double[] bbox, @Nullable JsonObject properties, @Nullable String id) { return Feature.fromGeometry(Polygon.fromLngLats( Collections.singletonList( Arrays.asList( Point.fromLngLat(bbox[0], bbox[1]), Point.fromLngLat(bbox[2], bbox[1]), Point.fromLngLat(bbox[2], bbox[3]), Point.fromLngLat(bbox[0], bbox[3]), Point.fromLngLat(bbox[0], bbox[1])))), properties, id); }
Example #29
Source File: TurfMeasurement.java From mapbox-java with MIT License | 5 votes |
/** * Takes a {@link BoundingBox} and uses its coordinates to create a {@link Polygon} * geometry. * * @param boundingBox a {@link BoundingBox} object to calculate with * @param properties a {@link JsonObject} containing the feature properties * @param id common identifier of this feature * @return a {@link Feature} object * @see <a href="http://turfjs.org/docs/#bboxPolygon">Turf BoundingBox Polygon documentation</a> * @since 4.9.0 */ public static Feature bboxPolygon(@NonNull BoundingBox boundingBox, @Nullable JsonObject properties, @Nullable String id) { return Feature.fromGeometry(Polygon.fromLngLats( Collections.singletonList( Arrays.asList( Point.fromLngLat(boundingBox.west(), boundingBox.south()), Point.fromLngLat(boundingBox.east(), boundingBox.south()), Point.fromLngLat(boundingBox.east(), boundingBox.north()), Point.fromLngLat(boundingBox.west(), boundingBox.north()), Point.fromLngLat(boundingBox.west(), boundingBox.south())))), properties, id); }
Example #30
Source File: TurfConversionTest.java From mapbox-java with MIT License | 5 votes |
@Test public void explodePolygonSingleFeature() throws NullPointerException { Polygon polygon = Polygon.fromLngLats(Arrays.asList( Arrays.asList( Point.fromLngLat(0, 101), Point.fromLngLat(1, 101), Point.fromLngLat(1, 100), Point.fromLngLat(0, 100)))); assertEquals(3, TurfConversion.explode(Feature.fromGeometry(polygon)).features().size()); }