Códigos postales de España

done#open-data#open-source

There was no open dataset telling you which municipality each Spanish postal code belongs to. Correos sells it, CartoCiudad stopped offering it in 2017 and the INE doesn't publish postal codes. So I built one from data that is open. I wrote about why it matters in Public is not the same as open.

What's in it

  • 10,790 postal codes across all 8,132 municipalities, each with its INE code
  • 1,864 codes shared by more than one municipality, with how much of the code belongs to each
  • Coordinates for 10,711 codes: the centre of each code's estimated area
  • Three CSVs: one row per postal code, one per postal code and municipality pair, and one per municipality with all its codes

How it works

The postal code of each street comes from the INE's electoral census street map: 1.5 million street segments, each with its municipality and postal code. Counting them tells you which codes exist and where they belong. Coordinates come from Diego Hernangómez's open estimate of postal code areas (Zenodo, CC BY 4.0), built from CartoCiudad addresses.

A Node script downloads the latest sources, filters out the typos in the street map (without dropping the border towns that really do use a neighbouring province's codes) and rewrites the CSVs. The INE updates the street map every January and July.

Limits

It's not Correos' database: PO boxes and codes for big companies or public bodies are missing. A postal code can span several municipalities, and the "main" one is the one with the most streets, not necessarily the most people.

License

Data under CC BY 4.0, code under MIT. Use it for anything, including a business. If you do, I'd love to know what you built.


Link: github.com/ITWASNOTG/codigos-postales-espana

← all projects