{ "cells": [ { "cell_type": "markdown", "id": "eb4d98e6", "metadata": {}, "source": [ "### In this notebook we will use Valhalla to snap the latitude/longitude points from VED to roads using OpenStreetMap data." ] }, { "cell_type": "code", "execution_count": 1, "id": "d99459b1", "metadata": {}, "outputs": [], "source": [ "import os\n", "import pandas as pd\n", "import numpy as np\n", "import requests\n", "import json\n", "from tqdm.notebook import tqdm" ] }, { "cell_type": "markdown", "id": "1b3e0b1f", "metadata": {}, "source": [ "Create the headers and the meili request body." ] }, { "cell_type": "code", "execution_count": 2, "id": "20178448", "metadata": {}, "outputs": [], "source": [ "def create_meili_request_body(df_trip):\n", " \"\"\"Returns the body for meili for its request.\n", " \"\"\"\n", " coordinates = df_trip.to_json(orient='records')\n", " head = '{\"shape\":'\n", " tail = \"\"\",\"search_radius\": 5, \"shape_match\":\"map_snap\", \"costing\":\"auto\", \"format\":\"osrm\"}\"\"\"\n", " body = head + coordinates + tail\n", " return body" ] }, { "cell_type": "code", "execution_count": 3, "id": "357a90c4", "metadata": {}, "outputs": [], "source": [ "headers = {'Content-type': 'application/json'}\n", "trace_url = \"http://localhost:8002/trace_attributes\"" ] }, { "cell_type": "markdown", "id": "154c0f88", "metadata": {}, "source": [ "Read all the file names" ] }, { "cell_type": "code", "execution_count": 4, "id": "f1097900", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "da818fc0e91c42fcb09ca4b0fadd0d45", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/54 [00:00