Home -> Examples -> vida

Buildings · vector

Every building in Iberia: 14.9 million of them.

The outline of nearly every building in Spain and Portugal, from the VIDA Open Buildings dataset (built from Google, Microsoft and OpenStreetMap). The file is 3.8 gigabytes, the kind of dataset that crashes a server that tries to load it all. TerraServe just doesn't.

vida · your screenshot here Iberia buildings in the TerraServe X-ray viewer

The approach

Read only what you look at.

Trick 1 · 4 MB, not 4 GB

Windowed reading

Most servers open a file by loading all of it into memory. That's impossible here. TerraServe instead keeps a tiny index of where each building sits, and when you look at a neighbourhood it jumps straight to just those buildings and reads only them. Opening the whole 3.8 GB file costs 4 megabytes of memory. A zoomed-in tile draws in 0.085 seconds, at full detail.

Trick 2 · the zoomed-out problem

Bake the wide views, draw the close ones live

Zoom all the way out and a single tile suddenly touches millions of buildings. That's slow and heavy for anyone. So the wide, zoomed-out views are baked ahead of time into a compact archive (a zoomed-out tile that took 40 seconds live now serves in 0.42 seconds). Zoom in, where a tile only touches a few thousand buildings, and TerraServe draws it live on the spot.

How it's served

The exact command.

The real command behind the live demo. Notice how much shorter it is than cos2023: windowed reading means none of the memory-fitting flags are needed.

terraserve serve # 14.9M Iberia buildings, vector tiles
  --vector /data/IBERIA.fgb
  --vec-style /data/vida.sld  --name vida
  --mvt-style /data/vida.mvt-style.json
  --pmtiles /data/IBERIA.pmtiles  # the baked zoomed-out views (z0 to 10)
  --mvt-cache 512  --wms-cache 512  --max-inflight 8
  --public-url https://terraserve.io/demo/vida/wms
--vector The data file: a FlatGeoBuf of 14.9 million building outlines. This format carries a built-in index, which is what makes windowed reading possible.
--vec-style How to colour the buildings: an SLD style (here, coloured by which source each building came from).
--mvt-style The matching style for the vector-tile view a browser draws itself.
--pmtiles Trick 2. The pre-baked archive of the zoomed-out views (zoom 0 to 10), served straight off disk. It's read-only here, so no write-back flag is needed.
--mvt-cache 512 Remember recently-drawn zoomed-in tiles (up to 512 MB) so revisiting a neighbourhood is free.
--wms-cache 512 Same idea for the picture (WMS) view.
--max-inflight 8 Draw at most 8 tiles at once, one per core, so a busy moment can't blow up memory.
--public-url The public address to advertise to GIS clients, since it runs behind a web proxy.

Measured: opening the 3.8 GB / 14.9 M-shape file uses 4 MB of memory; a zoomed-in tile renders in 0.085 s at full detail; a zoomed-out tile that took 40 s to draw live now serves from the archive in 0.42 s. This is the demo that would sink a load-everything server. Here, it runs on a small box.

Source. VIDA: Google-Microsoft-Open-Buildings, Iberia subset. Building footprints combined from Google Open Buildings, Microsoft Global ML Buildings, and OpenStreetMap.

In action

From all of Iberia down to a single building.

VIDA buildings zoomed to a city in the X-ray viewer
Zoom to a city and the buildings trace its footprint, millions in view, still instant.
VIDA buildings at street level with the feature inspector
Street level: individual outlines, and the inspector reading one building's attributes: source, area, country.