Hey there,
we have created a small Java project which takes GPS tracks from a PostGIS database, sends it to the GraphHopper MapMatching v8.2 and imports the matched track back into the database.
When I check the result in QGIS I can see, that the geometry has changed, but it is not matched against the OSM road network (blue is original, orange is the match result)
I suppose we do not use the the map matching class correctly. Here is our code:
public class MapMatcher {
private static GraphHopperOSM hopper;
private CarFlagEncoder encoder;
private AlgorithmOptions opts;
private void MapMatcher() {
encoder = new CarFlagEncoder();
hopper = new GraphHopperOSM();
hopper.setDataReaderFile("./src/main/resources/Dresden.osm.pbf");
hopper.setGraphHopperLocation("./src/main/resources/carTrack-gh");
hopper.setEncodingManager(new EncodingManager(encoder));
hopper.getCHFactoryDecorator().setEnabled(false);
hopper.importOrLoad();
opts = AlgorithmOptions.start()
.algorithm(Parameters.Algorithms.DIJKSTRA_BI).traversalMode(hopper.getTraversalMode())
.weighting(new FastestWeighting(encoder))
.maxVisitedNodes(1000)
.hints(new HintsMap().put("weighting", "fastest").put("vehicle", encoder.toString()))
.build();
}
public List<GPXEntry> doMapMatching(List<GPXEntry> gpxUnmatched) {
List<GPXEntry> gpxMatched = new ArrayList<GPXEntry>();
MapMatching mapMatching = new MapMatching(hopper, opts);
mapMatching.setMeasurementErrorSigma(50);
MatchResult mr = null;
try {
mr = mapMatching.doWork(gpxUnmatched);
}
catch (Exception ex) {
System.out.println("MapMatching error");
return null;
}
List<EdgeMatch> matches = mr.getEdgeMatches();
// finally transform EdgeMatch list to list of gpxEntries
for (EdgeMatch edgeMatch : matches) {
List<GPXExtension> gpxExtensions = edgeMatch.getGpxExtensions();
// add matched gpx to the list
for (GPXExtension gpxExtension : gpxExtensions) {
gpxMatched.add(gpxExtension.getEntry());
}
}
return gpxMatched;
}
}
The track on the screenshot has the following input values:
longitude:13.757166862487793; latitude:51.02519607543945; time:1414499495000 longitude:13.757805824279785; latitude:51.024723052978516; time:1414499500000 longitude:13.758500099182129; latitude:51.02427673339844; time:1414499505000 longitude:13.759222030639648; latitude:51.0238037109375; time:1414499510000 longitude:13.759944915771484; latitude:51.02336120605469; time:1414499515000 longitude:13.760777473449707; latitude:51.02288818359375; time:1414499520000 longitude:13.761638641357422; latitude:51.02244567871094; time:1414499525000 longitude:13.762527465820312; latitude:51.02199935913086; time:1414499530000 longitude:13.763416290283203; latitude:51.021610260009766; time:1414499535000 longitude:13.764277458190918; latitude:51.021305084228516; time:1414499540000 longitude:13.765193939208984; latitude:51.020999908447266; time:1414499545000
I hope that I just made an obvious mistake
Thx in advance
Felix