Skip to content

Commit

Permalink
Adding render_mode and description of polygons_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
arnasbr committed Oct 24, 2024
1 parent a84cbb6 commit 8d65efd
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 9 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Given origin coordinates, find shapes of zones reachable within corresponding tr
* remove_water_bodies: bool - if set to true (default) - returned shape will not cover large nearby water bodies.
False - returned shape may cover nearby water bodies like large lakes, wide rivers and seas.
* [snapping](#snapping): Snapping - Adjusts the process of looking up the nearest roads from the departure / arrival points.
* [polygons_filter](#polygons-filter): PolygonsFilter - Specifies polygon filter of a single shape.
* [render_mode](#render-mode): RenderMode - Specifies which render mode should be used.

### JSON response

Expand Down Expand Up @@ -295,6 +297,8 @@ A very fast version of `time_map()`. However, the request parameters are much mo
returns the reachable area for journeys departing from the chosen departure location if true.
* [level_of_detail](#level-of-detail): LevelOfDetail - When enabled, allows the user to specify how detailed the isochrones should be.
* [snapping](#snapping): Snapping - Adjusts the process of looking up the nearest roads from the departure / arrival points.
* [polygons_filter](#polygons-filter): PolygonsFilter - Specifies polygon filter of a single shape.
* [render_mode](#render-mode): RenderMode - Specifies which render mode should be used.

### JSON response

Expand Down Expand Up @@ -1069,3 +1073,33 @@ snapping=Snapping(
accept_roads=SnappingAcceptRoads.ANY_DRIVABLE
)
```

### Polygons Filter

`polygons_filter` specifies polygon filter of a single shape.

For a more detailed description of how to use this parameter, you can refer to our [API Docs](https://docs.traveltime.com/api/reference/isochrones#departure_searches-polygons_filter)

#### Examples

```python
from traveltimepy.dto.common import PolygonsFilter

polygons_filter = PolygonsFilter(limit=1)
polygons_filter = PolygonsFilter(limit=5)
```

### Render Mode

`render_mode` specifies how the shape should be rendered.

For a more detailed description of how to use this parameter, you can refer to our [API Docs](https://docs.traveltime.com/api/reference/isochrones#departure_searches-render_mode)

#### Examples

```python
from traveltimepy.dto.common import RenderMode

render_mode = RenderMode.APPROXIMATE_TIME_FILTER # default
render_mode = RenderMode.ROAD_BUFFERING
```
11 changes: 8 additions & 3 deletions traveltimepy/dto/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class SnappingAcceptRoads(str, Enum):

class Snapping(BaseModel):
penalty: Optional[SnappingPenalty] = SnappingPenalty.ENABLED
accept_roads: Optional[SnappingAcceptRoads] = (
SnappingAcceptRoads.BOTH_DRIVABLE_AND_WALKABLE
)
accept_roads: Optional[
SnappingAcceptRoads
] = SnappingAcceptRoads.BOTH_DRIVABLE_AND_WALKABLE


class PropertyProto(int, Enum):
Expand Down Expand Up @@ -165,6 +165,11 @@ class PolygonsFilter(BaseModel):
limit: int


class RenderMode(str, Enum):
APPROXIMATE_TIME_FILTER = "approximate_time_filter"
ROAD_BUFFERING = "road_buffering"


class TimeInfo:
def __init__(self, time_value: datetime):
self.value = time_value
Expand Down
4 changes: 3 additions & 1 deletion traveltimepy/dto/requests/time_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
CyclingPublicTransport,
LevelOfDetail,
)
from traveltimepy.dto.common import PolygonsFilter, Snapping
from traveltimepy.dto.common import PolygonsFilter, RenderMode, Snapping
from traveltimepy.dto.requests.request import TravelTimeRequest
from traveltimepy.dto.responses.time_map import TimeMapResponse
from traveltimepy.itertools import split, flatten
Expand All @@ -42,6 +42,7 @@ class DepartureSearch(BaseModel):
snapping: Optional[Snapping]
polygons_filter: Optional[PolygonsFilter]
remove_water_bodies: Optional[bool]
render_mode: Optional[RenderMode]


class ArrivalSearch(BaseModel):
Expand All @@ -63,6 +64,7 @@ class ArrivalSearch(BaseModel):
snapping: Optional[Snapping] = None
polygons_filter: Optional[PolygonsFilter]
remove_water_bodies: Optional[bool]
render_mode: Optional[RenderMode]


class Intersection(BaseModel):
Expand Down
6 changes: 4 additions & 2 deletions traveltimepy/dto/requests/time_map_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Coordinates,
LevelOfDetail,
PolygonsFilter,
RenderMode,
Snapping,
)
from traveltimepy.dto.requests.request import TravelTimeRequest
Expand All @@ -20,9 +21,10 @@ class Search(BaseModel):
transportation: Transportation
travel_time: int
arrival_time_period: str
level_of_detail: Optional[LevelOfDetail] = None
level_of_detail: Optional[LevelOfDetail]
snapping: Optional[Snapping] = None
polygons_filter: Optional[PolygonsFilter] = None
polygons_filter: Optional[PolygonsFilter]
render_mode: Optional[RenderMode]


class ArrivalSearches(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions traveltimepy/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async def send_post_request_async(
request: TravelTimeRequest,
rate_limit: AsyncLimiter,
) -> T:
print(request.model_dump_json())
async with rate_limit:
async with client.post(
url=url, headers=headers, data=request.model_dump_json()
Expand Down
31 changes: 28 additions & 3 deletions traveltimepy/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Range,
LevelOfDetail,
PropertyProto,
RenderMode,
TimeInfo,
ArrivalTime,
DepartureTime,
Expand Down Expand Up @@ -130,7 +131,8 @@ def create_time_map_fast(
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
one_to_many: bool = True,
render_mode: Optional[RenderMode],
one_to_many: bool,
) -> TimeMapFastRequest:
if one_to_many:
return TimeMapFastRequest(
Expand All @@ -145,6 +147,7 @@ def create_time_map_fast(
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -164,6 +167,7 @@ def create_time_map_fast(
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -179,7 +183,8 @@ def create_time_map_fast_geojson(
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
one_to_many: bool = True,
render_mode: Optional[RenderMode],
one_to_many: bool,
) -> TimeMapFastGeojsonRequest:
if one_to_many:
return TimeMapFastGeojsonRequest(
Expand All @@ -194,6 +199,7 @@ def create_time_map_fast_geojson(
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -213,6 +219,7 @@ def create_time_map_fast_geojson(
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -228,7 +235,8 @@ def create_time_map_fast_wkt(
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
one_to_many: bool = True,
render_mode: Optional[RenderMode],
one_to_many: bool,
) -> TimeMapFastWKTRequest:
if one_to_many:
return TimeMapFastWKTRequest(
Expand All @@ -243,6 +251,7 @@ def create_time_map_fast_wkt(
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -262,6 +271,7 @@ def create_time_map_fast_wkt(
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down Expand Up @@ -512,6 +522,7 @@ def create_time_map(
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
remove_water_bodies: Optional[bool],
render_mode: Optional[RenderMode],
) -> TimeMapRequest:
if isinstance(time_info, ArrivalTime):
return TimeMapRequest(
Expand All @@ -527,6 +538,7 @@ def create_time_map(
snapping=snapping,
polygons_filter=polygons_filter,
remove_water_bodies=remove_water_bodies,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -548,6 +560,7 @@ def create_time_map(
snapping=snapping,
polygons_filter=polygons_filter,
remove_water_bodies=remove_water_bodies,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down Expand Up @@ -577,6 +590,7 @@ def create_time_map_geojson(
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
remove_water_bodies: Optional[bool],
render_mode: Optional[RenderMode],
) -> TimeMapRequestGeojson:
if isinstance(time_info, ArrivalTime):
return TimeMapRequestGeojson(
Expand All @@ -592,6 +606,7 @@ def create_time_map_geojson(
snapping=snapping,
polygons_filter=polygons_filter,
remove_water_bodies=remove_water_bodies,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -611,6 +626,7 @@ def create_time_map_geojson(
snapping=snapping,
polygons_filter=polygons_filter,
remove_water_bodies=remove_water_bodies,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down Expand Up @@ -638,6 +654,7 @@ def create_time_map_wkt(
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
remove_water_bodies: Optional[bool],
render_mode: Optional[RenderMode],
) -> TimeMapWKTRequest:
if isinstance(time_info, ArrivalTime):
return TimeMapWKTRequest(
Expand All @@ -653,6 +670,7 @@ def create_time_map_wkt(
snapping=snapping,
polygons_filter=polygons_filter,
remove_water_bodies=remove_water_bodies,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -671,6 +689,7 @@ def create_time_map_wkt(
snapping=snapping,
polygons_filter=polygons_filter,
remove_water_bodies=remove_water_bodies,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down Expand Up @@ -757,6 +776,7 @@ def create_intersection(
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
remove_water_bodies: Optional[bool],
render_mode: Optional[RenderMode],
) -> TimeMapRequest:
if isinstance(time_info, ArrivalTime):
return TimeMapRequest(
Expand All @@ -772,6 +792,7 @@ def create_intersection(
snapping=snapping,
polygons_filter=polygons_filter,
remove_water_bodies=remove_water_bodies,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -798,6 +819,7 @@ def create_intersection(
snapping=snapping,
polygons_filter=polygons_filter,
remove_water_bodies=remove_water_bodies,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down Expand Up @@ -832,6 +854,7 @@ def create_union(
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
remove_water_bodies: Optional[bool],
render_mode: Optional[RenderMode],
) -> TimeMapRequest:
if isinstance(time_info, ArrivalTime):
return TimeMapRequest(
Expand All @@ -847,6 +870,7 @@ def create_union(
snapping=snapping,
polygons_filter=polygons_filter,
remove_water_bodies=remove_water_bodies,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -873,6 +897,7 @@ def create_union(
snapping=snapping,
polygons_filter=polygons_filter,
remove_water_bodies=remove_water_bodies,
render_mode=render_mode,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down
Loading

0 comments on commit 8d65efd

Please sign in to comment.