diff --git "a/code/export-processed-data.ipynb" "b/code/export-processed-data.ipynb" new file mode 100644--- /dev/null +++ "b/code/export-processed-data.ipynb" @@ -0,0 +1,339 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "56055bd3", + "metadata": {}, + "source": [ + "### Exporting the processed intersections, bus stops and focus points to the VED files." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b1e30678", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import pandas as pd\n", + "import numpy as np\n", + "from tqdm.notebook import tqdm\n", + "import folium\n", + "import csv" + ] + }, + { + "cell_type": "markdown", + "id": "0591f464", + "metadata": {}, + "source": [ + "Read three CSV files: intersections, focus points and bus stops." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b380a50a", + "metadata": {}, + "outputs": [], + "source": [ + "intersections = pd.read_csv('../data/processed/joined_coords_intersections.csv').to_numpy()\n", + "focus_points = pd.read_csv('../data/processed/joined_layer_coords_focus_points.csv')\n", + "# combine different focus points in the 'highway' column\n", + "focus_points['highway'] = focus_points.bfill(1)['highway']\n", + "focus_points = focus_points.to_numpy()\n", + "busstops = pd.read_csv('../data/processed/joined_coords_bus_stops.csv').to_numpy()" + ] + }, + { + "cell_type": "markdown", + "id": "bf202e40", + "metadata": {}, + "source": [ + "Create dictionaries where keys are the latitude/longitude coordinates." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "2a3c3ebb", + "metadata": {}, + "outputs": [], + "source": [ + "intersections_dict = {(intersections[i,0], intersections[i,1]) : 1 for i in range(len(intersections))}\n", + "busstops_dict = {(busstops[i,0], busstops[i,1]) : 1 for i in range(len(busstops))}\n", + "focus_points_dict = {(focus_points[i,0], focus_points[i,1]) : focus_points[i,4] for i in range(len(focus_points))}" + ] + }, + { + "cell_type": "markdown", + "id": "170161c7", + "metadata": {}, + "source": [ + "Let's visualize some of the intersections. Folium map is slow if we try to plot all of them. Therefore, we will plot the first 1000 intersections." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "66bb6abd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_map(latlon):\n", + " tiles = \"cartodbpositron\"\n", + " map = folium.Map(prefer_canvas=True, tiles=tiles)\n", + " t = folium.TileLayer(tiles).add_to(map)\n", + " lats = [point[0] for point in latlon]\n", + " lons = [point[1] for point in latlon]\n", + " min_lat, max_lat = min(lats), max(lats)\n", + " min_lon, max_lon = min(lons), max(lons)\n", + " map.fit_bounds([[min_lat, min_lon], [max_lat, max_lon]])\n", + " for point in latlon:\n", + " folium.CircleMarker(\n", + " location=[point[0], point[1]], radius=2, fill=True, color='red',\n", + " popup='').add_to(map)\n", + " return map\n", + "\n", + "plot_map(list(intersections_dict.keys())[0:1000])" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "453d7ed7", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f4c1c8888532499d99ef9a3b3122c2ad", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + " 0%| | 0/54 [00:00