Compute an isochrone with Thinwrap (Python)

Compute a travel-time or travel-distance polygon via the Thinwrap Isochrone facade in Python — one call shape for Mapbox, HERE, ESRI and TomTom.

1. Install

pip install thinwrap-location

2. Send the call

import os
from thinwrap.location import (
    Isochrone, IsochroneOptions, IsochroneType, MapboxConfig, LatLng, TravelMode, ConnectorError,
)

i = Isochrone(MapboxConfig(access_token=os.environ["MAPBOX_ACCESS_TOKEN"]))

try:
    res = i.isochrone(IsochroneOptions(
        center=LatLng(52.5200, 13.4050),
        type=IsochroneType.TIME,
        values=[300, 600],  # seconds
        travel_mode=TravelMode.DRIVING,
    ))
    # Each contour carries a GeoJSON Polygon (or MultiPolygon) of [lng, lat] rings.
    for c in res.contours:
        print(c.value, c.geometry.type, len(c.geometry.coordinates))
except ConnectorError as err:
    print(f"{err.provider_code.value}: {err.provider_message}")

Same code works for all supported providers — just change the provider ID.