Java Code Examples for com.mapbox.geojson.Point
The following examples show how to use
com.mapbox.geojson.Point.
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
Source Project: graphhopper-navigation-android Author: graphhopper File: TestRouteBuilder.java License: MIT License | 6 votes |
private DirectionsRoute buildRouteWithOptions(DirectionsRoute route) throws IOException { List<Point> coordinates = new ArrayList<>(); RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder() .baseUrl(Constants.BASE_API_URL) .user("user") .profile("profile") .accessToken(ACCESS_TOKEN) .requestUuid("uuid") .geometries("mocked_geometries") .voiceInstructions(true) .bannerInstructions(true) .coordinates(coordinates).build(); return route.toBuilder() .routeOptions(routeOptionsWithoutVoiceInstructions) .build(); }
Example #2
Source Project: mapbox-java Author: mapbox File: MapboxDirectionsTest.java License: MIT License | 6 votes |
@Test public void addNullBearings_doesGetFormattedInUrlCorrectly() throws Exception { List<Double> bearing1 = new ArrayList<>(); bearing1.add(45d); bearing1.add(90d); List<Double> bearing2 = new ArrayList<>(); bearing2.add(2d); bearing2.add(90d); List<List<Double>> bearings = new ArrayList<>(); bearings.add(null); bearings.add(null); bearings.add(bearing1); bearings.add(bearing2); bearings.add(null); MapboxDirections directions = MapboxDirections.builder() .destination(Point.fromLngLat(13.4930, 9.958)) .origin(Point.fromLngLat(1.234, 2.345)) .bearings(bearings) .accessToken(ACCESS_TOKEN) .build(); assertEquals(";;45,90;2,90;", directions.cloneCall().request().url().queryParameter("bearings")); }
Example #3
Source Project: mapbox-java Author: mapbox File: MapboxDirectionsTest.java License: MIT License | 6 votes |
@Test public void waypointsList_doesGetFormattedInUrlCorrectly() { List<Integer> waypointIndices = new ArrayList<>(); waypointIndices.add(0); waypointIndices.add(2); MapboxDirections directions = MapboxDirections.builder() .destination(Point.fromLngLat(13.4930, 9.958)) .addWaypoint(Point.fromLngLat(4.56, 7.89)) .origin(Point.fromLngLat(1.234, 2.345)) .waypointIndices(waypointIndices) .accessToken(ACCESS_TOKEN) .build(); String semicolon = "%3B"; assertTrue(directions.cloneCall().request().url().toString().contains("waypoints=0" + semicolon + "2")); }
Example #4
Source Project: mapbox-java Author: mapbox File: TurfMiscTest.java License: MIT License | 6 votes |
@Test public void testTurfPointOnLinePointsOnSidesOfLinesCustomUnit() 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, TurfConstants.UNIT_MILES); 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 #5
Source Project: mapbox-java Author: mapbox File: TurfMiscTest.java License: MIT License | 6 votes |
@Test public void testShortLine() throws IOException, TurfException { // Distance between points is about 186 miles LineString lineStringLine1 = LineString.fromLngLats(Arrays.asList( Point.fromLngLat(113.99414062499999, 22.350075806124867), Point.fromLngLat(116.76269531249999, 23.241346102386135))); double start = 50; double stop = 100; Point start_point = TurfMeasurement.along(lineStringLine1, start, TurfConstants.UNIT_MILES); Point end_point = TurfMeasurement.along(lineStringLine1, stop, TurfConstants.UNIT_MILES); LineString sliced = TurfMisc.lineSliceAlong(lineStringLine1, start, stop, TurfConstants.UNIT_MILES); assertEquals(sliced.coordinates().get(0).coordinates(), start_point.coordinates()); assertEquals(sliced.coordinates().get(sliced.coordinates().size() - 1).coordinates(), end_point.coordinates()); }
Example #6
Source Project: mapbox-java Author: mapbox File: MapboxDirectionsTest.java License: MIT License | 6 votes |
@Test public void waypointList_doesGetFormattedInUrlCorrectly() { List<Integer> waypointIndices = new ArrayList<>(); waypointIndices.add(0); waypointIndices.add(2); MapboxDirections directions = MapboxDirections.builder() .destination(Point.fromLngLat(13.4930, 9.958)) .addWaypoint(Point.fromLngLat(4.56, 7.89)) .origin(Point.fromLngLat(1.234, 2.345)) .addWaypoint(Point.fromLngLat(4.56, 7.89)) .waypointIndices(waypointIndices) .addWaypointIndex(3) .accessToken(ACCESS_TOKEN) .build(); assertEquals("0;2;3", directions.cloneCall().request().url().queryParameter("waypoints")); }
Example #7
Source Project: mapbox-java Author: mapbox File: TurfMeasurementTest.java License: 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 #8
Source Project: mapbox-java Author: mapbox File: MapboxMapMatchingTest.java License: MIT License | 6 votes |
@Test public void testGetIsUsed() { MapboxMapMatching.Builder builder = MapboxMapMatching.builder() .profile(PROFILE_CYCLING) .steps(true) .coordinate(Point.fromLngLat(-122.42,37.78)) .coordinate(Point.fromLngLat(-77.03,38.91)) .voiceInstructions(true) .voiceUnits(DirectionsCriteria.IMPERIAL) .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) .get(); retrofit2.Call<MapMatchingResponse> call = builder.build().initializeCall(); assertEquals("GET", call.request().method()); }
Example #9
Source Project: graphhopper-navigation-android Author: graphhopper File: ValidationUtilsTest.java License: MIT License | 6 votes |
private DirectionsRoute buildRouteWithNullInstructions() throws IOException { DirectionsRoute route = buildTestDirectionsRoute(); List<Point> coordinates = new ArrayList<>(); RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder() .baseUrl(Constants.BASE_API_URL) .user("user") .profile("profile") .accessToken(ACCESS_TOKEN) .requestUuid("uuid") .geometries("mocked_geometries") .coordinates(coordinates).build(); return route.toBuilder() .routeOptions(routeOptionsWithoutVoiceInstructions) .build(); }
Example #10
Source Project: mapbox-java Author: mapbox File: MapboxGeocodingTest.java License: MIT License | 6 votes |
@Test public void reverseMode_getsAddedToUrlCorrectly() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl("https://foobar.com") .query(Point.fromLngLat(-73.989,40.733)) .reverseMode(GeocodingCriteria.REVERSE_MODE_SCORE) .build(); assertTrue(mapboxGeocoding.cloneCall().request().url().toString() .contains("reverseMode=score")); mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl("https://foobar.com") .query(Point.fromLngLat(-73.989,40.733)) .reverseMode(GeocodingCriteria.REVERSE_MODE_DISTANCE) .build(); assertTrue(mapboxGeocoding.cloneCall().request().url().toString() .contains("reverseMode=distance")); }
Example #11
Source Project: mapbox-java Author: mapbox File: MapboxDirectionsTest.java License: MIT License | 6 votes |
@Test public void callFactoryNonNull() throws IOException { MapboxDirections client = MapboxDirections.builder() .accessToken(ACCESS_TOKEN) .origin(Point.fromLngLat(1.0, 2.0)) .destination(Point.fromLngLat(5.0, 6.0)) .baseUrl(mockUrl.toString()) .build(); // Setting a null call factory doesn't make the request fail // (the default OkHttp client is used) client.setCallFactory(null); Response<DirectionsResponse> response = client.executeCall(); assertEquals(200, response.code()); assertEquals("Ok", response.body().code()); }
Example #12
Source Project: mapbox-java Author: mapbox File: MapboxDirectionsTest.java License: MIT License | 6 votes |
@Test public void withWaypointNames() throws Exception { List<String> names = new ArrayList<>(); names.add("Home"); names.add("Work"); MapboxDirections mapboxDirections = MapboxDirections.builder() .profile(PROFILE_CYCLING) .origin(Point.fromLngLat(-122.42,37.78)) .destination(Point.fromLngLat(-77.03,38.91)) .steps(true) .voiceInstructions(true) .voiceUnits(DirectionsCriteria.IMPERIAL) .waypointNames(names) .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) .build(); mapboxDirections.setCallFactory(null); Response<DirectionsResponse> response = mapboxDirections.executeCall(); assertEquals(200, response.code()); assertEquals("Ok", response.body().code()); }
Example #13
Source Project: mapbox-java Author: mapbox File: MapboxDirectionsTest.java License: MIT License | 6 votes |
@Test public void postIsUsed() { MapboxDirections.Builder builder = MapboxDirections.builder() .profile(PROFILE_CYCLING) .steps(true) .origin(Point.fromLngLat(-122.42,37.78)) .destination(Point.fromLngLat(-77.03,38.91)) .voiceInstructions(true) .voiceUnits(DirectionsCriteria.IMPERIAL) .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) .post(); retrofit2.Call<DirectionsResponse> call = builder.build().initializeCall(); assertEquals("POST", call.request().method()); }
Example #14
Source Project: mapbox-java Author: mapbox File: MapMatchingResponseTest.java License: MIT License | 6 votes |
@Before public void setUp() throws Exception { server = new MockWebServer(); server.setDispatcher(new okhttp3.mockwebserver.Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { try { String response = loadJsonFixture(MAP_MATCHING_FIXTURE); return new MockResponse().setBody(response); } catch (IOException ioException) { throw new RuntimeException(ioException); } } }); server.start(); mockUrl = server.url(""); coordinates = new ArrayList<>(); coordinates.add(Point.fromLngLat(13.418946862220764, 52.50055852688439)); coordinates.add(Point.fromLngLat(13.419011235237122, 52.50113000479732)); coordinates.add(Point.fromLngLat(13.419756889343262, 52.50171780290061)); coordinates.add(Point.fromLngLat(13.419885635375975, 52.50237416816131)); coordinates.add(Point.fromLngLat(13.420631289482117, 52.50294888790448)); }
Example #15
Source Project: mapbox-java Author: mapbox File: TurfMiscTest.java License: 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 #16
Source Project: graphhopper-navigation-android Author: graphhopper File: MeasurementUtilsTest.java License: MIT License | 5 votes |
@Test public void userTrueDistanceFromStep_onlyOnePointInLineStringStillMeasuresDistanceCorrectly() { Point futurePoint = Point.fromLngLat(-95.3676974, 29.7589382); List<Point> geometryPoints = new ArrayList<>(); geometryPoints.add(Point.fromLngLat(-95.8427, 29.7757)); double[] rawLocation = {0, 0}; LegStep step = getLegStep(rawLocation, geometryPoints); double distance = MeasurementUtils.userTrueDistanceFromStep(futurePoint, step); assertEquals(45900.73617999494, distance, DELTA); }
Example #17
Source Project: mapbox-java Author: mapbox File: MapboxOptimizationTest.java License: MIT License | 5 votes |
@Test public void build_noAccessTokenExceptionThrown() throws Exception { thrown.expect(IllegalStateException.class); thrown.expectMessage("Missing required properties: accessToken"); MapboxOptimization.builder() .coordinate(Point.fromLngLat(1.0, 1.0)) .coordinate(Point.fromLngLat(1.0, 1.0)) .build(); }
Example #18
Source Project: mapbox-java Author: mapbox File: PolylineUtils.java License: MIT License | 5 votes |
private static List<Point> simplifyDpStep( List<Point> points, int first, int last, double sqTolerance, List<Point> simplified) { double maxSqDist = sqTolerance; int index = 0; ArrayList<Point> stepList = new ArrayList<>(); for (int i = first + 1; i < last; i++) { double sqDist = getSqSegDist(points.get(i), points.get(first), points.get(last)); if (sqDist > maxSqDist) { index = i; maxSqDist = sqDist; } } if (maxSqDist > sqTolerance) { if (index - first > 1) { stepList.addAll(simplifyDpStep(points, first, index, sqTolerance, simplified)); } stepList.add(points.get(index)); if (last - index > 1) { stepList.addAll(simplifyDpStep(points, index, last, sqTolerance, simplified)); } } return stepList; }
Example #19
Source Project: mapbox-java Author: mapbox File: MapboxMapMatchingTest.java License: MIT License | 5 votes |
@Test public void sanityApproachesOptional() throws Exception { MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(1.0, 1.0)) .coordinate(Point.fromLngLat(2.0, 2.0)) .coordinate(Point.fromLngLat(3.0, 3.0)) .coordinate(Point.fromLngLat(4.0, 4.0)) .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .build(); assertNotNull(mapMatching); assertFalse(mapMatching.cloneCall().request().url().toString() .contains("approaches")); }
Example #20
Source Project: mapbox-java Author: mapbox File: TurfMetaTest.java License: MIT License | 5 votes |
@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 #21
Source Project: mapbox-java Author: mapbox File: TurfMeasurementTest.java License: MIT License | 5 votes |
@Test public void turfAlong_returnsZeroWhenRouteIsPoint() throws Exception { List<Point> coords = new ArrayList<>(); coords.add(Point.fromLngLat(1.0, 1.0)); LineString lineString = LineString.fromLngLats(coords); Point point = TurfMeasurement.along(lineString, 0, TurfConstants.UNIT_METERS); assertEquals(1.0, point.latitude(), DELTA); assertEquals(1.0, point.longitude(), DELTA); }
Example #22
Source Project: graphhopper-navigation-android Author: graphhopper File: NavigationViewModel.java License: MIT License | 5 votes |
@Override public void userOffRoute(Location location) { if (hasNetworkConnection()) { speechPlayer.onOffRoute(); Point newOrigin = Point.fromLngLat(location.getLongitude(), location.getLatitude()); sendEventOffRoute(newOrigin); } }
Example #23
Source Project: mapbox-java Author: mapbox File: TurfMiscTest.java License: MIT License | 5 votes |
@Test public void testTurfPointOnLinePointAlongLine() throws TurfException { List<Point> line = new ArrayList<>(); line.add(Point.fromLngLat(-122.45717525482178, 37.7200330638563)); line.add(Point.fromLngLat(-122.45717525482178, 37.718242366859215)); Point pt = TurfMeasurement.along( LineString.fromLngLats(line), 0.019, 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.00001); }
Example #24
Source Project: mapbox-java Author: mapbox File: OptimizationWaypointTest.java License: MIT License | 5 votes |
@Test public void testSerializable() throws IOException, ClassNotFoundException { MapboxOptimization client = MapboxOptimization.builder() .coordinate(Point.fromLngLat(1.0, 1.0)) .coordinate(Point.fromLngLat(2.0, 2.0)) .baseUrl(mockUrl.toString()) .accessToken("pk.XXX") .build(); Response<OptimizationResponse> response = client.executeCall(); byte[] bytes = serialize(response.body().waypoints().get(0)); assertEquals(response.body().waypoints().get(0), deserialize(bytes, OptimizationWaypoint.class)); }
Example #25
Source Project: graphhopper-navigation-android Author: graphhopper File: NavigationMapRoute.java License: MIT License | 5 votes |
void addUpcomingManeuverArrow(RouteProgress routeProgress) { boolean invalidUpcomingStepPoints = routeProgress.upcomingStepPoints() == null || routeProgress.upcomingStepPoints().size() < TWO_POINTS; boolean invalidCurrentStepPoints = routeProgress.currentStepPoints().size() < TWO_POINTS; if (invalidUpcomingStepPoints || invalidCurrentStepPoints) { updateArrowLayersVisibilityTo(false); return; } updateArrowLayersVisibilityTo(true); List<Point> maneuverPoints = obtainArrowPointsFrom(routeProgress); updateArrowShaftWith(maneuverPoints); updateArrowHeadWith(maneuverPoints); }
Example #26
Source Project: mapbox-java Author: mapbox File: TurfTransformation.java License: MIT License | 5 votes |
/** * Takes a {@link Point} and calculates the circle polygon given a radius in degrees, radians, * miles, or kilometers; and steps for precision. * * @param center a {@link Point} which the circle will center around * @param radius the radius of the circle * @param steps number of steps which make up the circle parameter * @param units one of the units found inside {@link TurfConstants.TurfUnitCriteria} * @return a {@link Polygon} which represents the newly created circle * @since 3.0.0 */ public static Polygon circle(@NonNull Point center, double radius, @IntRange(from = 1) int steps, @TurfConstants.TurfUnitCriteria String units) { List<Point> coordinates = new ArrayList<>(); for (int i = 0; i < steps; i++) { coordinates.add(TurfMeasurement.destination(center, radius, i * 360d / steps, units)); } if (coordinates.size() > 0) { coordinates.add(coordinates.get(0)); } List<List<Point>> coordinate = new ArrayList<>(); coordinate.add(coordinates); return Polygon.fromLngLats(coordinate); }
Example #27
Source Project: mapbox-java Author: mapbox File: TurfMiscTest.java License: MIT License | 5 votes |
@Test public void testTurfLineSliceLine2() throws TurfException { Point start = Point.fromLngLat(0, 0.1); Point stop = Point.fromLngLat(.9, .8); ArrayList<Point> coordinates = new ArrayList<>(); coordinates.add(Point.fromLngLat(0, 0)); coordinates.add(Point.fromLngLat(1, 1)); LineString line2 = LineString.fromLngLats(coordinates); LineString sliced = TurfMisc.lineSlice(start, stop, line2); assertNotNull(sliced); }
Example #28
Source Project: graphhopper-navigation-example Author: graphhopper File: FetchSolutionTask.java License: Apache License 2.0 | 5 votes |
@Override protected List<Point> doInBackground(FetchSolutionConfig... solutions) { if (solutions.length != 1) throw new IllegalArgumentException("It's only possible to fetch one solution at a time"); List<Point> points = new ArrayList<>(); SolutionApi api = new SolutionApi(); try { com.graphhopper.directions.api.client.model.Response res = api.getSolution(ghKey, solutions[0].jobId); List<Route> routes = res.getSolution().getRoutes(); for (Route route : routes) { if (route.getVehicleId().equals(solutions[0].vehicleId) || solutions[0].vehicleId == null) { // Found the right vehicle List<Activity> activities = route.getActivities(); for (int i = 0; i < activities.size(); i++) { Activity activity = activities.get(i); Address address = activity.getAddress(); points.add(Point.fromLngLat(address.getLon(), address.getLat())); } break; } } if (points.isEmpty()) callbackInterface.onError(R.string.error_vehicle_not_found); } catch (ApiException e) { callbackInterface.onError(R.string.error_fetching_solution); Timber.e(e, "An exception occured when fetching a solution with jobId %s", solutions[0].jobId); } return points; }
Example #29
Source Project: graphhopper-navigation-android Author: graphhopper File: DynamicCameraTest.java License: MIT License | 5 votes |
@Test public void noRouteInformation_engineCreatesEmptyOverviewPointList() { DynamicCamera cameraEngine = buildDynamicCamera(); RouteInformation routeInformation = RouteInformation.create(null, null, null); List<Point> overviewPoints = cameraEngine.overview(routeInformation); assertTrue(overviewPoints.isEmpty()); }
Example #30
Source Project: mapbox-java Author: mapbox File: MapboxMatrix.java License: MIT License | 5 votes |
private static String formatCoordinates(List<Point> coordinates) { List<String> coordinatesFormatted = new ArrayList<>(); for (Point point : coordinates) { coordinatesFormatted.add(String.format(Locale.US, "%s,%s", FormatUtils.formatCoordinate(point.longitude()), FormatUtils.formatCoordinate(point.latitude()))); } return TextUtils.join(";", coordinatesFormatted.toArray()); }