Type: Package
Title: Administrative Boundaries of Spain
Version: 1.0.0
Description: Administrative Boundaries of Spain at several levels (Autonomous Communities, Provinces, Municipalities) based on the 'GISCO' 'Eurostat' database https://ec.europa.eu/eurostat/web/gisco and 'CartoBase SIANE' from 'Instituto Geografico Nacional' https://www.ign.es/. It also provides a 'leaflet' plugin and the ability of downloading and processing static tiles.
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, jsonlite, lifecycle, rappdirs (≥ 0.3.0), sf (≥ 1.0.0), tibble, utils
Suggests: dplyr, ggplot2 (≥ 3.5.0), knitr, leaflet (≥ 2.0.0), rmarkdown, terra (≥ 1.1-4), testthat (≥ 3.0.0), tidyterra
VignetteBuilder: knitr
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, dieghernan/geobounds
Config/testthat/edition: 3
Config/testthat/parallel: true
Copyright: © EuroGeographics for the administrative boundaries. Atlas Nacional de España (ANE) CC BY 4.0 <http://www.ign.es>. INE <https://www.ine.es/en/index.htm>
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.3
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, administrative-boundaries, ccaa, static-tiles, cran, ggplot2, gis
NeedsCompilation: no
Packaged: 2026-01-17 01:35:54 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-01-17 06:10:21 UTC

mapSpain: Administrative Boundaries of Spain

Description

logo

Administrative Boundaries of Spain at several levels (Autonomous Communities, Provinces, Municipalities) based on the 'GISCO' 'Eurostat' database https://ec.europa.eu/eurostat/web/gisco and 'CartoBase SIANE' from 'Instituto Geografico Nacional' https://www.ign.es/. It also provides a 'leaflet' plugin and the ability of downloading and processing static tiles.

Author(s)

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

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/ leaflet plugin, v1.3.3.

See Also

leaflet::leaflet(), leaflet::addTiles(), leaflet::addWMSTiles(), esp_tiles_providers.

Other functions for creating maps with images: 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

Description

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

Usage

esp_check_access()

Value

A logical.

See Also

giscoR::gisco_check_access().

Examples


esp_check_access()

Clear your mapSpain cache dir

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

logical. If TRUE displays 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()

Other cache utilities: esp_set_cache_dir()

Examples


# Don't 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 initial cache
esp_clear_cache(verbose = TRUE)

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

## End(Not run)

Database with codes and names of Spanish regions

Description

A tibble object used internally for translating codes and names of the different subdivisions of Spain. This tibble provides a hierarchical representation of Spain's subdivisions, including NUTS1 level, autonomous communities (equivalent to NUTS2), provinces, and NUTS3 level. See Note.

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

iso2.ccaa.code

ISO2 code of the autonomous community

nuts2.code

NUTS 2 Code

ine.ccaa.name

INE name of the autonomous community

iso2.ccaa.name.es

ISO2 name of the autonomous community (Spanish)

iso2.ccaa.name.ca

ISO2 name of the autonomous community (Catalan)

iso2.ccaa.name.gl

ISO2 name of the autonomous community (Galician)

iso2.ccaa.name.eu

ISO2 name of the autonomous community (Basque)

nuts2.name

NUTS 2 name

cldr.ccaa.name.en

CLDR name of the autonomous community (English)

cldr.ccaa.name.es

CLDR name of the autonomous community (Spanish)

cldr.ccaa.name.ca

CLDR name of the autonomous community (Catalan)

cldr.ccaa.name.ga

CLDR name of the autonomous community (Galician)

cldr.ccaa.name.eu

CLDR name of the autonomous community (Basque)

ccaa.shortname.en

Short (common) name of the autonomous community (English)

ccaa.shortname.es

Short (common) name of the autonomous community (Spanish)

ccaa.shortname.ca

Short (common) name of the autonomous community (Catalan)

ccaa.shortname.ga

Short (common) name of the autonomous community (Galician)

ccaa.shortname.eu

Short (common) name of the autonomous community (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 NUTS2 aligns with the first subdivision level of Spain (CCAA - Autonomous Communities), it is important to note that NUTS3 does not correspond to the second subdivision level of Spain (Provinces). NUTS3 provides dedicated codes for major islands, whereas provinces do not.

Ceuta and Melilla have a special status as Autonomous Cities but are treated as autonomous communities with a single province (like Madrid, Asturias, or Murcia) in this database.

Source

See Also

Other 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 between different coding schemes (NUTS, ISO2, province codes, etc.) or obtain 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 which 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:

  • "es": Spanish.

  • "en": English.

  • "ca": Catalan.

  • "ga": Galician.

  • "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

The 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 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_alert_warning().

esp_dict_translate() translates a vector of names from one language to another :

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 another 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)

Canary Islands inset box and outline

Description

Create an sf POLYGON or LINESTRING that can be used to 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

Other helpers for the Canary Islands: 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()
  )


City where the municipal public authorities are based - SIANE

Description

Get a sf POINT with the location of the political powers 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 be in formats 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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. NULL will 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. Setting this to TRUE will add 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 (province, CCAA or NUTS1), all the municipalities of that level will be added.

Value

A sf object.

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 provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other datasets representing political borders: esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

Political borders from CartoBase ANE: esp_get_ccaa_siane(), esp_get_countries_siane(), esp_get_munic_siane(), esp_get_prov_siane(), esp_get_spain_siane(), esp_siane_bulk_download()

Datasets representing municipalities: esp_get_munic(), esp_get_munic_siane()

Examples



# This code compares centroids of municipalities against esp_get_capimun

# Get shape
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 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 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 of Spain - GISCO

Description

Returns Autonomous Communities of Spain at a specified scale.

Usage

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

Arguments

ccaa

character string. A vector of names and/or codes for Autonomous Communities or NULL to get all the autonomous communities. 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

spatialtype

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

  • "RG": Regions - MULTIPOLYGON/POLYGON object.

  • "LB": Labels - POINT object.

ext

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

verbose

logical. If TRUE displays informational messages.

resolution

character string or number. Resolution of the geospatial data. 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 considered as Autonomous Communities in this function.

When calling a NUTS1 level, all the Autonomous Communities of that level will be added.

Value

A sf object.

Note

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

Source

https://gisco-services.ec.europa.eu/distribution/v2/.

Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.

See Also

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

Datasets provided by GISCO: esp_get_munic(), esp_get_nuts(), esp_get_prov(), esp_get_spain()

Examples

ccaa <- esp_get_ccaa()

library(ggplot2)

ggplot(ccaa) +
  geom_sf()

# Random CCAA
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 CCAA of a Zone plus an addition

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 # Set same resoluion

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 of Spain - SIANE

Description

Returns Autonomous Communities 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 and/or codes for Autonomous Communities or NULL to get all the autonomous communities. See Details.

year

character string or number. Release year, it must be in formats 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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. Setting this to TRUE will add 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 considered as Autonomous Communities in this function.

When calling a NUTS1 level, all the Autonomous Communities of that level will be added.

Value

A sf object.

Source

CartoBase ANE provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

Political borders from CartoBase ANE: 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()
dplyr::glimpse(ccaas1)

# Low res
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

Returns Comarcas of Spain. Comarcas are traditional informal territorial division, comprising several municipalities sharing geographical, economic or cultural traits, typically with not well 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 and/or codes 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. NULL will return all the 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", "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. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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 (Province, Autonomous Community or NUTS1), all the comarcas of that level will be added.

Value

A sf object.

About comarcas

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

In the case of Spain, comarcas only have an administrative character legally recognized in Catalonia, the Basque Country, Navarra (named merindades instead), in 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 one provided under different classification criteria.

Note

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

Note

The use of the information contained on the INE website may be carried out by users or re-use agents, at their own risk, and they will be the sole liable parties in the case of having to answer to third parties due to damages arising from such use.

Source

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

See Also

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

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 - SIANE

Description

This dataset contains the administrative boundaries at country level of the world.

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 be in formats 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays informational messages.

country

character vector of country codes. It can be either a vector of country names, a vector of ISO3 country codes or a vector of ISO2 country codes. See also countrycode::countrycode().

Value

A sf object.

Source

CartoBase ANE provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

giscoR::gisco_get_countries().

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

Political borders from CartoBase ANE: 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

Loads a sf POLYGON object with the geographic grids of Spain as provided by the Banco de Datos de la Naturaleza (Nature Data Bank), under the Ministry of Environment (MITECO).

This dataset provides:

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

esp_get_grid_BDN_ccaa() provides higher-resolution 1x1 kilometer grids for specific Autonomous Communities, 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 kms. Must be one of:

  • 5: 5x5 kilometer cells

  • 10: 10x10 kilometer cells (default)

type

character. The geographic scope of the grid:

  • "main": Mainland Spain (default)

  • "canary": Canary Islands

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays informational messages.

ccaa

character string. A vector of names and/or codes for Autonomous Communities. 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 is maintained via a custom CDN and is regularly updated.

Value

A sf object.

Source

Data sourced from the Banco de Datos de la Naturaleza (BDN) via a custom CDN. See the repository structure: https://github.com/rOpenSpain/mapSpain/tree/sianedata/MTN

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()

Other geographical grids: esp_get_grid_ESDAC(), esp_get_grid_MTN()

Examples



# Load a 10x10 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")



Get sf POLYGON of the national geographic grids from EEA

Description

[Defunct]

This function is defunct as the source file is not available any more.

Usage

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

Arguments

resolution

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

type

character. The geographic scope of the grid:

  • "main": Mainland Spain (default)

  • "canary": Canary Islands

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays informational messages.

Value

A sf POLYGON.

Source

EEA reference grid.


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

Description

Loads a sf POLYGON with the geographic grids of Spain as 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 kms Can be 1 or 10.

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays informational messages.

Value

A sf POLYGON.

Source

EEA reference grid.

References

See Also

Other geographical grids: 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 Topografico Nacional)

Description

Loads a 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. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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 MTN (Mapa Topografico Nacional) grids available:

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

A sf POLYGON.

Source

IGN data via a custom CDN (see https://github.com/rOpenSpain/mapSpain/tree/sianedata/MTN).

See Also

Other geographical grids: 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")



Get a sf hexbin or squared POLYGON of Spain

Description

Loads a hexbin map (sf object) or a map of squares with the boundaries of the provinces or autonomous communities 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 and/or codes for provinces and autonomous communities 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"/ "cpro" codes (see esp_codelist) and NUTS codes of different levels.

When using a code corresponding to a higher level (e.g. 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

esp_get_simpl.

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

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: CCAA")


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: CCAA")


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 - 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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. Possible values are "land", including only the groundwaters area or "landsea", groundwaters and coastal waters.

Details

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

Value

A sf object.

Source

CartoBase ANE provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other natural features: 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 = .4) +
  geom_sf(fill = "skyblue", alpha = .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 - SIANE

Description

Dataset representing 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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.

Source

CartoBase ANE provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other natural features: esp_get_hydrobasin(), esp_get_landwater

Examples



# This code will produce a nice plot - It will take 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 Manual pal
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 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
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 = .8
  ))



Rivers and wetlands of Spain - SIANE

Description

Object representing rivers, lagoons, reservoirs and wetlands of 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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 element(s) to be extracted.

Details

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

Value

A sf object.

Source

CartoBase ANE provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other natural features: 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 - GISCO

Description

This dataset shows 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. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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. NULL will 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 (province, CCAA or NUTS1), all the municipalities of that level will be added.

Value

A sf object.

Note

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

Source

https://gisco-services.ec.europa.eu/distribution/v2/.

Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units.

See Also

giscoR::gisco_get_lau(), giscoR::gisco_get_communes().

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

Datasets representing municipalities: esp_get_capimun(), esp_get_munic_siane()

Datasets provided by GISCO: esp_get_ccaa(), esp_get_nuts(), esp_get_prov(), esp_get_spain()

Examples



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

# Get munics
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 - SIANE

Description

This dataset shows 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 be in formats 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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. NULL will 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. Setting this to TRUE will add 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 (province, CCAA or NUTS1), all the municipalities of that level will be added.

Value

A sf object.

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 provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

Political borders from CartoBase ANE: esp_get_capimun(), esp_get_ccaa_siane(), esp_get_countries_siane(), esp_get_prov_siane(), esp_get_spain_siane(), esp_siane_bulk_download()

Datasets representing municipalities: esp_get_capimun(), esp_get_munic()

Examples



# Municipalities that have changed in the past: three cuts
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
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 = "Changes on boundaries over time",
    fill = ""
  )



Territorial Spanish units for statistics (NUTS) dataset

Description

The GISCO statistical unit dataset represents the 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 visualise multipart polygonal regions.

The NUTS are a hierarchical system divided into 3 levels:

Also, there is 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays informational messages.

resolution

character string or number. Resolution of the geospatial data. 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 - MULTIPOLYGON/POLYGON object.

  • "LB": Labels - POINT object.

region

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

nuts_level

character string. 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. A non-official 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.

An introduction to the NUTS classification is available here: https://ec.europa.eu/eurostat/web/nuts/overview.

Value

A sf object.

Note

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

Source

https://gisco-services.ec.europa.eu/distribution/v2/.

Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.

See Also

giscoR::gisco_get_nuts(), esp_dict_region_code().

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

Other nuts: esp_get_spain()

Datasets provided by GISCO: 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 = "NUTS1: 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 = "NUTS1: 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 = "NUTS1",
    subtitle = "Canary Islands on the 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 - GISCO

Description

Returns provinces of Spain at a specified scale.

Usage

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

Arguments

prov

A vector of names and/or codes 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, 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

spatialtype

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

  • "RG": Regions - MULTIPOLYGON/POLYGON object.

  • "LB": Labels - POINT object.

ext

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

verbose

logical. If TRUE displays informational messages.

resolution

character string or number. Resolution of the geospatial data. 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 as provinces in this dataset.

When calling a higher level (Autonomous Community or NUTS1), all the provinces of that level will be added.

Value

A sf object.

Note

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

Source

https://gisco-services.ec.europa.eu/distribution/v2/.

Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.

See Also

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

Datasets provided by GISCO: 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 an 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()

# ISO codes available

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 - SIANE

Description

Returns 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 and/or codes for provinces or NULL to get all the provinces. See Details.

year

character string or number. Release year, it must be in formats 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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. Setting this to TRUE will add 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 as provinces in this dataset.

When calling a higher level (Autonomous Community or NUTS1), all the provinces of that level will be added.

Value

A sf object.

Source

CartoBase ANE provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

Political borders from CartoBase ANE: 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() |>
  dplyr::glimpse() |>
  ggplot() +
  geom_sf()


Railways of Spain - SIANE

Description

Loads a 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays informational messages.

spatialtype

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

Value

A sf object.

Source

CartoBase ANE provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other man-made infrastructures: 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 - SIANE

Description

Object representing 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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.

Source

CartoBase ANE provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other man-made infrastructures: 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 of Spain

Description

Simplified map with the boundaries of the provinces or autonomous communities of Spain, as provided by the INE (Instituto Nacional de Estadistica).

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 and/or codes for provinces and autonomous communities or NULL to get all the data. See Details.

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays informational messages.

Details

Results are provided without CRS, as provided by source.

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

When using a code corresponding to a higher level (e.g. 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.

Source

INE: PC_Axis files

See Also

esp_get_gridmap.

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_spain(), esp_get_spain_siane(), esp_siane_bulk_download()

Examples



prov_simp <- esp_get_simpl_prov()

library(ggplot2)

ggplot(prov_simp) +
  geom_sf(aes(fill = ine.ccaa.name)) +
  labs(fill = "CCAA")

# Provs of Single CCAA

and_simple <- esp_get_simpl_prov("Andalucia")

ggplot(and_simple) +
  geom_sf()

# CCAAs

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 - 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

ext

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

verbose

logical. If TRUE displays informational messages.

resolution

character string or number. Resolution of the geospatial data. 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.

Note

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

Source

https://gisco-services.ec.europa.eu/distribution/v2/.

Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.

See Also

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain_siane(), esp_siane_bulk_download()

Other nuts: esp_get_nuts()

Datasets provided by GISCO: 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 - 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 be in formats 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 do caching. Default is TRUE. See Caching strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays informational messages.

Value

A sf object.

Source

CartoBase ANE provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_siane_bulk_download()

Political borders from CartoBase ANE: 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 tiles from public administrations of Spain

Description

Get static map tiles based on a spatial object. Maps can be fetched from various open map servers.

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

esp_get_attributions gets the attribution of a tile provider defined as the type argument.

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
)

esp_get_attributions(type, options = NULL)

Arguments

x

An sf or sfc object.

type

This argument can be either:

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, the results will be cropped 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. Provides transparent background, if supported.

mask

logical. TRUE if the result should be masked to x. See terra::mask().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

cache_dir

character string. A path to a cache directory. See Caching strategies section in esp_set_cache_dir().

verbose

logical. If TRUE displays 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". In case that the tile looks deformed, try projecting first x:

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

Value

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

Source

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

See Also

terra::rast(), esp_tiles_providers, maptiles::get_tiles()

giscoR::gisco_attributions()

Other functions for creating maps with images: addProviderEspTiles(), 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 WMS provided

custom_wms <- esp_make_provider(
  id = "an_id_for_caching",
  q = "https://idecyl.jcyl.es/geoserver/ge/wms?",
  service = "WMS",
  version = "1.3.0",
  format = "image/png",
  layers = "geolog_cyl_litologia"
)

custom_wms_tile <- esp_get_tiles(segovia, custom_wms)

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

# 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. It will be 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, like version, format, crs/srs, style, etc. depending on the capabilities of the service.

Details

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

Note that:

Value

A named list with two elements id and q.

See Also

esp_get_tiles().

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

Other functions for creating maps with images: addProviderEspTiles(), esp_get_tiles()

Examples


## Not run: 
custom_wms <- esp_make_provider(
  id = "an_id_for_caching",
  q = "https://idecyl.jcyl.es/geoserver/ge/wms?",
  service = "WMS",
  version = "1.3.0",
  layers = "geolog_cyl_litologia"
)

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

mytile <- esp_get_tiles(x, type = custom_wms)

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

## End(Not run)


Displace a sf object located in the Canary Islands

Description

Helper function to displace an external sf object (potentially representing a location in the Canary Islands) to align it with the objects provided by sf with the option moveCAN = TRUE.

Usage

esp_move_can(x, moveCAN = TRUE)

Arguments

x

An sf object. It can be 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.

Details

This is a helper function that intends to ease the representation of objects located in the Canary Islands that have been obtained from other sources rather than the package mapSpain.

Value

A sf object of the same class and same CRS as x but 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 using tiles (e.g. with esp_get_tiles() or addProviderEspTiles()) this option should be set to FALSE in order to get the actual coordinates, instead of the modified ones.

See Also

Other helpers for the Canary Islands: 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)

# If we use any mapSpain produced object with moveCAN = TRUE...

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"
  )


# But we can

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 for Spain sf object

Description

This dataset represents Spanish regions 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,3)⁠.

CNTR_CODE

Eurostat Country code.

NAME_LATN

NUTS name on Latin characters.

NUTS_NAME

NUTS name on local alphabet.

MOUNT_TYPE

Mount Type, see Details.

URBN_TYPE

Urban Type, see Details.

COAST_TYPE

Coast 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()

Other datasets: esp_codelist, esp_tiles_providers, pobmun25

Examples

data("esp_nuts_2024")
head(esp_nuts_2024)


Set your mapSpain cache dir

Description

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

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 key 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

logical. If TRUE displays 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 strategies

Some files can be read from its online source without caching using the option cache = FALSE. Otherwise the source file will be 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()

Other cache utilities: esp_clear_cache()

Examples


# Don't 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 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

Download zipped data from SIANE to the cache_dir and extract the relevant ones.

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 strategies section in esp_set_cache_dir().

update_cache

logical. Should the cached file be refreshed? Default is FALSE. When set to TRUE, it will force a new download.

verbose

logical. If TRUE displays informational messages.

Value

A (invisible) character vector with the full path of the files extracted. See Examples.

Source

CartoBase ANE provided by Instituto Geografico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.

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

It's necessary to always acknowledge authorship using the following formulas:

  1. When the original digital product is not modified or altered, it can be expressed in one of the following ways:

    • 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:

Data distributed via a custom CDN, see https://github.com/rOpenSpain/mapSpain/tree/sianedata.

See Also

Other datasets representing political borders: esp_get_capimun(), esp_get_ccaa(), esp_get_ccaa_siane(), esp_get_comarca(), esp_get_countries_siane(), esp_get_gridmap, esp_get_munic(), esp_get_munic_siane(), esp_get_nuts(), esp_get_prov(), esp_get_prov_siane(), esp_get_simpl, esp_get_spain(), esp_get_spain_siane()

Political borders from CartoBase ANE: 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
library(sf)
read_sf(dest_files[1]) |> head()

# Now we can connect the function with the downloaded data like:

connect <- esp_get_munic_siane(cache_dir = tmp, verbose = TRUE)

# Message shows that file is already cached ;)

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


Public WMS and WMTS providers for Spain

Description

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

Implementation of the JavaScript plugin leaflet-providersESP v1.3.3.

Format

A named list of available providers with the following structure:

Details

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

Source

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

See Also

Other 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 Estadistica https://www.ine.es/dyngs/INEbase/categoria.htm?c=Estadistica_P&cid=1254734710990.

See Also

Other datasets: esp_codelist, esp_nuts_2024, esp_tiles_providers

Examples

data("pobmun25")