1. Before you start¶
A good teacher works towards not being needed. This guide does not hand you conclusions about cities; it gives you the means to ask your own questions of the place you live, and to answer them with evidence you can check. You will learn to read a neighbourhood the way urban morphologists do: its streets as a network, its buildings as grain and density, its everyday places as access. Every measure is computed from open data in a notebook you run yourself, explained in words, shown on a map or chart, and accompanied by what it cannot tell you.
Four places are compared throughout, chosen because they were made in very different ways: the centre of Belfast, a port city grown over four centuries; the Eixample of Barcelona, planned on a grid by Ildéfons Cerdà in 1859; the Walled City of Lahore, a dense pre-modern fabric; and Brownlow in Craigavon, a new town of the 1970s laid out around roads and cul-de-sacs.
1.1 Two ways in¶
-
The Urban form explorer (ahmadammar.github.io/urban-form-explorer) is a web page: pan to any place in the world, zoom in to a neighbourhood, press Analyse this view, and read its streets, buildings, access and indices, each linked to its definition. Nothing to install.
-
The notebook in this guide does the same analyses step by step in Python, so you see and can change every calculation. Open the Notebooks page and choose Open in Colab, or on your own computer:
conda create -n urban python=3.12
conda activate urban
pip install osmnx momepy scikit-learn matplotlib jupyterlab
jupyter lab
Boxes labelled In [n] are code and Out [n] what it printed or drew. Run the cells in order. The first run downloads data from OpenStreetMap’s public servers and keeps a copy in data/cache, so later runs are fast and work offline.
1.2 Setup¶
This notebook teaches you to read a neighbourhood from open data: its streets, blocks, buildings and everyday places, measured with the same methods urban researchers use. It compares four places with very different histories: the centre of Belfast, Barcelona's planned Eixample, the Walled City of Lahore and the new town of Craigavon. You can then point it at your own street by changing one line.
Libraries: OSMnx downloads OpenStreetMap data and turns streets into a graph; NetworkX does the graph mathematics (shortest paths, centrality); GeoPandas holds buildings and places as tables with shapes; momepy measures urban form; matplotlib draws. In Colab the first cell installs what is missing.
import importlib.util, subprocess, sys
for pkg in ("osmnx", "momepy"):
if importlib.util.find_spec(pkg) is None:
subprocess.run([sys.executable, "-m", "pip", "install", "-q", pkg], check=True)
import warnings
warnings.filterwarnings("ignore")
from pathlib import Path
import math
import numpy as np
import pandas as pd
import geopandas as gpd
import networkx as nx
import osmnx as ox
import momepy
import matplotlib.pyplot as plt
Path("data").mkdir(exist_ok=True)
ox.settings.use_cache = True
ox.settings.cache_folder = "data/cache"
ox.settings.log_console = False
plt.rcParams.update({"figure.dpi": 100})
print("osmnx", ox.__version__, "| networkx", nx.__version__, "| momepy", momepy.__version__)
## The four places: (latitude, longitude) of a centre point. Change or add your own here.
PLACES = {
"Belfast centre": (54.5973, -5.9301),
"Barcelona Eixample": (41.3917, 2.1649),
"Lahore Walled City": (31.5820, 74.3150),
"Craigavon (Brownlow)": (54.4475, -6.3870),
}
RADIUS = 800 # metres: each study area is the square 1.6 km across around the point
osmnx 2.1.2 | networkx 3.7 | momepy 1.0.0