pycensus.census.countries.spain.ine¶
Spain Census 2021 (Censo de Población y Viviendas 2021) source.
Importing this module registers the gdf.ine GeoDataFrame accessor
(see :mod:pycensus.accessors). Use :func:load to fetch data.
Technical aspects
Unlike US census data which has APIs, Spain's INE Census 2021 data must be downloaded as files from INE's website. This module provides tools to: 1. Load and process the data into a common-schema GeoDataFrame 2. Cache processed data for efficient repeated access 3. Download data to the cache directory
Source
https://www.ine.es/dyngs/INEbase/es/operacion.htm?c=Estadistica_C&cid=1254736176780
download_census_data(level='municipality', regions=None, data_dir=None, overwrite=False)
¶
Force a fresh download of INE's Padron municipal table to the raw cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Accepted for interface parity; the Padron API returns every municipality in one request regardless of level. |
'municipality'
|
regions
|
Optional[Union[str, List[str]]]
|
Accepted for interface parity; not used to filter the download (the raw file always holds every municipality). |
None
|
data_dir
|
Optional[str]
|
Root directory for raw downloads. |
None
|
overwrite
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the raw cache file that was downloaded/refreshed. |
Note
Only the Padron (population by sex) is implemented here. INE's Census 2021 (Censo de Poblacion y Viviendas) publishes households, housing, education, and employment data at municipality level too, via the same Tempus API under a different operation/table id, but that was not identified and verified against a real downloaded file in this rebuild -- see the module docstring.
load(aoi=None, regions=None, level='municipality', year='latest', api_key=None, cache_dir=None, cache=True, data_dir=None)
¶
Load INE's Padron municipal population data as a common-schema GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
Optional[GeoDataFrame]
|
Area of interest. Used to auto-detect |
None
|
regions
|
Optional[Union[str, List[str]]]
|
Region code(s) -- autonomous community code, province code,
or 5-digit municipality code, matching |
None
|
level
|
str
|
Standard geometry level name. Spain supports |
'municipality'
|
year
|
Union[int, str]
|
Vintage year, or |
'latest'
|
api_key
|
Optional[str]
|
Not used -- INE's Padron Tempus API requires no API key. |
None
|
cache_dir
|
Optional[str]
|
Root of pyCensus' parquet cache. Defaults to
:func: |
None
|
cache
|
bool
|
If |
True
|
data_dir
|
Optional[str]
|
Root directory for raw INE/GISCO downloads (separate from
|
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame with |
GeoDataFrame
|
column per logical column in :data: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither |
NotImplementedError
|
If |