Last active
August 29, 2015 14:00
-
-
Save jlaura/11191702 to your computer and use it in GitHub Desktop.
Parse the OSRM data file into NumPy objects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from struct import unpack | |
import numpy as np | |
import sys | |
#OSRM data type - nodes | |
node_dtype = np.dtype([('lat', '<i'), ('long', '<i'), ('id', '<I'), ('Flags', '<i')]) | |
#Reading the .osrm file | |
f = open(sys.argv[1]) | |
f.seek(156) # Skip the header | |
numnodes = unpack('<I', f.read(4))[0] | |
osrm_node_data = np.fromfile(f, dtype=node_dtype, count=numnodes) | |
numedges = unpack('<I', f.read(4))[0] | |
edge_dtype = np.dtype([('source', '<I'),('dest', '<I'), ('length', '<i'), | |
('direction','<h'), ('weight', '<i'),('edge_type', '<h'), | |
('street_index', '<I'), ('flags', '<I')]) | |
osrm_edge_data = np.fromfile(f, dtype=edge_dtype, count = numedges) | |
print "OSRM file contains {} nodes and {} edges".format(numnodes, numedges) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment