pycensus.census.countries.spain.geography¶
Boundary fetching shared by every Spain census source.
Technical aspects
Boundaries come from Eurostat/GISCO's LAU (Local Administrative Units)
dataset, verified 2026-08-19:
https://gisco-services.ec.europa.eu/distribution/v2/lau/download/ref-lau-2021-01m.geojson.zip
(~106 MB zip containing every EU/EFTA/candidate country's municipalities
at 1:1,000,000 resolution; contains 8,131 Spanish features whose
LAU_ID is exactly INE's 5-digit municipality code -- verified by
cross-checking LAU_ID == "44001" (Ababuj, Teruel) against INE's own
Tempus API (:mod:pycensus.spain.ine.loader), and by summing every
Spanish feature's POP_2021 to get 47,385,107 -- matching INE table
2915's "Total Nacional" 2021 figure exactly).
Only municipality boundaries are downloaded directly.
province/autonomous_community/nation boundaries are built by
dissolving municipality geometries using the code prefixes/mapping in
:mod:pycensus.spain.constants (INE municipality codes are
{2-digit province code}{3-digit municipality code}, so the first two
characters of LAU_ID are the province code).
section (seccion censal) boundaries come from a real, verified
source found in this rebuild: INE's own OGC API Features service,
documented at
https://www.ine.es/geoserver/ogc/features/v1/collections?f=text/html
and https://www.ine.es/geoserver/www/guias/OGC_API_Feature_Seccionado.pdf
-- verified 2026-08-20 with a live request:
GET https://www.ine.es/geoserver/ogc/features/v1/collections/WMS_INE_SECCIONES_G01:Secciones_2025/items?filter=CPRO='20' AND TIPO='SECCIONADO'&filter-lang=cql-text&f=json&limit=2000
returned 544 real MultiPolygon features for Gipuzkoa (province code
"20"), each carrying a real CUSEC 10-digit code (CPRO 2 +
CMUN 3 + CDIS 2 + CSEC 3, e.g. "2000101001") matching
the format INE's own population-by-section files use for their
Sección column. The collection also contains TIPO='DISTRITO'
aggregate rows (CSEC='000') that are not real sections -- these
are filtered out via the TIPO='SECCIONADO' CQL clause. The
response's crs member is urn:ogc:def:crs:EPSG::4326, confirmed
live.
district/block (distrito/manzana) are still not implemented --
INE's cartography service exposes district only as the
TIPO='DISTRITO' aggregate rows within the same section collection
(usable, but not yet wired up here), and no stable direct-download URL
for block-level (manzana) cartography was verified in this
session. Requesting those levels raises NotImplementedError rather
than fabricating placeholder geometry (see :data:IMPLEMENTED_LEVELS).
Downloaded/derived files are cached under
<data_dir>/raw/gisco_lau/ (municipality+) and
<data_dir>/raw/ine_secciones/ (section, one parquet per province),
both persistent across runs, independent of :mod:pycensus.cache's
parquet cache.
Source
https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units/local-administrative-units
load_boundaries(level, region=None, year=2021, erase_water=None, data_dir=None)
¶
Fetch boundaries for one Spain geography level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Standard geometry level name, resolved through
:data: |
required |
region
|
Optional[str]
|
Region code -- an autonomous community code, province code,
or municipality code, matching |
None
|
year
|
int
|
Vintage year. GISCO LAU 2021 is the only vintage wired up for municipality+; INE's "Secciones_2025" collection is the only vintage wired up for sections. Kept as a parameter for interface parity with other countries. |
2021
|
erase_water
|
Optional[bool]
|
Whether to clip inland water bodies. Defaults to
:data: |
None
|
data_dir
|
Optional[str]
|
Root directory for the raw GISCO/INE cache. Defaults to
:data: |
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame with a |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
ValueError
|
If |
NotImplementedError
|
If |
load_boundaries_multi(level, regions=None, year=2021, erase_water=None, aoi=None, data_dir=None)
¶
Fetch and concatenate boundaries across one or more regions, optionally clipped to an AOI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Standard geometry level name. |
required |
regions
|
Optional[Union[str, List[str]]]
|
Region code(s). If |
None
|
year
|
int
|
Vintage year (see :func: |
2021
|
erase_water
|
Optional[bool]
|
Whether to clip inland water bodies. |
None
|
aoi
|
Optional[GeoDataFrame]
|
If given, the result is filtered to geometries intersecting it. |
None
|
data_dir
|
Optional[str]
|
Root directory for the raw GISCO cache. |
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame with a |
autonomous_communities_in_aoi(aoi, year=2021, data_dir=None)
¶
Return the INE codes of every autonomous community intersecting aoi.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
GeoDataFrame
|
Area of interest (GeoDataFrame). |
required |
year
|
int
|
Boundary year. |
2021
|
data_dir
|
Optional[str]
|
Folder of the raw downloads; |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
Community codes. |
provinces_in_aoi(aoi, year=2021, data_dir=None)
¶
Return the INE codes of every province intersecting aoi.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
GeoDataFrame
|
Area of interest (GeoDataFrame). |
required |
year
|
int
|
Boundary year. |
2021
|
data_dir
|
Optional[str]
|
Folder of the raw downloads; |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
Province codes. |
states_in_aoi(aoi, year=2021, data_dir=None)
¶
Alias for :func:autonomous_communities_in_aoi (interface parity with usa).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
GeoDataFrame
|
Area of interest (GeoDataFrame). |
required |
year
|
int
|
Boundary year. |
2021
|
data_dir
|
Optional[str]
|
Folder of the raw downloads; |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
Community codes. |