Skip to content

Instantly share code, notes, and snippets.

@jlaura
Last active August 29, 2015 14:00
Show Gist options
  • Save jlaura/11191702 to your computer and use it in GitHub Desktop.
Save jlaura/11191702 to your computer and use it in GitHub Desktop.
Parse the OSRM data file into NumPy objects.
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