Hello,
My intention was to evaluate if Graph Hopper Map Matching can be used for our project, where we have to match GPS tracks with road system/OSM. As a first step I started with the demo code as described in “github.com/graphhopper/map-matching#java-usage”. (sorry there are only 2 links per topic allewed for new members…)
I created a maven project in eclipse and ended up in following compile errors:
(see also the maven/dependency specified)
Please refer to the following screenshots for more detailed information:
source code
maven/dependency
I am wondering if this is caused by a version mismatch, but have no idea how this can be resolved?!
Do you have any hint for these problems?
Many thanks in advance!
The source code, Java demo/snippet :
import java.util.List;
import com.graphhopper.GraphHopper;
import com.graphhopper.matching.EdgeMatch;
import com.graphhopper.matching.GPXFile;
import com.graphhopper.matching.LocationIndexMatch;
import com.graphhopper.matching.MapMatching;
import com.graphhopper.routing.util.CarFlagEncoder;
import com.graphhopper.storage.GraphStorage;
public class MapMatcher {
// import OpenStreetMap data
public MapMatcher() {
super();
// TODO Auto-generated constructor stub
GraphHopper hopper = new GraphHopper();
hopper.setOSMFile("./map-data/leipzig_germany.osm.pbf");
hopper.setGraphHopperLocation("./target/mapmatchingtest");
CarFlagEncoder encoder = new CarFlagEncoder();
hopper.setEncodingManager(new EncodingManager(encoder));
hopper.setCHEnable(false);
hopper.importOrLoad();
// create MapMatching object, can and should be shared accross threads
GraphStorage graph = hopper.getGraph();
LocationIndexMatch locationIndex = new LocationIndexMatch(graph,
(LocationIndexTree) hopper.getLocationIndex());
locationIndex.prepareIndex();
MapMatching mapMatching = new MapMatching(graph, locationIndex, encoder);
// do the actual matching, get the GPX entries from a file or via stream
List<GPXEntry> inputGPXEntries = new GPXFile("nice.gpx").read();
MatchResult mr = mapMatching.doWork(inputGPXEntries);
// return GraphHopper edges with all associated GPX entries
List<EdgeMatch> matches = mr.getEdgeMatches();
// now do something with the edges like storing the edgeIds or doing fetchWayGeometry etc
matches.get(0).edgeState,
}
later I tried to fix compile errors by changing the demo source code as listed below:
public MapMatcher() {
super();
// TODO Auto-generated constructor stub
// import OpenStreetMap data
GraphHopper hopper = new GraphHopper();
hopper.setOSMFile("./map-data/leipzig_germany.osm.pbf");
hopper.setGraphHopperLocation("./target/mapmatchingtest");
CarFlagEncoder encoder = new CarFlagEncoder();
hopper.setEncodingManager(new EncodingManager(encoder));
hopper.setCHEnable(false);
hopper.importOrLoad();
// create MapMatching object, can and should be shared accross threads
GraphHopperStorage graph = hopper.getGraphHopperStorage();
LocationIndexMatch locationIndex = new LocationIndexMatch(graph,
(LocationIndexTree) hopper.getLocationIndex());
locationIndex.prepareIndex();
MapMatching mapMatching = new MapMatching(graph, locationIndex, encoder);
// do the actual matching, get the GPX entries from a file or via stream
GPXFile gpxFile = new GPXFile();
gpxFile.doImport("nice.gpx");
List<GPXEntry> inputGPXEntries = (new GPXFile()).getEntries();
MatchResult mr = mapMatching.doWork(inputGPXEntries);
// return GraphHopper edges with all associated GPX entries
List<EdgeMatch> matches = mr.getEdgeMatches();
// now do something with the edges like storing the edgeIds or doing fetchWayGeometry etc
matches.get(0).getEdgeState();
}
but this resulted in the following exception/stacktrace:
2015-10-06 17:07:25,329 [main] INFO com.graphhopper.GraphHopper - version 0.5.0|2015-08-12T12:33:51+0000 (4,12,3,2,2,1)
2015-10-06 17:07:25,335 [main] INFO com.graphhopper.GraphHopper - graph car|RAM_STORE|2D|NoExt|4,12,3,2,2, details:edges:74 567(3MB), nodes:53 723(1MB), name:(1MB), geo:232 915(1MB), bounds:16.243235943687765,16.818523224112166,47.96737744586268,48.397507855240434
Exception in thread “main” java.lang.IllegalThreadStateException: already created
at com.graphhopper.storage.RAMDataAccess.create(RAMDataAccess.java:87)
at com.graphhopper.storage.RAMDataAccess.create(RAMDataAccess.java:34)
at com.graphhopper.storage.index.LocationIndexTree.prepareIndex(LocationIndexTree.java:320)
at vbtmm.MapMatcher.(MapMatcher.java:39)
at vbtmm.main.main(main.java:17)