Accessibility Modelling
Using the R5Py library to calculate the travel time matrix and analyze the accessibility of urban amenities The R5Py library, is a Python wrapper for the R5 routing engine. R5 is a multimodal routing engine that can be used to calculate travel times between locations in a city using different modes of transport, such as walking, cycling, and public transport. It is open-source, efficient and use real-time data and OpenStreetMap to provide accurate travel time estimates.
R5Py calculates the travel time matrix between origins and destinations.
Step 1: Install and Import Packages¶
# You can use .explore() to interactively explore the data or .plot() to plot the data
# destinations_schools.plot()
Schools.explore()
Step 7: Accessibility Analysis¶
Opportunities accessible within a certain travel time¶
It is important to understand the accessibility of urban amenities, such as food outlets, schools, and healthcare facilities, to different parts of the city. This information can help urban planners and policymakers identify areas with limited access to essential services and improve the overall accessibility of the city.
Similar case can be made for the accessibility of opportunities, such as jobs and schools.
In this case, we will calculate the number of schools accessible within 45 minutes of sustainable travel (walking, cycling and public transport) from each population grid in the city.
# Or instead, you can use explore for an interactive plot.
join.explore(column="Access_Comprehensive Schools", scheme='natural_breaks',cmap="plasma")
import folium
from folium.plugins import MarkerCluster
from IPython.display import display
# Convert merged GeoDataFrame to WGS84 (EPSG:4326) for compatibility with Folium
merged = merged.to_crs(epsg=4326)
# Ensure consistent category naming to match color dictionary
merged["Access_Category"] = merged["Access_Category"].replace({
"Accessible": "With Access",
"Not Accessible": "Without Access"
})
# Define colors matching Access_Category
colors = {"With Access": "orange", "Without Access": "green"}
# Define the center of the map
map_center = [merged.geometry.centroid.y.mean(), merged.geometry.centroid.x.mean()]
# Create a folium map
m = folium.Map(location=map_center, zoom_start=10)
# Create feature groups for better control
accessible_group = folium.FeatureGroup(name="With Access")
non_accessible_group = folium.FeatureGroup(name="Without Access")
# Add points to the appropriate feature group
for _, row in merged.iterrows():
marker = folium.CircleMarker(
location=[row.geometry.y, row.geometry.x], # Extract lat/lon
radius=2, # Adjusted size for clarity
color=colors[row["Access_Category"]],
fill=True,
fill_color=colors[row["Access_Category"]],
fill_opacity=0.7,
popup=f"Access: {row['Access_Category']}"
)
# Add to the respective group
if row["Access_Category"] == "With Access":
accessible_group.add_child(marker)
else:
non_accessible_group.add_child(marker)
# Add feature groups to the map
m.add_child(accessible_group)
m.add_child(non_accessible_group)
# Add layer control to toggle visibility
folium.LayerControl().add_to(m)
# Display the map in Jupyter Notebook
display(m)
<ipython-input-35-7f6fc4076656>:18: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. map_center = [merged.geometry.centroid.y.mean(), merged.geometry.centroid.x.mean()]