Routingpy Readthedocs Io en Latest
Routingpy Readthedocs Io en Latest
Release 0.3.0
1 Installation 3
2 Routers 5
2.1 Default Options Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Google . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Graphhopper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.4 HereMaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.5 MapboxOSRM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.6 MapboxValhalla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.7 ORS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.8 OSRM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.9 Valhalla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3 Data 41
4 Exceptions 45
5 Changelog 47
Index 53
i
ii
RoutingPy, Release 0.3.0
Documentation https://routingpy.readthedocs.io/
Source Code https://github.com/gis-ops/routing-py
Issue Tracker https://github.com/gis-ops/routing-py/issues
Stack Overflow https://stackoverflow.com/questions/tagged/routingpy
PyPI https://pypi.org/project/routingpy
Conda https://conda.org/gis-ops/routingpy
MyBinder Interactive Examples https://mybinder.org/v2/gh/gis-ops/routing-py/master?filepath=
examples
routingpy is a Python 3 client for a lot of popular web routing services.
Using routingpy you can easily request directions, isochrones and matrices from many reliable online providers
in a consistent fashion. Base parameters are the same for all services, while still preserving each service’s special
parameters (for more info, please look at our README. Take a look at our Examples to see how simple you can
compare routes from different providers.
routingpy is tested against 3.5, 3.6, 3.7 and PyPy3.
Contents 1
RoutingPy, Release 0.3.0
2 Contents
CHAPTER 1
Installation
3
RoutingPy, Release 0.3.0
4 Chapter 1. Installation
CHAPTER 2
Routers
Every routing service below has a separate module in routingpy.routers, which hosts a class which bases
routingpy.routers.base.Router astracting the service’s API. Each router has at least a directions
method, many offer additionally matrix and/or isochrones methods. Other available provider endpoints are
allowed and generally encouraged. However, please refer to our contribution guidelines for general instructions.
routingpy’s dogma is, that all routers expose the same mandatory arguments for common methods in an attempt to
be consistent for the same method across different routers. Unlike other collective libraries, we additionally chose to
preserve each router’s special arguments, only abstracting the most basic arguments, such as locations and profile (car,
bike, pedestrian etc.), among others (full list here).
routingpy.routers.get_router_by_name(router_name)
Given a router’s name, try to return the router class.
class routingpy.routers.options
Contains default configuration options for all routers, e.g. timeout and proxies. Each router can take the same
configuration values, which will override the values set in options object.
Example for overriding default values for user_agent and proxies:
5
RoutingPy, Release 0.3.0
Attributes:
self.default_timeout: Combined connect and read timeout for HTTP requests, in seconds. Specify
“None” for no timeout. Integer.
self.default_retry_timeout: Timeout across multiple retriable requests, in seconds. Integer.
self.default_retry_over_query_limit: If True, client will not raise an exception on HTTP 429, but instead
jitter a sleeping timer to pause between requests until HTTP 200 or retry_timeout is reached. Boolean.
self.default_skip_api_error: Continue with batch processing if a routingpy.exceptions.
RouterApiError is encountered (e.g. no route found). If False, processing will discontinue and
raise an error. Boolean.
self.default_user_agent: User-Agent to send with the requests to routing API. String.
self.default_proxies: Proxies passed to the requests library. Dictionary.
default_proxies = None
default_retry_over_query_limit = True
default_retry_timeout = 60
default_skip_api_error = False
default_timeout = 60
default_user_agent = 'routingpy/v0.3.0'
2.2 Google
6 Chapter 2. Routers
RoutingPy, Release 0.3.0
• timeout (int or None) – Combined connect and read timeout for HTTP requests,
in seconds. Specify None for no timeout. Default routingpy.routers.options.
default_timeout.
• retry_timeout (int) – Timeout across multiple retriable requests, in seconds. De-
fault routingpy.routers.options.default_retry_timeout.
• requests_kwargs (dict) – Extra keyword arguments for the requests library, which
among other things allow for proxy auth to be implemented. Note, that proxies can be
set globally in routingpy.routers.options.default_proxies.
Example:
2.2. Google 7
RoutingPy, Release 0.3.0
• alternatives (bool) – Specifies whether more than one route should be returned.
Only available for requests without intermediate waypoints. Default False.
• avoid – Indicates that the calculated route(s) should avoid the indicated features. One or
more of [‘tolls’, ‘highways’, ‘ferries’, ‘indoor’]. Default None.
• avoid – list of str
• optimize (bool) – Optimize the given order of via waypoints (i.e. between first and
last location). Default False.
• language (str) – Language for routing instructions. The locale of the resulting turn
instructions. Visit https://developers.google.com/maps/faq#languagesupport for options.
• region (str) – Specifies the region code, specified as a ccTLD (“top-level domain”)
two-character value. See https://developers.google.com/maps/documentation/directions/
intro#RegionBiasing.
• units (str) – Specifies the unit system to use when displaying results. One of [‘metric’,
‘imperial’].
• arrival_time (int) – Specifies the desired time of arrival for transit directions, in
seconds since midnight, January 1, 1970 UTC. Incompatible with departure_time.
• departure_time – Specifies the desired time of departure. You can specify the time
as an integer in seconds since midnight, January 1, 1970 UTC.
• traffic_model (str) – Specifies the assumptions to use when calculating time in
traffic. One of [‘best_guess’, ‘pessimistic’, ‘optimistic’. See https://developers.google.
com/maps/documentation/directions/intro#optional-parameters for details.
• transit_mode (list/tuple of str) – Specifies one or more preferred modes of
transit. One or more of [‘bus’, ‘subway’, ‘train’, ‘tram’, ‘rail’].
• transit_routing_preference (str) – Specifies preferences for transit routes.
Using this parameter, you can bias the options returned, rather than accepting the default
best route chosen by the API. One of [‘less_walking’, ‘fewer_transfers’].
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns One or multiple route(s) from provided coordinates and restrictions.
Return type routingpy.direction.Direction or routingpy.direction.
Directions
isochrones()
Implement this method for the router’s isochrones endpoint or raise NotImplementedError
matrix(locations, profile, sources=None, destinations=None, avoid=None, language=None, re-
gion=None, units=None, arrival_time=None, departure_time=None, traffic_model=None,
transit_mode=None, transit_routing_preference=None, dry_run=None)
Gets travel distance and time for a matrix of origins and destinations.
Parameters
• locations (list of list) – Two or more pairs of lng/lat values.
• profile (str) – The vehicle for which the route should be calculated. Default “driv-
ing”. One of [‘driving’, ‘walking’, ‘bicycling’, ‘transit’].
• sources (list or tuple) – A list of indices that refer to the list of locations (start-
ing with 0). If not passed, all indices are considered.
8 Chapter 2. Routers
RoutingPy, Release 0.3.0
• destinations (list or tuple) – A list of indices that refer to the list of locations
(starting with 0). If not passed, all indices are considered.
• avoid – Indicates that the calculated route(s) should avoid the indicated features. One or
more of [‘tolls’, ‘highways’, ‘ferries’, ‘indoor’]. Default None.
• avoid – list of str
• language (str) – Language for routing instructions. The locale of the resulting turn
instructions. Visit https://developers.google.com/maps/faq#languagesupport for options.
• region (str) – Specifies the region code, specified as a ccTLD (“top-level domain”)
two-character value. See https://developers.google.com/maps/documentation/directions/
intro#RegionBiasing.
• units (str) – Specifies the unit system to use when displaying results. One of [‘metric’,
‘imperial’].
• arrival_time (int) – Specifies the desired time of arrival for transit directions, in
seconds since midnight, January 1, 1970 UTC. Incompatible with departure_time.
• departure_time (int) – Specifies the desired time of departure. You can specify the
time as an integer in seconds since midnight, January 1, 1970 UTC.
• traffic_model (str) – Specifies the assumptions to use when calculating time in
traffic. One of [‘best_guess’, ‘pessimistic’, ‘optimistic’. See https://developers.google.
com/maps/documentation/directions/intro#optional-parameters for details.
• transit_mode (list of str or tuple of str) – Specifies one or more pre-
ferred modes of transit. One or more of [‘bus’, ‘subway’, ‘train’, ‘tram’, ‘rail’].
• transit_routing_preference (str) – Specifies preferences for transit routes.
Using this parameter, you can bias the options returned, rather than accepting the default
best route chosen by the API. One of [‘less_walking’, ‘fewer_transfers’].
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns A matrix from the specified sources and destinations.
Return type routingpy.matrix.Matrix
2.3 Graphhopper
2.3. Graphhopper 9
RoutingPy, Release 0.3.0
10 Chapter 2. Routers
RoutingPy, Release 0.3.0
True and the points will be sorted regarding the minimum overall time - e.g. suiteable for
sightseeing tours or salesman. Keep in mind that the location limit of the Route Optimiza-
tion API applies and the credit costs are higher! Note to all customers with a self-hosted
license: this parameter is only available if your package includes the Route Optimization
API. Default False.
• instructions (bool) – Specifies whether to return turn-by-turn instructions. Default
True.
• elevation (bool) – If true a third dimension - the elevation - is included in the polyline
or in the GeoJson. IMPORTANT: If enabled you have to use a modified version of the
decoding method or set points_encoded to false. See the points_encoded attribute for
more details. Additionally a request can fail if the vehicle does not support elevation. See
the features object for every vehicle. Default False.
• points_encoded (bool) – If False the coordinates in point and snapped_waypoints
are returned as array using the order [lon,lat,elevation] for every point. If true the coordi-
nates will be encoded as string leading to less bandwith usage. Default True.
• calc_points (bool) – If the points for the route should be calculated at all, printing
out only distance and time. Default True.
• debug (bool) – If True, the output will be formated. Default False.
• point_hint (list of str) – The point_hint is typically a road name to which the
associated point parameter should be snapped to. Specify no point_hint parameter or the
same number as you have locations. Optional.
• details (list of str) – Optional parameter to retrieve path details. You can
request additional details for the route: street_name, time, distance, max_speed, toll,
road_class, road_class_link, road_access, road_environment, lanes, and surface.
• ch_disable (bool) – Always use ch_disable=true in combination with one or more
parameters of this table. Default False.
• weighting (str) – Which kind of ‘best’ route calculation you need. Other options are
shortest (e.g. for vehicle=foot or bike) and short_fastest if not only time but also distance
is expensive. Default “fastest”.
• heading (list of int) – Optional parameter. Favour a heading direction for a cer-
tain point. Specify either one heading for the start point or as many as there are points. In
this case headings are associated by their order to the specific points. Headings are given
as north based clockwise angle between 0 and 360 degree.
• heading_penalty (int) – Optional parameter. Penalty for omitting a specified head-
ing. The penalty corresponds to the accepted time delay in seconds in comparison to the
route without a heading. Default 120.
• pass_through (bool) – Optional parameter. If true u-turns are avoided at via-points
with regard to the heading_penalty. Default False.
• block_area (str) – Optional parameter. Block road access via a point with the
format latitude,longitude or an area defined by a circle lat,lon,radius or a rectangle
lat1,lon1,lat2,lon2.
• avoid (list of str) – Optional semicolon separated parameter. Specify which road
classes you would like to avoid (currently only supported for motor vehicles like car).
Possible values are ferry, motorway, toll, tunnel and ford.
• algorithm (str) – Optional parameter. round_trip or alternative_route.
2.3. Graphhopper 11
RoutingPy, Release 0.3.0
12 Chapter 2. Routers
RoutingPy, Release 0.3.0
• buckets (int) – For how many sub intervals an additional polygon should be calcu-
lated. Default 1.
• reverse_flow – If false the flow goes from point to the polygon, if true the flow goes
from the polygon “inside” to the point. Default False.
• reverse_flow – bool
• debug (bool) – If true, the output will be formatted. Default False
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns An isochrone with the specified range.
Return type routingpy.isochrone.Isochrones
matrix(locations, profile, sources=None, destinations=None, out_array=[’times’, ’distances’], de-
bug=None, dry_run=None)
Gets travel distance and time for a matrix of origins and destinations.
For more details visit https://docs.graphhopper.com/#tag/Matrix-API.
Parameters
• locations (List[List[float]|Tuple[float]]|Tuple[List[float]|Tuple[float]])
– Specifiy multiple points for which the weight-, route-, time- or distance-matrix should
be calculated. In this case the starts are identical to the destinations. If there are N
points, then NxN entries will be calculated. The order of the point parameter is important.
Specify at least three points. Is a string with the format latitude,longitude.
• profile (str) – Specifies the mode of transport. One of bike, car, foot or https://
graphhopper.com/api/1/docs/supported-vehicle-profiles/Default. Default “car”.
• sources (List[int]) – The starting points for the routes. Specifies an index referring
to locations.
• destinations (List[int]) – The destination points for the routes. Specifies an
index referring to locations.
• out_array (List[str]) – Specifies which arrays should be included in the response.
Specify one or more of the following options ‘weights’, ‘times’, ‘distances’. The units of
the entries of distances are meters, of times are seconds and of weights is arbitrary and it
can differ for different vehicles or versions of this API. Default [“times”, “distance”].
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns A matrix from the specified sources and destinations.
Return type routingpy.matrix.Matrix
2.4 HereMaps
2.4. HereMaps 13
RoutingPy, Release 0.3.0
14 Chapter 2. Routers
RoutingPy, Release 0.3.0
2.4. HereMaps 15
RoutingPy, Release 0.3.0
closed links are roads that may be closed during the winter due to weather conditions or
ferries that may be out of operation for the season (based on past closure dates).
• avoid_turns (str) – List of turn types that the route should avoid. De-
faults to empty list. https://developer.here.com/documentation/routing/topics/
resource-type-enumerations.html
• allowed_zones (list of int) – Identifiers of zones where routing engine should
not take zone restrictions into account (for example in case of a special permission to ac-
cess a restricted environmental zone). https://developer.here.com/documentation/routing/
topics/resource-get-routing-zones.html
• exclude_zones (list of int) – Identifiers of zones which the route must not
cross under any circumstances. https://developer.here.com/documentation/routing/topics/
resource-get-routing-zones.html
• exclude_zone_types (list of str) – List of zone types which the route must
not cross under any circumstances. https://developer.here.com/documentation/routing/
topics/resource-type-enumerations.html #resource-type-enumerations__enum-routing-
zone-type-type
• exclude_countries – Countries that must be excluded from route calculation.
• departure (str) – Time when travel is expected to start. Traffic speed and incidents
are taken into account when calculating the route (note that in case of a past departure
time the historical traffic is limited to one year). You can use now to specify the current
time. Specify either departure or arrival, not both. When the optional timezone offset is
not specified, the time is assumed to be the local. Formatted as iso time, e.g. 2018-07-
04T17:00:00+02.
• arrival (str) – Time when travel is expected to end. Specify either departure or
arrival, not both. When the optional timezone offset is not specified, the time is assumed
to be the local. Formatted as iso time, e.g. 2018-07-04T17:00:00+02.
• alternatives (int) – Maximum number of alternative routes that will be calculated
and returned. Alternative routes can be unavailable, thus they are not guaranteed to be
returned. If at least one via point is used in a route request, returning alternative routes is
not supported. 0 stands for “no alternative routes”, i.e. only best route is returned.
• metric_system (str) – Defines the measurement system used in instruction text.
When imperial is selected, units used are based on the language specified in the request.
Defaults to metric when not specified.
• view_bounds (list or tuple) – If the view bounds are given in the request then
only route shape points which fit into these bounds will be returned. The route shape
beyond the view bounds is reduced to the points which are referenced by links, legs or
maneuvers.
• resolution (dict) – Specifies the resolution of the view and a possible snap reso-
lution in meters per pixel in the response. You must specify a whole, positive integer.
If you specify only one value, then this value defines the view resolution only. You can
use snap resolution to adjust waypoint links to the resolution of the client display. e.g.
{‘viewresolution’: 300,’snapresolution’: 300}
• instruction_format (str) – Defines the representation format of the maneuver’s
instruction text. Html or txt.
• language (str) – A list of languages for all textual information, the first sup-
ported language is used. If there are no matching supported languages the response
16 Chapter 2. Routers
RoutingPy, Release 0.3.0
2.4. HereMaps 17
RoutingPy, Release 0.3.0
18 Chapter 2. Routers
RoutingPy, Release 0.3.0
• return_elevation (bool) – If set to true, all shapes inside routing response will
consist of 3 values instead of 2. Third value will be elevation. If there are no elevation data
available for given shape point, elevation will be interpolated from surrounding points. In
case there is no elevation data available for any of the shape points, elevation will be 0.0.
If jsonattributes=32, elevation cannot be returned.
• consumption_model (str) – If you request information on consumption, you must
provide a consumption model. The possible values are default and standard. When you
specify the value standard, you must provide additional information in the query parameter
customconsumptiondetails
• custom_consumption_details (str) – Provides vehicle specific information
for use in the consumption model. This information can include such things as the
amount of energy consumed while travelling at a given speed. https://developer.here.com/
documentation/routing/topics/resource-param-type-custom-consumption-details.html#
type-standard
• speed_profile (str) – Specifies the speed profile variant for a given routing
mode. The speed profile affects travel time estimation as well as roads evalua-
tion when computing the fastest route. Note that computed routes might differ de-
pending on a used profile. https://developer.here.com/documentation/routing/topics/
resource-param-type-speed-profile-type.html
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns One or multiple route(s) from provided coordinates and restrictions.
Return type routingpy.direction.Direction or routingpy.direction.
Directions
isochrones(locations, profile, intervals, mode_type=’fastest’, interval_type=’time’, for-
mat=’json’, center_type=’start’, request_id=None, arrival=None, departure=None,
single_component=None, resolution=None, max_points=None, quality=None,
json_attributes=None, json_callback=None, truck_type=None, trailers_count=None,
shipped_hazardous_goods=None, limited_weight=None, weight_per_axle=None,
height=None, width=None, length=None, tunnel_category=None, consump-
tion_model=None, custom_consumption_details=None, speed_profile=None,
dry_run=None)
Gets isochrones or equidistants for a range of time/distance values around a given set of coordinates.
For more information, https://developer.here.com/documentation/routing/topics/
resource-calculate-isoline.html.
Parameters
• locations (list of float) – One pair of lng/lat values.
• profile (str or HereMaps.RoutingMode) – Specifies the routing mode of transport
and further options. Can be a str or HereMaps.RoutingMode https://developer.here.
com/documentation/routing/topics/resource-param-type-routing-mode.html
• intervals – Range of isoline. Several comma separated values can be specified. The
unit is defined by parameter rangetype.
• mode_type (str) – RoutingType relevant to calculation. One of [fastest, short-
est, balanced]. Default fastest. https://developer.here.com/documentation/routing/topics/
resource-param-type-routing-mode.html#ariaid-title2
2.4. HereMaps 19
RoutingPy, Release 0.3.0
• interval_type – Specifies type of range. Possible values are distance, time, con-
sumption. For distance the unit is meters. For time the unit is seconds. For consumption it
is defined by consumption model
• format (str) – Currently only “json” supported.
• center_type (str) – If ‘start’ then the isoline will cover all roads which can be
reached from this point within given range. It cannot be used in combination with des-
tination parameter. If ‘destination’ Center of the isoline request. Isoline will cover all
roads from which this point can be reached within given range. It cannot be used in com-
bination with start parameter.
• departure (str) – Time when travel is expected to start. Traffic speed and incidents
are taken into account when calculating the route (note that in case of a past departure
time the historical traffic is limited to one year). You can use now to specify the current
time. Specify either departure or arrival, not both. When the optional timezone offset is
not specified, the time is assumed to be the local. Formatted as iso time, e.g. 2018-07-
04T17:00:00+02.
• arrival (str) – Time when travel is expected to end. Specify either departure or
arrival, not both. When the optional timezone offset is not specified, the time is assumed
to be the local. Formatted as iso time, e.g. 2018-07-04T17:00:00+02.
• single_component (bool) – If set to true the isoline service will always return single
polygon, instead of creating a separate polygon for each ferry separated island. Default
value is false.
• resolution (int) – Allows to specify level of detail needed for the isoline polygon.
Unit is meters per pixel. Higher resolution may cause increased response time from the
service.
• max_points (int) – Allows to limit amount of points in the returned isoline. If isoline
consists of multiple components, sum of points from all components is considered. Each
component will have at least 2 points, so it is possible that more points than maxpoints
value will be returned. This is in case when 2 * number of components is higher than
maxpoints. Enlarging number of maxpoints may cause increased response time from the
service.
• quality (int) – Allows to reduce the quality of the isoline in favor of the response
time. Allowed values are 1, 2, 3. Default value is 1 and it is the best quality.
• json_attributes (int) – Flag to control JSON output. Combine parame-
ters by adding their values. https://developer.here.com/documentation/routing/topics/
resource-param-type-json-representation.html
• truck_type (str) – Truck routing only, specifies the vehicle type. Defaults to truck.
• trailers_count (int) – Truck routing only, specifies number of trailers pulled by a
vehicle. The provided value must be between 0 and 4. Defaults to 0.
• shipped_hazardous_goods (list of str) – Truck routing only, list of
hazardous materials in the vehicle. Please refer to the enumeration type Haz-
ardousGoodTypeType for available values. Note the value allhazardousGoods
does not apply to the request parameter. https://developer.here.com/documentation/
routing/topics/resource-type-enumerations.html#resource-type-enumerations_
_enum-hazardous-good-type-type
• limited_weight (int) – Truck routing only, vehicle weight including trailers and
shipped goods, in tons. The provided value must be between 0 and 1000.
20 Chapter 2. Routers
RoutingPy, Release 0.3.0
• weight_per_axle – Truck routing only, vehicle weight per axle in tons. The provided
value must be between 0 and 1000.
• height (int) – Truck routing only, vehicle height in meters. The provided value must
be between 0 and 50.
• width (int) – Truck routing only, vehicle width in meters. The provided value must be
between 0 and 50.
• length (int) – Truck routing only, vehicle length in meters. The provided value must
be between 0 and 300.
• tunnel_category (list of str) – Truck routing only, specifies the tunnel cate-
gory to restrict certain route links. The route will pass only through tunnels of a less strict
category.
• consumption_model (str) – If you request information on consumption, you must
provide a consumption model. The possible values are default and standard. When you
specify the value standard, you must provide additional information in the query parameter
customconsumptiondetails
• custom_consumption_details (str) – Provides vehicle specific information
for use in the consumption model. This information can include such things as the
amount of energy consumed while travelling at a given speed. https://developer.here.com/
documentation/routing/topics/resource-param-type-custom-consumption-details.html#
type-standard
• speed_profile (str) – Specifies the speed profile variant for a given routing
mode. The speed profile affects travel time estimation as well as roads evalua-
tion when computing the fastest route. Note that computed routes might differ de-
pending on a used profile. https://developer.here.com/documentation/routing/topics/
resource-param-type-speed-profile-type.html
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns raw JSON response
Return type dict
matrix(locations, profile, format=’json’, mode_type=’fastest’, sources=None, des-
tinations=None, search_range=None, avoid_areas=None, avoid_links=None,
avoid_turns=None, exclude_countries=None, departure=None, matrix_attributes=None,
summary_attributes=[’traveltime’, ’costfactor’, ’distance’], truck_type=None,
trailers_count=None, shipped_hazardous_goods=None, limited_weight=None,
weight_per_axle=None, height=None, width=None, length=None, tunnel_category=None,
speed_profile=None, dry_run=None)
Gets travel distance and time for a matrix of origins and destinations.
Parameters
• locations (list of list or list of HereMaps.Waypoint) – The coordinates tu-
ple the route should be calculated from in order of visit. Can be a list/tuple
of [lon, lat] or HereMaps.Waypoint instance or a combination of those.
For further explanation, see https://developer.here.com/documentation/routing/topics/
resource-param-type-waypoint.html
• profile (str or HereMaps.RoutingMode) – Specifies the routing mode of transport
and further options. Can be a str or HereMaps.RoutingMode https://developer.here.
com/documentation/routing/topics/resource-param-type-routing-mode.html
2.4. HereMaps 21
RoutingPy, Release 0.3.0
22 Chapter 2. Routers
RoutingPy, Release 0.3.0
• weight_per_axle – Truck routing only, vehicle weight per axle in tons. The provided
value must be between 0 and 1000.
• height (int) – Truck routing only, vehicle height in meters. The provided value must
be between 0 and 50.
• width (int) – Truck routing only, vehicle width in meters. The provided value must be
between 0 and 50.
• length (int) – Truck routing only, vehicle length in meters. The provided value must
be between 0 and 300.
• tunnel_category (list of str) – Truck routing only, specifies the tunnel cate-
gory to restrict certain route links. The route will pass only through tunnels of a less strict
category.
• speed_profile (str) – Specifies the speed profile variant for a given routing
mode. The speed profile affects travel time estimation as well as roads evalua-
tion when computing the fastest route. Note that computed routes might differ de-
pending on a used profile. https://developer.here.com/documentation/routing/topics/
resource-param-type-speed-profile-type.html
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns raw JSON response
Return type dict
2.5 MapboxOSRM
2.5. MapboxOSRM 23
RoutingPy, Release 0.3.0
24 Chapter 2. Routers
RoutingPy, Release 0.3.0
• overview (str) – Add overview geometry either full, simplified according to highest
zoom level it could be display on, or not at all. One of [“simplified”, “full”, “false”, False].
Default simplified.
• exclude (str) – Exclude certain road types from routing. One of [‘toll’, ‘motorway’,
‘ferry’] if profile=driving*. ‘ferry’ for profile=cycling. None for profile=walking. Default
none.
• approaches (list of str) – Indicating the side of the road from which to approach
waypoint in a requested route. One of [“unrestricted”, “curb”]. unrestricted: route can
arrive at the waypoint from either side of the road. curb: route will arrive at the waypoint
on the driving_side of the region. If provided, the number of approaches must be the same
as the number of waypoints. Default unrestricted.
• banner_instructions (bool) – Whether to return banner objects associated with
the route steps. Default False.
• language (str) – The language of returned turn-by-turn text instructions. Default
is en. See the full list here of supported languages here: https://docs.mapbox.com/api/
navigation/#instructions-languages
• roundabout_exits (bool) – Whether to emit instructions at roundabout exits or not.
Without this parameter, roundabout maneuvers are given as a single instruction that in-
cludes both entering and exiting the roundabout. With roundabout_exits=true, this ma-
neuver becomes two instructions, one for entering the roundabout and one for exiting it.
Default false.
• voice_instructions (bool) – Whether to return SSML marked-up text for voice
guidance along the route or not. Default false.
• voice_units (str) – Specify which type of units to return in the text for voice instruc-
tions. One of [“imperial”, “metric”]. Default imperial.
• waypoint_names (list of str) – List of custom names for entries in the list of
coordinates, used for the arrival instruction in banners and voice instructions. Values can
be any string, and the total number of all characters cannot exceed 500. If provided, the
list of waypoint_names must be the same length as the list of coordinates. The first value
in the list corresponds to the route origin, not the first destination.
• waypoint_targets (list of list of float) – List of coordinate pairs used
to specify drop-off locations that are distinct from the locations specified in coordinates.
If this parameter is provided, the Directions API will compute the side of the street, left
or right, for each target based on the waypoint_targets and the driving direction. The
maneuver.modifier, banner and voice instructions will be updated with the computed side
of street. The number of waypoint_targets must be the same as the number of coordinates.
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns One or multiple route(s) from provided coordinates and restrictions.
Return type routingpy.direction.Direction or routingpy.direction.
Directions
isochrones(locations, profile, intervals, contours_colors=None, polygons=None, denoise=None,
generalize=None, dry_run=None)
Gets isochrones or equidistants for a range of time values around a given set of coordinates.
For more information, visit https://github.com/valhalla/valhalla/blob/master/docs/api/isochrone/
api-reference.md.
2.5. MapboxOSRM 25
RoutingPy, Release 0.3.0
Parameters
• locations (list of float) – One pair of lng/lat values. Takes the form [Longi-
tude, Latitude].
• profile (str) – Specifies the mode of transport to use when calculating directions.
One of [“mapbox/driving”, “mapbox/walking”, “mapbox/cycling”.
• intervals (list of int) – Time ranges to calculate isochrones for. Up to 4 ranges
are possible. In seconds.
• contours_colors (list of str) – The color for the output of the contour. Spec-
ify it as a Hex value, but without the #, such as “color”:”ff0000” for red. If no color is
specified, the isochrone service will assign a default color to the output.
• polygons (bool) – Controls whether polygons or linestrings are returned in GeoJSON
geometry. Default False.
• denoise (float) – Can be used to remove smaller contours. In range [0, 1]. A value
of 1 will only return the largest contour for a given time value. A value of 0.5 drops any
contours that are less than half the area of the largest contour in the set of contours for that
same time value. Default 1.
• generalize (float) – A floating point value in meters used as the tolerance for
Douglas-Peucker generalization. Note: Generalization of contours can lead to self-
intersections, as well as intersections of adjacent contours.
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns An isochrone with the specified range.
Return type routingpy.isochrone.Isochrones
matrix(locations, profile, sources=None, destinations=None, annotations=None, fall-
back_speed=None, dry_run=None)
Gets travel distance and time for a matrix of origins and destinations.
For more information visit https://docs.mapbox.com/api/navigation/#matrix.
Parameters
• locations (list or tuple) – The coordinates tuple the route should be calculated
from in order of visit.
• profile (str) – Specifies the mode of transport to use when calculating directions.
One of [“car”, “bike”, “foot”].
• sources (list or tuple) – A list of indices that refer to the list of locations (start-
ing with 0). If not passed, all indices are considered.
• destinations (list or tuple) – A list of indices that refer to the list of locations
(starting with 0). If not passed, all indices are considered.
• annotations (list of str) – Used to specify the resulting matrices. One or more
of [“duration”, “distance”]. Default [“duration”]
• fallback_speed (int) – By default, if there is no possible route between two points,
the Matrix API sets the resulting matrix element to null. To circumvent this behavior,
set the fallback_speed parameter to a value greater than 0 in kilometers per hour. The
Matrix API will replace a null value with a straight-line estimate between the source and
destination based on the provided speed value.
• dry_run – Print URL and parameters without sending the request.
26 Chapter 2. Routers
RoutingPy, Release 0.3.0
• dry_run – bool
Returns A matrix from the specified sources and destinations.
Return type routingpy.matrix.Matrix
2.6 MapboxValhalla
2.6. MapboxValhalla 27
RoutingPy, Release 0.3.0
28 Chapter 2. Routers
RoutingPy, Release 0.3.0
2.6. MapboxValhalla 29
RoutingPy, Release 0.3.0
2.7 ORS
30 Chapter 2. Routers
RoutingPy, Release 0.3.0
• base_url (str) – The base URL for the request. Defaults to the ORS API server.
Should not have a trailing slash.
• user_agent (str) – User Agent to be used when requesting. Default routingpy.
routers.options.default_user_agent.
• timeout (int or None) – Combined connect and read timeout for HTTP requests,
in seconds. Specify None for no timeout. Default routingpy.routers.options.
default_timeout.
• retry_timeout (int) – Timeout across multiple retriable requests, in seconds. De-
fault routingpy.routers.options.default_retry_timeout.
• requests_kwargs (dict) – Extra keyword arguments for the requests library, which
among other things allow for proxy auth to be implemented. Note, that proxies can be
set globally in routingpy.routers.options.default_proxies.
Example:
2.7. ORS 31
RoutingPy, Release 0.3.0
32 Chapter 2. Routers
RoutingPy, Release 0.3.0
2.7. ORS 33
RoutingPy, Release 0.3.0
• sources (list of int) – A list of indices that refer to the list of locations (starting
with 0). If not passed, all indices are considered.
• destinations (list of int) – A list of indices that refer to the list of locations
(starting with 0). If not passed, all indices are considered.
• metrics (list of str) – Specifies a list of returned metrics. One or more of [“dis-
tance”, “duration”]. Default [‘duration’].
• resolve_locations (bool) – Specifies whether given locations are resolved or not.
If set ‘true’, every element in destinations and sources will contain the name element that
identifies the name of the closest street. Default False.
• units (str) – Specifies the unit system to use when displaying results. One of [“m”,
“km”, “m”]. Default “m”.
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns A matrix from the specified sources and destinations.
Return type routingpy.matrix.Matrix
2.8 OSRM
34 Chapter 2. Routers
RoutingPy, Release 0.3.0
2.8. OSRM 35
RoutingPy, Release 0.3.0
• dry_run – bool
Returns One or multiple route(s) from provided coordinates and restrictions.
Return type routingpy.direction.Direction or routingpy.direction.
Directions
isochrones()
Implement this method for the router’s isochrones endpoint or raise NotImplementedError
matrix(locations, profile, radiuses=None, bearings=None, sources=None, destinations=None,
dry_run=None, annotations=[’duration’, ’distance’])
Gets travel distance and time for a matrix of origins and destinations.
For more information visit http://project-osrm.org/docs/v5.5.1/api/#table-service.
Parameters
• locations (list of list) – The coordinates tuple the route should be calculated
from.
• profile (str) – Specifies the mode of transport to use when calculating directions.
One of [“car”, “bike”, “foot”].
• radiuses (list of int) – A list of maximum distances (measured in meters) that
limit the search of nearby road segments to every given waypoint. The values must be
greater than 0, an empty element signifies to use the backend default radius. The number
of radiuses must correspond to the number of waypoints.
• bearings (list of list) – Specifies a list of pairs (bearings and deviations) to
filter the segments of the road network a waypoint can snap to. For example bear-
ings=[[45,10],[120,20]]. Each pair is a comma-separated list that can consist of one or
two float values, where the first value is the bearing and the second one is the allowed de-
viation from the bearing. The bearing can take values between 0 and 360 clockwise from
true north. If the deviation is not set, then the default value of 100 degrees is used. The
number of pairs must correspond to the number of waypoints.
• sources (list of int) – A list of indices that refer to the list of locations (starting
with 0). If not passed, all indices are considered.
• destinations (list of int) – A list of indices that refer to the list of locations
(starting with 0). If not passed, all indices are considered.
• dry_run (bool) – Print URL and parameters without sending the request.
• annotations (List[str]) – Return the requested table or tables in response. One
or more of [“duration”, “distance”].
Returns A matrix from the specified sources and destinations.
Return type routingpy.matrix.Matrix
Changed in version 0.3.0: Add annotations parameter to get both distance and duration
2.9 Valhalla
36 Chapter 2. Routers
RoutingPy, Release 0.3.0
2.9. Valhalla 37
RoutingPy, Release 0.3.0
Parameters
• locations (list of list or list of Valhalla.WayPoint) – The coordinates tuple the
route should be calculated from in order of visit. Can be a list/tuple of [lon, lat] or
Valhalla.WayPoint instance or a combination of both.
• profile (str) – Specifies the mode of transport to use when calculating directions.
One of [“auto”, “auto_shorter”, “bicycle”, “bus”, “hov”, “motor_scooter”, “motorcycle”,
“multimodal”, “pedestrian”.
• options (dict) – Profiles can have several options that can be adjusted to de-
velop the route path, as well as for estimating time along the path. Only spec-
ify the actual options dict, the profile will be filled automatically. For more in-
formation, visit: https://github.com/valhalla/valhalla/blob/master/docs/api/turn-by-turn/
api-reference.md#costing-options
• units (str) – Distance units for output. One of [‘mi’, ‘km’]. Default km.
• language (str) – The language of the narration instructions based on the IETF BCP
47 language tag string. One of [‘ca’, ‘cs’, ‘de’, ‘en’, ‘pirate’, ‘es’, ‘fr’, ‘hi’, ‘it’, ‘pt’, ‘ru’,
‘sl’, ‘sv’]. Default ‘en’.
• directions_type (str) – ‘none’: no instructions are returned. ‘maneuvers’: only
maneuvers are returned. ‘instructions’: maneuvers with instructions are returned. Default
‘instructions’.
• avoid_locations (list of list or list of Valhalla.WayPoint) – A set of locations
to exclude or avoid within a route. Specified as a list of coordinates, similar to coordinates
object.
• date_time (dict) – This is the local date and time at the location. Field type: 0:
Current departure time, 1: Specified departure time. Field value`: the date and time
is specified in ISO 8601 format (YYYY-MM-DDThh:mm), local time. E.g. date_time =
{type: 0, value: 2019-03-03T08:06:23}
• id (str) – Name your route request. If id is specified, the naming will be sent thru to the
response.
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns A route from provided coordinates and restrictions.
Return type routingpy.direction.Direction
isochrones(locations, profile, intervals, colors=None, polygons=None, denoise=None, gener-
alize=None, options=None, units=None, language=None, directions_type=None,
avoid_locations=None, date_time=None, show_locations=None, id=None,
dry_run=None)
Gets isochrones or equidistants for a range of time values around a given set of coordinates.
For more information, visit https://github.com/valhalla/valhalla/blob/master/docs/api/isochrone/
api-reference.md.
Parameters
• locations (list of float) – One pair of lng/lat values. Takes the form [Longi-
tude, Latitude].
• profile (str) – Specifies the mode of transport to use when calculating directions.
One of [“auto”, “bicycle”, “multimodal”, “pedestrian”.
38 Chapter 2. Routers
RoutingPy, Release 0.3.0
2.9. Valhalla 39
RoutingPy, Release 0.3.0
• destinations (list of int) – A list of indices that refer to the list of locations
(starting with 0). If not passed, all indices are considered.
• options (dict) – Profiles can have several options that can be adjusted to de-
velop the route path, as well as for estimating time along the path. Only spec-
ify the actual options dict, the profile will be filled automatically. For more in-
formation, visit: https://github.com/valhalla/valhalla/blob/master/docs/api/turn-by-turn/
api-reference.md#costing-options
• avoid_locations (list of list) – A set of locations to exclude or avoid within
a route. Specified as a list of coordinates, similar to coordinates object.
• units (str) – Distance units for output. One of [‘mi’, ‘km’]. Default km.
• id (str) – Name your route request. If id is specified, the naming will be sent through to
the response.
• dry_run – Print URL and parameters without sending the request.
• dry_run – bool
Returns A matrix from the specified sources and destinations.
Return type routingpy.matrix.Matrix
40 Chapter 2. Routers
CHAPTER 3
Data
41
RoutingPy, Release 0.3.0
[
[
duration(origin1-destination1),
duration(origin1-destination2),
duration[origin1-destination3),
...
],
[
duration(origin2-destination1),
duration(origin2-destination2),
duration[origin3-destination3),
...
},
...
]
durations
The durations matrix as list akin to:
[
[
duration(origin1-destination1),
duration(origin1-destination2),
duration[origin1-destination3),
...
],
[
duration(origin2-destination1),
duration(origin2-destination2),
duration[origin3-destination3),
...
},
...
]
42 Chapter 3. Data
RoutingPy, Release 0.3.0
raw
Returns the matrices raw, unparsed response. For details, consult the routing engine’s API documentation.
Return type dict or None
routingpy.utils.decode_polyline5(polyline, is3d=False)
Decodes an encoded polyline string which was encoded with a precision of 5.
Parameters
• polyline (str) – An encoded polyline, only the geometry.
• is3d (bool) – Specifies if geometry contains Z component. Currently only GraphHopper
and OpenRouteService support this. Default False.
Returns List of decoded coordinates with precision 5.
Return type list
routingpy.utils.decode_polyline6(polyline, is3d=False)
Decodes an encoded polyline string which was encoded with a precision of 6.
Parameters
• polyline (str) – An encoded polyline, only the geometry.
• is3d (bool) – Specifies if geometry contains Z component. Currently only GraphHopper
and OpenRouteService support this. Default False.
Returns List of decoded coordinates with precision 6.
Return type list
43
RoutingPy, Release 0.3.0
44 Chapter 3. Data
CHAPTER 4
Exceptions
45
RoutingPy, Release 0.3.0
46 Chapter 4. Exceptions
CHAPTER 5
Changelog
47
RoutingPy, Release 0.3.0
48 Chapter 5. Changelog
CHAPTER 6
• genindex
• search
49
RoutingPy, Release 0.3.0
r
routingpy, 1
routingpy.routers, 5
51
RoutingPy, Release 0.3.0
C G
geometry (routingpy.direction.Direction attribute), 41
center (routingpy.isochrone.Isochrone attribute), 42
geometry (routingpy.isochrone.Isochrone attribute), 42
D get_router_by_name() (in module rout-
ingpy.routers), 5
decode_polyline5() (in module routingpy.utils), 43 Google (class in routingpy.routers), 6
decode_polyline6() (in module routingpy.utils), 43 Google.WayPoint (class in routingpy.routers), 7
default_proxies (routingpy.routers.options at- Graphhopper (class in routingpy.routers), 9
tribute), 6
default_retry_over_query_limit (rout- H
ingpy.routers.options attribute), 6 HereMaps (class in routingpy.routers), 13
default_retry_timeout (rout- HereMaps.RoutingMode (class in rout-
ingpy.routers.options attribute), 6 ingpy.routers), 14
default_skip_api_error (rout- HereMaps.Waypoint (class in routingpy.routers), 14
ingpy.routers.options attribute), 6
default_timeout (routingpy.routers.options at- I
tribute), 6 Isochrone (class in routingpy.isochrone), 41
default_user_agent (routingpy.routers.options at- Isochrones (class in routingpy.isochrone), 41
tribute), 6 isochrones() (routingpy.routers.Google method), 8
Direction (class in routingpy.direction), 41 isochrones() (routingpy.routers.Graphhopper
Directions (class in routingpy.direction), 41 method), 12
directions() (routingpy.routers.Google method), 7 isochrones() (routingpy.routers.HereMaps method),
directions() (routingpy.routers.Graphhopper 19
method), 10 isochrones() (routingpy.routers.MapboxOSRM
directions() (routingpy.routers.HereMaps method), method), 25
15 isochrones() (routingpy.routers.MapboxValhalla
method), 28
53
RoutingPy, Release 0.3.0
M
MapboxOSRM (class in routingpy.routers), 23
MapboxValhalla (class in routingpy.routers), 27
MapboxValhalla.Waypoint (class in rout-
ingpy.routers), 27
Matrix (class in routingpy.matrix), 42
matrix() (routingpy.routers.Google method), 8
matrix() (routingpy.routers.Graphhopper method), 13
matrix() (routingpy.routers.HereMaps method), 21
matrix() (routingpy.routers.MapboxOSRM method),
26
matrix() (routingpy.routers.MapboxValhalla method),
30
matrix() (routingpy.routers.ORS method), 33
matrix() (routingpy.routers.OSRM method), 36
matrix() (routingpy.routers.Valhalla method), 39
O
options (class in routingpy.routers), 5
ORS (class in routingpy.routers), 30
OSRM (class in routingpy.routers), 34
OverQueryLimit (class in routingpy.exceptions), 45
R
raw (routingpy.direction.Directions attribute), 41
raw (routingpy.isochrone.Isochrones attribute), 41
raw (routingpy.matrix.Matrix attribute), 43
req (routingpy.routers.MapboxValhalla attribute), 30
RetriableRequest (class in routingpy.exceptions),
45
RouterApiError (class in routingpy.exceptions), 45
RouterError (class in routingpy.exceptions), 45
RouterNotFound (class in routingpy.exceptions), 45
RouterServerError (class in routingpy.exceptions),
45
routingpy (module), 1
routingpy.routers (module), 5
T
Timeout (class in routingpy.exceptions), 45
V
Valhalla (class in routingpy.routers), 36
Valhalla.Waypoint (class in routingpy.routers), 37
54 Index