{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# BRouter profiles tester" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here are some test cases to check BRouter profiles and help with development of new profiles. You need a running BRouter-server instance (see `BROUTER_URL` below).\n", "\n", "The tests assume the BRouter instance uses [these `segments4` files](https://pub.phyks.me/brouter-testing/segments4/) which are built from the [Geofabrik.de](https://download.geofabrik.de/) extracts of metropolitan France, New York state (US) and Sachsen state (Germany) from the 10th of November, 2018. The `profiles2` folder used to build the `segments4` files is available [here](https://pub.phyks.me/brouter-testing/profiles2/) (including the `lookups.dat` file). The SRTM data used to build the `segments4` are available [here](https://pub.phyks.me/brouter-testing/srtm/).\n", "\n", "Beware that the map tiles used across this notebook are the live map tiles (using up to date OSM data) contrary to the `segments4` files which are using a fixed dump of OSM data. Then, the map background may come out of sync with the data used by BRouter and are only there as an eyeguide.\n", "\n", "The map show the route computed with the selected profile (in blue), the route computed by the reference profile (in grey) as well as a route computed by a human (in green). Note that the human route is not necessarily the best one or the unique valid solution." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2019-05-06T13:49:03.629948Z", "start_time": "2019-05-06T13:49:02.938187Z" } }, "outputs": [], "source": [ "import folium\n", "import requests" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2019-05-06T13:51:51.367704Z", "start_time": "2019-05-06T13:51:51.354939Z" } }, "outputs": [], "source": [ "BROUTER_URL = 'http://127.0.0.1:17777' # URL of the BRouter-server instance, no trailing slash\n", "PROFILE = 'trekking-custom' # Profile to test\n", "REFERENCE_PROFILE = 'trekking' # Profile to compare to, used as a reference\n", "FORMAT = 'geojson'\n", "ALTERNATIVEIDX = 0\n", "\n", "TILES = 'openstreetmap' # Map background is regular OSM style\n", "\n", "BROUTER_WEB_URL = 'http://127.0.0.1:8000'" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2019-05-06T13:53:31.401284Z", "start_time": "2019-05-06T13:53:31.343919Z" } }, "outputs": [], "source": [ "def brouter_route(start_point, end_point, profile):\n", " return requests.get(\n", " '%s/brouter' % BROUTER_URL,\n", " params={\n", " 'lonlats': '%s|%s' % (\n", " ','.join(str(x) for x in start_point),\n", " ','.join(str(x) for x in end_point)\n", " ),\n", " 'profile': profile,\n", " 'alternativeidx': ALTERNATIVEIDX,\n", " 'format': FORMAT\n", " }\n", " )\n", "\n", "def plot_route(start_point, end_point, human_geojson=None):\n", " \"\"\"\n", " Helper to plot routes on the map.\n", " \n", " :param start_point: A (longitude, latitude) tuple for the starting point.\n", " :param end_point: A (longitude, latitude) tuple for the ending point.\n", " :returns: A ``folium`` map object.\n", " \"\"\"\n", " r = brouter_route(start_point, end_point, PROFILE)\n", " r_ref = brouter_route(start_point, end_point, REFERENCE_PROFILE)\n", " \n", " mapa = folium.Map(\n", " list(reversed(start_point)),\n", " zoom_start=17,\n", " tiles=TILES\n", " )\n", "\n", " route_ref = folium.features.GeoJson(r_ref.json())\n", " route_ref.style_function = lambda feature: {\n", " 'color': '#666666',\n", " }\n", " mapa.add_child(route_ref)\n", " \n", " if human_geojson:\n", " route_human = folium.features.GeoJson(human_geojson)\n", " route_human.style_function = lambda feature: {\n", " 'color': '#5CA423',\n", " }\n", " mapa.add_child(route_human)\n", "\n", " route = folium.features.GeoJson(r.json())\n", " mapa.add_child(route)\n", " \n", " mapa.add_child(folium.Marker(list(reversed(start_point)), icon=folium.Icon(icon='play')))\n", " mapa.add_child(folium.Marker(list(reversed(end_point)), icon=folium.Icon(icon='stop')))\n", " mapa.fit_bounds(route.get_bounds())\n", " \n", " print('%s/#map=%s/%s/%s/OpenStreetMap&lonlats=%s|%s&profile=%s' % (\n", " BROUTER_WEB_URL,\n", " mapa.zoom_start,\n", " start_point[1],\n", " start_point[0],\n", " ','.join(str(x) for x in start_point),\n", " ','.join(str(x) for x in end_point),\n", " PROFILE\n", " ))\n", " \n", " return mapa" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Complete routes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From Montrouge to Le Plessis-Robinson:\n", "\n", "* there is a continuous cycle way along the \"Avenue de Paris\" / \"Avenue de Verdun\" which should be taken." ] }, { "cell_type": "code", "execution_count": 423, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "http://127.0.0.1:8000/#map=17/48.817086/2.318587/OpenStreetMap&lonlats=2.318587,48.817086|2.239258,48.780444&profile=trekking-custom\n" ] }, { "data": { "text/html": [ "