OSMnx
OSMnx is a Python package that simplifies the process of downloading, modeling, analyzing, and visualizing street networks and other geospatial features directly from OpenStreetMap. It is built upon NetworkX and GeoPandas, providing a powerful toolkit for urban and spatial analysis. The current version is 2.1.0, and the library maintains an active development cycle with regular updates and major releases that may introduce breaking changes.
Warnings
- breaking The OSMnx 2.0 release (November 2024) introduced significant breaking changes, including a streamlined API, refactored modules, and the removal of previously deprecated functionality. Code written for v1.x will likely require updates to be compatible with v2.x.
- gotcha Installing OSMnx via `pip` can be challenging on some systems due to its dependencies (e.g., GeoPandas, Shapely, Rasterio) which rely on compiled C/C++ libraries. Compilation issues can arise.
- gotcha OSMnx heavily leverages NetworkX graphs and GeoPandas GeoDataFrames. Users unfamiliar with these underlying libraries may struggle to effectively use or troubleshoot OSMnx, as its data models are built upon them.
- gotcha As OSMnx retrieves data from OpenStreetMap, all derivative works and visualizations generated using OSMnx must provide proper attribution to OpenStreetMap, in accordance with its open data license.
- deprecated In recent pandas versions, directly accessing elements of a `pandas.Series` by positional index (e.g., `x[0]`, `x[1]`) within `.apply()` functions for geographic coordinates (latitude/longitude) is deprecated and will raise a `FutureWarning`. This is common in functions like `ox.distance.nearest_nodes`.
- gotcha OSMnx uses the OpenStreetMap Overpass API for data retrieval. Frequent or very large data requests can lead to hitting API rate limits, which may result in failed queries or temporary IP blocks from the Overpass server.
- gotcha For very large graphs, some network analysis functions provided by NetworkX (and consequently used by OSMnx) can be computationally intensive and slow, as NetworkX is primarily a Python-native library.
Install
-
pip install osmnx -
conda install -c conda-forge osmnx
Imports
- osmnx
import osmnx as ox
- graph
import osmnx.graph as ox_graph
- plot
import osmnx.plot as ox_plot
Quickstart
import osmnx as ox # Configure osmnx to use a cache for API calls ox.settings.use_cache = True # Download and model a street network for a place place = "Piedmont, California, USA" G = ox.graph.graph_from_place(place, network_type="drive") # Plot the graph fig, ax = ox.plot_graph(G)