catastro-enrichment-es
Spain does not have one cadastre but five. This library queries them all through the same interface and fills in an inventory with coordinates, areas, year, use and an image.
- 5cadastres behind one interface (DGC and four foral ones)
- 139network-free tests, 97% coverage
- <1e-6°UTM ↔ WGS84 round-trip error, zones 28 to 31
- 1runtime dependency (pyproj)
- 0writes without a dry run or a backup first
- MITlicence · PyPI 0.1.0
Real results, one cadastre per tab
Queries made with the published package against the public services, from a point next to a well-known building in each territory. The reference shown is the parcel the service returns at that point.
- 1Query point
Next to the Prado Museum, Madrid ·40.4138, -3.6921 - 2Router
INE code28079→ province28→ National Directorate (DGC) · OVC XML services + INSPIRE WFS - 3Cadastral reference
1341701VK4714A
Obtained from the point withrc_at_point: PS PRADO 11 MADRID (MADRID) - 4Result
- WGS84
40.413461, -3.691671- Built area
- 30,456 m²
- Year per cadastre (oldest unit)
- 1999
- Cadastral use
- Cultural
Live links (never stored): Google Maps ↗ · Street View ↗
Source: Dirección General del Catastro (Sede Electrónica del Catastro)
- 1Query point
Next to the Kursaal, Donostia / San Sebastián ·43.3246, -1.9787 - 2Router
INE code20069→ province20→ Gipuzkoa foral cadastre · INSPIRE WFS 2.0 stored query - 3Cadastral reference
069-8297591-3232 - 4Result
- WGS84
43.324548, -1.978755- Parcel area
- 12,097 m²
- Physical data
NOT_SUPPORTEDonly the DGC publishes them
Live links (never stored): Google Maps ↗ · Street View ↗
Source: Gipuzkoako Foru Aldundia / Diputación Foral de Gipuzkoa (CC-BY)
- 1Query point
Next to the Palace of Navarre, Pamplona ·42.8147, -1.6447 - 2Router
INE code31201→ province31→ Navarre cadastre · INSPIRE WFS 2.0 with cql_filter - 3Cadastral reference
201011340 - 4Result
- WGS84
42.815440, -1.644551- Parcel area
- 7,977 m²
- Physical data
NOT_SUPPORTEDonly the DGC publishes them
Live links (never stored): Google Maps ↗ · Street View ↗
Source: Gobierno de Navarra - IDENA (CC-BY 4.0)
- 1Query point
Next to Santa María Cathedral, Vitoria-Gasteiz ·42.8505, -2.6720 - 2Router
INE code01059→ province01→ Álava foral cadastre · ArcGIS WFS with FES XML filter - 3Cadastral reference
05900600287 - 4Result
- WGS84
42.850681, -2.672293- Parcel area
- 3,191 m²
- Physical data
NOT_SUPPORTEDonly the DGC publishes them
Live links (never stored): Google Maps ↗ · Street View ↗
Source: Arabako Foru Aldundia / Diputación Foral de Álava (CC-BY)
- 1Query point
Next to the Guggenheim Museum, Bilbao ·43.2687, -2.9340 - 2Router
INE code48020→ province48→ Bizkaia foral cadastre · ArcGIS WFS, reference split into municipality, polygon and parcel - 3Cadastral reference
20-1601-1904 - 4Result
- WGS84
43.268602, -2.933277- Parcel area
- 25,943 m²
- Physical data
NOT_SUPPORTEDonly the DGC publishes them
Live links (never stored): Google Maps ↗ · Street View ↗
Source: Bizkaiko Foru Aldundia / Diputación Foral de Bizkaia (CC-BY 4.0)
Router: which cadastre answers a municipality?
Try 28079 (Madrid), 20069 (Donostia), 31201 (Pamplona), 01059 (Vitoria) or 48020 (Bilbao).
Fallback geocoding: precision by OSM class
When the cadastre cannot resolve, the address goes to Nominatim. The library labels each hit by its OpenStreetMap class and only stores «exact» ones by default: a neighbourhood centroid is not the property.
| Query | OSM class | Precision | Stored by default |
|---|---|---|---|
| Paseo del Prado 8, Madrid | tourism/museum | exact | ✔ |
| Lavapiés, Madrid | railway/station | zone | ✘ (--accept-zone) |
Results obtained on 2026-11-22 with catastro-enrich 0.1.0 against the public services; the page shows them without querying anything.
The problem
Public-sector asset registers and property portfolios arrive incomplete: cadastral references without coordinates, free-text addresses without a reference, empty areas and years, no image. Completing them by hand is slow and error-prone. And Spain does not have one cadastre but five: the National Directorate of Cadastre for most of the country and the foral cadastres of Álava, Bizkaia, Gipuzkoa and Navarre, each with its own protocol, reference format, filtering dialect and coordinate system.
How I solved it
- One contract, five drivers. The same interface (
lookup_rc,physical_data,batch) for every territory. A router picks the cadastre from the municipality’s INE code, which takes precedence over the province name. - Coordinate cascade. With a reference, the territory’s cadastre is asked. If it does not resolve and there is an address, geocoding takes over. If nothing resolves, the asset stays pending with its reason. Geocoding never overwrites a cadastral coordinate.
- Honest precision. Each Nominatim hit is labelled by its OpenStreetMap class as
exact,zoneoradministrative, and only exact ones are stored by default: a neighbourhood centroid is not the property. - Images according to their licence. PNOA orthophotos and Mapillary views are stored with their attribution; Google only as a live link, because its terms forbid storing.
- Repeatable batches. Dry run by default, additive writes, a backup before writing and telemetry for each run. Business errors, which these services return with HTTP 200, are treated as data: a batch counts the failure and carries on.
Decisions
| Decision | Rejected alternative | Reason |
|---|---|---|
| One driver per cadastre and an INE router | A single parametrised client | ArcGIS ignores cql_filter, INSPIRE services lack the unified reference, and axis order and formats differ |
| Nominatim | Google Geocoding | Cost, no-storage terms and sending data to a commercial third party |
| Confidence by OSM class | An importance threshold | Importance measures global relevance: rural streets would be discarded |
| Standard library with an injectable transport | requests or httpx | A single runtime dependency and network-free tests |
| Errors as data | Exceptions | A batch must count and carry on |
How it is built
Python 3.11+ with the standard library and pyproj for UTM ↔ WGS84 conversions. 139 tests that run without network (every service response is synthetic), with 97% coverage. A six-command CLI and a reference SQLite adapter. Published on PyPI.
A clean-room case study
The patterns come from my work at Intervalor Data and are published with the company’s permission. The repository is an independent implementation from a written specification, with synthetic data only, and an anti-leak test in CI keeps out any term from clients or the original system. The examples on this page are well-known public buildings, unrelated to any client.
Technologies
- Python 3.11+
- pyproj
- urllib
- sqlite3
- pytest
- ruff
- GitHub Actions
- gitleaks