How to visualize street networks

Huang
4 min readApr 11, 2021

Many of us use map apps every day. Have you ever take a moment to appreciate the beauty of street networks around us? In this blog post, we would explore how to visualize street networks and coordinate data. Allan Jacobs famously compared several cities’ urban forms through figure-ground diagrams of 1 square mile of each’s street network in his book Great Streets. As shown in figure 1, this blog recreates these amazing graphs. [1]

Figure 1. Street networks (Copyright to Geoff Boeing)

One of the major goals of visualizing street networks is to make the topology of our geospatial surroundings more intuitive. To achieve this goal, visual encoding such as color position, and size can be used. For instance, we can use colors to highlight routes or junctions. After building and visualizing a road network, we can do many interesting routing or stats analysis such as finding the shortest route. Thus, this post will introduce a few ways to visualize street networks and coordinate data.

The tools we are going to use are NetworkX and OSMnx packages. NetworkX is a popular Python package to build, manipulate, and analyze graphs. OSMnx is a handy Python package built on top of NetworkX, geopandas, and matplotlib. It allows us to easily get access to street networks and any other geospatial geometries from OpenStreetMap. These powerful tools have made the analysis and visualization of networks very easy and fun. You are very welcomed to follow along play with the code, which can be found in this colab link.

Firstly, we can create a network of different network types (walkable, drivable, or bikeable) with a single line of code. Moreover, we can do many cool things with the network. As can be seen in figure 3, by calculating and plotting the shortest path between points, the visualizations can be used for navigation or planning purposes.

Figure 2. The street network of Singapore.
Figure 3. Highlight the shortest path between two points.

Besides using the existing method from OSMnx[2] to create and visualize street networks, we can also use networkX[3], which gives us more flexibility if we want to do some customizations on nodes and edges data. To make such modifications, we can simply convert downloaded data into GeoDataFrames, which can be manipulated easily if you are familiar with pandas data frames. Below are figures of the street networks of Los Angeles visualized using two methods.

Figure 4. The street network of Los Angeles created using OSMnx.
Figure 5. The street network of Los Angeles created using NetworkX.

Now that we have a street network using data from the OpenStreetMap. What if we want to plot some new data on top of it? To illustrate, we would use the US accident dataset as an example. This dataset contains data regarding traffic accidents that occurred in America between 2016 to 2020. We will mainly use coordinate data for the purpose of this post.

Given the coordinates of traffic accidents. We would like to plot the exact locations of accidents on top of the street network. To illustrate the network structure more clearly, let us zoom in and focus on downtown Los Angeles. The figures below demonstrate the network with and without accident locations. Green points show the locations of accidents.

Figure 6. Plot accident locations on top of the street network of downtown LA.

So far, we have directly plotted the locations of the accidents without any background. We can also add background such as a city map, which can be exported as images from the OpenStreetMap. Take Los Angeles and California for example, figure 7 and figure 8 demonstrate this approach.

Figure 8. Traffic accidents of Los Angeles.
Figure 8. Traffic accidents of California.

In conclusion, we have learned to build and visualize street networks. And we are able do some simple manipulations and analyses of the networks. I hope you have learn something useful from this post. Check out this link to find out more about OSMnx.

Reference

[1] geoffboeing.com/2017/01/square-mile-street-network-visualization

[2] osmnx.readthedocs.io/en/stable

[3] networkx.org

--

--