This is a quick python wrapper for the Valhalla service from MapZen
pip install valhallapy
from valhalla import Valhalla
valhalla = Valhalla(host="http://192.168.99.100:5333")
start = {'lat': '', 'lon':''}
end = {'lat':'', 'lon':''}
route = valhalla.route(start, end, costing='pedestrian')
print 'that route as %d km long and took %d s ' %(route.distance(), route.time())
print 'GEOJSON %s' % ((route.geoJSON())
To connect to a server initialize a valhalla object
from valhalla import Valhalla
valhalla = Valhalla(host="http://192.168.99.100:5333", api_key="")
where the api key is optional (get your api keys here if you are running locally. Once you have a connection, request a route by
Request a route using the following
route = valhalla.route(start, end, costing)
where costing can be 'pedestrian', 'auto' etc (full list of costing models).
This returns a ValhallaRoute object which can be interegated for information about the returned route
route.time() # The time in seconds the route will take
route.distance() # The distance in km the route was
route.instructions() # A set of turn by turn instructions for the route
route.geoJSON(parameters=[]) # Return the route as geojson appending extra parameters in the optional parameters argument
- refactor
- create a method to do batches of routes
- change the route method to allow for multiple waypoints