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());
}
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);
}
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);
}
}
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;
}
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);
}
Aggregations