Trece is a CLI tool for downloading and managing authoritative Spanish geospatial and address data, including administrative boundaries, road networks, postal codes, and address points for all Spanish provinces. The data is sourced from CartoCiudad, an official national geospatial database maintained by the Instituto Geográfico Nacional. Refer to Data Source and Attribution for more.
CartoCiudad data is widely used for mapping, spatial analysis, urban planning, and research. The data is open, regularly updated, and available in various formats suitable for GIS and data science workflows.
Each province's dataset is distributed as a GeoPackage (.gpkg
) file, a spatial database format that supports multiple vector layers. It includes two main layers
-
portalpk_publi: Point layer representing address portals (building entrances) and kilometer markers along the road network. Each record contains
id
: Unique identifiergeom
: Point geometry (location)id_porpk
: Portal or kilometer marker IDtipo_vial
: Type of road/streetnombre_via
: Street namenumero
: Street number or kilometerextension
: Additional address infodgc_via
: Road code (from Dirección General de Catastro)id_pob
: Population entity IDpoblacion
: Population entity namecod_postal
: Postal codetipo_porpk
: Portal/marker typetipoporpkd
: Portal/marker type descriptionfuented
: Data sourcefecha_modificacion
: Last modification datemunicipio
: Municipality nameine_mun
: Municipality code (INE)provincia
: Province namecomunidad_autonoma
: Autonomous community name
-
manzana: Polygon layer representing cadastral blocks (manzanas) as defined by the Spanish Cadastre and regional authorities. Each record contains
id
: Unique identifiergeom
: Polygon geometry (block shape)ID_MANZ
: Block identifierALTA_DB
: Database registration dateINE_MUN
: Municipality code (INE)
Coordinate Reference System:
- Mainland Spain and Balearic Islands: ETRS89 (EPSG:4258)
- Canary Islands: REGCAN95 (EPSG:4081)
All attributes are standardized for integration with GIS and spatial analysis tools. The data structure and schema are consistent across provinces, enabling automated processing and analysis.
- Fast & Simple: Download CartoCiudad data for all Spanish provinces with a single command.
- Province Selection: Choose a province or fetch all at once.
- Scriptable: Easily integrate into your data pipelines or automation scripts.
Install via PyPI
pip install trece
Download CartoCiudad data for all provinces
trece download
or for a single province
trece download --province madrid
This will download a ZIP archive for the Madrid province at ./data/CARTOCIUDAD_CALLEJERO_MADRID.zip
by default, but you can specify an output directory with the -o
option. See the Options section for more.
trece [OPTIONS] COMMAND [ARGS]...
download
— Download CartoCiudad data
-v, --version
— Print trece version-h, --help
— Show help message and exit-p, --province
— (Fordownload
) Specify a Spanish province (optional)-o, --output
— (Fordownload
) Output directory for downloaded files (optional)
Clone the repository and install development dependencies:
git clone https://github.com/ernestofgonzalez/trece.git
cd trece
pip install -r requirements.txt
Run tests:
make test
Contributions, issues, and feature requests are welcome! Feel free to check issues page or submit a pull request.
This project uses data from CartoCiudad, a product of the Instituto Geográfico Nacional (IGN) and Centro Nacional de Información Geográfica (CNIG), Spain. For more information, visit: CartoCiudad and SCNE Productos.
Attribution: Fuente: CartoCiudad. © Instituto Geográfico Nacional de España, Centro Nacional de Información Geográfica
Please review the full terms of use and attribution requirements at https://www.scne.es/productos.php#CartoCiudad
This project is licensed under the Apache License 2.0. See the LICENSE file for details.