This repository contains a tutorial on how to create an interactive map of Mexico City's metro system using Python, GeoPandas, and Folium. The map includes metro stations and 15-minute walking isochrones for each station.
You can run this tutorial directly in your browser using Google Colab. Click the badge below to open the notebook:
- Python 3.7+
- GeoPandas
- Folium
- Requests
-
Clone this repository:
git clone https://github.com/yourusername/mexico-city-metro-map.git cd mexico-city-metro-map -
Install the required packages:
pip install geopandas folium requests
-
Convert the shapefile to GeoJSON:
python convert_shapefile.py -
Create the interactive map:
python create_map.py -
Open the generated
mexico_city_metro_map.htmlfile in your web browser to view the map.
To change the isochrone radius (currently set to 15 minutes), modify the create_map.py file. Locate the following line in the create_map() function:
isochrone = get_isochrone(lat, lng, 15) # 15-minute isochroneChange the number 15 to your desired time in minutes. For example, to create 30-minute isochrones:
isochrone = get_isochrone(lat, lng, 30) # 30-minute isochroneThe current map uses walking as the mode of transportation for isochrones. To change this, you need to modify the API endpoint in the get_isochrone() function in create_map.py. Find this line:
url = "https://api.openrouteservice.org/v2/isochrones/foot-walking"You can change foot-walking to one of the following options:
driving-carfor drivingcycling-regularfor cyclingfoot-walkingfor walking (current setting)
For example, to change to driving:
url = "https://api.openrouteservice.org/v2/isochrones/driving-car"Remember to adjust the isochrone time accordingly, as different transportation modes will cover different distances in the same time.
README.md: This file, containing an overview and instructions.convert_shapefile.py: Script to convert the shapefile to GeoJSON.create_map.py: Script to create the interactive map with stations and isochrones.Mexico_City_Metro_Map.ipynb: Jupyter notebook for running the tutorial in Google Colab.STC_Metro_estaciones_utm14n.shp: Input shapefile (not included in the repository).mexico_city_subway_stations.geojson: Output GeoJSON file (generated byconvert_shapefile.py).mexico_city_metro_map.html: Output HTML file containing the interactive map (generated bycreate_map.py).
You'll need to obtain an API key from OpenRouteService and replace the placeholder in create_map.py with your actual key.
This project is open source and available under the MIT License.