Search in sources :

Example 6 with MatchResult

use of com.graphhopper.matching.MatchResult in project graphhopper by graphhopper.

the class MapMatching2Test method testIssue13.

@Test
public void testIssue13() throws IOException {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile("../map-matching/files/map-issue13.osm.gz");
    hopper.setGraphHopperLocation(GH_LOCATION);
    hopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    hopper.importOrLoad();
    MapMatching mapMatching = new MapMatching(hopper, new PMap().putObject("profile", "my_profile"));
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/issue-13.gpx"), Gpx.class);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    // make sure no virtual edges are returned
    int edgeCount = hopper.getGraphHopperStorage().getAllEdges().length();
    for (EdgeMatch em : mr.getEdgeMatches()) {
        assertTrue(em.getEdgeState().getEdge() < edgeCount, "result contains virtual edges:" + em.getEdgeState().toString());
        validateEdgeMatch(em);
    }
    assertEquals(mr.getGpxEntriesLength(), mr.getMatchLength(), 2.5);
    assertEquals(28790, mr.getMatchMillis(), 50);
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) EdgeMatch(com.graphhopper.matching.EdgeMatch) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) MatchResult(com.graphhopper.matching.MatchResult) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Gpx(com.graphhopper.jackson.Gpx) Test(org.junit.jupiter.api.Test)

Example 7 with MatchResult

use of com.graphhopper.matching.MatchResult in project graphhopper by graphhopper.

the class MapMatching2Test method testIssue70.

@Test
public void testIssue70() throws IOException {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile("../map-matching/files/issue-70.osm.gz");
    hopper.setGraphHopperLocation(GH_LOCATION);
    hopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    hopper.importOrLoad();
    MapMatching mapMatching = new MapMatching(hopper, new PMap().putObject("profile", "my_profile"));
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/issue-70.gpx"), Gpx.class);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    assertEquals(Arrays.asList("Милана Видака", "Бранка Радичевића", "Здравка Челара"), fetchStreets(mr.getEdgeMatches()));
    for (EdgeMatch edgeMatch : mr.getEdgeMatches()) {
        validateEdgeMatch(edgeMatch);
    }
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) EdgeMatch(com.graphhopper.matching.EdgeMatch) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) MatchResult(com.graphhopper.matching.MatchResult) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Gpx(com.graphhopper.jackson.Gpx) Test(org.junit.jupiter.api.Test)

Example 8 with MatchResult

use of com.graphhopper.matching.MatchResult in project graphhopper by graphhopper.

the class ExtendedJsonResponseTest method shouldCreateBasicStructure.

@Test
public void shouldCreateBasicStructure() {
    JsonNode jsonObject = MapMatchingResource.convertToTree(new MatchResult(getEdgeMatch()), false, false);
    JsonNode route = jsonObject.get("diary").get("entries").get(0);
    JsonNode link = route.get("links").get(0);
    JsonNode geometry = link.get("geometry");
    assertEquals("LineString", geometry.get("type").asText(), "geometry should have type");
    assertEquals("LINESTRING (-38.999 -3.4445, -38.799 -3.555)", geometry.get("coordinates").asText(), "geometry should have coordinates");
    assertEquals("-3.4446", link.get("wpts").get(0).get("y").asText(), "wpts[0].y should exists");
    assertEquals("-38.9996", link.get("wpts").get(0).get("x").asText(), "wpts[0].x should exists");
    assertEquals("-3.4449", link.get("wpts").get(1).get("y").asText(), "wpts[1].y should exists");
    assertEquals("-38.9999", link.get("wpts").get(1).get("x").asText(), "wpts[1].x should exists");
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MatchResult(com.graphhopper.matching.MatchResult) Test(org.junit.jupiter.api.Test)

Example 9 with MatchResult

use of com.graphhopper.matching.MatchResult in project graphhopper by graphhopper.

the class MapMatching2Test method testIssue127.

@Test
public void testIssue127() throws IOException {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile("../map-matching/files/map-issue13.osm.gz");
    hopper.setGraphHopperLocation(GH_LOCATION);
    hopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    hopper.importOrLoad();
    MapMatching mapMatching = new MapMatching(hopper, new PMap().putObject("profile", "my_profile"));
    // query with two identical points
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/issue-127.gpx"), Gpx.class);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    // make sure no virtual edges are returned
    int edgeCount = hopper.getGraphHopperStorage().getAllEdges().length();
    for (EdgeMatch em : mr.getEdgeMatches()) {
        assertTrue(em.getEdgeState().getEdge() < edgeCount, "result contains virtual edges:" + em.getEdgeState().toString());
        validateEdgeMatch(em);
    }
    assertEquals(0, mr.getMatchMillis(), 50);
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) EdgeMatch(com.graphhopper.matching.EdgeMatch) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) MatchResult(com.graphhopper.matching.MatchResult) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Gpx(com.graphhopper.jackson.Gpx) Test(org.junit.jupiter.api.Test)

Example 10 with MatchResult

use of com.graphhopper.matching.MatchResult 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)

Aggregations

MatchResult (com.graphhopper.matching.MatchResult)12 MapMatching (com.graphhopper.matching.MapMatching)11 Gpx (com.graphhopper.jackson.Gpx)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)7 PMap (com.graphhopper.util.PMap)5 GraphHopper (com.graphhopper.GraphHopper)4 ResponsePath (com.graphhopper.ResponsePath)4 EdgeMatch (com.graphhopper.matching.EdgeMatch)4 Observation (com.graphhopper.matching.Observation)4 Test (org.junit.jupiter.api.Test)4 GHRequest (com.graphhopper.GHRequest)3 LMProfile (com.graphhopper.config.LMProfile)3 Profile (com.graphhopper.config.Profile)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 GraphHopperConfig (com.graphhopper.GraphHopperConfig)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1