What I want to do:
I want to get road graph (ways and their relations) from OSM file to write my own routing program.
What I tried to do:
I tried to use OSMtoRoadGraph, but it returns me a UnicodeDecodeError
(base) C:\Windows\system32>python
C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\run.py -f
C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\data\siberian-fed-district-latest.osm_01_01.osm -n c
starting convert_osm_to_roadgraph
selected network type: car
accepted highway tags: {'pedestrian': {'path', 'secondary_link', 'footway', 'secondary', 'tertiary_link', 'pedestrian', 'track', 'primary', 'tertiary', 'primary_link', 'unclassified', 'road', 'steps', 'service', 'living_street', 'residential'}, 'bicycle': {'secondary_link', 'secondary', 'tertiary_link', 'cycleway', 'track', 'primary', 'tertiary', 'primary_link', 'unclassified', 'road', 'path', 'service', 'living_street', 'residential'}, 'car': {'secondary_link', 'motorway', 'motorway_link', 'secondary', 'trunk', 'tertiary_link', 'trunk_link', 'primary', 'tertiary', 'primary_link', 'unclassified', 'service', 'living_street', 'residential'}}
opening file: C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\data\siberian-fed-district-latest.osm_01_01.osm
starting read_file
starting _read_ways
0%..Traceback (most recent call last):
File "C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\run.py", line 65, in <module>
convert_osm_to_roadgraph(filename, network_type, options)
File "C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\utils\timer.py", line 11, in wrapper
result = function(*args, **kwargs)
File "C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\run.py", line 25, in convert_osm_to_roadgraph
nodes, ways = osm.read_osm.read_file(filename, configuration)
File "C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\utils\timer.py", line 11, in wrapper
result = function(*args, **kwargs)
File "C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\osm\read_osm.py", line 11, in read_file
ways, found_node_ids = _read_ways(PercentageFile(osm_filename), parserHelper)
File "C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\utils\timer.py", line 11, in wrapper
result = function(*args, **kwargs)
File "C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\osm\read_osm.py", line 23, in _read_ways
parser.parse(osm_file)
File "C:\ProgramData\Anaconda3\lib\xml\sax\expatreader.py", line 111, in parse
xmlreader.IncrementalParser.parse(self, source)
File "C:\ProgramData\Anaconda3\lib\xml\sax\xmlreader.py", line 123, in parse
buffer = file.read(self._bufsize)
File "C:\Users\Horseman.mini\Desktop\OsmToRoadGraph-master\osm\xml_handler.py", line 25, in read
data = self.f.read(size)
File "C:\ProgramData\Anaconda3\lib\encodings\cp1251.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 993: character maps to <undefined>
I think the problem is that OSM uses utf-8 format, but I see in the error this line at the very end "C:\ProgramData\Anaconda3\lib\encodings\cp1251.py", line 23, in decode
so unicode error is predictable. If no ways to solve unicode problem or any ways to fix this problem using this soft - I haven't found any other ways to import roads graph from OSM.