use of com.graphhopper.ResponsePath in project graphhopper by graphhopper.
the class MapMatchingTest method testClosePoints.
/**
* This test is to check behavior over short tracks. GPX input:
* https://graphhopper.com/maps/?point=51.342422%2C12.3613358&point=51.3423281%2C12.3613358&layer=Lyrk
*/
@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testClosePoints(PMap hints) {
MapMatching mapMatching = new MapMatching(graphHopper, hints);
ResponsePath route = graphHopper.route(new GHRequest(new GHPoint(51.342422, 12.3613358), new GHPoint(51.342328, 12.3613358)).setProfile("my_profile")).getBest();
List<Observation> inputGPXEntries = createRandomGPXEntriesAlongRoute(route);
MatchResult mr = mapMatching.match(inputGPXEntries);
assertFalse(mr.getEdgeMatches().isEmpty());
assertEquals(3, mr.getMatchLength(), 1);
// GraphHopper travel times aren't exactly additive
assertThat(Math.abs(route.getTime() - mr.getMatchMillis()), is(lessThan(1000L)));
}
use of com.graphhopper.ResponsePath in project graphhopper by graphhopper.
the class GpxTravelTimeConsistencyTest method testGPXListTravelTimeConsistency.
@Test
public void testGPXListTravelTimeConsistency() {
GHPoint routeStart = new GHPoint(43.727687, 7.418737);
GHPoint routeEnd = new GHPoint(43.74958, 7.436566);
GHRequest request = new GHRequest(routeStart, routeEnd);
request.setProfile("profile");
ResponsePath path = hopper.route(request).getBest();
List<GpxConversions.GPXEntry> gpxList = GpxConversions.createGPXList(path.getInstructions());
for (GpxConversions.GPXEntry entry : gpxList) {
if (entry.getTime() != null) {
GHRequest requestForWaypoint = new GHRequest(routeStart, entry.getPoint());
requestForWaypoint.setProfile("profile");
ResponsePath partialPath = hopper.route(requestForWaypoint).getBest();
assertEquals(partialPath.getTime(), entry.getTime().longValue(), "GPXListEntry timeStamp is expected to be the same as route duration.");
}
}
}
use of com.graphhopper.ResponsePath in project graphhopper by graphhopper.
the class GHResponseTest method testHasNoErrorIfEmpty.
@Test
public void testHasNoErrorIfEmpty() {
assertFalse(new GHResponse().hasErrors());
GHResponse rsp = new GHResponse();
rsp.add(new ResponsePath());
assertFalse(rsp.hasErrors());
}
use of com.graphhopper.ResponsePath in project graphhopper by graphhopper.
the class NavigateResponseConverter method convertFromGHResponse.
/**
* Converts a GHResponse into a json that follows the Mapbox API specification
*/
public static ObjectNode convertFromGHResponse(GHResponse ghResponse, TranslationMap translationMap, Locale locale, DistanceConfig distanceConfig) {
ObjectNode json = JsonNodeFactory.instance.objectNode();
if (ghResponse.hasErrors())
throw new IllegalStateException("If the response has errors, you should use the method NavigateResponseConverter#convertFromGHResponseError");
PointList waypoints = ghResponse.getBest().getWaypoints();
final ArrayNode routesJson = json.putArray("routes");
List<ResponsePath> paths = ghResponse.getAll();
for (int i = 0; i < paths.size(); i++) {
ResponsePath path = paths.get(i);
ObjectNode pathJson = routesJson.addObject();
putRouteInformation(pathJson, path, i, translationMap, locale, distanceConfig);
}
final ArrayNode waypointsJson = json.putArray("waypoints");
for (int i = 0; i < waypoints.size(); i++) {
ObjectNode waypointJson = waypointsJson.addObject();
// TODO get names
waypointJson.put("name", "");
putLocation(waypoints.getLat(i), waypoints.getLon(i), waypointJson);
}
json.put("code", "Ok");
// TODO: Maybe we need a different format... uuid: "cji4ja4f8004o6xrsta8w4p4h"
json.put("uuid", UUID.randomUUID().toString().replaceAll("-", ""));
return json;
}
Aggregations