Map matching load osm file error

I convert a .shp file to .osm format, and I want to do map matching base on this osm file.
but when I import the graph (MapMatchingMain’s import action), it tells me :

2016-10-26 15:30:22,157 [main] INFO  com.graphhopper.matching.MapMatchingMain - Configuration: {action=import, datasource=F:\\a_road.osm, graph.location=./graph-cache, graph.flag_encoders=car, datareader.file=F:\\a_road.osm, prepare.min_one_way_network_size=200}
2016-10-26 15:30:22,731 [main] INFO  com.graphhopper.reader.osm.GraphHopperOSM - version 0.8|2016-10-21T11:43:53Z (5,14,4,3,3,2)
2016-10-26 15:30:22,754 [main] INFO  com.graphhopper.reader.osm.GraphHopperOSM - graph car|RAM_STORE|2D|NoExt|,,,,, details:edges:0(0MB), nodes:0(0MB), name:(0MB), geo:0(0MB), bounds:1.7976931348623157E308,-1.7976931348623157E308,1.7976931348623157E308,-1.7976931348623157E308
2016-10-26 15:30:22,816 [main] INFO  com.graphhopper.reader.osm.GraphHopperOSM - start creating graph from F:\\a_road.osm
2016-10-26 15:30:22,816 [main] INFO  com.graphhopper.reader.osm.GraphHopperOSM - using car|RAM_STORE|2D|NoExt|,,,,, memory:totalMB:57, usedMB:14
2016-10-26 15:30:23,374 [main] INFO  com.graphhopper.reader.osm.OSMReader - creating graph. Found nodes (pillar+tower):0, totalMB:57, usedMB:10
2016-10-26 15:30:23,488 [main] INFO  com.graphhopper.reader.osm.OSMReader - 7 189, now parsing ways
Exception in thread "main" java.lang.IllegalStateException: osm must not be empty. read 10164 lines and 0 locations
	at com.graphhopper.reader.osm.OSMReader.writeOsm2Graph(OSMReader.java:309)
	at com.graphhopper.reader.osm.OSMReader.readGraph(OSMReader.java:150)
	at com.graphhopper.GraphHopper.importData(GraphHopper.java:712)
	at com.graphhopper.GraphHopper.process(GraphHopper.java:681)
	at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:659)
	at com.graphhopper.matching.MapMatchingMain.start(MapMatchingMain.java:67)
	at com.graphhopper.matching.MapMatchingMain.main(MapMatchingMain.java:43)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
2016-10-26 15:30:23,775 [main] INFO  com.graphhopper.reader.osm.OSMReader - finished way processing. nodes: 0, osmIdMap.size:0, osmIdMap:0MB, nodeFlagsMap.size:0, relFlagsMap.size:0, zeroCounter:0 totalMB:72, usedMB:10 

It looks like the OSMReader can not find nodes or locations in my osm file. But I check the file, it has and items.
And it do not has item, I am not sure .shp file have ‘relations’?
what should I do to work it out?

As we take into account only OSM ways with certain highway tags make sure you attach e.g. highway=primary to every road that you need.

Thanks! it really works.
another relative question, if I add “highway” tag to way element, what value should I choose?
I browse a normal osm file exported from openstreetmap, there are many values of highway, like “trunck”, “primary_link”, “service”, “trunk_link”…what’s the meaning of each value and how can i decide each way’s highway result when convert a shp file?

See https://wiki.openstreetmap.org/wiki/Key:highway

1 Like

Thanks! this help me a lot!

Hi, I repeated a convert work and insure every way element has a highway tag. but graphhopper report another exception:
Exception in thread "main" java.lang.RuntimeException: Problem while parsing file at com.graphhopper.reader.osm.OSMReader.preProcess(OSMReader.java:205) at com.graphhopper.reader.osm.OSMReader.readGraph(OSMReader.java:146) at com.graphhopper.GraphHopper.importData(GraphHopper.java:712) at com.graphhopper.GraphHopper.process(GraphHopper.java:681) at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:659) at com.graphhopper.matching.MapMatchingMain.start(MapMatchingMain.java:67) at com.graphhopper.matching.MapMatchingMain.main(MapMatchingMain.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) **Caused by: java.lang.IllegalArgumentException: Illegal key -1** at com.graphhopper.coll.GHLongIntBTree.put(GHLongIntBTree.java:96) at com.graphhopper.reader.osm.OSMReader.prepareHighwayNode(OSMReader.java:583) at com.graphhopper.reader.osm.OSMReader.preProcess(OSMReader.java:178) ... 11 more

Then I look into com.graphhopper.coll.GHLongIntBTree, it has a “noNumberValue”, and value is -1.
And I found there is a Node’s id is -1 in my osm file.
If I change this node’s id to another number, all data will be processed normally.
my question is , why Node’s id can not be -1?

As you pointed out: we use this negative value in the map as “empty” markers.