traveltime-dev / traveltime-python-sdk

TravelTime SDK for Python programming language
https://docs.traveltime.com/
MIT License
20 stars 5 forks source link

Setting scale_type and level parameters in TravelTime API POST request #84

Closed sampeters1 closed 1 year ago

sampeters1 commented 1 year ago

I'm working on generating isochrones with the TravelTime API but struggling with configuring scale_type and level parameters for detail control.

How can I include these parameters in the code below?

import asyncio
from datetime import datetime

from traveltimepy import Driving, Coordinates, TravelTimeSdk

async def main():
    sdk = TravelTimeSdk("YOUR_APP_ID", "YOUR_APP_KEY")

    results = await sdk.time_map_geojson_async(
        coordinates=[Coordinates(lat=51.507609, lng=-0.128315), Coordinates(lat=51.517609, lng=-0.138315)],
        arrival_time=datetime.now(),
        transportation=Driving()
    )
    print(results)

asyncio.run(main())
arnasbr commented 1 year ago

Working on adding support for level_of_detail and it's child attributes scale_type, level and square_size

arnasbr commented 1 year ago

Added support for level_of_detail. Here are some examples of how you might use it:

from traveltimepy import LevelOfDetail

scale_type "simple"

results = await sdk.time_map_async(
    coordinates=[Coordinates(lat=51.507609, lng=-0.128315)],
    arrival_time=datetime.now(),
    transportation=Driving(),
    level_of_detail=LevelOfDetail(scale_type="simple", level="lowest")
)

scale_type "simple_numeric"

results = await sdk.time_map_async(
    coordinates=[Coordinates(lat=51.507609, lng=-0.128315)],
    arrival_time=datetime.now(),
    transportation=Driving(),
    level_of_detail=LevelOfDetail(scale_type="simple_numeric", level=0)
)

scale_type "coarse_grid"

results = await sdk.time_map_async(
    coordinates=[Coordinates(lat=51.507609, lng=-0.128315)],
    arrival_time=datetime.now(),
    transportation=Driving(),
    level_of_detail=LevelOfDetail(scale_type="coarse_grid", square_size=600)
)

For a more detailed explanation of what values to use, you can refer to our API docs

Changes will be live in realease v3.6.2