Finding suitable housing near our children’s school is a common concern for many families. Fortunately, isochrone maps offer an effective way to visualize accessible areas based on travel time. In this blogpost, you will learn how to use Python and the Leaflet and Folium libraries to create an interactive isochrone map of the city of Nantes, France, and find the ideal place to live near your children’s new school.

Prerequisites
Before you start, make sure you have the following Python libraries installed in your environment:
- Folium
- Requests
- Shapely
import folium
import requests
from shapely.geometry import Polygon
from shapely.ops import cascaded_union
In addition, you will need to obtain an access token for the Mapbox isochron service. If you don’t already have one, you can create a free Mapbox account and get the token from their website.
Step 1: Set location and time intervals
First, we need to set the location of your children’s new school in Nantes. Use latitude and longitude coordinates to mark this location on the map.
# Defines the location and starting point (Nantes, France)
lat = 47.23864
lon = -1.53362
I used Google Maps to locate the place. Right click on the red node on the map and it will show you the coordinates you need. 📍🗺
Then, determine the desired time intervals in minutes, considering the maximum time you are willing to spend on your children’s daily commute to and from school. For example, you could set intervals of 10, 20 and 30 minutes.
# Defines the time intervals in minutes for the isochrones.
intervals = [5, 10, 15] # Adjusted to 5, 10 and 15 minutes at average speed of a walking person

Step 2: Get the isochron data
We will use the requests library to send an HTTP request to the Mapbox isochron service and get the data corresponding to each time interval.
# Define the isochron service access token
token = "pk.token.mapbox" # Replace with your own token
# Create an interactive map using Folium
map = folium.Map(location=[lat, lon], zoom_start=15)
# Traverse the time intervals and get the isochrones.
for interval in intervals:
# Construct the URL of the isochrone request.
url = f "https://api.mapbox.com/isochrone/v1/mapbox/walking/{lon},{lat}?contours_minutes={interval}&polygons=true&access_token={token}"
# Performs HTTP request and gets the response data.
response = requests.get(url)
data = response.json()
We will construct the URL of the isochron request using the coordinates of the school location and the access token provided by Mapbox. Then, we will send the request and get the response in JSON format.
Step 3: Processing the data and generating the polygons
Once we get the JSON data for each isochron, we will extract the coordinates of the isochron polygons using the shapely library.
# Extract the coordinates of the isochron polygons
coordinates = data["features"][0]["geometry"]["coordinates"]]
# Create a Shapely polygon and add the points of the polygon
polygon = Polygon(coordinates[0])
# Add the polygon to the map as a GeoJSON layer
folium.GeoJson(
data=data,
style_function=lambda x: {'fillColor': '#e26e4d', 'color': '#ea4141', 'weight': 1, 'fillOpacity': 0.3},
name=f"{interval} min"
).add_to(map)
Next, we will use shapely’s cascaded_union operation to combine the isochron polygons into one. This will give us a polygon that represents all accessible areas within the set time intervals.
Step 4: Create the interactive map with Folium
We will use the folium library to create an interactive map and add the isochron polygon as a GeoJSON layer. We will set a style for the polygon and adjust the opacity for better visualization.
# Add a control layer to toggle the display of isochrones
folium.LayerControl().add_to(map)
In addition, we will add other useful layers, such as nearby schools, public transportation or stores, to help you make an informed decision about the location of your new home.
Step 5: Save and view the interactive map
Finally, we will save the interactive map in an HTML file and view it in a web browser. The HTML file will contain all the necessary elements to help you make an informed decision about the location of your new home.
# Saves the interactive map as an HTML file
map.save("webmap.html")
https://javierladino.com/es/wp-content/uploads/2023/05/webmap.html
You will be able to explore ☝ the interactive map to find areas that fall within your desired time range and are close to your children’s school. This will help you identify potential neighborhoods and make an informed decision about where to look for your new home.
Conclusions
In this blogpost, you have learned how to use isochron maps to find a home near your children’s new school using Python and the Leaflet and Folium libraries. These interactive maps will allow you to visualize accessible areas based on travel time and make an informed decision about the location of your home. Now you’re ready to start your search and find the perfect place to live near your kids’ school – good luck!
Download the code from Github
You can access the Python notebook code at the link below: