Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding render_mode and description of polygons_filter #150

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1070,3 +1074,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
```
5 changes: 5 additions & 0 deletions traveltimepy/dto/common.py
Original file line number Diff line number Diff line change
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
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 @@ -760,6 +779,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 @@ -775,6 +795,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 @@ -801,6 +822,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 @@ -835,6 +857,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 @@ -850,6 +873,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 @@ -876,6 +900,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
Loading