Skip to content
GuidesPlaygroundDashboard

Calculate a distance matrix between points

routing.matrix(RoutingMatrixParams**kwargs) -> MatrixResult
POST/api/v1/matrix

Calculate a distance matrix between points

ParametersExpand Collapse
destinations: GeoJsonGeometryParam

Destination points (GeoJSON MultiPoint geometry)

coordinates: Union[List[float], List[List[float]], List[List[List[float]]], List[List[List[List[float]]]]]

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
List[float]
List[List[float]]
List[List[List[float]]]
List[List[List[List[float]]]]
type: Literal["Point", "LineString", "Polygon", 3 more]
One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"

Origin points (GeoJSON MultiPoint geometry)

coordinates: Union[List[float], List[List[float]], List[List[List[float]]], List[List[List[List[float]]]]]

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
List[float]
List[List[float]]
List[List[List[float]]]
List[List[List[List[float]]]]
type: Literal["Point", "LineString", "Polygon", 3 more]
One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"
mode: Optional[Literal["auto", "foot", "bicycle"]]

Travel mode

One of the following:
"auto"
"foot"
"bicycle"
ReturnsExpand Collapse
class MatrixResult:
distances: List[List[Optional[float]]]

Distance matrix (meters), origins x destinations

durations: List[List[Optional[float]]]

Duration matrix (seconds), origins x destinations

Calculate a distance matrix between points

import os
from plaza import Plaza

client = Plaza(
    api_key=os.environ.get("PLAZA_API_KEY"),  # This is the default and can be omitted
)
matrix_result = client.routing.matrix(
    destinations={
        "coordinates": [0],
        "type": "Point",
    },
    origins={
        "coordinates": [0],
        "type": "Point",
    },
)
print(matrix_result.distances)
{
  "distances": [
    [
      0
    ]
  ],
  "durations": [
    [
      0
    ]
  ]
}
Returns Examples
{
  "distances": [
    [
      0
    ]
  ],
  "durations": [
    [
      0
    ]
  ]
}