OSMnx: A Python package to work with graph-theoretic OpenStreetMap street networks


OSMnx is a Python package for downloading OpenStreetMap street network data and then constructing it into NetworkX graphs. OSMnx can simplify and correct the network's topology automatically to ensure that nodes actually exclusively represent intersections and dead-ends. Once the network is constructed and corrected, OSMnx can calculate shortest paths from one node to another. It can also calculate various network measures relevant to urban design and transportation (Ewing and Cervero 2010) as well as statistical physics (Newman 2010; Barthélemy 2011), including intersection density, average intersection degree, edge density, average street segment length, circuity (Giacomin and Levinson 2015), clustering coefficients, betweenness centrality (Crucitti, Latora, and Porta 2006), closeness centrality, PageRank (Brin and Page 1998), and many more. Its built-in visualization capabilities leverage matplotlib to easily plot routes (Figure 1), one-way streets, dead-ends, high/low connectivity intersections, and figure-ground diagrams of street networks and urban form (Figure 2).

OpenStreetMap presents an important new source of geospatial network data (Jokar Arsanjani et al. 2015; Karduni, Kermanshah, and Derrible 2016). This package makes it easy to work with OpenStreetMap data for urban planning, transportation engineering, and network analysis purposes. Although scholars in urban studies and physics have studied street networks in numerous ways, the existing software landscape limits researchers' capabilities. The labor-intensive challenge of compiling street network data sets, especially for multiple countries, tends to limit sample sizes and most studies fall back on planar representations of the graph for tractibility (e.g., Porta, Crucitti, and Latora 2006; Strano et al. 2013). There is currently no ideal tool that offers a consistent, scalable, configurable method for collecting street network data from anywhere in the world and assembling it into graph-theoretic objects (rather than simple spatial geometries).

OSMnx facilitates all of these use cases. It automates the downloading and algorithmic correction of street network and building footprint data for anywhere in the world from OpenStreetMap. It allows researchers to save street networks as ESRI shapefiles, GraphML files, or scalable vector graphics (SVG) files. Finally, it calculates routes and various network statistics, and projects and visualizes networks. Unlike expensive commercial software like ArcGIS and its limited network analysis capabilities, OSMnx is free, open-source, and natively provides rich network analysis abilities. Unlike network analysis software like Gephi, OSMnx natively provides geospatial abilities and interacts directly with OpenStreetMap's Nominatim and Overpass APIs. OSMnx leverages the geopandas, NetworkX, and matplotlib Python packages for geospatial analysis, network analysis, and the visualization of network statistics and built environment characteristics.

The latest stable release of the software can be installed via pip and full documentation can be found at https://osmnx.readthedocs.io.

Figure 1. OSMnx retrieves the street network for Los Angeles, California and plots a shortest-path route along it. Figure 1. OSMnx retrieves the street network for Los Angeles, California and plots a shortest-path route along it.

Figure 2. OSMnx visualizes street networks in various ways to facilitate consistent comparison of urban form. Figure 2. OSMnx visualizes street networks in various ways to facilitate consistent comparison of urban form.


Barthélemy, Marc. 2011. “Spatial Networks.” Physics Reports 499 (1-3): 1–101. doi:10.1016/j.physrep.2010.11.002.

Brin, Sergey, and Lawrence Page. 1998. “The Anatomy of a Large-Scale Hypertextual Web Search Engine.” Computer Networks and ISDN Systems: Proceedings of the Seventh International World Wide Web Conference 30 (1-7): 107–17. doi:10.1016/S0169-7552(98)00110-X.

Crucitti, Paolo, Vito Latora, and Sergio Porta. 2006. “Centrality Measures in Spatial Networks of Urban Streets.” Physical Review E 73 (3): 036125. doi:10.1103/PhysRevE.73.036125.

Ewing, Reid, and Robert Cervero. 2010. “Travel and the Built Environment: A Meta-Analysis.” Journal of the American Planning Association 76 (3): 265–94. doi:10.1080/01944361003766766.

Giacomin, David J, and David M Levinson. 2015. “Road Network Circuity in Metropolitan Areas.” Environment and Planning B: Planning and Design 42 (6): 1040–53. doi:10.1068/b130131p.

Jokar Arsanjani, Jamal, Alexander Zipf, Peter Mooney, and Marco Helbich, eds. 2015. OpenStreetMap in GIScience. Lecture Notes in Geoinformation and Cartography. Cham, Switzerland: Springer International.

Karduni, Alireza, Amirhassan Kermanshah, and Sybil Derrible. 2016. “A Protocol to Convert Spatial Polyline Data to Network Formats and Applications to World Urban Road Networks.” Scientific Data 3 (June): 160046. doi:10.1038/sdata.2016.46.

Newman, M. E. J. 2010. Networks: An Introduction. Oxford, England: Oxford University Press.

Porta, Sergio, Paolo Crucitti, and Vito Latora. 2006. “The Network Analysis of Urban Streets: A Primal Approach.” Environment and Planning B: Planning and Design 33 (5): 705–25. doi:10.1068/b32045.

Strano, Emanuele, Matheus Viana, Luciano da Fontoura Costa, Alessio Cardillo, Sergio Porta, and Vito Latora. 2013. “Urban Street Networks, a Comparative Analysis of Ten European Cities.” Environment and Planning B: Planning and Design 40 (6): 1071–86. doi:10.1068/b38216.