Nine Points, Four Numbers, One Ordinance: Read Your Site's Noise in Python Before You Draw
Query BAFU's sonBASE road and rail noise maps for any Swiss address in 52 lines of Python, then set the worst value against the LSV limits for your zone.
Noise is a site condition, like slope, sun or the old tree on the boundary. You would not start a feasibility study without knowing which way the ground falls. You can know just as early which façade gets the traffic. The federation has already done the hard part. BAFU’s sonBASE has been a GIS noise database since 2009 and is built on swisstopo’s swissBUILDINGS3D, swissTLM3D and swissALTI3D. Per BAFU’s sonBASE page, it models noise on more than 45,000 km of roads and 4,000 km of rail lines. BAFU’s state-of-the-environment page gives the reason it exists: in 2021, 740,000 people in Switzerland were affected at home by harmful or annoying road noise, and 33,000 by rail noise.
Behind those maps are acousticians, GIS modellers and data stewards at BAFU and swisstopo, and their names never reach a plan set. Their work lets a 12-person studio in Zürich read a noise level before lunch. This tutorial shows how, in 52 lines of plain Python 3 using only the standard library.
The ordinance in one table
The Lärmschutz-Verordnung (LSV, SR 814.41) sets three thresholds for each Empfindlichkeitsstufe (ES). The ES is the noise-sensitivity level that the communal zoning plan assigns to each zone. All values are the rating level Lr in dB(A), day / night:
- ES I (recreation): Planungswert 50/40 · Immissionsgrenzwert 55/45 · Alarmwert 65/60
- ES II (residential): 55/45 · 60/50 · 70/65
- ES III (mixed): 60/50 · 65/55 · 70/65
- ES IV (industrial): 65/55 · 70/60 · 75/70
Day means 06–22 h and night 22–06 h, based on hourly traffic averaged over the year (Anhang 3 Ziff. 32). Anhang 4 carries the identical table for rail, and trams running on streets count as road noise. I quote the LSV as consolidated on fedlex, Stand 1 April 2026; the limit tables are unchanged from the 2021 version. Read your ES from the zoning plan or the ÖREB-Kataster and type it in yourself.
The Tool: the federal geodata API at geo.admin.ch. It is run by swisstopo and publishes BAFU’s sonBASE layers ch.bafu.laerm-strassenlaerm_tag / _nacht and ch.bafu.laerm-bahnlaerm_tag / _nacht. It is public, needs no key and is built on open OGC standards. One HTTP request answers a planning question, and the plain-text reply will still open in a notepad decades from now.
Setup:
# Python 3.10+ (tested on 3.10.11), standard library only - no pip install
python --version
mkdir laerm
cd laerm
# save the program below as laerm.py, then:
python -I laerm.py "Rosengartenstrasse 1 Zürich" IIIFirst steps:
- Save the program below as laerm.py in an empty folder. The -I flag runs Python in isolated mode.
- Run it with the sample address. You get a nine-row table (the address plus eight compass probes) and four verdict lines.
- Swap in your own site and ES, for example python -I laerm.py “Your Street 5 Bern” II. Change only the ES and only the limits move, because the map does not know your zoning.
The code, explained:
# Is this address over the LSV road / rail noise limits? sonBASE noise maps via geo.admin.ch, standard library only
import json, math, re, sys, urllib.parse, urllib.request
sys.stdout.reconfigure(encoding="utf-8")
ADDRESS = sys.argv[1] if len(sys.argv) > 1 else "Rosengartenstrasse 1 Zürich"
ES = sys.argv[2] if len(sys.argv) > 2 else "III" # Empfindlichkeitsstufe from the zoning plan
RING_M = 12 # also probe 8 points this far from the address
# LSV Anhang 3 (road) and Anhang 4 (rail) - same table: (PW, IGW, AW) for (day, night) in dB(A)
LIMITS = {"I": ((50, 40), (55, 45), (65, 60)), "II": ((55, 45), (60, 50), (70, 65)),
"III": ((60, 50), (65, 55), (70, 65)), "IV": ((65, 55), (70, 60), (75, 70))}
LAYERS = {("road", 0): "ch.bafu.laerm-strassenlaerm_tag", ("road", 1): "ch.bafu.laerm-strassenlaerm_nacht",
("rail", 0): "ch.bafu.laerm-bahnlaerm_tag", ("rail", 1): "ch.bafu.laerm-bahnlaerm_nacht"}
def geocode(text):
url = "https://api3.geo.admin.ch/rest/services/api/SearchServer?" + urllib.parse.urlencode(
dict(searchText=text, type="locations", sr=2056, limit=1))
a = json.load(urllib.request.urlopen(url, timeout=30))["results"][0]["attrs"]
return a["y"], a["x"], re.sub("<.*?>", "", a["label"]) # East, North, label
def level(layer, e, n):
"""Ask the WMS for the raster value (Lr in dB(A)) under one LV95 point."""
q = dict(SERVICE="WMS", VERSION="1.3.0", REQUEST="GetFeatureInfo", LAYERS=layer, QUERY_LAYERS=layer,
CRS="EPSG:2056", BBOX=f"{e-10},{n-10},{e+10},{n+10}", WIDTH=101, HEIGHT=101, I=50, J=50,
INFO_FORMAT="text/plain")
txt = urllib.request.urlopen("https://wms.geo.admin.ch/?" + urllib.parse.urlencode(q), timeout=30).read().decode()
m = re.search(r"value_0\.name = '([\d.]+)'", txt)
return float(m.group(1)) if m else None # None = below the map's lowest class / no source
e0, n0, label = geocode(ADDRESS)
print(f"{label} E {e0:.0f} / N {n0:.0f} Empfindlichkeitsstufe {ES}")
probes = {"address": (e0, n0)}
for i, name in enumerate(["N", "NE", "E", "SE", "S", "SW", "W", "NW"]):
a = math.radians(45 * i)
probes[name] = (e0 + RING_M * math.sin(a), n0 + RING_M * math.cos(a))
print(f"\n{'probe':<8} {'road day':>8} {'road night':>10} {'rail day':>8} {'rail night':>10}")
worst = {}
for name, (e, n) in probes.items():
row = {k: level(lay, e, n) for k, lay in LAYERS.items()}
for k, v in row.items():
if v is not None and v > worst.get(k, (-1, ""))[0]:
worst[k] = (v, name)
print(f"{name:<8}" + "".join(f"{'-' if row[k] is None else row[k]:>{w}}" for k, w in
((("road", 0), 9), (("road", 1), 11), (("rail", 0), 9), (("rail", 1), 11))))
print(f"\nWorst probe vs LSV, ES {ES} (PW = Planungswert, IGW = Immissionsgrenzwert, AW = Alarmwert)")
for (src, night), (v, where) in sorted(worst.items()):
pw, igw, aw = (lim[night] for lim in LIMITS[ES])
verdict = ("over AW" if v > aw else "over IGW" if v > igw else "over PW" if v > pw else "below PW")
print(f"{src} {'night' if night else 'day '}: {v:4.1f} dB(A) at {where:<7} "
f"PW {pw} / IGW {igw} / AW {aw} -> {verdict} (margin to IGW {igw - v:+.1f} dB)")Lines 1–13 — the ordinance as data: sys.argv is the list of words typed after the script name. The address and the ES arrive from the command line, and the sample address is the fallback. LIMITS is a dictionary, a lookup table from a key to a value. Each ES maps to three (day, night) pairs: PW, IGW and AW. So LIMITS[“III”][1][0] is the IGW by day, 65 dB(A). LAYERS is keyed by the tuple (source, night-flag), which lets one loop handle all four maps.
Lines 15–19 — address to coordinates: swisstopo’s SearchServer turns text into a point in LV95 (EPSG:2056, the Swiss national grid in metres). Watch for the beginner mistake here. In this response y is East and x is North, which is the Swiss surveying convention. If you swap them, every probe lands kilometres away and the table fills with dashes. The regex <.*?> (a regular expression, a text pattern) strips the bold tags from the label.
Lines 21–28 — the API lesson: the noise maps are rasters, grids of pixels that each hold a value, with no vector objects to click. The usual geo.admin.ch identify call fails on them with “No GeoTable”. The answer is the WMS (Web Map Service, an open OGC standard) request GetFeatureInfo. You describe a 20 × 20 m box around the point, treat it as a 101 × 101-pixel image, and ask for pixel I=50, J=50. That pixel is the exact centre, so it sits on your point. The reply contains a line like value_0.name = ‘74.6’, and the regex pulls out the number. None means the map has no value at that point.
Lines 30–35 — the ring: eight probes, 45° apart, 12 m from the geocoded point. sin gives the East offset and cos the North offset, so i=0 points due north. One point tells you how loud the site is. The ring tells you which side is quieter.
Lines 37–52 — table and verdict: each probe asks all four layers and prints a row. The highest value per layer is kept in worst and then set against PW, IGW and AW for your ES. The script reads “überschritten” as a strict “greater than”. A negative margin to the IGW means the probe reads above the limit.
Here is the real run from 13 November 2026 at Rosengartenstrasse 1, 8037 Zürich (E 2681957 / N 1249707). ES III is assumed for the demo, not taken from the zoning plan:
probe road day road night rail day rail night
address 70.8 62.6 24.1 15.9
SE 74.6 66.4 25.4 17.3
W 65.5 57.3 23.7 15.5
NW 65.9 57.7 23.3 15.1
(five more probe rows)
rail day : 25.4 dB(A) at SE PW 60 / IGW 65 / AW 70 -> below PW (margin to IGW +39.6 dB)
rail night: 17.3 dB(A) at SE PW 50 / IGW 55 / AW 65 -> below PW (margin to IGW +37.7 dB)
road day : 74.6 dB(A) at SE PW 60 / IGW 65 / AW 70 -> over AW (margin to IGW -9.6 dB)
road night: 66.4 dB(A) at SE PW 50 / IGW 55 / AW 65 -> over AW (margin to IGW -11.4 dB)Read that honestly. The flag describes the street, not any building or anyone living there, and a probe 12 m out can sit on the carriageway itself. Each value is a modelled pixel with Datenstand 31.12.2021, and BAFU’s own layer legend states “Die Daten sind gesetzlich nicht verbindlich”. Binding values come from the Vollzugsbehörden: ASTRA for national roads, the cantons for everything else. Rail sits far below every limit, at 25 / 17 dB(A).
←TODAY: 74.6 / 66.4 dB(A) at the south-east probe and 65.9 / 57.7 at the north-west: about 9 dB across one plot. →3012: the façades that aged well in my time were the ones whose quiet side was decided before the first line was drawn. Fulcrum: a public map today plus a ring of eight points yields a floor-plan decision that lasts decades.
Those 9 dB matter because of LSV Art. 31 Abs. 1 (Stand 1 April 2026). Where the IGW is exceeded, new buildings with noise-sensitive rooms are approved only if the limits can be met “durch die Anordnung der lärmempfindlichen Räume auf der dem Lärm abgewandten Seite des Gebäudes”, or through structural or design measures. Since 1 April 2026 the revised Umweltschutzgesetz (Art. 22 Abs. 2) sets the fallback when that fails; one of its options is that at least half of a unit’s noise-sensitive rooms have a window where the IGW are met. So the ring is a first draft of where the bedrooms go. For bedrooms, read the night column first. The traffic will not move for your render. Your bedrooms can.
Atelier: Offices using AI to speed up feasibility studies keep reporting the same pattern. A fast first massing is worthless if a site constraint arrives three weeks later and flips the plan. Noise is exactly that kind of constraint, and it is already public. Monday move: add laerm.py to the project-start checklist, and file its output next to the cadastral extract before anyone opens a massing model.
Hack: Make the script name the quiet side at night and write it down for you. Append these three lines and predict the answer from the table first: on the sample address it should print W at 57.3. The lines query the road-night map once more at every probe and keep the lowest reading.
road_n = {name: level(LAYERS[("road", 1)], e, n) for name, (e, n) in probes.items()}
quiet = min((v, k) for k, v in road_n.items() if v is not None)
print(f"quiet side at night: {quiet[1]} at {quiet[0]} dB(A) - start the bedrooms here")If it prints something else, check the East/North order first. The binding check is still the façade level at the window of a noise-sensitive room, done in a Lärmgutachten with the cantonal authority. This script is not legal advice. It tells you which question to bring to that meeting.
Learn-it:
- swisstopo — geo.admin.ch SearchServer (address to LV95)
- BAFU — legend of the road-noise layer Lr_Tag (Datenstand, legal status)
- BAFU — sonBASE, the national noise database
- LSV SR 814.41 on fedlex, Stand 1.4.2026 — Anhang 3 and 4, Art. 31
- PAZ Academy — Archicad Python Automatisierung, for when the quiet side should land in the model
Run the script on your next site before the first sketch, and mark the quiet side on the plan in red.
PAZ Kaffi · multidisciplinary editorial, led by PAZ Academy