Skip to content
Ariel Luján Giamportone

← Projects

Open package 11/2026 · Autor (especificación, implementación clean-room y revisión)

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.

Public-sector dataAI and data scienceAI-powered software

Repository ↗PyPI: catastro-enrich ↗

  • 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.

  1. 1
    Query point
    Next to the Prado Museum, Madrid · 40.4138, -3.6921
  2. 2
    Router
    INE code 28079 → province 28 → National Directorate (DGC) · OVC XML services + INSPIRE WFS
  3. 3
    Cadastral reference
    1341701VK4714A
    Obtained from the point with rc_at_point: PS PRADO 11 MADRID (MADRID)
  4. 4
    Result
    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)

PNOA orthophoto centred on the returned point
PNOA orthophoto, stored with its attribution · PNOA © Instituto Geográfico Nacional

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.

QueryOSM classPrecisionStored by default
Paseo del Prado 8, Madridtourism/museumexact✔
Lavapiés, Madridrailway/stationzone✘ (--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, zone or administrative, 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

DecisionRejected alternativeReason
One driver per cadastre and an INE routerA single parametrised clientArcGIS ignores cql_filter, INSPIRE services lack the unified reference, and axis order and formats differ
NominatimGoogle GeocodingCost, no-storage terms and sending data to a commercial third party
Confidence by OSM classAn importance thresholdImportance measures global relevance: rural streets would be discarded
Standard library with an injectable transportrequests or httpxA single runtime dependency and network-free tests
Errors as dataExceptionsA 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