Skip to content

Commit

Permalink
remove mapbox valhalla (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsnolde committed Aug 3, 2023
1 parent 862a7cf commit 72be9ea
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 160 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added
- Valhalla `/expansion` examples in the Jupyter Notebook
- OpenTripPlanner v2 support for routing & isochrones

### Fixed
- Google router's `duration` and `distance` attributes not being calculated correctly in single route response ([#107](https://github.com/gis-ops/routingpy/issues/107))
- pointer issue when requesting multiple times with the same connection

### Removed
- `MapboxValhalla` provider, since Mapbox doesn't expose a public Valhalla endpoint anymore

## [v1.2.1](https://pypi.org/project/routingpy/1.2.1/)
### Fixed
Expand Down
5 changes: 2 additions & 3 deletions examples/basic_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@
},
"outputs": [],
"source": [
"# Create your own API key at https://account.mapbox.com/access-tokens/\n",
"key_mapbox = \"\"\n",
"api = rp.MapboxValhalla(api_key=key_mapbox)\n",
"# defaults to https://valhalla1.openstreetmap.de\n",
"api = rp.Valhalla()\n",
"\n",
"isochrones = api.isochrones(locations=coordinates[0],\n",
" profile='auto',\n",
Expand Down
9 changes: 1 addition & 8 deletions examples/compare_providers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@
" 'isochrones_profile': 'mapbox/driving',\n",
" 'isochrones': True\n",
" },\n",
" 'mapbox_valhalla': {\n",
" 'api_key': ''\n",
" 'display_name': 'MapBox (Valhalla)',\n",
" 'profile': 'auto',\n",
" 'color': '#40b6b8',\n",
" 'isochrones': True\n",
" },\n",
" 'google': {\n",
" 'api_key': '',\n",
" 'display_name': 'Google',\n",
Expand Down Expand Up @@ -347,7 +340,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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)."
"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."
]
},
{
Expand Down
7 changes: 3 additions & 4 deletions routingpy/routers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from .graphhopper import Graphhopper
from .heremaps import HereMaps
from .mapbox_osrm import MapboxOSRM
from .mapbox_valhalla import MapboxValhalla
from .openrouteservice import ORS
from .opentripplanner_v2 import OpenTripPlannerV2
from .osrm import OSRM
Expand All @@ -33,15 +32,15 @@
"here": HereMaps,
"heremaps": HereMaps,
"mapbox_osrm": MapboxOSRM,
"mapbox_valhalla": MapboxValhalla,
"mapbox-osrm": MapboxOSRM,
"mapbox-valhalla": MapboxValhalla,
"mapbox": MapboxOSRM,
"mapboxosrm": MapboxOSRM,
"mapboxvalhalla": MapboxValhalla,
"openrouteservice": ORS,
"opentripplanner": OpenTripPlannerV2,
"opentripplanner_v2": OpenTripPlannerV2,
"ors": ORS,
"osrm": OSRM,
"otp": OpenTripPlannerV2,
"otp_v2": OpenTripPlannerV2,
"valhalla": Valhalla,
}
Expand Down
84 changes: 0 additions & 84 deletions routingpy/routers/mapbox_valhalla.py

This file was deleted.

48 changes: 19 additions & 29 deletions routingpy/routers/valhalla.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
class Valhalla:
"""Performs requests to a Valhalla instance."""

_DEFAULT_BASE_URL = "https://valhalla1.openstreetmap.de"

def __init__(
self,
base_url: str,
api_key: Optional[str] = None,
base_url: str = _DEFAULT_BASE_URL,
user_agent: Optional[str] = None,
timeout: Optional[Union[int, None]] = DEFAULT,
retry_timeout: Optional[int] = None,
Expand All @@ -46,9 +47,7 @@ def __init__(
"""
Initializes a Valhalla client.
:param api_key: Mapbox API key. Required if base_url='https://api.mapbox.com/valhalla/v1'.
:param base_url: The base URL for the request. Defaults to the ORS API
:param base_url: The base URL for the request. Defaults to the public OSM
server. Should not have a trailing slash.
:param user_agent: User Agent to be used when requesting.
Expand All @@ -75,8 +74,6 @@ def __init__(
:param client_kwargs: Additional arguments passed to the client, such as headers or proxies.
"""

self.api_key = api_key

self.client = client(
base_url,
user_agent,
Expand Down Expand Up @@ -203,10 +200,8 @@ def directions(
**kwargs
)

get_params = {"access_token": self.api_key} if self.api_key else {}

return self.parse_direction_json(
self.client._request("/route", get_params=get_params, post_params=params, dry_run=dry_run),
self.client._request("/route", post_params=params, dry_run=dry_run),
units,
)

Expand Down Expand Up @@ -391,11 +386,8 @@ def isochrones( # noqa: C901
**kwargs
)

get_params = {"access_token": self.api_key} if self.api_key else {}
return self.parse_isochrone_json(
self.client._request(
"/isochrone", get_params=get_params, post_params=params, dry_run=dry_run
),
self.client._request("/isochrone", post_params=params, dry_run=dry_run),
intervals,
locations,
interval_type,
Expand Down Expand Up @@ -513,6 +505,7 @@ def matrix(
avoid_locations: Optional[List[List[float]]] = None,
avoid_polygons: Optional[List[List[List[float]]]] = None,
units: Optional[str] = None,
date_time: Optional[dict] = None,
id: Optional[str] = None,
dry_run: Optional[bool] = None,
**kwargs
Expand Down Expand Up @@ -555,6 +548,10 @@ def matrix(
:param units: Distance units for output. One of ['mi', 'km']. Default km.
:param date_time: This is the local date and time at the location. Field ``type``: 0: Current departure time,
1: Specified departure time. Field ``value```: the date and time is specified
in format YYYY-MM-DDThh:mm, local time.
:param id: Name your route request. If id is specified, the naming will be sent through to the response.
:param dry_run: Print URL and parameters without sending the request.
Expand All @@ -573,16 +570,13 @@ def matrix(
avoid_locations,
avoid_polygons,
units,
date_time,
id,
**kwargs
)

get_params = {"access_token": self.api_key} if self.api_key else {}

return self.parse_matrix_json(
self.client._request(
"/sources_to_targets", get_params=get_params, post_params=params, dry_run=dry_run
),
self.client._request("/sources_to_targets", post_params=params, dry_run=dry_run),
units,
)

Expand All @@ -597,6 +591,7 @@ def get_matrix_params(
avoid_locations=None,
avoid_polygons=None,
units=None,
date_time=None,
id=None,
**kwargs
):
Expand Down Expand Up @@ -642,6 +637,9 @@ def get_matrix_params(
if units:
params["units"] = units

if date_time:
params["date_time"] = date_time

if id:
params["id"] = id

Expand Down Expand Up @@ -717,8 +715,6 @@ def expansion(
:returns: An expansions object consisting of single line strings and their attributes (if specified).
"""

get_params = {"access_token": self.api_key} if self.api_key else {}
params = self.get_expansion_params(
locations,
profile,
Expand All @@ -732,9 +728,7 @@ def expansion(
**kwargs
)
return self.parse_expansion_json(
self.client._request(
"/expansion", get_params=get_params, post_params=params, dry_run=dry_run
),
self.client._request("/expansion", post_params=params, dry_run=dry_run),
locations,
expansion_properties,
interval_type,
Expand Down Expand Up @@ -827,8 +821,6 @@ def trace_attributes(
:raises: ValueError if 'locations' and 'encoded_polyline' was specified
:returns: A :class:`MatchedResults` object with matched edges and points set.
"""

get_params = {"access_token": self.api_key} if self.api_key else {}
if locations and encoded_polyline:
raise ValueError

Expand All @@ -837,9 +829,7 @@ def trace_attributes(
)

return self.parse_trace_attributes_json(
self.client._request(
"/trace_attributes", get_params=get_params, post_params=params, dry_run=dry_run
)
self.client._request("/trace_attributes", post_params=params, dry_run=dry_run)
)

@classmethod
Expand Down
32 changes: 0 additions & 32 deletions tests/test_mapbox_valhalla.py

This file was deleted.

0 comments on commit 72be9ea

Please sign in to comment.