Skip to content

City context from open data, and what the APIs don't say

A Blender extension that builds a site's surroundings from municipal open data, and the undocumented limits of every service behind it.

radiusinside: built · outside: just data┄ 256 px elevation tilesFIG. 1 · ONE ADDRESS, ONE RADIUSdrawn for this post
address and radius · drawn for this postfig. 1

Most early design models sit in a void. The building is there; the city is not. Someone eventually spends a day pulling massing from a GIS export, tracing roads off an aerial, and guessing at the neighbours’ heights, and the result is still a cardboard town with no terrain and no trees.

The data to do better has been public for years. Toronto publishes a 3D massing model, building footprints with heights, parcel lines, a tree inventory and LiDAR. Natural Resources Canada publishes elevation for the whole country. OpenStreetMap covers the rest. What was missing was something that would take an address and a radius and just build it.

GhostTown is that. It is a Blender extension: type an address, pick a radius, press Build, and the surroundings appear as clean geometry, with a photo on the ground and contours ready for Revit. It covers Toronto, Windsor, Mississauga, Markham and Hamilton in depth and falls back to OpenStreetMap and national elevation everywhere else. Two hundred and seventy commits in six weeks. The part I did not expect was the data.

Two Blender viewports side by side: on the left an empty scene with the GhostTown panel showing an address and a 150-metre radius; on the right the same panel after Build, with a circular site of grey building masses, trees and an aerial photo on the ground.
Before and after Build Context, same panel, one click apart.

How it is put together

The Blender side is thin: operators, a panel, and a scene builder that turns plain Python dictionaries into meshes. All the work happens in a separate pure-Python package with no Blender dependency, which talks to ArcGIS services, reads GeoTIFFs with a minimal reader I wrote because I did not want to ship GDAL, pulls vector tiles and OpenStreetMap, samples LiDAR for roofs, and caches everything on disk. That split means the fetch layer is tested offline, against recorded fixtures, with network access disabled during the test run. The Revit side is a small pyRevit extension that imports what Blender exported, so Revit never has to talk to a city server at all.

Each source came with a surprise. In order of how long they took to find:

The elevation that was secretly flat

Every site larger than about 225 metres in radius came back with flat ground. Smaller sites had terrain. There was no error.

The national elevation service answers an image request with a GeoTIFF. What its documentation does not say is that it will only answer requests whose coverage fits inside a single 256-pixel tile. Ask for more and you get a null response, or sometimes a truncated file that parses as a flat plane. The fix is to tile every request at 250 pixels or less and stitch. The stitching needs a one-millimetre overlap between pieces, because the service counts int(width / offset) + 1 pixels, and without the overlap adjacent tiles disagree about who owns the boundary row.

Left: a site circle larger than a single 256-pixel tile, labelled flat ground. Right: the same circle covered by a grid of 250-pixel tiles with a small overlap, labelled stitched terrain.
The undocumented limit, and the workaround.

Two thousand trees where there were nineteen hundred

At a 1,000-metre radius, the tree layer returned 2,181 features. De-duplicated, there were 1,914. Lot lines were similar: 2,435 returned for 2,080 real.

ArcGIS services page their results. Toronto’s server pages on bounding-box hits first and applies the circular filter afterwards, so a feature near a page boundary can appear on two pages. The usual fix is to order the results by a stable field so paging is deterministic. ArcGIS Online ignores the ordering parameter for this layer. So the client now de-duplicates by feature id, which is boring and correct.

The fields that went away

On the fourth of November, lot lines stopped appearing. No error on my side, no change on my side. The City had removed two fields from the parcel layer, ADDRESS_NUMBER and LINEAR_NAME_FULL, and the service refuses any query that names a field the layer no longer has, with the helpful message “Unable to complete operation.” My query named both. A Toronto build came back without lot lines, and the development-applications layer, which places itself by parcel, had nowhere to go.

The parcel query now asks for the three fields it actually needs and nothing else. A Toronto parcel no longer has a name in the data, and it turned out the name was never shown in Blender anyway, where the lot lines are one merged object.

The infinitely tall building

One footprint in the massing layer had an average height of inf. It passed the “is the height at least half a metre” check, because infinity is indeed at least half a metre, and produced a building that extended past the far clipping plane. Heights that are not finite numbers are now dropped, the way NaN already was.

LiDAR older than the tower

Roofs come from LiDAR: sample the point cloud over each footprint and clip the massing to it, so a hipped roof is hipped and a mechanical penthouse is there. This works beautifully for houses.

Rows of low-poly houses with pitched roofs derived from LiDAR, on a flat grey disc.
Suburban Markham, roofs from LiDAR. Every pitch is real.

It also turned an eighteen-storey tower into a two-metre slab, because the LiDAR flight predated the tower and recorded a car park. The rule is now: if more than half of a footprint’s LiDAR samples are at ground level, or missing, the building keeps its flat top at the published height. The data was not wrong. It was old, which is a different thing and needs a different check.

The hundred-second street view

Street Look takes a point on the street and works out what you would see, using the massing plus facade photos from Mapillary, and it does that by casting rays, tens of thousands of them from a grid over the site. The first version took ninety seconds and 1.4 GB of memory for a downtown corner, and nearly four minutes for a denser one, because it held every ray against every wall at once.

Three changes fixed it. A ray is retired once it is below the foot of every wall and still falling, because it can never hit anything again. Rays are marched in 50-metre pieces, 4,096 at a time, so the ray-by-wall pairs never all exist together. And the expensive sight test only runs on photo points sharp enough to be worth choosing. The first corner went from 90.9 seconds to 50.7 and peak memory from 1,401 MB to 1,005; the second from 233 seconds to 99. The output was byte-identical before and after, which is the only reason I trusted the numbers.

An eye-level rendering of a city street with pale massing buildings, a tower, green trees and a hazy sky.
Street Look. Massing from the City, trees from the inventory, mood from the sky.

Getting it into Revit

Export writes contours as a DXF so Revit can build a toposolid from them. DXF R12 layer names may only contain capital letters, digits, dollar, underscore and hyphen, up to thirty-one characters. Autodesk’s importers reject anything else, usually with a message that does not mention layer names. The contour layer is now called CONTEXT_-_CONTOUR, which is ugly and imports every time.

Revit’s own importer had one more rule: a face boundary may not touch itself at a single vertex. Footprints traced from GIS do this constantly, where two courtyards meet at a corner. The exporter now splits a loop wherever it revisits a vertex and decides which pieces are holes by counting containment.

What it looks like now

A rendered waterfront site: blue water with slips and piers, mid-rise blocks along the edge and tall towers behind.
The waterfront, built from public data in one click. Water is a layer too.

Version 0.9.0. It is GPL-licensed at github.com/winterweken/GhostTown, with the fixtures, the design notes and a list of known limits that is longer than I would like and shorter than it was. The pipeline started life inside a toolbar at work; this is the rebuilt, open version.

Open data is a collection of live services run by people with other priorities. Treat every response as untrusted, test against recordings, and make silence loud.