Skip to content

Commit 72be9ea

Browse files
authored
remove mapbox valhalla (#114)
1 parent 862a7cf commit 72be9ea

File tree

7 files changed

+30
-160
lines changed

7 files changed

+30
-160
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010

1111
### Added
1212
- Valhalla `/expansion` examples in the Jupyter Notebook
13+
- OpenTripPlanner v2 support for routing & isochrones
1314

1415
### Fixed
1516
- Google router's `duration` and `distance` attributes not being calculated correctly in single route response ([#107](https://github.com/gis-ops/routingpy/issues/107))
17+
- pointer issue when requesting multiple times with the same connection
18+
19+
### Removed
20+
- `MapboxValhalla` provider, since Mapbox doesn't expose a public Valhalla endpoint anymore
1621

1722
## [v1.2.1](https://pypi.org/project/routingpy/1.2.1/)
1823
### Fixed

examples/basic_examples.ipynb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@
8989
},
9090
"outputs": [],
9191
"source": [
92-
"# Create your own API key at https://account.mapbox.com/access-tokens/\n",
93-
"key_mapbox = \"\"\n",
94-
"api = rp.MapboxValhalla(api_key=key_mapbox)\n",
92+
"# defaults to https://valhalla1.openstreetmap.de\n",
93+
"api = rp.Valhalla()\n",
9594
"\n",
9695
"isochrones = api.isochrones(locations=coordinates[0],\n",
9796
" profile='auto',\n",

examples/compare_providers.ipynb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@
125125
" 'isochrones_profile': 'mapbox/driving',\n",
126126
" 'isochrones': True\n",
127127
" },\n",
128-
" 'mapbox_valhalla': {\n",
129-
" 'api_key': ''\n",
130-
" 'display_name': 'MapBox (Valhalla)',\n",
131-
" 'profile': 'auto',\n",
132-
" 'color': '#40b6b8',\n",
133-
" 'isochrones': True\n",
134-
" },\n",
135128
" 'google': {\n",
136129
" 'api_key': '',\n",
137130
" 'display_name': 'Google',\n",
@@ -347,7 +340,7 @@
347340
"cell_type": "markdown",
348341
"metadata": {},
349342
"source": [
350-
"Unfortunately, the `isochrones` methods are not as consistent as the other endpoints. Graphhopper does not allow for arbitrary ranges, while all others do. And Mapbox did the glorious decision to name their `isochrones` profiles different than their `directions` profiles. Here, it's interesting to note though, that their OSRM isochrone extension is not supported anymore and instead their isochrone endpoint runs on Valhalla (as you will see when you compare the Mapbox OSRM and Valhalla isochrones in the map below)."
343+
"Unfortunately, the `isochrones` methods are not as consistent as the other endpoints. Graphhopper does not allow for arbitrary ranges, while all others do. And Mapbox did the glorious decision to name their `isochrones` profiles different than their `directions` profiles. Here, it's interesting to note though, that their OSRM isochrone extension is not supported anymore and instead their isochrone endpoint runs on Valhalla."
351344
]
352345
},
353346
{

routingpy/routers/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from .graphhopper import Graphhopper
2121
from .heremaps import HereMaps
2222
from .mapbox_osrm import MapboxOSRM
23-
from .mapbox_valhalla import MapboxValhalla
2423
from .openrouteservice import ORS
2524
from .opentripplanner_v2 import OpenTripPlannerV2
2625
from .osrm import OSRM
@@ -33,15 +32,15 @@
3332
"here": HereMaps,
3433
"heremaps": HereMaps,
3534
"mapbox_osrm": MapboxOSRM,
36-
"mapbox_valhalla": MapboxValhalla,
3735
"mapbox-osrm": MapboxOSRM,
38-
"mapbox-valhalla": MapboxValhalla,
3936
"mapbox": MapboxOSRM,
4037
"mapboxosrm": MapboxOSRM,
41-
"mapboxvalhalla": MapboxValhalla,
4238
"openrouteservice": ORS,
39+
"opentripplanner": OpenTripPlannerV2,
40+
"opentripplanner_v2": OpenTripPlannerV2,
4341
"ors": ORS,
4442
"osrm": OSRM,
43+
"otp": OpenTripPlannerV2,
4544
"otp_v2": OpenTripPlannerV2,
4645
"valhalla": Valhalla,
4746
}

routingpy/routers/mapbox_valhalla.py

Lines changed: 0 additions & 84 deletions
This file was deleted.

routingpy/routers/valhalla.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
class Valhalla:
3232
"""Performs requests to a Valhalla instance."""
3333

34+
_DEFAULT_BASE_URL = "https://valhalla1.openstreetmap.de"
35+
3436
def __init__(
3537
self,
36-
base_url: str,
37-
api_key: Optional[str] = None,
38+
base_url: str = _DEFAULT_BASE_URL,
3839
user_agent: Optional[str] = None,
3940
timeout: Optional[Union[int, None]] = DEFAULT,
4041
retry_timeout: Optional[int] = None,
@@ -46,9 +47,7 @@ def __init__(
4647
"""
4748
Initializes a Valhalla client.
4849
49-
:param api_key: Mapbox API key. Required if base_url='https://api.mapbox.com/valhalla/v1'.
50-
51-
:param base_url: The base URL for the request. Defaults to the ORS API
50+
:param base_url: The base URL for the request. Defaults to the public OSM
5251
server. Should not have a trailing slash.
5352
5453
:param user_agent: User Agent to be used when requesting.
@@ -75,8 +74,6 @@ def __init__(
7574
:param client_kwargs: Additional arguments passed to the client, such as headers or proxies.
7675
"""
7776

78-
self.api_key = api_key
79-
8077
self.client = client(
8178
base_url,
8279
user_agent,
@@ -203,10 +200,8 @@ def directions(
203200
**kwargs
204201
)
205202

206-
get_params = {"access_token": self.api_key} if self.api_key else {}
207-
208203
return self.parse_direction_json(
209-
self.client._request("/route", get_params=get_params, post_params=params, dry_run=dry_run),
204+
self.client._request("/route", post_params=params, dry_run=dry_run),
210205
units,
211206
)
212207

@@ -391,11 +386,8 @@ def isochrones( # noqa: C901
391386
**kwargs
392387
)
393388

394-
get_params = {"access_token": self.api_key} if self.api_key else {}
395389
return self.parse_isochrone_json(
396-
self.client._request(
397-
"/isochrone", get_params=get_params, post_params=params, dry_run=dry_run
398-
),
390+
self.client._request("/isochrone", post_params=params, dry_run=dry_run),
399391
intervals,
400392
locations,
401393
interval_type,
@@ -513,6 +505,7 @@ def matrix(
513505
avoid_locations: Optional[List[List[float]]] = None,
514506
avoid_polygons: Optional[List[List[List[float]]]] = None,
515507
units: Optional[str] = None,
508+
date_time: Optional[dict] = None,
516509
id: Optional[str] = None,
517510
dry_run: Optional[bool] = None,
518511
**kwargs
@@ -555,6 +548,10 @@ def matrix(
555548
556549
:param units: Distance units for output. One of ['mi', 'km']. Default km.
557550
551+
:param date_time: This is the local date and time at the location. Field ``type``: 0: Current departure time,
552+
1: Specified departure time. Field ``value```: the date and time is specified
553+
in format YYYY-MM-DDThh:mm, local time.
554+
558555
:param id: Name your route request. If id is specified, the naming will be sent through to the response.
559556
560557
:param dry_run: Print URL and parameters without sending the request.
@@ -573,16 +570,13 @@ def matrix(
573570
avoid_locations,
574571
avoid_polygons,
575572
units,
573+
date_time,
576574
id,
577575
**kwargs
578576
)
579577

580-
get_params = {"access_token": self.api_key} if self.api_key else {}
581-
582578
return self.parse_matrix_json(
583-
self.client._request(
584-
"/sources_to_targets", get_params=get_params, post_params=params, dry_run=dry_run
585-
),
579+
self.client._request("/sources_to_targets", post_params=params, dry_run=dry_run),
586580
units,
587581
)
588582

@@ -597,6 +591,7 @@ def get_matrix_params(
597591
avoid_locations=None,
598592
avoid_polygons=None,
599593
units=None,
594+
date_time=None,
600595
id=None,
601596
**kwargs
602597
):
@@ -642,6 +637,9 @@ def get_matrix_params(
642637
if units:
643638
params["units"] = units
644639

640+
if date_time:
641+
params["date_time"] = date_time
642+
645643
if id:
646644
params["id"] = id
647645

@@ -717,8 +715,6 @@ def expansion(
717715
718716
:returns: An expansions object consisting of single line strings and their attributes (if specified).
719717
"""
720-
721-
get_params = {"access_token": self.api_key} if self.api_key else {}
722718
params = self.get_expansion_params(
723719
locations,
724720
profile,
@@ -732,9 +728,7 @@ def expansion(
732728
**kwargs
733729
)
734730
return self.parse_expansion_json(
735-
self.client._request(
736-
"/expansion", get_params=get_params, post_params=params, dry_run=dry_run
737-
),
731+
self.client._request("/expansion", post_params=params, dry_run=dry_run),
738732
locations,
739733
expansion_properties,
740734
interval_type,
@@ -827,8 +821,6 @@ def trace_attributes(
827821
:raises: ValueError if 'locations' and 'encoded_polyline' was specified
828822
:returns: A :class:`MatchedResults` object with matched edges and points set.
829823
"""
830-
831-
get_params = {"access_token": self.api_key} if self.api_key else {}
832824
if locations and encoded_polyline:
833825
raise ValueError
834826

@@ -837,9 +829,7 @@ def trace_attributes(
837829
)
838830

839831
return self.parse_trace_attributes_json(
840-
self.client._request(
841-
"/trace_attributes", get_params=get_params, post_params=params, dry_run=dry_run
842-
)
832+
self.client._request("/trace_attributes", post_params=params, dry_run=dry_run)
843833
)
844834

845835
@classmethod

tests/test_mapbox_valhalla.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)