garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/building-identity-and-bag.md

raw


topic: buildings triggers: [building_facts.rs, systems::building_facts, scaffolding.rs, scaffold, vacant, pipeline/bag.rs, pipeline/lod22.rs, formats/bag.rs, building_windows.wesl, BAG, identificatie, bouwjaar, gebruiksdoel, PDOK, Kadaster, BIM, IFC] updated: 2026-10-06

The building id, and what the Dutch registers hang off it

The id was not an id

The LoD2.2 extractor has always written an id on each mesh element, and until 2026-08-27 it was made like this:

digits = "".join(ch for ch in oid if ch.isdigit())
return int(digits[-15:]) if digits else abs(hash(oid)) % (10 ** 15)

The comment called it "a stable-ish int", which is exactly what it was — a dedupe key inside one build, and nothing else. 3DBAG names an object NL.IMBAG.Pand.0014100010903891-0, where the sixteen digits are the BAG identificatie and -0 numbers the parts one pand was split into. The part suffix contributes a digit of its own, so keeping "the last fifteen digits" shifted the number by a decade for every object that had one, and dropped the leading zeros that say which municipality it is. The digitless fallback was worse: Python salts hash per process, so two runs of the same build produced different ids.

The client then threw it away regardless — El in lod22.rs deserialised p and t only.

None of that mattered while the id was internal. It mattered the moment anyone wanted to ask a question about a particular building, because the identificatie is the key the whole Dutch open-data estate is joined on: the BAG's own rows, addresses, the monuments register, energy labels — and any BIM model of the building, whoever holds it. Matching a mass to a model by geometry is the alternative, and it is not one.

So the id is now the identificatie verbatim, as a string (leading zeros are load-bearing), with part beside it rather than inside it.

Where the facts come from, and why not the obvious place

api.bag.kadaster.nl is the Kadaster's own BAG API and needs a key. PDOK's service.pdok.nl/lv/bag/wfs/v2_0 serves the same register, open, keyless, and that is what the BAG extractor pages.

The layer split is worth knowing because it is not what you would guess: bag:pand already carries the attributes per building — bouwjaar, status, gebruiksdoel (comma-joined for a mixed-use block), the floor-area range of the units inside and how many there are — so the common case needs no join at all. bag:verblijfsobject is the per-unit layer, and its value is the point: the register's own position for each addressable unit, at or near its entrance, which is the closest thing to a national door-position dataset that exists. bag:ligplaats and bag:standplaats are addressed places with no building on them, which is precisely why a map built from buildings has never shown them.

The 1000-feature truncation

Measured 2026-08-27. This service caps a GeoJSON response at 1000 features however large a count you ask for, and usually omits numberMatched from GeoJSON entirely. That combination defeats the ordinary page-until-short-page loop: asking for 10 000 returns a full page that looks like a short one, the walk ends after the first thousand rows, and nothing anywhere reports a problem — the output is a city that quietly knows about a tenth of its buildings.

Note the sibling LoD1.2 extractor pages the 3DBAG WFS with PAGE = 10_000, and that is correct for that server. The two are different services with different caps; the number is not shareable.

It therefore pages at 1000 and calls resultType=hits (a small XML read) once per layer, purely so the walk can be checked against a total it did not compute itself. It warns when the two disagree.

startIndex stops at 50 000

Also measured 2026-08-27, and this one is not survivable by paging at all: startIndex=50000 answers, startIndex=50001 is a flat HTTP 400. Groningen's default bbox holds 94 052 panden and 129 270 addressed units, so no page size reaches the end of it.

It therefore quarters the bbox recursively until every piece is under 40 000 features and pages each piece. A WFS bbox is an intersects test, so a building straddling a cut comes back from both halves — every collector dedupes on identificatie, which it can do precisely because the id is now a real one.

Two files per cell, and which one is heavy

Measured on Groningen's densest z14 cell: 8 000 buildings are 0.53 MB, and the 17 785 addressed units in the same cell are 2.04 MB. lod22 fetches a cell's facts inside its own mesh job and reads only the years and the uses; with one file it was pulling five times what it reads, on the lane that already owns the largest assets in the client. So y.json is buildings and y.places.json is addresses plus berths plus their street table, and the mesh lane fetches only the first. Either file may be absent — an industrial estate has no addresses, a canal bank has berths and no buildings — so a 404 on one is not a failed cell.

Why a pand is written into several cells

The mesh pipeline bins a building by the first vertex of its 3D solid. The attribute pipeline has only a 2D footprint and cannot reproduce that rule, and a building whose attributes landed one cell over from its mesh would never join — silently, and only for buildings near a cell edge, which is the worst possible distribution for noticing. So atlas's pipeline/bag.rs writes each pand into every z14 cell its footprint bbox touches. The duplication is a few bytes on a handful of buildings; the alternative is a bug that reproduces on a tenth of a percent of the city.

Two consumers, two shapes

A colour baked into a vertex has to be known on the worker that builds the mesh. So lod22's job fetches its own cell's facts inside itself (load_bag_cell), which is a second request that lands on the same storage cache key as the streamer's — at worst a cache read. In exchange, a mesh and the facts it is coloured by cannot arrive in the wrong order.

The alternative was to share one parse through the BuildingFacts resource and rebuild meshes when a facts cell landed. That is the terrain-revision retear, and it is affordable for a 6.4 km field that arrives once per anchor — not for a stream that lands 25 cells and re-lands them as you walk.

BuildingFacts still exists, streamed on its own ring, because everything that is not a vertex colour — the readout, a lookup, a panel — wants a resource it can ask at any time.

What the facts are used for

What is still unused, and where it would go

The pipeline ships more than is consumed, deliberately — the data is free once the request is made, and a second pass over the WFS to add a column is not.

Unconsumed today: per-unit floor areas beyond the readout, units beyond its small lift to the window lighting, postcodes beyond the readout, and every BuildingStatus other than the six above (the two that suppress a building, the two that scaffold one and the two that board one up).

Not built at all, in rough order of value:

Coverage is Netherlands-only, and fails quiet

bag_covers() answers false until the manifest lands and for ever on a host with no bag/ tree, so every consumer's fallback is the behaviour that was there before. One difference from the 3DBAG manifests next door: those retry an unreachable host indefinitely, because they are the difference between real buildings and guessed ones. This tree is additive, and a host that has never run the BAG extractor answers 404 permanently — so it gives up after three attempts rather than asking the same question every 30 seconds for the life of the process.

--dump-state carries bag_buildings / bag_addresses / bag_berths, because the failure mode here is silence: a missing coverage manifest produces a perfectly good-looking city with the generated palette, and no capture can tell that apart from the facts having landed and changed little.

Each cell file is parsed once, and JSON is not what is slow

Three readers want a cell's files: the BuildingFacts streamer (both), lod22's mesh job (the buildings, for the colours it bakes) and map_geometry's moorings (the places, and the buildings again to tell a housed berth). Each parsed its own copy until 2026-10-05, so the buildings file was parsed up to three times per cell per start. building_facts::parse_part now hands every reader the same parse.

A binary format for these files, like lod22's .bin, was considered and is not worth it. Measured 2026-10-05 on Groningen's densest cell (8490/5319), best of five, one core of the VPS: the 1.9 MB buildings file parses in 10.4 ms and the 1.6 MB places file in 9.3 ms in a release build (54.5 and 33.3 ms in the dev profile). lod22's binary paid for itself in bytes on a phone link, not parse time, and its mesh build is ~370 ms beside a 23 ms parse. The bag_facts worker time a dev-build capture reports (~500 ms a job) is the conversion into BagCell at the dev profile's opt-level = 1, on a box whose cores the software renderer is also using — not the format.