Author: Geoff Boeing
Compare the spatial orientations of city street networks with OSMnx.
import matplotlib.pyplot as plt
import numpy as np
import osmnx as ox
%matplotlib inline
weight_by_length = False
ox.__version__
# define the study sites as label : query
places = {
# 'Atlanta' : 'Atlanta, Georgia, USA',
# 'Boston' : 'Boston, MA, USA',
"Buffalo": "Buffalo, NY, USA",
# 'Charlotte' : 'Charlotte, NC, USA',
# 'Chicago' : 'Chicago, IL, USA',
"Cleveland": "Cleveland, OH, USA",
# 'Dallas' : 'Dallas, TX, USA',
# 'Houston' : 'Houston, TX, USA',
# 'Denver' : 'Denver, CO, USA',
# 'Detroit' : 'Detroit, MI, USA',
# 'Las Vegas' : 'Las Vegas, NV, USA',
# 'Los Angeles' : {'city':'Los Angeles', 'state':'CA', 'country':'USA'},
# 'Manhattan' : 'Manhattan, NYC, NY, USA',
"Miami": "Miami, FL, USA",
"Minneapolis": "Minneapolis, MN, USA",
# 'Orlando' : 'Orlando, FL, USA',
# 'Philadelphia' : 'Philadelphia, PA, USA',
# 'Phoenix' : 'Phoenix, AZ, USA',
# 'Portland' : 'Portland, OR, USA',
# 'Sacramento' : 'Sacramento, CA, USA',
"San Francisco": {"city": "San Francisco", "state": "CA", "country": "USA"},
# 'Seattle' : 'Seattle, WA, USA',
# 'St Louis' : 'St. Louis, MO, USA',
# 'Tampa' : 'Tampa, FL, USA',
"Washington": "District of Columbia, USA",
}
# verify OSMnx geocodes each query to what you expect (i.e., a [multi]polygon geometry)
gdf = ox.geocode_to_gdf(list(places.values()))
gdf
# create figure and axes
n = len(places)
ncols = int(np.ceil(np.sqrt(n)))
nrows = int(np.ceil(n / ncols))
figsize = (ncols * 5, nrows * 5)
fig, axes = plt.subplots(nrows, ncols, figsize=figsize, subplot_kw={"projection": "polar"})
# plot each city's polar histogram
for ax, place in zip(axes.flat, sorted(places.keys())):
print(ox.utils.ts(), place)
# get undirected graphs with edge bearing attributes
G = ox.graph_from_place(place, network_type="drive")
Gu = ox.add_edge_bearings(ox.get_undirected(G))
fig, ax = ox.bearing.plot_orientation(Gu, ax=ax, title=place, area=True)
# add figure title and save image
suptitle_font = {
"family": "DejaVu Sans",
"fontsize": 60,
"fontweight": "normal",
"y": 1,
}
fig.suptitle("City Street Network Orientation", **suptitle_font)
fig.tight_layout()
fig.subplots_adjust(hspace=0.35)
fig.savefig("images/street-orientations.png", facecolor="w", dpi=100, bbox_inches="tight")
plt.close()
You can also calculate the orientation entropy of a spatial graph with the ox.bearing.orientation_entropy
function.