Package {mapSpain}


Type: Package
Title: Administrative Boundaries and Static Map Tiles for Spain
Version: 1.2.1
Description: Administrative boundaries of Spain at several levels (Autonomous Communities and Cities, provinces, municipalities and 'NUTS'), based on 'GISCO' from 'Eurostat' https://ec.europa.eu/eurostat/web/gisco and 'CartoBase ANE' from 'Instituto Geográfico Nacional' https://www.ign.es/. Includes tools to download and process static map tiles and a 'leaflet' plugin for Spanish public administration tile providers.
License: GPL-3
URL: https://ropenspain.github.io/mapSpain/, https://github.com/rOpenSpain/mapSpain
BugReports: https://github.com/rOpenSpain/mapSpain/issues
Depends: R (≥ 4.1.0)
Imports: cli (≥ 3.6.0), countrycode (≥ 1.2.0), giscoR (≥ 1.0.0), httr2 (≥ 1.2.0), jsonlite, leaflet (≥ 2.0.0), lifecycle, rappdirs (≥ 0.3.0), sf (≥ 1.0.0), terra (≥ 1.1-4), tibble, tools, utils
Suggests: dplyr, ggplot2 (≥ 3.5.0), knitr, quarto, testthat (≥ 3.0.0), tidyterra, withr
VignetteBuilder: quarto
Config/Needs/check: curl
Config/Needs/coverage: covr
Config/Needs/website: ragg, reactable, rnaturalearth, tidyverse, devtools, remotes, ropenspain/rostemplate, ropensci/rnaturalearthhires, geodata, sessioninfo, sfheaders, rapidjsonr, jsonify, geometries, geobounds
Config/roxygen2/markdown: TRUE
Config/roxygen2/version: 8.1.0
Config/testthat/edition: 3
Config/testthat/parallel: true
Copyright: © EuroGeographics for the administrative boundaries. Atlas Nacional de España (ANE) CC-BY 4.0 <https://www.ign.es>. INE <https://www.ine.es/en/index.htm>
Encoding: UTF-8
LazyData: true
X-schema.org-applicationCategory: cartography
X-schema.org-isPartOf: https://ropenspain.es/
X-schema.org-keywords: ropenspain, tiles, r, maps, spatial, rstats, r-package, municipalities, spain, gisco, provinces, ign, autonomous-communities, administrative-boundaries, static-tiles, cran, ggplot2, gis, nuts, ccaa
NeedsCompilation: no
Packaged: 2026-08-31 09:00:32 UTC; diego
Author: Diego Hernangómez ORCID iD [aut, cre, cph], Eurostat ROR ID [cph], Instituto Geográfico Nacional ROR ID [cph], Francisco J. Goerlich ORCID iD [ctb]
Maintainer: Diego Hernangómez <diego.hernangomezherrero@gmail.com>
Repository: CRAN
Date/Publication: 2026-08-31 17:00:13 UTC

mapSpain: Administrative Boundaries and Static Map Tiles for Spain

Description

logo

Administrative boundaries of Spain at several levels (Autonomous Communities and Cities, provinces, municipalities and 'NUTS'), based on 'GISCO' from 'Eurostat' https://ec.europa.eu/eurostat/web/gisco and 'CartoBase ANE' from 'Instituto Geográfico Nacional' https://www.ign.es/. Includes tools to download and process static map tiles and a 'leaflet' plugin for Spanish public administration tile providers.

Author(s)

Maintainer: Diego Hernangómez diego.hernangomezherrero@gmail.com (ORCID) [copyright holder]

Authors:

Other contributors:

See Also

Useful links:


Add a tile layer from Spanish public administrations to a leaflet map

Description

Add a tile layer from Spanish public administrations to a leaflet map

Usage

addProviderEspTiles(
  map,
  provider,
  layerId = NULL,
  group = NULL,
  options = leaflet::providerTileOptions()
)

Arguments

map

the map to add the tile layer to

provider

The name of the provider. See esp_tiles_providers or https://dieghernan.github.io/leaflet-providersESP/preview/.

layerId

the layer id to assign

group

the name of the group the newly created layers should belong to (for clearGroup() and addLayersControl() purposes). Human-friendly group names are permitted–they need not be short, identifier-style names.

options

tile options

Value

modified map object

Source

https://dieghernan.github.io/leaflet-providersESP/, a plugin for leaflet, v1.3.3.

See Also

Static map tiles and imagery: esp_get_attributions(), esp_get_tiles(), esp_make_provider()

Examples

library(leaflet)
leafmap <- leaflet(width = "100%", height = "60vh") |>
  setView(lat = 40.4166, lng = -3.7038400, zoom = 10) |>
  addTiles(group = "Default (OSM)") |>
  addProviderEspTiles(
    provider = "IDErioja.Claro",
    group = "IDErioja Claro"
  ) |>
  addProviderEspTiles(
    provider = "RedTransporte.Carreteras",
    group = "Carreteras"
  ) |>
  addLayersControl(
    baseGroups = c("IDErioja Claro", "Default (OSM)"),
    overlayGroups = "Carreteras",
    options = layersControlOptions(collapsed = FALSE)
  )

leafmap

Check access to SIANE data resources

Description

Check whether R has access to resources at https://github.com/rOpenSpain/mapSpain/tree/sianedata.

Usage

esp_check_access()

Value

Logical scalar, TRUE if accessible and FALSE otherwise.

See Also

giscoR::gisco_check_access().

Examples


esp_check_access()

Clear your mapSpain cache directory

Description

Use this function with caution. It clears your cached data and configuration, specifically:

Usage

esp_clear_cache(config = FALSE, cached_data = TRUE, verbose = FALSE)

Arguments

config

Logical. If TRUE, deletes the configuration folder of mapSpain.

cached_data

Logical. If TRUE, deletes your cache_dir and all its contents.

verbose

A logical value indicating whether to display informational messages.

Details

This is an aggressive function intended to reset your installation as if you had never installed or used mapSpain.

Value

Invisible. This function is called for its side effects.

See Also

tools::R_user_dir().

Cache management utilities: esp_set_cache_dir()

Examples


# Do not run this. It would modify your current state.
## Not run: 
my_cache <- esp_detect_cache_dir()

# Set an example cache.
ex <- file.path(tempdir(), "example", "cache")
esp_set_cache_dir(ex, verbose = FALSE)

# Restore the initial cache.
esp_clear_cache(verbose = TRUE)

esp_set_cache_dir(my_cache)
identical(my_cache, esp_detect_cache_dir())

## End(Not run)

Spanish subdivision codes and names

Description

A tibble object used internally to translate codes and names for different Spanish subdivisions. This tibble provides a hierarchical representation of Spain's subdivisions, including NUTS 1, Autonomous Communities and Cities (equivalent to NUTS 2), provinces and province-level NUTS 3 units. See the note below for coverage details.

Format

A tibble with 59 rows and columns:

nuts1.code

NUTS 1 code.

nuts1.name

NUTS 1 name.

nuts1.name.alt

NUTS 1 alternative name.

nuts1.shortname.es

NUTS 1 short (common) name (Spanish).

codauto

INE code of the Autonomous Community or City.

iso2.ccaa.code

ISO2 code of the Autonomous Community or City.

nuts2.code

NUTS 2 code.

ine.ccaa.name

INE name of the Autonomous Community or City.

iso2.ccaa.name.es

ISO2 name of the Autonomous Community or City (Spanish).

iso2.ccaa.name.ca

ISO2 name of the Autonomous Community or City (Catalan).

iso2.ccaa.name.gl

ISO2 name of the Autonomous Community or City (Galician).

iso2.ccaa.name.eu

ISO2 name of the Autonomous Community or City (Basque).

nuts2.name

NUTS 2 name.

cldr.ccaa.name.en

CLDR name of the Autonomous Community or City (English).

cldr.ccaa.name.es

CLDR name of the Autonomous Community or City (Spanish).

cldr.ccaa.name.ca

CLDR name of the Autonomous Community or City (Catalan).

cldr.ccaa.name.ga

CLDR name of the Autonomous Community or City (Galician).

cldr.ccaa.name.eu

CLDR name of the Autonomous Community or City (Basque).

ccaa.shortname.en

Short (common) name of the subdivision (English).

ccaa.shortname.es

Short (common) name of the subdivision (Spanish).

ccaa.shortname.ca

Short (common) name of the subdivision (Catalan).

ccaa.shortname.ga

Short (common) name of the subdivision (Galician).

ccaa.shortname.eu

Short (common) name of the subdivision (Basque).

cpro

INE code of the province.

iso2.prov.code

ISO2 code of the province.

nuts.prov.code

NUTS code of the province.

ine.prov.name

INE name of the province.

iso2.prov.name.es

ISO2 name of the province (Spanish).

iso2.prov.name.ca

ISO2 name of the province (Catalan).

iso2.prov.name.ga

ISO2 name of the province (Galician).

iso2.prov.name.eu

ISO2 name of the province (Basque).

cldr.prov.name.en

CLDR name of the province (English).

cldr.prov.name.es

CLDR name of the province (Spanish).

cldr.prov.name.ca

CLDR name of the province (Catalan).

cldr.prov.name.ga

CLDR name of the province (Galician).

cldr.prov.name.eu

CLDR name of the province (Basque).

prov.shortname.en

Short (common) name of the province (English).

prov.shortname.es

Short (common) name of the province (Spanish).

prov.shortname.ca

Short (common) name of the province (Catalan).

prov.shortname.ga

Short (common) name of the province (Galician).

prov.shortname.eu

Short (common) name of the province (Basque).

nuts3.code

NUTS 3 code.

nuts3.name

NUTS 3 name.

nuts3.shortname.es

NUTS 3 short (common) name.

Note

Although NUTS 2 aligns with the first subdivision level of Spain (Autonomous Communities and Cities), NUTS 3 does not correspond to the second subdivision level of Spain (provinces). NUTS 3 provides dedicated codes for major islands, whereas provinces do not.

Ceuta and Melilla have special status as Autonomous Cities but are represented at the Autonomous Communities and Cities level with a single province, like Madrid, Asturias or Murcia, in this database.

Source

See Also

esp_dict_region_code().

Included package datasets: esp_nuts_2024, esp_tiles_providers, pobmun25

Examples


data("esp_codelist")
esp_codelist

Convert and translate Spanish subdivision names and codes

Description

Convert Spanish subdivision names or identifiers among coding schemes such as NUTS, ISO2 and province codes. The function can also return human-readable names.

Usage

esp_dict_region_code(sourcevar, origin = "text", destination = "text")

esp_dict_translate(sourcevar, lang = "en", all = FALSE)

Arguments

sourcevar

Character string. Vector that contains the codes or names to be converted.

origin, destination

Character string. Coding scheme of origin and destination. One of "text", "nuts", "iso2", "codauto" or "cpro".

lang

Character string. Target language code. Available values are "es" (Spanish), "en" (English), "ca" (Catalan), "ga" (Galician) and "eu" (Basque).

all

Logical. If TRUE the function returns all possible translations for each input as a named list. When FALSE (default), a single preferred translation per input is returned as a character vector.

Details

This function uses internal dictionaries together with countrycode to map between schemes. When ⁠origin == destination == "text"⁠ the input is returned unchanged. Mixing names from different administrative levels, for example Autonomous Community or City and province, may produce NA values for some entries.

Value

esp_dict_region_code() returns a character vector with converted subdivision identifiers or names. If a value cannot be matched, the corresponding element will be NA and a warning is emitted via cli::cli_warn().

esp_dict_translate() translates a vector of names from one language to another. If all = FALSE, it returns a character vector with the translated name for each element of sourcevar. If all = TRUE, it returns a named list where each element contains all available translations for the corresponding input value.

See Also

Examples

vals <- c("Errioxa", "Coruna", "Gerona", "Madrid")

esp_dict_region_code(vals)
esp_dict_region_code(vals, destination = "nuts")
esp_dict_region_code(vals, destination = "cpro")
esp_dict_region_code(vals, destination = "iso2")

# From ISO2 to other codes.

iso2vals <- c("ES-M", "ES-S", "ES-SG")
esp_dict_region_code(iso2vals, origin = "iso2")
esp_dict_region_code(iso2vals,
  origin = "iso2",
  destination = "nuts"
)
esp_dict_region_code(iso2vals,
  origin = "iso2",
  destination = "cpro"
)

# Mixing levels.
valsmix <- c("Centro", "Andalucia", "Seville", "Menorca")
esp_dict_region_code(valsmix, destination = "nuts")

esp_dict_region_code(valsmix, destination = "codauto")
esp_dict_region_code(valsmix, destination = "iso2")

vals <- c("La Rioja", "Sevilla", "Madrid", "Jaen", "Orense", "Baleares")

esp_dict_translate(vals)
esp_dict_translate(vals, lang = "es")
esp_dict_translate(vals, lang = "ca")
esp_dict_translate(vals, lang = "eu")
esp_dict_translate(vals, lang = "ga")

esp_dict_translate(vals, lang = "ga", all = TRUE)

Get the attribution for a tile provider

Description

esp_get_attributions() returns the attribution for a tile provider defined by the type argument.

Usage

esp_get_attributions(type, options = NULL)

Arguments

type

This argument can be one of:

options

A named list containing additional options to pass to the query.

Value

A character string with the provider attribution, or NULL if no attribution is available.

See Also

Static map tiles and imagery: addProviderEspTiles(), esp_get_tiles(), esp_make_provider()

Examples

esp_get_attributions("IGNBase.Todo")

Canary Islands inset box and outline

Description

Create an sf POLYGON or LINESTRING that can mark or frame the Canary Islands when they are displayed as an inset on maps of Spain. This object is useful together with esp_move_can() and the moveCAN arguments available in other mapSpain getters.

esp_get_can_provinces() returns a small LINESTRING used to mark the separator between the two provinces of the Canary Islands. This helper is intended for cartographic use when composing inset maps of Spain.

Usage

esp_get_can_box(
  style = c("right", "left", "box", "poly"),
  moveCAN = TRUE,
  epsg = 4258
)

esp_get_can_provinces(moveCAN = TRUE, epsg = "4258")

Arguments

style

Character string. One of "right", "left", "box" or "poly". Default is "right", see Details.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

Details

The style parameter controls the geometry returned:

Value

An sf object: a POLYGON (when style = "poly") or a LINESTRING (other styles).

Source

Coordinates of esp_get_can_provinces() derived from CartoBase ANE (se89_mult_admin_provcan_l.shp).

See Also

Helpers for Canary Islands insets and displacement: esp_move_can()

Examples


provs <- esp_get_prov()
box <- esp_get_can_box()
line <- esp_get_can_provinces()

library(ggplot2)
ggplot(provs) +
  geom_sf() +
  geom_sf(data = box, linewidth = 0.15) +
  geom_sf(data = line, linewidth = 0.15) +
  theme_linedraw()


# Displacing the Canary Islands by a custom offset.
displace <- c(15, 0)
provs_disp <- esp_get_prov(moveCAN = displace)
box_disp <- esp_get_can_box(style = "left", moveCAN = displace)
line_disp <- esp_get_can_provinces(moveCAN = displace)
ggplot(provs_disp) +
  geom_sf() +
  geom_sf(data = box_disp, linewidth = 0.15) +
  geom_sf(data = line_disp, linewidth = 0.15) +
  theme_linedraw()

# Example using the polygon style together with other layers.
library(giscoR)
res <- "20"
countries <- gisco_get_countries(
  res = res, epsg = "4326",
  country = c("France", "Portugal", "Andorra", "Morocco", "Argelia")
)
can_box <- esp_get_can_box(
  style = "poly", epsg = "4326",
  moveCAN = c(12.5, 0)
)
ccaa <- esp_get_ccaa(res = res, epsg = "4326", moveCAN = c(12.5, 0))
ggplot(countries) +
  geom_sf(fill = "#DFDFDF") +
  geom_sf(data = can_box, fill = "#C7E7FB", linewidth = 1) +
  geom_sf(data = ccaa, fill = "#FDFBEA") +
  coord_sf(xlim = c(-10, 4.3), ylim = c(34.6, 44)) +
  theme(
    panel.background = element_rect(fill = "#C7E7FB"),
    panel.grid = element_blank()
  )



Municipal seats of government from SIANE

Description

This function returns an sf POINT object that locates the seat of government for each municipality.

Note that this differs from the centroid of the boundaries of the municipality, returned by esp_get_munic_siane().

Usage

esp_get_capimun(
  year = Sys.Date(),
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  region = NULL,
  munic = NULL,
  moveCAN = TRUE,
  rawcols = FALSE
)

Arguments

year

Character string or number. Release year. It must use format YYYY (assuming end of year) or YYYY-MM-DD. Historical information starts as of 2005.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

region

Optional. A vector of region names, NUTS or ISO codes (see esp_dict_region_code()).

munic

Character string. A name or regex expression with the names of the required municipalities. Use NULL to return all municipalities.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

rawcols

Logical. If TRUE, retains the raw columns of the resulting object as provided by IGN.

Details

When using region you can use and mix names and NUTS codes (levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or "cpro" (see esp_codelist).

When calling a higher level, such as a province, Autonomous Community, Autonomous City or NUTS 1 region, all municipalities of that level are added.

Value

An sf POINT object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

CartoBase ANE boundaries and utilities: esp_get_ccaa_siane(), esp_get_countries_siane(), esp_get_munic_siane(), esp_get_prov_siane(), esp_get_spain_siane(), esp_siane_bulk_download()

Municipality-level datasets: esp_get_munic(), esp_get_munic_siane()

Examples



# Compare municipality centroids against municipal seats of government.

# Get the municipality boundary.
area <- esp_get_munic_siane(munic = "Valladolid", epsg = 3857)

# Area in km2.
print(paste0(round(as.double(sf::st_area(area)) / 1000000, 2), " km2"))

# Extract the centroid.
centroid <- sf::st_centroid(area)
centroid$type <- "Centroid"

# Compare with capimun.
capimun <- esp_get_capimun(munic = "Valladolid", epsg = 3857)
capimun$type <- "Capimun"

# Join both point geometries.
points <- dplyr::bind_rows(centroid, capimun)

# Check on a plot.
library(ggplot2)

ggplot(points) +
  geom_sf(data = area, fill = NA, color = "blue") +
  geom_sf(data = points, aes(fill = type), size = 5, shape = 21) +
  scale_fill_manual(values = c("green", "red")) +
  labs(title = "Centroid vs. capimun")



Autonomous Communities and Cities of Spain from GISCO

Description

Return Autonomous Communities and Cities of Spain at a specified scale.

Usage

esp_get_ccaa(ccaa = NULL, moveCAN = TRUE, ...)

Arguments

ccaa

Character string. A vector of names, codes or both for Autonomous Communities and Cities, or NULL to get all Autonomous Communities and Cities. See Details.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

...

Arguments passed on to esp_get_nuts

year

Year character string or number. Release year of the file. See giscoR::gisco_get_nuts() for valid values.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

spatialtype

Character string. Type of geometry to be returned. Options available are:

  • "RG": regions, returned as a MULTIPOLYGON/POLYGON object.

  • "LB": labels, returned as a POINT object.

ext

Character. Extension of the file (default "gpkg"). See giscoR::gisco_get_nuts().

verbose

A logical value indicating whether to display informational messages.

resolution

A character string or numeric value with the geospatial data resolution. One of:

  • "60": 1:60 million.

  • "20": 1:20 million.

  • "10": 1:10 million.

  • "03": 1:3 million.

  • "01": 1:1 million.

Details

When using ccaa you can use and mix names and NUTS codes (levels 1 or 2), ISO codes (corresponding to level 2) or codauto (see esp_codelist). Ceuta and Melilla are included at the Autonomous Communities and Cities level in this function.

When calling a NUTS 1 level, all Autonomous Communities and Cities of that level are added.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

GISCO NUTS distribution API: https://gisco-services.ec.europa.eu/distribution/v2/nuts/.

See Also

esp_get_ccaa_siane().

GISCO boundary data: esp_get_munic(), esp_get_nuts(), esp_get_prov(), esp_get_spain()

Examples


ccaa <- esp_get_ccaa()

library(ggplot2)

ggplot(ccaa) +
  geom_sf()

# Random Autonomous Communities and Cities.
random_ccaa <- esp_get_ccaa(ccaa = c(
  "Euskadi",
  "Catalunya",
  "ES-EX",
  "Canarias",
  "ES52",
  "01"
))

ggplot(random_ccaa) +
  geom_sf(aes(fill = codauto), show.legend = FALSE) +
  geom_sf_label(aes(label = codauto), alpha = 0.3) +
  coord_sf(crs = 3857)

# All Autonomous Communities and Cities of a NUTS 1 region plus one.

mixed <- esp_get_ccaa(ccaa = c("La Rioja", "Noroeste"))

ggplot(mixed) +
  geom_sf()

# Combine with giscoR to get countries.


library(giscoR)
library(sf)

res <- 20 # Use the same resolution.

europe <- gisco_get_countries(resolution = res)
ccaa <- esp_get_ccaa(moveCAN = FALSE, resolution = res)

ggplot(europe) +
  geom_sf(fill = "#DFDFDF", color = "#656565") +
  geom_sf(data = ccaa, fill = "#FDFBEA", color = "#656565") +
  coord_sf(
    xlim = c(23, 74) * 10e4,
    ylim = c(14, 55) * 10e4,
    crs = 3035
  ) +
  theme(panel.background = element_rect(fill = "#C7E7FB"))



Autonomous Communities and Cities of Spain from SIANE

Description

Return Autonomous Communities and Cities of Spain at a specified scale.

Usage

esp_get_ccaa_siane(
  ccaa = NULL,
  year = Sys.Date(),
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  resolution = c(3, 6.5, 10),
  moveCAN = TRUE,
  rawcols = FALSE
)

Arguments

ccaa

Character string. A vector of names, codes or both for Autonomous Communities and Cities, or NULL to get all Autonomous Communities and Cities. See Details.

year

Character string or number. Release year. It must use format YYYY (assuming end of year) or YYYY-MM-DD. Historical information starts as of 2005.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

resolution

Character string or number. Resolution of the geospatial data. One of:

  • "10": 1:10 million.

  • "6.5": 1:6.5 million.

  • "3": 1:3 million.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

rawcols

Logical. If TRUE, retains the raw columns of the resulting object as provided by IGN.

Details

When using ccaa you can use and mix names and NUTS codes (levels 1 or 2), ISO codes (corresponding to level 2) or codauto (see esp_codelist). Ceuta and Melilla are included at the Autonomous Communities and Cities level in this function.

When calling a NUTS 1 level, all Autonomous Communities and Cities of that level are added.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

esp_get_ccaa().

CartoBase ANE boundaries and utilities: esp_get_capimun(), esp_get_countries_siane(), esp_get_munic_siane(), esp_get_prov_siane(), esp_get_spain_siane(), esp_siane_bulk_download()

Examples


ccaas1 <- esp_get_ccaa_siane()
utils::head(ccaas1)

# Low resolution.
ccaas_low <- esp_get_ccaa_siane(
  rawcols = TRUE, moveCAN = FALSE,
  resolution = 10, epsg = 3035
)

library(ggplot2)

ggplot(ccaas_low) +
  geom_sf(aes(fill = nuts1.name)) +
  scale_fill_viridis_d(option = "cividis")


Comarcas of Spain

Description

Get comarcas of Spain. Comarcas are traditional informal territorial divisions comprising several municipalities that share geographical, economic or cultural traits, typically with poorly defined limits.

Usage

esp_get_comarca(
  region = NULL,
  comarca = NULL,
  moveCAN = TRUE,
  type = c("INE", "IGN", "AGR", "LIV"),
  epsg = 4258,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

region

Character string. A vector of names, codes or both for provinces, or NULL to get all the comarcas. See Details.

comarca

Character string. A name or regex expression with the names of the required comarcas. Use NULL to return all possible comarcas.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

type

Character string. One of "INE", "IGN", "AGR" or "LIV". Type of comarca to return. See Details.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

Details

When using region you can use and mix names and NUTS codes (levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or "cpro" (see esp_codelist).

When calling a higher level, such as a province, Autonomous Community, Autonomous City or NUTS 1 region, all comarcas of that level are added.

Value

A sf object.

About comarcas

Comarcas (English equivalent: district, county, area or zone) do not always have a formal legal status. They correspond mainly to natural areas (valleys, river basins and similar areas), historical regions or ancient kingdoms.

In Spain, comarcas only have an administrative character legally recognized in Catalonia, the Basque Country, Navarra (named merindades instead), the region of El Bierzo (Castilla y Leon) and Aragon. Galicia, the Principality of Asturias and Andalusia have functional comarcas.

Types

esp_get_comarca() can retrieve several types of comarcas, each provided under different classification criteria.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Note

The use of the information contained on the INE website is at the sole risk of users and re-use agents. They are liable for damages to third parties arising from such use.

Source

INE: PC_Axis files, IGN, Ministry of Agriculture, Fisheries and Food (MAPA).

See Also

Additional boundary datasets and representations: esp_get_gridmap, esp_get_simpl

Examples



comarcas <- esp_get_comarca(moveCAN = FALSE)

library(ggplot2)

ggplot(comarcas) +
  geom_sf()

# IGN provides recognized comarcas.

rec <- esp_get_comarca(type = "IGN")

ggplot(rec) +
  geom_sf(aes(fill = t_comarca))

# Legal comarcas of Catalunya.

comarcas_cat <- esp_get_comarca("Catalunya", type = "IGN")

ggplot(comarcas_cat) +
  geom_sf(aes(fill = ine.prov.name)) +
  labs(fill = "Province")



Countries of the world from SIANE

Description

This dataset contains worldwide country-level administrative boundaries.

The data included in this cartographic database do not imply any opinion of the IGN regarding its legal status.

Usage

esp_get_countries_siane(
  year = Sys.Date(),
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  country = NULL
)

Arguments

year

Character string or number. Release year. It must use format YYYY (assuming end of year) or YYYY-MM-DD. Historical information starts as of 2005.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

country

Character vector of country codes. Accepts country names, ISO3 country codes or ISO2 country codes. See also countrycode::countrycode().

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

giscoR::gisco_get_countries().

CartoBase ANE boundaries and utilities: esp_get_capimun(), esp_get_ccaa_siane(), esp_get_munic_siane(), esp_get_prov_siane(), esp_get_spain_siane(), esp_siane_bulk_download()

Examples


cntries <- esp_get_countries_siane()

library(ggplot2)
ggplot(cntries) +
  geom_sf()


National geographic grids from BDN (Nature Data Bank)

Description

This function loads an sf POLYGON object with the geographic grids of Spain provided by the Banco de Datos de la Naturaleza (Nature Data Bank), under the Ministry of Environment (MITECO).

This dataset provides two accessors. esp_get_grid_BDN() extracts country-wide regular grids with resolutions of 5 x 5 or 10 x 10 kilometers for mainland Spain or the Canary Islands. esp_get_grid_BDN_ccaa() extracts 1 x 1 kilometer resolution grids for individual Autonomous Communities and Cities.

These grids are useful for biodiversity analysis, environmental monitoring and spatial statistical applications.

esp_get_grid_BDN_ccaa() provides higher-resolution 1 x 1 kilometer grids for specific Autonomous Communities and Cities, useful for regional analysis with finer spatial detail.

Usage

esp_get_grid_BDN(
  resolution = c(10, 5),
  type = c("main", "canary"),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

esp_get_grid_BDN_ccaa(
  ccaa,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

resolution

Numeric. Resolution of the grid in kilometers. Must be one of:

  • 5: 5 x 5 kilometer cells.

  • 10: 10 x 10 kilometer cells (default).

type

Character. The geographic scope of the grid:

  • "main": Mainland Spain (default).

  • "canary": Canary Islands.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

ccaa

Character string. A vector of names, codes or both for Autonomous Communities and Cities. See Details on esp_get_ccaa() for accepted formats.

Details

The BDN provides standardized geographic grids for Spain that follow the Nature Data Bank's specifications. The data are downloaded from the sianedata/MITECO/dist data branch and are regularly updated.

Value

An sf POLYGON object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

Data sourced from the Banco de Datos de la Naturaleza (BDN). See the repository structure: https://github.com/rOpenSpain/mapSpain/tree/sianedata/MITECO/dist

For more information about BDN grids and other resources, visit: https://www.miteco.gob.es/es/biodiversidad/servicios/banco-datos-naturaleza/informacion-disponible/bdn-cart-aux-descargas-ccaa.html.

See Also

esp_get_ccaa()

Geographic grid data: esp_get_grid_ESDAC(), esp_get_grid_MTN()

Examples



# Load a 10 x 10 km grid for mainland Spain.
grid <- esp_get_grid_BDN(resolution = 10, type = "main")

# Visualize the grid.
library(ggplot2)

ggplot(grid) +
  geom_sf(fill = NA, color = "steelblue") +
  theme_light() +
  labs(title = "BDN Geographic Grid: 10x10 km Spain")



National geographic grids from EEA

Description

[Defunct]

This function is defunct because the source file is no longer available.

Usage

esp_get_grid_EEA(
  resolution = 100,
  type = "main",
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

resolution

Resolution of the grid in kilometers. Can be 1, 10 or 100.

type

Character. The geographic scope of the grid:

  • "main": Mainland Spain (default).

  • "canary": Canary Islands.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

Value

An sf POLYGON object.

Source

EEA reference grid.


National geographic grids from the European Soil Data Centre (ESDAC)

Description

This function loads an sf POLYGON with the geographic grids of Spain provided by the European Soil Data Centre (ESDAC).

Usage

esp_get_grid_ESDAC(
  resolution = c(10, 1),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

resolution

Numeric. Resolution of the grid in kilometers. Can be 1 or 10.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

Value

An sf POLYGON object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

EEA reference grid.

References

See Also

Geographic grid data: esp_get_grid_BDN(), esp_get_grid_MTN()

Examples


## Not run: 
grid <- esp_get_grid_ESDAC()
esp <- esp_get_spain(moveCAN = FALSE)

library(ggplot2)

ggplot(grid) +
  geom_sf() +
  geom_sf(data = esp, color = "grey50", fill = NA) +
  theme_light() +
  labs(title = "ESDAC Grid for Spain")

## End(Not run)


National geographic grids from IGN MTN (Mapa Topográfico Nacional)

Description

This function loads an sf POLYGON with the geographic grids of Spain.

Usage

esp_get_grid_MTN(
  grid = "MTN25_ETRS89_Peninsula_Baleares_Canarias",
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

grid

Name of the grid to be loaded. See Details.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

Details

Metadata available on https://github.com/rOpenSpain/mapSpain/tree/sianedata/MTN.

Possible values of grid are:

grid_name
MTN25_ED50_Peninsula_Baleares
MTN25_ETRS89_ceuta_melilla_alboran
MTN25_ETRS89_Peninsula_Baleares_Canarias
MTN25_RegCan95_Canarias
MTN50_ED50_Peninsula_Baleares
MTN50_ETRS89_Peninsula_Baleares_Canarias
MTN50_RegCan95_Canarias

MTN grids

A description of the available MTN (Mapa Topográfico Nacional) grids:

MTN25_ED50_Peninsula_Baleares

MTN25 grid corresponding to the Peninsula and Balearic Islands, in ED50 and geographical coordinates (longitude, latitude). This is the real MTN25 grid, that is, the one that divides the current printed series of the map, taking into account special sheets and irregularities.

MTN50_ED50_Peninsula_Baleares

MTN50 grid corresponding to the Peninsula and Balearic Islands, in ED50 and geographical coordinates (longitude, latitude). This is the real MTN50 grid, that is, the one that divides the current printed series of the map, taking into account special sheets and irregularities.

MTN25_ETRS89_ceuta_melilla_alboran

MTN25 grid corresponding to Ceuta, Melilla, Alboran and Spanish territories in North Africa, adjusted to the new official geodetic reference system ETRS89, in geographical coordinates (longitude, latitude).

MTN25_ETRS89_Peninsula_Baleares_Canarias

MTN25 real grid corresponding to the Peninsula, the Balearic Islands and the Canary Islands, adjusted to the new ETRS89 official reference geodetic system, in geographical coordinates (longitude, latitude).

MTN50_ETRS89_Peninsula_Baleares_Canarias

MTN50 real grid corresponding to the Peninsula, the Balearic Islands and the Canary Islands, adjusted to the new ETRS89 official reference geodetic system, in geographical coordinates (longitude, latitude).

MTN25_RegCan95_Canarias

MTN25 grid corresponding to the Canary Islands, in REGCAN95 (WGS84 compatible) and geographic coordinates (longitude, latitude). It is the real MTN25 grid, that is, the one that divides the current printed series of the map, taking into account the special distribution of the Canary Islands sheets.

MTN50_RegCan95_Canarias

MTN50 grid corresponding to the Canary Islands, in REGCAN95 (WGS84 compatible) and geographic coordinates (longitude, latitude). This is the real grid of the MTN50, that is, the one that divides the current printed series of the map, taking into account the special distribution of the Canary Islands sheets.

Value

An sf POLYGON object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

IGN data distributed through the sianedata/MTN data branch (see https://github.com/rOpenSpain/mapSpain/tree/sianedata/MTN).

See Also

Geographic grid data: esp_get_grid_BDN(), esp_get_grid_ESDAC()

Examples



grid <- esp_get_grid_MTN(grid = "MTN50_ETRS89_Peninsula_Baleares_Canarias")

library(ggplot2)

ggplot(grid) +
  geom_sf() +
  theme_light() +
  labs(title = "MTN50 Grid for Spain")



Hexbin or square grid maps of Spain

Description

This function loads a hexbin map (sf object) or a map of squares with boundaries of the provinces or Autonomous Communities and Cities of Spain.

Usage

esp_get_hex_prov(prov = NULL)

esp_get_hex_ccaa(ccaa = NULL)

esp_get_grid_prov(prov = NULL)

esp_get_grid_ccaa(ccaa = NULL)

Arguments

prov, ccaa

Character. A vector of names, codes or both for provinces and Autonomous Communities and Cities, or NULL to get all the data. See Details.

Details

Hexbin (or grid) maps have an advantage over traditional choropleth maps. In choropleths, regions with larger polygons tend to appear more prominent simply because of their size, which introduces visual bias. With hexbin maps, each region is represented equally, reducing this bias.

You can use and mix names, ISO codes, "codauto" or "cpro" codes (see esp_codelist) and NUTS codes of different levels.

When using a code corresponding to a higher level (for example, esp_get_prov("Andalucia")), all the corresponding units of that level are provided (in this case, all the provinces of Andalusia).

Results are provided in EPSG:4258. Use sf::st_transform() to change the projection.

Value

A sf object.

See Also

Additional boundary datasets and representations: esp_get_comarca(), esp_get_simpl

Examples



esp <- esp_get_spain()
hexccaa <- esp_get_hex_ccaa()

library(ggplot2)

ggplot(hexccaa) +
  geom_sf(data = esp) +
  geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
  geom_sf_text(aes(label = label), check_overlap = TRUE) +
  theme_void() +
  labs(title = "Hexbin: Autonomous Communities and Cities")

hexprov <- esp_get_hex_prov()

ggplot(hexprov) +
  geom_sf(data = esp) +
  geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
  geom_sf_text(aes(label = label), check_overlap = TRUE) +
  theme_void() +
  labs(title = "Hexbin: Provinces")

gridccaa <- esp_get_grid_ccaa()

ggplot(gridccaa) +
  geom_sf(data = esp) +
  geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
  geom_sf_text(aes(label = label), check_overlap = TRUE) +
  theme_void() +
  labs(title = "Grid: Autonomous Communities and Cities")

gridprov <- esp_get_grid_prov()

ggplot(gridprov) +
  geom_sf(data = esp) +
  geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
  geom_sf_text(aes(label = label), check_overlap = TRUE) +
  theme_void() +
  labs(title = "Grid: Provinces")



River basin districts of Spain from SIANE

Description

River basin districts are the areas of land and sea, made up of one or more neighbouring river basins together with their associated groundwaters and coastal waters.

Usage

esp_get_hydrobasin(
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  resolution = c(3, 6.5, 10),
  domain = c("land", "landsea")
)

Arguments

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

resolution

Character string or number. Resolution of the geospatial data. One of:

  • "10": 1:10 million.

  • "6.5": 1:6.5 million.

  • "3": 1:3 million.

domain

Character string. Type of river basin district:

  • "land" includes only groundwater areas.

  • "landsea" includes groundwater areas and coastal waters.

Details

Metadata available on https://github.com/rOpenSpain/mapSpain/tree/sianedata/.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Natural feature datasets: esp_get_hypsobath(), esp_get_landwater

Examples



hydroland <- esp_get_hydrobasin(domain = "land")
hydrolandsea <- esp_get_hydrobasin(domain = "landsea")

library(ggplot2)

ggplot(hydroland) +
  geom_sf(data = hydrolandsea, fill = "skyblue4", alpha = 0.4) +
  geom_sf(fill = "skyblue", alpha = 0.5) +
  geom_sf_text(aes(label = rotulo),
    size = 2, check_overlap = TRUE,
    fontface = "bold",
    family = "serif"
  ) +
  coord_sf(
    crs = 3857,
    xlim = c(-9.5, 4.5),
    ylim = c(35, 44)
  ) +
  theme_void()



Hypsometry and bathymetry of Spain from SIANE

Description

This dataset represents the hypsometry and bathymetry of Spain.

Usage

esp_get_hypsobath(
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  resolution = c(3, 6.5),
  spatialtype = c("area", "line")
)

Arguments

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

resolution

Character string or number. Resolution of the geospatial data. One of:

  • "6.5": 1:6.5 million.

  • "3": 1:3 million.

spatialtype

Character string. Spatial type of the output. Use "area" for POLYGON or "line" for LINESTRING.

Details

Metadata available on https://github.com/rOpenSpain/mapSpain/tree/sianedata/.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Natural feature datasets: esp_get_hydrobasin(), esp_get_landwater

Examples



# This code produces a plot and takes a few seconds to run.
library(ggplot2)

hypsobath <- esp_get_hypsobath()

# Tints from Wikipedia.
# https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Maps/Conventions/
# Topographic_maps

levels <- sort(unique(hypsobath$val_inf))

# Create the manual palette.
br_bath <- length(levels[levels < 0])
br_terrain <- length(levels) - br_bath
pal <- c(
  tidyterra::hypso.colors(br_bath, "wiki-2.0_bathy"),
  tidyterra::hypso.colors(br_terrain, "wiki-2.0_hypso")
)

# Plot the Canary Islands.
ggplot(hypsobath) +
  geom_sf(aes(fill = as.factor(val_inf)),
    color = NA
  ) +
  coord_sf(
    xlim = c(-18.6, -13),
    ylim = c(27, 29.5)
  ) +
  scale_fill_manual(values = pal) +
  guides(fill = guide_legend(
    title = "Elevation",
    direction = "horizontal",
    label.position = "bottom",
    title.position = "top",
    nrow = 1
  )) +
  theme(legend.position = "bottom")

# Plot mainland Spain.
ggplot(hypsobath) +
  geom_sf(aes(fill = as.factor(val_inf)),
    color = NA
  ) +
  coord_sf(
    xlim = c(-9.5, 4.4),
    ylim = c(35.8, 44)
  ) +
  scale_fill_manual(values = pal) +
  guides(fill = guide_legend(
    title = "Elevation",
    reverse = TRUE,
    keyheight = 0.8
  ))



Rivers and wetlands of Spain from SIANE

Description

This dataset represents rivers, lagoons, reservoirs and wetlands in Spain.

Usage

esp_get_rivers(
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  resolution = deprecated(),
  spatialtype = c("line", "area"),
  moveCAN = TRUE,
  name = NULL
)

esp_get_wetlands(
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  moveCAN = TRUE,
  name = NULL
)

Arguments

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

resolution

[Deprecated] character string. Ignored. Resolution 3 (the most detailed) will always be provided.

spatialtype

[Deprecated] character string. Use esp_get_wetlands() instead of "spatialtype" for wetlands.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

name

Character string or regex expression. Name of the elements to extract.

Details

Metadata available on https://github.com/rOpenSpain/mapSpain/tree/sianedata/.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Natural feature datasets: esp_get_hydrobasin(), esp_get_hypsobath()

Examples



# Use of regex.

regex1 <- esp_get_rivers(name = "Tajo|Segura")
unique(regex1$rotulo)

regex2 <- esp_get_rivers(name = "Tajo$| Segura")
unique(regex2$rotulo)

# See the difference.

# Rivers in Spain.
iberian <- giscoR::gisco_get_countries(
  country = c("ES", "PT", "FR"), resolution = 3
)

main_rivers <- esp_get_rivers() |>
  dplyr::filter(t_rio == 1)

library(ggplot2)

ggplot(iberian) +
  geom_sf() +
  geom_sf(data = main_rivers, color = "skyblue", linewidth = 2) +
  coord_sf(
    xlim = c(-10, 5),
    ylim = c(35, 44)
  )

# Wetlands in South-West Andalucia.
and <- esp_get_prov(c("Huelva", "Sevilla", "Cadiz"))
wetlands <- esp_get_wetlands()
wetlands_south <- sf::st_filter(wetlands, and)

ggplot(and) +
  geom_sf() +
  geom_sf(
    data = wetlands_south, fill = "skyblue",
    color = "skyblue", alpha = 0.5
  )



Municipalities of Spain from GISCO

Description

Get boundaries of municipalities in Spain.

Usage

esp_get_munic(
  year = 2024,
  epsg = 4258,
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  region = NULL,
  munic = NULL,
  moveCAN = TRUE,
  ext = "gpkg"
)

Arguments

year

Year character string or number. Release year of the file. See giscoR::gisco_get_lau() and giscoR::gisco_get_communes() for valid values.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

[Deprecated]. This argument is deprecated. The dataset will always be downloaded to the cache_dir.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

region

Optional. A vector of region names, NUTS or ISO codes (see esp_dict_region_code()).

munic

Character string. A name or regex expression with the names of the required municipalities. Use NULL to return all municipalities.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

ext

Character. Extension of the file (default "gpkg"). See giscoR::gisco_get_nuts().

Details

When using region you can use and mix names and NUTS codes (levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or "cpro" (see esp_codelist).

When calling a higher level, such as a province, Autonomous Community, Autonomous City or NUTS 1 region, all municipalities of that level are added.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Note

Please check the download and usage provisions on giscoR::gisco_attributions().

Source

GISCO Local Administrative Units distribution API: https://gisco-services.ec.europa.eu/distribution/v2/lau/.

See Also

Municipality-level datasets: esp_get_capimun(), esp_get_munic_siane()

GISCO boundary data: esp_get_ccaa(), esp_get_nuts(), esp_get_prov(), esp_get_spain()

Examples



# The Spanish Lapland:
# https://en.wikipedia.org/wiki/Celtiberian_Range

# Get municipalities.
spanish_laplad <- esp_get_munic(
  year = 2023,
  region = c(
    "Cuenca", "Teruel",
    "Zaragoza", "Guadalajara",
    "Soria", "Burgos",
    "La Rioja"
  )
)

breaks <- sort(c(0, 5, 10, 50, 100, 200, 500, 1000, Inf))
spanish_laplad$dens_breaks <- cut(spanish_laplad$POP_DENS_2023, breaks,
  dig.lab = 20
)

cut_labs <- prettyNum(breaks, big.mark = " ")[-1]
cut_labs[length(breaks)] <- "> 1000"

library(ggplot2)
ggplot(spanish_laplad) +
  geom_sf(aes(fill = dens_breaks), color = "grey30", linewidth = 0.1) +
  scale_fill_manual(
    values = hcl.colors(length(breaks) - 1, "Spectral"), na.value = "black",
    name = "people per sq. kilometer",
    labels = cut_labs,
    guide = guide_legend(
      direction = "horizontal",
      nrow = 1
    )
  ) +
  theme_void() +
  labs(
    title = "The Spanish Lapland",
    caption = giscoR::gisco_attributions()
  ) +
  theme(
    text = element_text(colour = "white"),
    plot.background = element_rect(fill = "grey2"),
    plot.title = element_text(hjust = 0.5),
    plot.subtitle = element_text(hjust = 0.5, face = "bold"),
    plot.caption = element_text(
      color = "grey60", hjust = 0.5, vjust = 0,
      margin = margin(t = 5, b = 10)
    ),
    legend.position = "bottom",
    legend.title.position = "top",
    legend.text.position = "bottom",
    legend.key.height = unit(0.5, "lines"),
    legend.key.width = unit(1, "lines")
  )



Municipalities of Spain from SIANE

Description

Get boundaries of municipalities in Spain.

Usage

esp_get_munic_siane(
  year = Sys.Date(),
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  resolution = c(3, 6.5, 10),
  region = NULL,
  munic = NULL,
  moveCAN = TRUE,
  rawcols = FALSE
)

Arguments

year

Character string or number. Release year. It must use format YYYY (assuming end of year) or YYYY-MM-DD. Historical information starts as of 2005.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

resolution

Character string or number. Resolution of the geospatial data. One of:

  • "10": 1:10 million.

  • "6.5": 1:6.5 million.

  • "3": 1:3 million.

region

Optional. A vector of region names, NUTS or ISO codes (see esp_dict_region_code()).

munic

Character string. A name or regex expression with the names of the required municipalities. Use NULL to return all municipalities.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

rawcols

Logical. If TRUE, retains the raw columns of the resulting object as provided by IGN.

Details

When using region you can use and mix names and NUTS codes (levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or "cpro" (see esp_codelist).

When calling a higher level, such as a province, Autonomous Community, Autonomous City or NUTS 1 region, all municipalities of that level are added.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Note

Although mapSpain supplies cartographically suitable datasets, a historical database of Spanish municipal boundaries is also available, offering higher-resolution geometries that may be more appropriate for GIS-oriented workflows:

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

esp_get_munic().

CartoBase ANE boundaries and utilities: esp_get_capimun(), esp_get_ccaa_siane(), esp_get_countries_siane(), esp_get_prov_siane(), esp_get_spain_siane(), esp_siane_bulk_download()

Municipality-level datasets: esp_get_capimun(), esp_get_munic()

Examples



# Municipalities that have changed in the past: three snapshots.
munis2005 <- esp_get_munic_siane(year = 2005, rawcols = TRUE)
munis2015 <- esp_get_munic_siane(year = 2015, rawcols = TRUE)
munis2024 <- esp_get_munic_siane(year = 2024, rawcols = TRUE)

# Manipulate data.
library(dplyr)
allmunis_unique <- bind_rows(munis2005, munis2015, munis2024) |>
  distinct()

id_all <- allmunis_unique |>
  sf::st_drop_geometry() |>
  group_by(id_ine, name) |>
  count() |>
  ungroup() |>
  arrange(desc(n)) |>
  slice_head(n = 1) |>
  glimpse()

library(ggplot2)
allmunis_unique |>
  filter(id_ine == id_all$id_ine) |>
  ggplot() +
  geom_sf(aes(fill = as.factor(fecha_alta)),
    alpha = 0.7,
    show.legend = FALSE
  ) +
  scale_fill_viridis_d() +
  facet_wrap(~fecha_alta) +
  labs(
    title = id_all$name,
    subtitle = "Boundary changes over time",
    fill = ""
  )



Territorial Spanish units for statistics (NUTS) dataset

Description

The GISCO statistical unit dataset represents NUTS (Nomenclature of Territorial Units for Statistics) and statistical regions using multipart polygon, polyline and point topology. The NUTS geographical information is completed by attribute tables and a set of cartographic help lines to better visualize multipart polygonal regions.

NUTS is a hierarchical system divided into three levels:

There is also a NUTS 0 level, which usually corresponds to the national boundaries.

Usage

esp_get_nuts(
  year = 2024,
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  resolution = 1,
  spatialtype = c("RG", "LB"),
  region = NULL,
  nuts_level = c("all", "0", "1", "2", "3"),
  moveCAN = TRUE,
  ext = "gpkg"
)

Arguments

year

Year character string or number. Release year of the file. See giscoR::gisco_get_nuts() for valid values.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

resolution

A character string or numeric value with the geospatial data resolution. One of:

  • "60": 1:60 million.

  • "20": 1:20 million.

  • "10": 1:10 million.

  • "03": 1:3 million.

  • "01": 1:1 million.

spatialtype

Character string. Type of geometry to be returned. Options available are:

  • "RG": regions, returned as a MULTIPOLYGON/POLYGON object.

  • "LB": labels, returned as a POINT object.

region

Optional. A vector of region names, NUTS or ISO codes (see esp_dict_region_code()).

nuts_level

A character string with the NUTS level. One of 0, 1, 2, 3 or all for all levels.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

ext

Character. Extension of the file (default "gpkg"). See giscoR::gisco_get_nuts().

Details

The NUTS nomenclature is a hierarchical classification of statistical regions and subdivides the EU economic territory into regions of three different levels (NUTS 1, 2 and 3, moving respectively from larger to smaller territorial units). NUTS 1 is the most aggregated level. An additional country level (NUTS 0) is also available for countries where the nation at statistical level does not coincide with the administrative boundaries.

The NUTS classification has been officially established through Commission Delegated Regulation 2019/1755. An unofficial NUTS-like classification has been defined for the EFTA countries, candidate countries and potential candidates based on a bilateral agreement between Eurostat and the respective statistical agencies.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Note

Please check the download and usage provisions on giscoR::gisco_attributions().

Source

GISCO NUTS distribution API: https://gisco-services.ec.europa.eu/distribution/v2/nuts/.

See Also

NUTS boundary datasets: esp_get_spain()

GISCO boundary data: esp_get_ccaa(), esp_get_munic(), esp_get_prov(), esp_get_spain()

Examples


nuts1 <- esp_get_nuts(nuts_level = 1, moveCAN = TRUE)

library(ggplot2)

ggplot(nuts1) +
  geom_sf() +
  labs(
    title = "NUTS 1: Displacing Canary Islands",
    caption = giscoR::gisco_attributions()
  )

nuts1_alt <- esp_get_nuts(nuts_level = 1, moveCAN = c(15, 0))

ggplot(nuts1_alt) +
  geom_sf() +
  labs(
    title = "NUTS 1: Displacing Canary Islands",
    subtitle = "to the right",
    caption = giscoR::gisco_attributions()
  )

nuts1_orig <- esp_get_nuts(nuts_level = 1, moveCAN = FALSE)

ggplot(nuts1_orig) +
  geom_sf() +
  labs(
    title = "NUTS 1",
    subtitle = "Canary Islands in their true location",
    caption = giscoR::gisco_attributions()
  )

and_orient <- esp_get_nuts(region = c(
  "Almeria", "Granada",
  "Jaen", "Malaga"
))

ggplot(and_orient) +
  geom_sf()

random_regions <- esp_get_nuts(region = c("ES1", "ES300", "ES51"))

ggplot(random_regions) +
  geom_sf() +
  labs(title = "Random Regions")

mixing_codes <- esp_get_nuts(region = c("ES4", "ES-PV", "Valencia"))

ggplot(mixing_codes) +
  geom_sf() +
  labs(title = "Mixing Codes")


Provinces of Spain from GISCO

Description

Return provinces of Spain at a specified scale.

Usage

esp_get_prov(prov = NULL, moveCAN = TRUE, ...)

Arguments

prov

A vector of names, codes or both for provinces, or NULL to get all the provinces. See Details.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

...

Arguments passed on to esp_get_nuts

year

Year character string or number. Release year of the file. See giscoR::gisco_get_nuts() for valid values.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

spatialtype

Character string. Type of geometry to be returned. Options available are:

  • "RG": regions, returned as a MULTIPOLYGON/POLYGON object.

  • "LB": labels, returned as a POINT object.

ext

Character. Extension of the file (default "gpkg"). See giscoR::gisco_get_nuts().

verbose

A logical value indicating whether to display informational messages.

resolution

A character string or numeric value with the geospatial data resolution. One of:

  • "60": 1:60 million.

  • "20": 1:20 million.

  • "10": 1:10 million.

  • "03": 1:3 million.

  • "01": 1:1 million.

Details

When using prov you can use and mix names and NUTS codes (levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or "cpro" (see esp_codelist).

Ceuta and Melilla are considered provinces in this dataset.

When calling a higher level, such as an Autonomous Community, Autonomous City or NUTS 1 region, all provinces of that level are added.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

GISCO NUTS distribution API: https://gisco-services.ec.europa.eu/distribution/v2/nuts/.

See Also

esp_get_prov_siane().

GISCO boundary data: esp_get_ccaa(), esp_get_munic(), esp_get_nuts(), esp_get_spain()

Examples


prov <- esp_get_prov()

library(ggplot2)

ggplot(prov) +
  geom_sf() +
  theme_minimal()


# Random provinces.
random <- esp_get_prov(prov = c(
  "Zamora", "Palencia", "ES-GR",
  "ES521", "01"
))

ggplot(random) +
  geom_sf(aes(fill = codauto), show.legend = FALSE, alpha = 0.5) +
  scale_fill_manual(values = hcl.colors(nrow(random), "Spectral")) +
  theme_minimal()

# All provinces of a zone plus one addition.
mix <- esp_get_prov(prov = c(
  "Noroeste",
  "Castilla y Leon", "La Rioja"
))

mix$ccaa <- esp_dict_region_code(
  mix$codauto,
  origin = "codauto"
)

ggplot(mix) +
  geom_sf(aes(fill = ccaa), alpha = 0.5) +
  scale_fill_discrete(type = hcl.colors(5, "Temps")) +
  theme_classic()

# Available ISO codes.

allprovs <- esp_get_prov()

ggplot(allprovs) +
  geom_sf(fill = NA) +
  geom_sf_text(aes(label = iso2.prov.code),
    check_overlap = TRUE,
    fontface = "bold"
  ) +
  coord_sf(crs = 3857) +
  theme_void()



Provinces of Spain from SIANE

Description

Return provinces of Spain at a specified scale.

Usage

esp_get_prov_siane(
  prov = NULL,
  year = Sys.Date(),
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  resolution = c(3, 6.5, 10),
  moveCAN = TRUE,
  rawcols = FALSE
)

Arguments

prov

A vector of names, codes or both for provinces, or NULL to get all the provinces. See Details.

year

Character string or number. Release year. It must use format YYYY (assuming end of year) or YYYY-MM-DD. Historical information starts as of 2005.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

resolution

Character string or number. Resolution of the geospatial data. One of:

  • "10": 1:10 million.

  • "6.5": 1:6.5 million.

  • "3": 1:3 million.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

rawcols

Logical. If TRUE, retains the raw columns of the resulting object as provided by IGN.

Details

When using prov you can use and mix names and NUTS codes (levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or "cpro" (see esp_codelist).

Ceuta and Melilla are considered provinces in this dataset.

When calling a higher level, such as an Autonomous Community, Autonomous City or NUTS 1 region, all provinces of that level are added.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

esp_get_prov().

CartoBase ANE boundaries and utilities: esp_get_capimun(), esp_get_ccaa_siane(), esp_get_countries_siane(), esp_get_munic_siane(), esp_get_spain_siane(), esp_siane_bulk_download()

Examples


library(ggplot2)

esp_get_ccaa_siane() |>
  ggplot() +
  geom_sf()


Railways of Spain from SIANE

Description

This function loads an sf LINESTRING or POINT object representing the nodes and railway lines of Spain.

Usage

esp_get_railway(
  year = Sys.Date(),
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  spatialtype = c("line", "point")
)

esp_get_stations(
  year = Sys.Date(),
  epsg = 4258,
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

year

Ignored.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

spatialtype

[Deprecated] character string. Use esp_get_stations() instead of "point" for stations.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Transport infrastructure datasets: esp_get_roads()

Examples



provs <- esp_get_prov()
ccaa <- esp_get_ccaa()

# Railways.
rails <- esp_get_railway()

# Stations.
stations <- esp_get_stations()

# Map.

library(ggplot2)

ggplot(provs) +
  geom_sf(fill = "grey99", color = "grey50") +
  geom_sf(data = ccaa, fill = NA) +
  geom_sf(
    data = rails, aes(color = t_ffcc_desc),
    show.legend = FALSE,
    linewidth = 1.5
  ) +
  geom_sf(
    data = stations,
    color = "red", alpha = 0.5
  ) +
  scale_colour_viridis_d() +
  facet_wrap(~t_ffcc_desc) +
  theme_minimal()



Roads of Spain from SIANE

Description

This dataset represents the main roads of Spain.

Usage

esp_get_roads(
  year = Sys.Date(),
  epsg = "4258",
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  moveCAN = TRUE
)

Arguments

year

Ignored.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Transport infrastructure datasets: esp_get_railway()

Examples




country <- esp_get_spain()
roads <- esp_get_roads()

library(ggplot2)

ggplot(country) +
  geom_sf(fill = "grey90") +
  geom_sf(data = roads, aes(color = t_ctra_desc), show.legend = "line") +
  scale_color_manual(
    values = c("#003399", "#003399", "#ff0000", "#ffff00")
  ) +
  guides(color = guide_legend(direction = "vertical")) +
  theme_minimal() +
  labs(color = "Road type") +
  theme(legend.position = "bottom")



Simplified map of provinces and Autonomous Communities and Cities of Spain

Description

Simplified map with the boundaries of the provinces or Autonomous Communities of Spain, as provided by the INE (Instituto Nacional de Estadística).

Usage

esp_get_simpl_prov(
  prov = NULL,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

esp_get_simpl_ccaa(
  ccaa = NULL,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

prov, ccaa

Character. A vector of names, codes or both for provinces and Autonomous Communities and Cities, or NULL to get all the data. See Details.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

Details

Results are provided without CRS, as provided by the source.

You can use and mix names, ISO codes, "codauto" or "cpro" codes (see esp_codelist) and NUTS codes of different levels.

When using a code corresponding to a higher level (for example, esp_get_prov("Andalucia")), all the corresponding units of that level are provided (in this case, all the provinces of Andalusia).

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

INE: PC-Axis files.

See Also

Additional boundary datasets and representations: esp_get_comarca(), esp_get_gridmap

Examples



prov_simp <- esp_get_simpl_prov()

library(ggplot2)

ggplot(prov_simp) +
  geom_sf(aes(fill = ine.ccaa.name)) +
  labs(fill = "Autonomous Communities and Cities")

# Provinces of a single Autonomous Community or City.

and_simple <- esp_get_simpl_prov("Andalucia")

ggplot(and_simple) +
  geom_sf()

# Autonomous Communities and Cities.

ccaa_simp <- esp_get_simpl_ccaa()

ggplot(ccaa_simp) +
  geom_sf() +
  geom_sf_text(aes(label = ine.ccaa.name), check_overlap = TRUE)



Boundaries of Spain from GISCO

Description

Returns the boundaries of Spain as a single sf POLYGON at a specified scale.

Usage

esp_get_spain(moveCAN = TRUE, ...)

Arguments

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

...

Arguments passed on to esp_get_nuts

year

Year character string or number. Release year of the file. See giscoR::gisco_get_nuts() for valid values.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

ext

Character. Extension of the file (default "gpkg"). See giscoR::gisco_get_nuts().

verbose

A logical value indicating whether to display informational messages.

resolution

A character string or numeric value with the geospatial data resolution. One of:

  • "60": 1:60 million.

  • "20": 1:20 million.

  • "10": 1:10 million.

  • "03": 1:3 million.

  • "01": 1:1 million.

Details

Dataset derived from NUTS data provided by GISCO. Check esp_get_nuts() for details.

Value

A sf POLYGON object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

GISCO NUTS distribution API: https://gisco-services.ec.europa.eu/distribution/v2/nuts/.

See Also

esp_get_spain_siane().

NUTS boundary datasets: esp_get_nuts()

GISCO boundary data: esp_get_ccaa(), esp_get_munic(), esp_get_nuts(), esp_get_prov()

Examples



original_can <- esp_get_spain(moveCAN = FALSE)

# One row only.
original_can

library(ggplot2)

ggplot(original_can) +
  geom_sf(fill = "grey70")

# Less resolution.
moved_can <- esp_get_spain(moveCAN = TRUE, resolution = 20)

ggplot(moved_can) +
  geom_sf(fill = "grey70")



Boundaries of Spain from SIANE

Description

Returns the boundaries of Spain as a single sf POLYGON.

Usage

esp_get_spain_siane(moveCAN = TRUE, ...)

Arguments

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

...

Arguments passed on to esp_get_ccaa_siane

year

Character string or number. Release year. It must use format YYYY (assuming end of year) or YYYY-MM-DD. Historical information starts as of 2005.

resolution

Character string or number. Resolution of the geospatial data. One of:

  • "10": 1:10 million.

  • "6.5": 1:6.5 million.

  • "3": 1:3 million.

epsg

Character string or number. Projection of the map: 4-digit EPSG code. One of:

cache

Logical. Whether to cache downloaded files. Defaults to TRUE. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

Value

A sf object.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

esp_get_spain().

CartoBase ANE boundaries and utilities: esp_get_capimun(), esp_get_ccaa_siane(), esp_get_countries_siane(), esp_get_munic_siane(), esp_get_prov_siane(), esp_siane_bulk_download()

Examples



original_can <- esp_get_spain_siane(moveCAN = FALSE)

# One row only.
original_can

library(ggplot2)

ggplot(original_can) +
  geom_sf(fill = "grey70")

# Less resolution.
moved_can <- esp_get_spain_siane(moveCAN = TRUE, resolution = 10)

ggplot(moved_can) +
  geom_sf(fill = "grey70")



Get static map tiles from public administrations of Spain

Description

Get static map tiles based on a spatial object. Maps can be fetched from WMS and WMTS providers.

This function is an implementation of the JavaScript plugin leaflet-providersESP v1.3.3.

Usage

esp_get_tiles(
  x,
  type = "IDErioja",
  zoom = NULL,
  zoommin = 0,
  crop = TRUE,
  res = 512,
  bbox_expand = 0.05,
  transparent = TRUE,
  mask = FALSE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  options = NULL
)

Arguments

x

An sf or sfc object.

type

This argument can be one of:

zoom

Character string or number. Only valid for WMTS providers, zoom level to be downloaded. If NULL, it is determined automatically. If set, it overrides zoommin. If a single sf POINT and zoom = NULL, the function sets a zoom level of 18. See Details.

zoommin

Character string or number. Delta on default zoom. The default value is designed to download fewer tiles than you probably want. Use 1 or 2 to increase the resolution.

crop

Logical. If TRUE, crop results to the specified x extent. If x is an sf object with one POINT, crop is set to FALSE. See terra::crop().

res

Character string or number. Only valid for WMS providers. Resolution (in pixels) of the final tile.

bbox_expand

Number. Expansion percentage of the bounding box of x.

transparent

Logical. Whether to use a transparent background, if supported.

mask

Logical. TRUE to mask the result to x. See terra::mask().

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

cache_dir

Character string. A path to a cache directory. See Caching.

verbose

A logical value indicating whether to display informational messages.

options

A named list containing additional options to pass to the query.

Details

Zoom levels are described on the OpenStreetMap wiki:

zoom area to represent
0 whole world
3 large country
5 state
8 county
10 metropolitan area
11 city
13 village or suburb
16 streets
18 some buildings, trees

For a complete list of providers, see esp_tiles_providers.

Most WMS/WMTS providers provide tiles on "EPSG:3857". If the tile looks deformed, try projecting x first:

x <- sf::st_transform(x, 3857)

Value

A SpatRaster with 3 (RGB) or 4 (RGBA) layers, depending on the provider. See terra::rast().

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

https://dieghernan.github.io/leaflet-providersESP/, a plugin for leaflet, v1.3.3.

See Also

Static map tiles and imagery: addProviderEspTiles(), esp_get_attributions(), esp_make_provider()

Examples


## Not run: 

# This example downloads data to your local computer.

segovia <- esp_get_prov_siane("segovia", epsg = 3857)
tile <- esp_get_tiles(segovia, "IGNBase.Todo")

library(ggplot2)
library(tidyterra)

ggplot(segovia) +
  geom_spatraster_rgb(data = tile, maxcell = Inf) +
  geom_sf(fill = NA, linewidth = 1)

# Another provider.

tile2 <- esp_get_tiles(segovia, type = "MDT")

ggplot(segovia) +
  geom_spatraster_rgb(data = tile2, maxcell = Inf) +
  geom_sf(fill = NA, linewidth = 1, color = "red")

# A custom WMTS provider.

custom_wmts <- esp_make_provider(
  id = "cyl_wmts",
  q = "https://www.ign.es/wmts/pnoa-ma?",
  service = "WMTS",
  layer = "OI.OrthoimageCoverage"
)

custom_wmts_tile <- esp_get_tiles(segovia, custom_wmts)

autoplot(custom_wmts_tile, maxcell = Inf) +
  geom_sf(data = segovia, fill = NA, color = "white", linewidth = 1)

# Example from https://leaflet-extras.github.io/leaflet-providers/preview/.
cartodb_dark <- list(
  id = "CartoDB_DarkMatter",
  q = "https://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png"
)
cartodb_dark_tile <- esp_get_tiles(segovia, cartodb_dark,
  zoommin = 1,
  update_cache = TRUE
)

autoplot(cartodb_dark_tile, maxcell = Inf) +
  geom_sf(data = segovia, fill = NA, color = "white", linewidth = 1)

## End(Not run)


Create a custom tile provider

Description

Helper function for esp_get_tiles() that helps to create a custom provider.

Usage

esp_make_provider(id, q, service, layers, ...)

Arguments

id

An identifier for the user. Used for identifying cached tiles.

q

The base URL of the service.

service

The type of tile service, either "WMS" or "WMTS".

layers

The name of the layer to retrieve.

...

Additional arguments to the query, such as version, format, crs/srs and style, depending on the capabilities of the service.

Details

This function is meant to work with services provided under the OGC Standard.

Note that:

Value

A named list with two elements id and q.

For a list of potential providers from Spain, check the IDEE Directory.

See Also

Static map tiles and imagery: addProviderEspTiles(), esp_get_attributions(), esp_get_tiles()

Examples


## Not run: 
custom_wmts <- esp_make_provider(
  id = "example",
  q = "https://www.ign.es/wmts/ign-base?",
  service = "WMTS",
  layer = "IGNBaseTodo"
)

x <- esp_get_ccaa("Castilla y León", epsg = 3857)

mytile <- esp_get_tiles(x, type = custom_wmts)

tidyterra::autoplot(mytile) +
  ggplot2::geom_sf(data = x, fill = NA)

## End(Not run)


Displace an sf or sfc object located in the Canary Islands

Description

Helper function to displace an external sf or sfc object, potentially representing a location in the Canary Islands, to align it with mapSpain objects generated with moveCAN = TRUE.

Usage

esp_move_can(x, moveCAN = TRUE)

Arguments

x

An sf or sfc object.

moveCAN

A logical TRUE/FALSE or a vector of coordinates c(lat, lon). It places the Canary Islands close to Spain's mainland. Initial position can be adjusted using the vector of coordinates. See Displacing the Canary Islands in esp_move_can().

Details

This helper function makes it easier to represent objects located in the Canary Islands that have been obtained from sources other than mapSpain.

Value

An object of the same class and with the same CRS as x, displaced accordingly.

Displacing the Canary Islands

While moveCAN is useful for visualization, it will alter the actual geographic position of the Canary Islands. When using the output for spatial analysis or tiles (for example, with esp_get_tiles() or addProviderEspTiles()), set this option to FALSE to get the actual coordinates instead of the modified ones.

See Also

Helpers for Canary Islands insets and displacement: esp_get_can_box()

Examples


library(sf)
teide <- data.frame(
  name = "Teide Peak",
  lon = -16.6437593,
  lat = 28.2722883
)

teide_sf <- st_as_sf(teide, coords = c("lon", "lat"), crs = 4326)

# A mapSpain object with moveCAN = TRUE is displaced.

esp <- esp_get_spain(moveCAN = c(13, 0))

library(ggplot2)

ggplot(esp) +
  geom_sf() +
  geom_sf(data = teide_sf, color = "red") +
  labs(
    title = "Canary Islands displaced",
    subtitle = "But not the external Teide object"
  )

# Displace the external object too.

teide_sf_disp <- esp_move_can(teide_sf, moveCAN = c(13, 0))

ggplot(esp) +
  geom_sf() +
  geom_sf(data = teide_sf_disp, color = "red") +
  labs(
    title = "Canary Islands displaced",
    subtitle = "And also the external Teide object"
  )


NUTS 2024 boundaries for Spain

Description

This dataset represents Spanish subdivisions at NUTS levels 0, 1, 2 and 3 according to the Nomenclature of Territorial Units for Statistics (NUTS) classification for 2024.

Format

An sf object with MULTIPOLYGON geometries at 1:1 million resolution in EPSG:4258 projection, containing 86 rows and 10 variables:

NUTS_ID

NUTS identifier.

LEVL_CODE

NUTS level code (0, 1, 2 or 3).

CNTR_CODE

Eurostat country code.

NAME_LATN

NUTS name in Latin characters.

NUTS_NAME

NUTS name in the local alphabet.

MOUNT_TYPE

Mountain type, see Details.

URBN_TYPE

Urban type, see Details.

COAST_TYPE

Coastal type, see Details.

geo

Same as NUTS_ID, provided for compatibility with eurostat.

geometry

Geometry field.

Details

MOUNT_TYPE: Mountain typology:

URBN_TYPE: Urban-rural typology:

COAST_TYPE: Coastal typology:

Source

NUTS_RG_01M_2024_4326.gpkg file.

See Also

esp_get_nuts().

Included package datasets: esp_codelist, esp_tiles_providers, pobmun25

Examples

data("esp_nuts_2024")
head(esp_nuts_2024)


Set your mapSpain cache directory

Description

This function stores your cache_dir path on your local machine and loads it for future sessions. Use Sys.getenv("MAPSPAIN_CACHE_DIR") or esp_detect_cache_dir() to find the cached path.

Usage

esp_set_cache_dir(
  cache_dir = NULL,
  overwrite = FALSE,
  install = FALSE,
  verbose = TRUE
)

esp_detect_cache_dir()

Arguments

cache_dir

A path to a cache directory. When NULL, the function stores cached files in a temporary directory (see base::tempdir()).

overwrite

Logical. If TRUE, overwrites an existing MAPSPAIN_CACHE_DIR on your local machine.

install

Logical. If TRUE, installs the path on your local machine for use in future sessions. Defaults to FALSE. If cache_dir is FALSE, this argument is automatically set to FALSE.

verbose

A logical value indicating whether to display informational messages.

Details

By default, when no cache_dir is set, the package uses a folder inside base::tempdir() (files are temporary and removed when the R session ends). To persist a cache across R sessions, use esp_set_cache_dir(cache_dir, install = TRUE), which writes the chosen path to a configuration file under tools::R_user_dir("mapSpain", "config").

Value

esp_set_cache_dir() returns an invisible character string with the path to your cache_dir. It is primarily called for its side effect.

esp_detect_cache_dir() returns the path to the cache_dir used in the current session.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Caching strategies

Some files can be read from their online source without caching using the option cache = FALSE. Otherwise the source files are downloaded to your computer. mapSpain implements the following caching options:

Sometimes cached files may be corrupted. In that case, try re-downloading the data by setting update_cache = TRUE in the corresponding function.

If you experience download problems, try downloading the file by another method and save it to your cache_dir. Use verbose = TRUE to debug the API query and esp_detect_cache_dir() to identify your cache path.

Note

In mapSpain >= 1.0.0, the configuration file location has moved from rappdirs::user_config_dir("mapSpain", "R") to tools::R_user_dir("mapSpain", "config"). A migration function automatically transfers previous configuration files from the old to the new location. A message appears once during this migration.

See Also

tools::R_user_dir().

Cache management utilities: esp_clear_cache()

Examples


# Do not run this. It would modify your current state.
## Not run: 
my_cache <- esp_detect_cache_dir()

# Set an example cache.
ex <- file.path(tempdir(), "example", "cachenew")
esp_set_cache_dir(ex)

esp_detect_cache_dir()

# Restore the initial cache.
esp_set_cache_dir(my_cache)
identical(my_cache, esp_detect_cache_dir())

## End(Not run)


esp_detect_cache_dir()


SIANE bulk download

Description

This function downloads zipped data from SIANE to cache_dir and extracts the relevant files.

Usage

esp_siane_bulk_download(
  cache_dir = NULL,
  update_cache = FALSE,
  verbose = FALSE
)

Arguments

cache_dir

Character string. A path to a cache directory. See Caching.

update_cache

Logical. If TRUE, refreshes the cached file and forces a new download. Defaults to FALSE.

verbose

A logical value indicating whether to display informational messages.

Value

An invisible character vector with the full paths of the extracted files. See Examples.

Caching

Functions that download data store files in cache_dir. When cache_dir is NULL, they use the active package cache, which defaults to a temporary directory. Set update_cache = TRUE to replace an existing cached file. See Caching strategies in esp_set_cache_dir() to configure a persistent cache.

Source

CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), https://www.ign.es/web/ign/portal. Data are available from 2005 to the present.

Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane

Always acknowledge authorship using the following statements:

  1. When the original digital product is not modified or altered, use one of the following statements:

    • CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

    • CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.

  2. When a new product is generated:

    • Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.

Data distributed through the sianedata data branch, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

CartoBase ANE boundaries and utilities: esp_get_capimun(), esp_get_ccaa_siane(), esp_get_countries_siane(), esp_get_munic_siane(), esp_get_prov_siane(), esp_get_spain_siane()

Examples


tmp <- file.path(tempdir(), "testexample")
dest_files <- esp_siane_bulk_download(cache_dir = tmp)

# Read one file.
library(sf)
read_sf(dest_files[1]) |> head()

# Connect the function with the downloaded data.

invisible(esp_get_munic_siane(cache_dir = tmp, verbose = TRUE))

# The message shows that the file is already cached.

# Clean up.
unlink(tmp, force = TRUE, recursive = TRUE)


Public WMS and WMTS providers for Spain

Description

A named list of length 102, containing URL information from different public WMS and WMTS tile providers in Spain.

This dataset is an implementation of the JavaScript plugin leaflet-providersESP v1.3.3.

Format

A named list of available providers with the following structure:

Each list item is named with the provider alias. Each element contains two nested named lists. static contains the parameters required to obtain static map tiles and an additional item named attribution. leaflet contains additional parameters to pass to addProviderEspTiles().

Details

Providers available to be passed to type in esp_get_tiles() are:

Source

https://dieghernan.github.io/leaflet-providersESP/, a plugin for leaflet, v1.3.3.

See Also

Included package datasets: esp_codelist, esp_nuts_2024, pobmun25

Examples

data("esp_tiles_providers")
# Get a single provider.

single <- esp_tiles_providers[["IGNBase.Todo"]]
single$static

single$leaflet


Population of Spain by municipality (2025)

Description

Population of Spain by municipality (2025)

Format

A tibble object with 8,132 rows containing population data by municipality in Spain for 2025.

cpro

INE code of the province.

provincia

Name of the province.

cmun

INE code of the municipality.

name

Name of the municipality.

pob25

Total population (2025).

men

Male population (2025).

women

Female population (2025).

Source

INE: Instituto Nacional de Estadística. https://www.ine.es/dyngs/INEbase/categoria.htm?c=Estadistica_P&cid=1254734710990.

See Also

Included package datasets: esp_codelist, esp_nuts_2024, esp_tiles_providers

Examples

data("pobmun25")