{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import pandas as pd\n", "\n", "\n", "df = pd.read_csv(os.path.join(\"data\", \"highlight_flight_trajectories.csv\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us take a glance at the data.\n", "Each row represents the trajectory of a flight,\n", "and the last column contains the coordinates of the flight path in `GeoJSON` format." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0depdestgeojson
00Place_MontpellierMediterranee_AirportPlace_BastiaPoretta_Airport{\"type\": \"LineString\", \"coordinates\": [[3.9613...
11Place_Bristol___LulsgatePlace_TenerifeSur_ReinaSofia_Airport{\"type\": \"LineString\", \"coordinates\": [[-2.719...
22Place_Valencia_Manises_AirportPlace_Bucuresti_HenriCoanda_Airport{\"type\": \"LineString\", \"coordinates\": [[-0.481...
\n", "
" ], "text/plain": [ " Unnamed: 0 dep \\\n", "0 0 Place_MontpellierMediterranee_Airport \n", "1 1 Place_Bristol___Lulsgate \n", "2 2 Place_Valencia_Manises_Airport \n", "\n", " dest \\\n", "0 Place_BastiaPoretta_Airport \n", "1 Place_TenerifeSur_ReinaSofia_Airport \n", "2 Place_Bucuresti_HenriCoanda_Airport \n", "\n", " geojson \n", "0 {\"type\": \"LineString\", \"coordinates\": [[3.9613... \n", "1 {\"type\": \"LineString\", \"coordinates\": [[-2.719... \n", "2 {\"type\": \"LineString\", \"coordinates\": [[-0.481... " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import folium\n", "\n", "\n", "m = folium.Map(location=[40, 10], zoom_start=4, control_scale=True, prefer_canvas=True)\n", "\n", "\n", "def style_function(feature):\n", " return {\"fillColor\": \"#ffaf00\", \"color\": \"blue\", \"weight\": 1.5, \"dashArray\": \"5, 5\"}\n", "\n", "\n", "def highlight_function(feature):\n", " return {\"fillColor\": \"#ffaf00\", \"color\": \"green\", \"weight\": 3, \"dashArray\": \"5, 5\"}\n", "\n", "\n", "for index, row in df.iterrows():\n", " c = folium.GeoJson(\n", " row[\"geojson\"],\n", " name=(\"{}{}\".format(row[\"dep\"], row[\"dest\"])),\n", " overlay=True,\n", " style_function=style_function,\n", " highlight_function=highlight_function,\n", " )\n", " folium.Popup(\"{}\\n{}\".format(row[\"dep\"], row[\"dest\"])).add_to(c)\n", " c.add_to(m)\n", "\n", "folium.LayerControl().add_to(m)\n", "\n", "m" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.0" } }, "nbformat": 4, "nbformat_minor": 2 }