Search in sources :

Example 1 with EdgeMatch

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

the class MapMatchingTest method testDoWork.

/**
 * TODO: split this test up into smaller units with better names?
 */
@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testDoWork(PMap hints) {
    MapMatching mapMatching = new MapMatching(graphHopper, hints);
    ResponsePath route2 = graphHopper.route(new GHRequest(new GHPoint(51.358735, 12.360574), new GHPoint(51.358594, 12.360032)).setProfile("my_profile")).getBest();
    List<Observation> inputGPXEntries = createRandomGPXEntriesAlongRoute(route2);
    MatchResult mr = mapMatching.match(inputGPXEntries);
    // make sure no virtual edges are returned
    int edgeCount = graphHopper.getGraphHopperStorage().getAllEdges().length();
    for (EdgeMatch em : mr.getEdgeMatches()) {
        assertTrue(em.getEdgeState().getEdge() < edgeCount, "result contains virtual edges:" + em.getEdgeState().toString());
    }
    // create street names
    assertEquals(Arrays.asList("Platnerstraße"), fetchStreets(mr.getEdgeMatches()));
    assertEquals(mr.getGpxEntriesLength(), mr.getMatchLength(), 1.5);
    ResponsePath route1 = graphHopper.route(new GHRequest(new GHPoint(51.33099, 12.380267), new GHPoint(51.330531, 12.380396)).setProfile("my_profile")).getBest();
    inputGPXEntries = createRandomGPXEntriesAlongRoute(route1);
    mapMatching.setMeasurementErrorSigma(5);
    mr = mapMatching.match(inputGPXEntries);
    assertEquals(Arrays.asList("Windmühlenstraße", "Bayrischer Platz"), fetchStreets(mr.getEdgeMatches()));
    assertEquals(mr.getGpxEntriesLength(), mr.getMatchLength(), .1);
    ResponsePath route = graphHopper.route(new GHRequest(new GHPoint(51.377781, 12.338333), new GHPoint(51.323317, 12.387085)).setProfile("my_profile")).getBest();
    inputGPXEntries = createRandomGPXEntriesAlongRoute(route);
    mapMatching = new MapMatching(graphHopper, hints);
    mapMatching.setMeasurementErrorSigma(20);
    mr = mapMatching.match(inputGPXEntries);
    assertEquals(route.getDistance(), mr.getMatchLength(), 0.5);
    // GraphHopper travel times aren't exactly additive
    assertThat(Math.abs(route.getTime() - mr.getMatchMillis()), is(lessThan(1000L)));
    assertEquals(142, mr.getEdgeMatches().size());
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) ResponsePath(com.graphhopper.ResponsePath) EdgeMatch(com.graphhopper.matching.EdgeMatch) GHRequest(com.graphhopper.GHRequest) Observation(com.graphhopper.matching.Observation) GHPoint(com.graphhopper.util.shapes.GHPoint) MatchResult(com.graphhopper.matching.MatchResult) GHPoint(com.graphhopper.util.shapes.GHPoint) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 2 with EdgeMatch

use of com.graphhopper.matching.EdgeMatch 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 3 with EdgeMatch

use of com.graphhopper.matching.EdgeMatch 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 4 with EdgeMatch

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

the class ExtendedJsonResponseTest method getEdgeMatch.

private List<EdgeMatch> getEdgeMatch() {
    List<EdgeMatch> list = new ArrayList<>();
    list.add(new EdgeMatch(getEdgeIterator(), getGpxExtension()));
    return list;
}
Also used : EdgeMatch(com.graphhopper.matching.EdgeMatch) ArrayList(java.util.ArrayList)

Example 5 with EdgeMatch

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

Aggregations

EdgeMatch (com.graphhopper.matching.EdgeMatch)6 MapMatching (com.graphhopper.matching.MapMatching)4 MatchResult (com.graphhopper.matching.MatchResult)4 GraphHopper (com.graphhopper.GraphHopper)3 LMProfile (com.graphhopper.config.LMProfile)3 Profile (com.graphhopper.config.Profile)3 Gpx (com.graphhopper.jackson.Gpx)3 PMap (com.graphhopper.util.PMap)3 Test (org.junit.jupiter.api.Test)3 GHPoint (com.graphhopper.util.shapes.GHPoint)2 ArrayList (java.util.ArrayList)2 GHRequest (com.graphhopper.GHRequest)1 ResponsePath (com.graphhopper.ResponsePath)1 Observation (com.graphhopper.matching.Observation)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)1