The Grey Context Model Got a Key: Join swissBUILDINGS3D to the GWR in Rhino 8
swisstopo added the EGID to swissBUILDINGS3D for Zürich, Zug and Ticino. One Rhino 8 Python script colours each neighbour by GWR Baujahr or heating.
On 24 November 2026 swisstopo published a short update note with a long consequence: “3D building models with the federal building identifier (EGID) are now also available” for Ticino, Zug, Zurich and Liechtenstein. The grey context model every Machbarkeitsstudie starts from now has a key. The number that identifies a building in the federal building register (GWR) now identifies its solid in swissBUILDINGS3D 3.0.
Grey boxes are honest. They just never answer questions.
The GWR answers plenty of them. It knows when each neighbour was built, how many storeys it has and what heats it. This tutorial joins register and geometry with one Python script in Rhino 8, colours every neighbour by construction period or heat source, and writes the register values into each object’s user text.
←TODAY: swisstopo reports that EGID now covers 22 cantons plus Liechtenstein; only GE, GR, VD and VS are still missing.
→3012: Every Zürich neighbour carries its own number, and a site model is a query before it is a drawing.
Fulcrum: A shared key turns two public datasets into one site model nobody had to buy.
The register in five fields
The GWR is kept alive by people nobody names: the municipal building authorities who enter each permit and each new boiler, and the teams at the Bundesamt für Statistik (BFS) who clean and publish the national file. For a site model you need five fields:
- EGID — the federal building identifier, the key.
- GKODE / GKODN — the building’s coordinates in LV95 (EPSG 2056), in metres.
- GBAUJ / GBAUP — construction year, or a period code (8011 “vor 1919” up to 8023 “nach 2015”) when the year is unknown.
- GASTW — number of storeys.
- GENH1 — main heat source (7530 Heizöl, 7520 Gas, 7511 Erdwärmesonde, 7580 Fernwärme, among others).
According to the BFS licence inside each download, citing Art. 16 VGWR: “Freie Nutzung. Quellenangabe ist Pflicht.” Commercial use is allowed. Put this credit on every plan that uses the data: Bundesamt für Statistik; Eidg. Gebäude- und Wohnungsregister.
The Tool: Rhino 8’s ScriptEditor running Python 3 against RhinoCommon, the geometry SDK the McNeel team has documented in public for years, fed by two open federal datasets: swisstopo’s swissBUILDINGS3D 3.0 tiles and the BFS public GWR export. No plugin, no licence beyond Rhino itself, about a hundred lines you can read top to bottom.
Setup: Get the register for your canton and prove the pure-Python half works before Rhino is open (Python 3.10 tested; tar ships with Windows 10 and 11):
mkdir gwr_zg
cd gwr_zg
curl -O https://public.madd.bfs.admin.ch/zg.zip
tar -xf zg.zip
# save the script below as gwr_tile.py one folder up, then:
python ../gwr_tile.py gebaeude_batiment_edificio.csv
# expect two lines: 'period [...]' and 'heat [...]' with counts
# tiles: pick a .dwg.zip from the STAC collection
curl "https://data.geo.admin.ch/api/stac/v0.9/collections/ch.swisstopo.swissbuildings3d_3_0/items?bbox=8.50,47.15,8.54,47.18"Swap zg for zh or ti; on 29 November the Zürich ZIP was 122 MB, Zug’s 10.4 MB. A DWG tile is about 40 MB and covers 1/16 of a 1:25,000 sheet.
First steps:
- Open a new Rhino 8 file in metres and import the unzipped DWG tile. If buildings arrive as block instances, run
Explodeon them. - Type
ScriptEditor, create a Python 3 script, paste the program below, press Run. - Pick
gebaeude_batiment_edificio.csvin the dialog. Neighbours turn colour by construction period; the ScriptEditor output prints how many objects were tagged. - Change line 5 to
MODE = "heat"and run again for the heating map.
The code, explained:
#! python3
# Colour a swissBUILDINGS3D tile by GWR Baujahr or heating. Rhino 8 ScriptEditor.
# Data: Bundesamt fuer Statistik; Eidg. Gebaeude- und Wohnungsregister
import csv
MODE = "period" # or "heat"
PERIODS = [("vor 1919", 1918, (120, 40, 30)), ("1919-1945", 1945, (180, 80, 40)),
("1946-1970", 1970, (220, 140, 60)), ("1971-1990", 1990, (235, 200, 100)),
("1991-2010", 2010, (150, 190, 150)), ("ab 2011", 9999, (60, 130, 170))]
GBAUP = {"8011": 1918, "8012": 1945, "8013": 1960, "8014": 1970, "8015": 1980,
"8016": 1985, "8017": 1990, "8018": 1995, "8019": 2000, "8020": 2005,
"8021": 2010, "8022": 2015, "8023": 2016}
HEAT = [("Heizoel", {"7530"}, (90, 60, 40)), ("Gas", {"7520"}, (200, 120, 50)),
("Waermepumpe", {"7501", "7510", "7511", "7512", "7513"}, (60, 160, 120)),
("Holz", {"7540", "7541", "7542", "7543"}, (130, 150, 60)),
("Fernwaerme", {"7580", "7581", "7582"}, (70, 110, 190))]
OTHER = ("andere / keine Angabe", (170, 170, 170))
def year_of(r):
y = r.get("GBAUJ", "").strip()
return int(y) if y.isdigit() else GBAUP.get(r.get("GBAUP", "").strip())
def classify(r, mode=MODE):
if mode == "heat":
return next(((l, c) for l, s, c in HEAT if r.get("GENH1") in s), OTHER)
y = year_of(r)
return OTHER if y is None else next((l, c) for l, top, c in PERIODS if y <= top)
def load_gwr(path, bbox=None):
rows = []
with open(path, encoding="utf-8", newline="") as f:
for r in csv.DictReader(f, delimiter="\t"):
if r.get("GSTAT") != "1004": # 1004 = bestehend
continue
try:
e, n = float(r["GKODE"]), float(r["GKODN"])
except (KeyError, ValueError):
continue
if bbox is None or (bbox[0] <= e <= bbox[2] and bbox[1] <= n <= bbox[3]):
r["_E"], r["_N"] = e, n
rows.append(r)
return rows
class Grid: # 25 m buckets
def __init__(self, cell=25.0):
self.cell, self.cells = cell, {}
def add(self, item, x0, y0, x1, y1):
c = self.cell
for i in range(int(x0 // c), int(x1 // c) + 1):
for j in range(int(y0 // c), int(y1 // c) + 1):
self.cells.setdefault((i, j), []).append((item, x0, y0, x1, y1))
def query(self, x, y):
key = (int(x // self.cell), int(y // self.cell))
return [it for it, a, b, c, d in self.cells.get(key, [])
if a <= x <= c and b <= y <= d]
def run_in_rhino():
import System.Drawing, rhinoscriptsyntax as rs, scriptcontext as sc
from Rhino.Geometry import Point3d, Line, Mesh, MeshingParameters, BoundingBox, Brep, Extrusion
from Rhino.Geometry.Intersect import Intersection
from Rhino.DocObjects import ObjectType, ObjectColorSource
path = rs.OpenFileName("GWR gebaeude_batiment_edificio.csv", "CSV (*.csv)|*.csv||")
if not path:
return
want = (ObjectType.Brep, ObjectType.Extrusion, ObjectType.Mesh)
grid, shapes, box = Grid(), {}, BoundingBox.Empty
for o in [o for o in sc.doc.Objects if o.ObjectType in want]:
g = o.Geometry.ToBrep() if isinstance(o.Geometry, Extrusion) else o.Geometry
if isinstance(g, Brep):
m = Mesh()
for p in Mesh.CreateFromBrep(g, MeshingParameters.FastRenderMesh) or []:
m.Append(p)
g = m
bb = g.GetBoundingBox(True)
if bb.IsValid:
shapes[o.Id] = (o, g, bb.Min.Z - 10, bb.Max.Z + 10)
grid.add(o.Id, bb.Min.X, bb.Min.Y, bb.Max.X, bb.Max.Y)
box = BoundingBox.Union(box, bb)
rows = load_gwr(path, (box.Min.X, box.Min.Y, box.Max.X, box.Max.Y))
hits = {}
for r in rows: # vertical line through the register point
for oid in grid.query(r["_E"], r["_N"]):
o, m, z0, z1 = shapes[oid]
ln = Line(Point3d(r["_E"], r["_N"], z0), Point3d(r["_E"], r["_N"], z1))
pts = Intersection.MeshLine(m, ln)
if pts is not None and len(pts) > 0:
hits.setdefault(oid, []).append(r)
multi = 0
for oid, recs in hits.items():
o = shapes[oid][0]
r = min(recs, key=lambda x: year_of(x) or 9999) # oldest record wins
label, rgb = classify(r)
a = o.Attributes.Duplicate()
a.SetUserString("EGID", ",".join(x["EGID"] for x in recs))
for k in ("GBAUJ", "GBAUP", "GENH1", "GASTW"):
a.SetUserString("GWR_" + k, r.get(k, ""))
a.SetUserString("GWR_CLASS", label)
a.ObjectColor = System.Drawing.Color.FromArgb(*rgb)
a.ColorSource = ObjectColorSource.ColorFromObject
sc.doc.Objects.ModifyAttributes(o, a, True)
multi += len(recs) > 1
sc.doc.Views.Redraw()
print("{} objects, {} GWR rows, {} tagged, {} with several EGIDs".format(
len(shapes), len(rows), len(hits), multi))
if __name__ == "__main__":
try:
import Rhino
except ImportError: # plain Python: python gwr_tile.py zg.csv
import sys
for mode in ("period", "heat"):
t = {}
for r in load_gwr(sys.argv[1]):
t[classify(r, mode)[0]] = t.get(classify(r, mode)[0], 0) + 1
print(mode, sorted(t.items(), key=lambda kv: -kv[1]))
else:
run_in_rhino()Lines 1–16 — the legend lives at the top: #! python3 tells ScriptEditor to run Python 3, not the older IronPython. Every class (label, matching codes, RGB colour) sits in a plain list, so changing the legend never touches the logic. GBAUP maps each period code to the last year of its period: a building listed only as 8014 behaves as if built in 1970.
Lines 18–26 — one row in, one class out: year_of trusts the exact year first and falls back to the period. The fallback earns its place: in our own count of the 29 November Zug export, 7,652 of 27,465 existing buildings have no GBAUJ. next(...) returns the first class that fits, which is why the periods must stay in ascending order.
Lines 28–41 — read the register, keep what stands: the CSV is tab-separated, hence delimiter="\t". Only GSTAT 1004 (“Gebäude bestehend”) survives, rows without coordinates are skipped, and the optional bbox (the min and max corners of a rectangle) trims the canton to your tile.
Lines 43–54 — the 25 m grid: a dictionary of square buckets. Each footprint box goes into every cell it touches, so a register point is tested only against the few solids in its own cell.
Lines 56–86 — the vertical line join: every solid becomes a mesh (a surface of triangles and quads). For each register point the script draws a line from 10 m below the building to 10 m above and asks Intersection.MeshLine whether it pierces the mesh; the RhinoCommon documentation lists that method since Rhino 7.3. The join uses position only, so it does not depend on any attribute surviving the DWG import.
Lines 87–104 — write, colour, count: each hit object gets its EGIDs, four GWR fields and a class label as user text, plus a colour. The last line prints something shaped like 412 objects, 980 GWR rows, 398 tagged, 37 with several EGIDs, with your tile’s numbers. The beginner mistake: a file in millimetres. LV95 is metres, every line lands kilometres away, and the script reports 0 tagged. Check units first.
Reading the result
The “several EGIDs” count is the interesting one. Where swisstopo models a terrace of row houses as one solid, the register may list four buildings. The script keeps all the numbers and colours by the oldest record, so the count shows where the context model is coarser than the register.
Run the heating map on Zug and the Fernwärme conversation appears in colour. In our own count of the 29 November export, 5,915 of 16,293 residential buildings (36.3 %) are listed in the GWR as heated mainly by Heizöl, and 2,806 (17.2 %) by gas. These are reported, dated register values, our count rather than a BFS statistic, and they belong on a plan as aggregates only, never paired with an address or an owner.
The trade-off is plain: a register point is a reported coordinate, not a survey, so where it falls beside the solid, the building stays grey. According to the swisstopo product page, dormers and small annexes are generally omitted and the accuracy is ±30–50 cm.
PAZ has covered the vocabulary side of this thread in our piece on buildingSMART Switzerland’s Data Dictionaries: agreeing on one name, here on one number. From the late 2070s, the site files that survived were the ones a newcomer could open in a text editor. Keep the CSV next to the model.
Atelier: A Zürich or Zug studio starting a feasibility study this week can stop drawing the neighbourhood as anonymous mass and start reading it: which neighbours are post-war stock heading for renovation, where a district-heating argument already has density. Monday move: run the script on the tile of your current competition site and save the coloured file as the office’s base context model.
Hack: Reproduce our Zug heating figure in plain Python before you trust any colour in Rhino. Copy gwr_tile.py into the gwr_zg folder next to the CSV and run there:
from gwr_tile import load_gwr
RES = {"1020", "1030", "1040"} # GKAT residential
rows = [r for r in load_gwr("gebaeude_batiment_edificio.csv") if r.get("GKAT") in RES]
heat = sum(1 for r in rows if r.get("GENH1") == "7530")
print(len(rows), heat, round(100 * heat / len(rows), 1))Predict first: on the 29 November Zug export, expect 16,293, 5,915 and 36.3, or within a row, since load_gwr drops the one existing building without coordinates. A newer export will drift; that is the register doing its job.
For the same read-the-data-first habit in Archicad, our Archicad Python Automatisierung course is the next step, and PAZ Academy, a Rhino centre in Switzerland, sells Rhino 9 licences.
Learn-it:
- swisstopo — swissBUILDINGS3D update note, 24 Nov 2026
- swisstopo — swissBUILDINGS3D 3.0 product page
- STAC collection ch.swisstopo.swissbuildings3d_3_0
- BFS — GWR public export, Canton Zug (readme, licence, code table)
- RhinoCommon — Intersection.MeshLine
Data credit for every plan: Bundesamt für Statistik; Eidg. Gebäude- und Wohnungsregister. Download your canton tonight and colour one tile before your next site meeting.
PAZ Kaffi · multidisciplinary editorial, led by PAZ Academy