Search in sources :

Example 26 with ResponsePath

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)));
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) ResponsePath(com.graphhopper.ResponsePath) GHRequest(com.graphhopper.GHRequest) Observation(com.graphhopper.matching.Observation) GHPoint(com.graphhopper.util.shapes.GHPoint) MatchResult(com.graphhopper.matching.MatchResult) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 27 with ResponsePath

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.");
        }
    }
}
Also used : ResponsePath(com.graphhopper.ResponsePath) GHRequest(com.graphhopper.GHRequest) GpxConversions(com.graphhopper.gpx.GpxConversions) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.jupiter.api.Test)

Example 28 with ResponsePath

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());
}
Also used : ResponsePath(com.graphhopper.ResponsePath) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 29 with ResponsePath

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ResponsePath(com.graphhopper.ResponsePath) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ResponsePath (com.graphhopper.ResponsePath)29 GHResponse (com.graphhopper.GHResponse)15 GHRequest (com.graphhopper.GHRequest)13 GHPoint (com.graphhopper.util.shapes.GHPoint)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 Test (org.junit.jupiter.api.Test)7 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 MapMatching (com.graphhopper.matching.MapMatching)4 MatchResult (com.graphhopper.matching.MatchResult)4 Observation (com.graphhopper.matching.Observation)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Path (com.graphhopper.routing.Path)3 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)3 Snap (com.graphhopper.storage.index.Snap)3 PathDetail (com.graphhopper.util.details.PathDetail)3 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2