Modern GIS toolkit for Python - Simplifying geospatial workflows with built-in data sources, intelligent caching, and fluent APIs
This example demonstrates how to perform common network analysis tasks—calculating the shortest path and generating isochrones (reachability polygons)—using osmnx, a powerful Python library for street network analysis. pymapgis would typically wrap or provide similar functionalities, often leveraging osmnx or networkx in the backend.
The network_analysis_example.py script performs the following:
osmnx.graph_from_place. The graph is then projected to a suitable UTM zone for metric calculations.ox.isochrones.isochrones_from_node which considers travel speeds, or alpha shapes).To run this example, you will need:
pymapgis: The core library (assumed to be in your environment).osmnx: For downloading and modeling street networks from OpenStreetMap.networkx: Used by osmnx for graph theory operations (e.g., shortest path).matplotlib: For plotting the graphs and results.geopandas: For handling geospatial data, particularly for the isochrone polygons.shapely: For geometric objects and operations (dependency of geopandas and osmnx).pandas: A core dependency for geopandas and osmnx.descartes: For plotting GeoPandas objects with Matplotlib (often used by osmnx plotting).You can typically install these using pip:
pip install osmnx networkx matplotlib geopandas shapely pandas descartes
cd path/to/your/pymapgis/docs/examples/network_analysis_advanced/
python network_analysis_example.py
The script requires an active internet connection to download map data from OpenStreetMap.
The script will print information to the console and display two plot windows (one after the other):
Console Output:
Plot Windows:
Note: The plot windows might require you to close them manually to allow the script to proceed or finish. The appearance of plots can vary based on your Matplotlib backend and environment.
If you encounter errors, ensure all dependencies are correctly installed and that you have a stable internet connection. Some locations might occasionally have incomplete data on OpenStreetMap, which could affect osmnx’s ability to build a graph.