Profile Mode
Profile mode supports:
unlimited region
Matrix Sizes up to 10,000 x 10,000
Profile mode does not support:
Custom Options
Time Awareness (including Live Traffic)
This section refers to calculating matrices with routes of arbitrary length, using one of the supported profiles. If you want to define custom options, see Flexible Mode
.
The special variant world
needs to be set as region definition. No additional request options or departure_time can be provided except for matrix_attributes.
Below is an example of a 7 x 7 matrix request with these origins and destinations:
Berlin at (52.54, 13.40)
Kyiv at (50.43, 30.52)
London at (51.50, -0.08)
Madrid at (40.40, -3.68)
Moscow at (55.75, 37.60)
Paris at (48.87, 2.33)
Rome at (41.90, 12.48)
To calculate a car distance matrix, you can use the code below. Since the request does not specify the destinations array, the origins are taken as destinations and the resulting matrix is a 7 x 7 matrix. The region definition is the special variant world. In the request, we use the profile carFast which uses transport mode car and optimizes the route calculations for travel time. By default, the service calculates a travel times matrix, but since we want to get distances in the response instead of times, the request specifies the matrix_attributes property with the value distances.
Example
import os
from here_location_services import LS
from here_location_services.config.matrix_routing_config import (
BoundingBoxRegion,
AutoCircleRegion,
MATRIX_ATTRIBUTES,
PROFILE,
WorldRegion
)
LS_API_KEY = os.environ.get("LS_API_KEY") # Get API KEY from environment.
ls = LS(api_key=LS_API_KEY) # Create Location Services object using API KEY.
origins = [
{"lat": 52.54, "lng": 13.40},
{"lat": 50.43, "lng": 30.52},
{"lat": 51.50, "lng": -0.08},
{"lat": 40.40, "lng": -3.68},
{"lat": 55.75, "lng": 37.60},
{"lat": 48.87, "lng": 2.33},
{"lat": 41.90, "lng": 12.48},
]
profile = PROFILE.carFast
region_definition = WorldRegion()
matrix_attributes = [MATRIX_ATTRIBUTES.distances]
result = ls.matrix(
origins=origins,
region_definition=region_definition,
matrix_attributes=matrix_attributes,
async_req=True
)
result.to_distnaces_matrix()
0 | 1 | 2 | 3 | 4 | 5 | 6 | |
---|---|---|---|---|---|---|---|
0 | 0 | 1384369 | 1094968 | 2322042 | 1844574 | 1056851 | 1511490 |
1 | 1367912 | 0 | 2422355 | 3649061 | 854550 | 2380158 | 2419242 |
2 | 1105209 | 2421238 | 0 | 1723053 | 2886992 | 456891 | 1815498 |
3 | 2321308 | 3634558 | 1715379 | 0 | 4107351 | 1272353 | 1961866 |
4 | 1842866 | 853543 | 2893229 | 4120303 | 0 | 2855112 | 3020364 |
5 | 1053421 | 2376243 | 451757 | 1271250 | 2835204 | 0 | 1427551 |
6 | 1509819 | 2424691 | 1813866 | 1961635 | 3014813 | 1426715 | 0 |
Attributes
Attribute |
Type |
Doc |
---|---|---|
origins |
list |
A list of dictionaries containing lat and long for origin points. |
region_definition |
object |
|
async_req |
bool |
If set to True reuqests will be sent to asynchronous matrix routing API else It will be sent to synchronous matrix routing API. For larger matrices, or longer routes, or routes in denser road networks, it is recommended to set to True. |
destinations |
list |
A list of dictionaries containing lat and long for destination points. When no destinations are specified the matrix is assumed to be quadratic with origins used as destinations. |
profile |
string |
Use values from config: |
departure_time |
|
When it is not specified, it is implicitly assumed to be the current time. The special value |
routing_mode |
string |
Use values from config: |
transport_mode |
string |
Use values from config: |
avoid_features |
list |
Use values from config: |
avoid_areas |
list |
Use object of |
truck |
object of |
Used to define truck options when transport mode is truck |
matrix_attributes |
list |
Use values from config: |