Search
Measuring density

Measuring density is a typical exercise in urban analytics. momepy allows to measure different types (see API/Intensity); this notebook will outline the main principles.

import momepy
import geopandas as gpd
import matplotlib.pyplot as plt

We will again use osmnx to get the data for our example and after preprocessing of building layer will generate tessellation layer.

import osmnx as ox

point = (40.731603, -73.977857)
dist = 1000
gdf = ox.footprints.footprints_from_point(point=point, distance=dist)
gdf_projected = ox.project_gdf(gdf)

buildings = momepy.preprocess(gdf_projected, size=30,
                              compactness=True, islands=True)
buildings['uID'] = momepy.unique_id(buildings)
limit = momepy.buffered_limit(buildings)
tessellation = momepy.Tessellation(buildings, unique_id='uID', limit=limit).tessellation
Loop 1 out of 2.
Identifying changes: 100%|██████████| 3201/3201 [00:00<00:00, 3753.96it/s]
Changing geometry: 100%|██████████| 20/20 [00:00<00:00, 68.43it/s]
Loop 2 out of 2.
Identifying changes: 100%|██████████| 3168/3168 [00:00<00:00, 4162.82it/s]
Changing geometry: 100%|██████████| 2/2 [00:00<00:00, 60.73it/s]
Inward offset...
Discretization...
  1%|          | 33/3166 [00:00<00:09, 328.67it/s]
Generating input point array...
100%|██████████| 3166/3166 [00:08<00:00, 386.00it/s]
Generating Voronoi diagram...
Generating GeoDataFrame...
Vertices to Polygons: 100%|██████████| 497117/497117 [00:13<00:00, 37484.10it/s]
Dissolving Voronoi polygons...
Preparing limit for edge resolving...
Building R-tree...
 22%|██▏       | 36/163 [00:00<00:00, 358.69it/s]
Identifying edge cells...
100%|██████████| 163/163 [00:00<00:00, 330.03it/s]
100%|██████████| 95/95 [00:00<00:00, 641.39it/s]
/Users/martin/Strathcloud/Personal Folders/momepy/momepy/momepy/elements.py:429: UserWarning: Tessellation contains MultiPolygon elements. Initial objects should be edited. unique_id of affected elements: [833, 1979, 2870, 2875, 3132]
  "unique_id of affected elements: {}".format(list(uids))
Cutting...
f, ax = plt.subplots(figsize=(10, 10))
tessellation.plot(ax=ax)
buildings.plot(ax=ax, color='white', alpha=.5)
ax.set_axis_off()
plt.show()

We have some edge effect here as we are using the buffer as a limit for tessellation in the middle of the urban fabric, but for these examples, we can work with it anyway. Keep in mind that values on the edge of this area will be skewed.

Covered Area Ratio

Covered area ratio, in our case measured on tessellation cells, requires GeoDataFrame containing spatial unit (cell, plot), and GeoDataFrame containing covering objects (buildings). On top of that, it currently requires passed areas for both gdfs and unique ID which links together spatial units and objects on them. We can either calculate areas before:

tessellation['area'] = momepy.Area(tessellation).series
buildings['area'] = momepy.Area(buildings).series
tess_car = momepy.AreaRatio(tessellation, buildings, 'area', 'area', 'uID')
tessellation['CAR'] = tess_car.series

Or we can pass momepy.Area().series directly:

tess_car = momepy.AreaRatio(tessellation, buildings,
                            momepy.Area(tessellation).series,
                            momepy.Area(buildings).series, 'uID')
tessellation['CAR'] = tess_car.series
f, ax = plt.subplots(figsize=(10, 10))
tessellation.plot(ax=ax, column='CAR', legend=True, scheme='quantiles', k=10, cmap='viridis')
buildings.plot(ax=ax, color='white', alpha=0.5)
ax.set_axis_off()
plt.show()

Note: At the time of preparing this notebook, there was a duplicated building within the used area, causing the value 1.33.

Floor Area Ratio

Because we know building heights for our buildings gdf, we can also calculate FAR. This part of New York has height data, only stored as strings, so we have to convert them to floats (or int) and fill NaN values with zero.

FAR requires floor areas for building gdf instead of covered area.

buildings['height'] = buildings['height'].fillna(0).astype(float)

buildings['floor_area'] = momepy.FloorArea(buildings, 'height').series
tessellation['FAR'] = momepy.AreaRatio(tessellation, buildings,
                                       'area', 'floor_area', 'uID').series
f, ax = plt.subplots(figsize=(10, 10))
tessellation.plot(ax=ax, column='FAR', legend=True, scheme='quantiles', k=10, cmap='viridis')
buildings.plot(ax=ax, color='white', alpha=0.5)
ax.set_axis_off()
plt.show()

Location-based density is described in examples using spatial weights.