Categories
Data

What’s New with OSMnx, Part 1

There have been some major changes to OSMnx in the past couple months. I’ll review them briefly here, demonstrate some usage examples, then reflect on a couple upcoming improvements on the horizon. First, what’s new:

  • new consolidate_intersections function with topological option
  • new speed module to impute missing street speeds and calculate travel times for all edges
  • generalized POIs module to query with a flexible tags dict
  • you can now query OSM by date
  • you can now save graph as a geopackage file
  • clean up and streamline the OSMnx API
Categories
Data

New Article in Frontiers in Neurology

I recently teamed up with an international group of public health researchers and spatial analysts to co-author an article, An Introduction to Software Tools, Data, and Services for Geospatial Analysis of Stroke Services, that has been accepted for publication at Frontiers in Neurology (download free PDF).

Hospital catchment basin for stroke services. Spatial analysis in python, geopandas, osmnx.

Categories
Data

Network-Based Spatial Clustering

Jobs, establishments, and other amenities tend to agglomerate and cluster in cities. To identify these agglomerations and explore their causes and effects, we often use spatial clustering algorithms. However, urban space cannot simply be traversed as-the-crow-flies: human mobility is network-constrained. To properly model agglomeration along a city’s street network, we must use network-based spatial clustering.

The code for this example can be found in this GitHub repo. We use OSMnx to download and assemble the street network for a small city. We also have a dataframe of points representing the locations of (fake) restaurants in this city. Our restaurants cluster into distinct districts, as many establishments and industries tend to do:

firm locations on the street network to be clustered: python, osmnx, matplotlib, scipy, scikit-learn, geopandas

Categories
Data

OSMnx Features Round-Up

OSMnx is a Python package for quickly and easily downloading, modeling, analyzing, and visualizing street networks and other spatial data from OpenStreetMap. Here’s a quick round-up of recent updates to OSMnx. I’ll try to keep this up to date as a single reference source. A lot of new features have appeared in the past few months, and people have been asking about what’s new and what’s possible. You can:

  • Download and model street networks or other networked infrastructure anywhere in the world with a single line of code
  • Download any other spatial geometries, place boundaries, building footprints, or points of interest as a GeoDataFrame
  • Download by city name, polygon, bounding box, or point/address + network distance
  • Download drivable, walkable, bikeable, or all street networks
  • Download node elevations and calculate edge grades (inclines)
  • Impute missing speeds and calculate graph edge travel times
  • Simplify and correct the network’s topology to clean-up nodes and consolidate intersections
  • Fast map-matching of points, routes, or trajectories to nearest graph edges or nodes
  • Save networks to disk as shapefiles, geopackages, and GraphML
  • Save/load street network to/from a local .osm xml file
  • Conduct topological and spatial analyses to automatically calculate dozens of indicators
  • Calculate and visualize street bearings and orientations
  • Calculate and visualize shortest-path routes that minimize distance, travel time, elevation, etc
  • Visualize street networks as a static map or interactive leaflet web map
  • Visualize travel distance and travel time with isoline and isochrone maps
  • Plot figure-ground diagrams of street networks and building footprints
Categories
Data

Street Network Orientation

OSMnx is a Python package for easily downloading and analyzing street networks anywhere in the world. Among other analyses, we can use it to explore street network orientation. That is, what are the bearings and spatial orientations of the streets in the network? All of the code for this example is in this GitHub notebook. First we use OSMnx to download the street network of Moraga, California, a small town in the hills just east of Berkeley:

Moraga, California street network OSMnx OpenStreetMap Python

OSMnx automatically calculates all of the streets’ bearings. Specifically it calculates the compass bearing from each directed edge’s origin node u to its destination node v. Now we can visualize these bearings, binned together as a histogram to get a sense of the relative frequency of the streets’ spatial orientations. Or better yet, we can project that histogram as a polar plot to match the compass bearings:

Moraga, California street network orientation edge bearings polar plot OSMnx OpenStreetMap Python

Categories
Data

Urban Street Network Centrality

Check out the journal article about OSMnx.

We can measure and visualize how “important” a node or an edge is in a network by calculating its centrality. Lots of flavors of centrality exist in network science, including closeness, betweenness, degree, eigenvector, and PageRank. Closeness centrality measures the average shortest path between each node in the network and every other node: more central nodes are closer to all other nodes. We can calculate this easily with OSMnx, as seen in this GitHub demo. For example, here is the node closeness centrality for Piedmont, California:

Urban street network graph node closeness and betweenness centrality

Categories
Planning

Estimating Daytime Population Density

Check out the journal article about this project.

I was recently asked: “how might someone figure out the local daytime population density across the Bay Area from public data?” My answer, in short, was that you really couldn’t accurately. But you could at least produce a coarse, biased estimate. Here’s how.

I examined the Bay Area’s tract-level daytime population density using three input data products: the 2010 TIGER/Line census tracts shapefile with DP1 attributes, the 2010 California LEHD LODES data, and the census bureau’s 2010 US states shapefile. I preferred the 2010 census demographic data to (more recent) ACS data because the ACS tract-level variables are five-year rolling averages. Given this, I preferred not to compare 2014 LODES data to 2010-2014 ACS data as the Bay Area experienced substantial housing, economic, and demographic upheaval over this interval – patterns obscured in the ACS rolling average. To avoid inconsistent comparison, I opted for more stale – but more accurate and comparable – data.

Map of the estimated daytime population density in the San Francisco Bay Area

Categories
Data

OSMnx and Street Network Elevation Data

Check out the journal article about OSMnx.

OSMnx can now download street network elevation data for anywhere in the world. In one line of code it downloads the elevation in meters of each network node, and in one more line of code it can calculate every street (i.e., edge) grade. Here is the complete street network of San Francisco, California, with nodes colored according to their elevation:

OSMnx street network elevation data for San Francisco, California to calculate street grade and steepness

Categories
Planning

Urban Form Figure-Ground Diagrams

Check out the journal article about OSMnx.

I previously demonstrated how to create figure-ground square-mile visualizations of urban street networks with OSMnx to consistently compare city patterns, design paradigms, and connectivity. OSMnx downloads, analyzes, and visualizes street networks from OpenStreetMap but it can also get building footprints. If we mash-up these building footprints with the street networks, we get a fascinating comparative window into urban form:

Figure-ground map of building footprints and street network in New York, San Francisco, Monrovia, and Port au Prince from OpenStreetMap data, created in Python with OSMnx

Categories
Tech

Getting Started with Python

Piedmont, California street network created in Python with OSMnx, networkx, matplotlibThis is a guide for absolute beginners to get started using Python. Since releasing OSMnx a few weeks ago, I’ve received a lot of comments from people who would love to try it out, but don’t know where to begin with Python. I’ll demonstrate how to get Python up and running on your system, how to install packages, and how to run code.