While the majority of momepy functions require interaction of more GeoDataFrames or using spatial weights matrix, there are some which are calculated on single GeoDataFrame assessing the dimensions or shapes of features. This notebook illustrates this group on small part of Manhattan, New York.

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. You can show the code with the button on the right side.

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)
tess = momepy.Tessellation(buildings, unique_id='uID', limit=limit)
tessellation = tess.tessellation
Loop 1 out of 2.
Identifying changes: 100%|██████████| 3201/3201 [00:01<00:00, 3139.30it/s]
Changing geometry: 100%|██████████| 20/20 [00:00<00:00, 63.77it/s]
Loop 2 out of 2.
Identifying changes: 100%|██████████| 3168/3168 [00:00<00:00, 3225.04it/s]
Changing geometry: 100%|██████████| 2/2 [00:00<00:00, 59.39it/s]
Inward offset...
  1%|          | 32/3166 [00:00<00:09, 313.58it/s]
Generating input point array...
100%|██████████| 3166/3166 [00:08<00:00, 358.98it/s]
Generating Voronoi diagram...
Generating GeoDataFrame...
Vertices to Polygons: 100%|██████████| 497117/497117 [00:22<00:00, 21887.26it/s]
Dissolving Voronoi polygons...
Preparing limit for edge resolving...
Building R-tree...
 21%|██        | 34/163 [00:00<00:00, 331.79it/s]
Identifying edge cells...
100%|██████████| 163/163 [00:00<00:00, 301.95it/s]
100%|██████████| 95/95 [00:00<00:00, 566.87it/s]
/Users/martin/Strathcloud/Personal Folders/momepy/momepy/momepy/ 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))
f, ax = plt.subplots(figsize=(10, 10))
buildings.plot(ax=ax, color='white', alpha=.5)

We have some edge effect here as we are using the buffer as a limit for tessellation in the middle of urban fabric, but for this examples we can work with it anyway.


Some work the same for more elements (buildings, tessellation, plots) like area, some makes sense only for a relevant ones. Area works for both, buildings and tessellation of our case study.

Resulting values can be accessed using area attribute, while original gdf using gdf.

blg_area = momepy.Area(buildings)
buildings['area'] = blg_area.series
f, ax = plt.subplots(figsize=(10, 10))
buildings.plot(ax=ax, column='area', legend=True, scheme='quantiles', k=15, cmap='viridis')
tes_area = momepy.Area(tessellation)
tessellation['area'] = tes_area.series
f, ax = plt.subplots(figsize=(10, 10))
tessellation.plot(ax=ax, column='area', legend=True, scheme='quantiles', k=10, cmap='viridis')
buildings.plot(ax=ax, color='white', alpha=0.5)


We can also work with building heights (if we have the data). 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.

buildings['height'] = buildings['height'].fillna(0).astype(float)
f, ax = plt.subplots(figsize=(10, 10))
buildings.plot(ax=ax, column='height', scheme='quantiles', k=10, legend=True, cmap='Blues')

There are not many simple characters we can do with height, but Volume is possible. Unlike before, you have to pass the name of the column, np.array, or pd.Series where is stored height value. We have a column already.

blg_volume = momepy.Volume(buildings, heights='height')
buildings['volume'] = blg_volume.series
f, ax = plt.subplots(figsize=(10, 10))
buildings.plot(ax=ax, column='volume', legend=False, scheme='quantiles', k=10, cmap='Greens')

Overview of all characters is available in API, with additional examples of usage. Some characters make sense to calculate only in specific cases. Prime example is CourtyarArea - there are many places where all buildings are courtyard-less, resulting in a Series full of zeros.