Package 'mapSpainHist'

Title: Historical Municipal Boundaries of Spain (1900-2001)
Description: Municipal boundaries of Spain for each population census between 1900 and 2001, together with provinces, judicial districts and electoral districts (Cortes of the Restoration in 1920 and constituencies of the Second Republic in 1931, 1933 and 1936) built from them, and the census figures of every municipality from 1842 to 2011. All maps derive from a single partition of the territory, so they have no gaps or overlaps and can be aggregated consistently. Boundaries of historical municipalities are an approximate reconstruction. Geometries are downloaded from 'Zenodo' <doi:10.5281/zenodo.23663208> and cached locally.
Authors: Pau Vall Prat [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-1418-7833>)
Maintainer: Pau Vall Prat <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-11-11 23:58:04 UTC
Source: https://github.com/cran/mapSpainHist

Help Index


Census figures of Spanish municipalities, 1842-2011

Description

Population census data for every municipality and census edition, from ⁠Municipis_Espanya_1842-2011.xlsx⁠. A municipality is in force at a census when hogares is not missing. Rows with no_munic == 1 are the non-municipal territories (codes 53xxx) present in the maps, which have no census figures.

Usage

censos

Format

A data frame with columns:

cod_ine

INE municipality code (5 characters; 6 for municipalities extinct before 1900).

censo

Census year.

municipio

Municipality name.

prov

Province.

cod_ccaa, ccaa

Autonomous community code and name.

PJ

Judicial district (partido judicial).

hogares

Households.

pder

De jure population.

phec

De facto population.

pob_serie

Continuous population series.

no_munic

1 for non-municipal territories (53xxx), 0 otherwise.


Historical electoral districts of Spain

Description

Electoral districts built by dissolving the municipalities of the census:

  • 1920: districts for the Cortes of the Restoration, on the 1920 municipalities (Melilla has no district and is not included).

  • 1931, 1933, 1936: constituencies (circunscripciones) of the Second Republic, on the 1930 municipalities.

cod_unit has 4 digits: the province code and the district number (alphabetical order within the province). Non-municipal territories (53xxx) are assigned to the district of their province with which they share the longest boundary.

Usage

esp_get_circ_hist(
  year,
  epsg = 4258,
  moveCAN = FALSE,
  census_data = TRUE,
  cache_dir = NULL,
  update_cache = FALSE,
  verbose = FALSE
)

Arguments

year

1920, 1931, 1933 or 1936. Census figures come from the 1920 census (1920) or the 1930 census (1931-1936).

epsg

EPSG code of the output (default 4258, ETRS89, as in mapSpain).

moveCAN

Position of the Canary Islands. FALSE (default) keeps their real position. TRUE moves them next to the Peninsula exactly as mapSpain::esp_move_can() does. A numeric vector c(lon, lat) adds an extra displacement, also as in mapSpain. When the islands are moved, draw the box that separates them with mapSpain::esp_get_can_box(), which matches this displacement.

census_data

If TRUE (default), adds the number of municipalities and the sum of the census figures (hogares, pder, phec, pob_serie) of the municipalities of each unit.

cache_dir

Cache directory. If NULL, mhist_cache_dir() is used.

update_cache

If TRUE, downloads the geometries again.

verbose

If TRUE, shows download messages.

Value

An sf object with columns cod_unit, nom, n_mun and, optionally, the census figures.

Examples

c1933 <- esp_get_circ_hist(1933, cache_dir = tempdir())

Historical municipalities of Spain for a census year

Description

Returns the municipalities in force at the given census. All census maps come from the same partition of the territory, so they have no gaps or overlaps and can be aggregated (provinces, judicial districts, electoral districts...) without slivers.

Usage

esp_get_munic_hist(
  year,
  epsg = 4258,
  moveCAN = FALSE,
  include_nonmunicipal = TRUE,
  census_data = TRUE,
  cache_dir = NULL,
  update_cache = FALSE,
  verbose = FALSE
)

Arguments

year

Census year, one of mhist_census_years().

epsg

EPSG code of the output (default 4258, ETRS89, as in mapSpain).

moveCAN

Position of the Canary Islands. FALSE (default) keeps their real position. TRUE moves them next to the Peninsula exactly as mapSpain::esp_move_can() does. A numeric vector c(lon, lat) adds an extra displacement, also as in mapSpain. When the islands are moved, draw the box that separates them with mapSpain::esp_get_can_box(), which matches this displacement.

include_nonmunicipal

If FALSE, drops the non-municipal territories (codes 53xxx, no_munic == 1).

census_data

If TRUE (default), adds the census figures of year from censos (municipality name, province, households, population...). If FALSE, returns only cod_ine, no_munic and the geometry.

cache_dir

Cache directory. If NULL, mhist_cache_dir() is used.

update_cache

If TRUE, downloads the geometries again.

verbose

If TRUE, shows download messages.

Details

The geometries are downloaded from Zenodo the first time and stored in a cache directory (see mhist_cache_dir()).

Value

An sf object with one row per municipality, or NULL (with a message) if the geometries cannot be downloaded.

Warning

the boundaries of most historical municipalities are an approximate reconstruction. See mapSpainHist-package.

Examples

m1930 <- esp_get_munic_hist(1930, cache_dir = tempdir())
m1930_can <- esp_get_munic_hist(1930, moveCAN = TRUE, cache_dir = tempdir())
if (!is.null(m1930)) plot(sf::st_geometry(m1930))
if (!is.null(m1930_can) && requireNamespace("mapSpain", quietly = TRUE)) {
  plot(sf::st_geometry(m1930_can))
  plot(sf::st_geometry(mapSpain::esp_get_can_box()), add = TRUE)
}

Historical judicial districts (partidos judiciales) of Spain

Description

Judicial districts for the censuses of 1900, 1910, 1920 and 1930, built by dissolving the municipalities of each census. cod_unit has 4 digits: the province code and the district number (alphabetical order within the province, the same in all censuses). Non-municipal territories (53xxx) are assigned to the district of their province with which they share the longest boundary.

Usage

esp_get_pj_hist(
  year,
  epsg = 4258,
  moveCAN = FALSE,
  census_data = TRUE,
  cache_dir = NULL,
  update_cache = FALSE,
  verbose = FALSE
)

Arguments

year

Census year: 1900, 1910, 1920 or 1930.

epsg

EPSG code of the output (default 4258, ETRS89, as in mapSpain).

moveCAN

Position of the Canary Islands. FALSE (default) keeps their real position. TRUE moves them next to the Peninsula exactly as mapSpain::esp_move_can() does. A numeric vector c(lon, lat) adds an extra displacement, also as in mapSpain. When the islands are moved, draw the box that separates them with mapSpain::esp_get_can_box(), which matches this displacement.

census_data

If TRUE (default), adds the number of municipalities and the sum of the census figures (hogares, pder, phec, pob_serie) of the municipalities of each unit.

cache_dir

Cache directory. If NULL, mhist_cache_dir() is used.

update_cache

If TRUE, downloads the geometries again.

verbose

If TRUE, shows download messages.

Value

An sf object with columns cod_unit, nom, n_mun and, optionally, the census figures.

Examples

pj1910 <- esp_get_pj_hist(1910, cache_dir = tempdir())

Historical provinces of Spain for a census year

Description

Provinces built by dissolving the municipalities of the census, so they nest exactly with esp_get_munic_hist(). Non-municipal territories (53xxx) are assigned to the province that contains them.

Usage

esp_get_prov_hist(
  year,
  epsg = 4258,
  moveCAN = FALSE,
  census_data = TRUE,
  cache_dir = NULL,
  update_cache = FALSE,
  verbose = FALSE
)

Arguments

year

Census year, one of mhist_census_years().

epsg

EPSG code of the output (default 4258, ETRS89, as in mapSpain).

moveCAN

Position of the Canary Islands. FALSE (default) keeps their real position. TRUE moves them next to the Peninsula exactly as mapSpain::esp_move_can() does. A numeric vector c(lon, lat) adds an extra displacement, also as in mapSpain. When the islands are moved, draw the box that separates them with mapSpain::esp_get_can_box(), which matches this displacement.

census_data

If TRUE (default), adds the number of municipalities and the sum of the census figures (hogares, pder, phec, pob_serie) of the municipalities of each unit.

cache_dir

Cache directory. If NULL, mhist_cache_dir() is used.

update_cache

If TRUE, downloads the geometries again.

verbose

If TRUE, shows download messages.

Value

An sf object with columns cod_unit (2-digit INE province code), nom, n_mun and, optionally, the census figures; NULL (with a message) if the geometries cannot be downloaded.

Examples

p1930 <- esp_get_prov_hist(1930, cache_dir = tempdir())

Cache directory of mapSpainHist

Description

The geometries are downloaded from Zenodo the first time they are needed and stored in a cache directory. By default it is the user cache directory given by tools::R_user_dir(). It can be changed for the session with mhist_set_cache_dir() or with the cache_dir argument of the ⁠esp_get_*_hist()⁠ functions.

Usage

mhist_cache_dir(cache_dir = NULL)

mhist_set_cache_dir(cache_dir)

Arguments

cache_dir

Path of the cache directory. If NULL, returns the current one.

Value

The path of the cache directory (invisibly for mhist_set_cache_dir()).

Examples

mhist_cache_dir()

old <- mhist_set_cache_dir(tempdir())
options(mapSpainHist.cache_dir = NULL)

Census editions available

Description

Census editions available

Usage

mhist_census_years()

Value

Integer vector with the census years covered by the package.

Examples

mhist_census_years()

Clear the cache of mapSpainHist

Description

Deletes the downloaded geometries, which will be downloaded again the next time they are needed.

Usage

mhist_clear_cache(cache_dir = NULL)

Arguments

cache_dir

Path of the cache directory. If NULL, returns the current one.

Value

TRUE invisibly if a file was deleted, FALSE otherwise.

Examples

mhist_clear_cache(tempdir())

Municipalities of each historical higher-level unit

Description

Correspondence between municipalities (cod_ine) and the units returned by esp_get_prov_hist(), esp_get_pj_hist() and esp_get_circ_hist(). Useful to aggregate municipal data. Non-municipal territories (53xxx) are included with the unit they were assigned to.

Usage

unitats

Format

A data frame with columns:

tipus

"prov", "pj" (judicial district) or "circ" (electoral district).

any

Census year (prov, pj) or election year (circ: 1920, 1931, 1933, 1936).

cod_ine

INE municipality code.

cod_unit

Unit code (2 digits for provinces, 4 digits otherwise).