| Type: | Package |
| Title: | Administrative Boundaries and Static Map Tiles for Spain |
| Version: | 1.2.0 |
| Description: | Administrative boundaries of Spain at several levels (Autonomous Communities and Cities, provinces, municipalities and 'NUTS'), based on 'GISCO' from 'Eurostat' https://ec.europa.eu/eurostat/web/gisco and 'CartoBase ANE' from 'Instituto Geográfico Nacional' https://www.ign.es/. Includes tools to download and process static map tiles and a 'leaflet' plugin for Spanish public administration tile providers. |
| License: | GPL-3 |
| URL: | https://ropenspain.github.io/mapSpain/, https://github.com/rOpenSpain/mapSpain |
| BugReports: | https://github.com/rOpenSpain/mapSpain/issues |
| Depends: | R (≥ 4.1.0) |
| Imports: | cli (≥ 3.6.0), countrycode (≥ 1.2.0), giscoR (≥ 1.0.0), httr2 (≥ 1.2.0), jsonlite, leaflet (≥ 2.0.0), lifecycle, rappdirs (≥ 0.3.0), sf (≥ 1.0.0), terra (≥ 1.1-4), tibble, tools, utils |
| Suggests: | dplyr, ggplot2 (≥ 3.5.0), knitr, quarto, testthat (≥ 3.0.0), tidyterra, withr |
| VignetteBuilder: | quarto |
| Config/Needs/check: | curl |
| Config/Needs/coverage: | covr |
| Config/Needs/website: | ragg, reactable, rnaturalearth, tidyverse, devtools, remotes, ropenspain/rostemplate, ropensci/rnaturalearthhires, geodata, sessioninfo, sfheaders, rapidjsonr, jsonify, geometries, geobounds |
| Config/roxygen2/markdown: | TRUE |
| Config/roxygen2/version: | 8.0.0 |
| Config/testthat/edition: | 3 |
| Config/testthat/parallel: | true |
| Copyright: | © EuroGeographics for the administrative boundaries. Atlas Nacional de España (ANE) CC-BY 4.0 <http://www.ign.es>. INE <https://www.ine.es/en/index.htm> |
| Encoding: | UTF-8 |
| LazyData: | true |
| X-schema.org-applicationCategory: | cartography |
| X-schema.org-isPartOf: | https://ropenspain.es/ |
| X-schema.org-keywords: | ropenspain, tiles, r, maps, spatial, rstats, r-package, municipalities, spain, gisco, provinces, ign, autonomous-communities, administrative-boundaries, static-tiles, cran, ggplot2, gis, nuts, ccaa |
| NeedsCompilation: | no |
| Packaged: | 2026-06-17 12:41:37 UTC; diego |
| Author: | Diego Hernangómez |
| Maintainer: | Diego Hernangómez <diego.hernangomezherrero@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-06-17 14:50:02 UTC |
mapSpain: Administrative Boundaries and Static Map Tiles for Spain
Description
Administrative boundaries of Spain at several levels (Autonomous Communities and Cities, provinces, municipalities and 'NUTS'), based on 'GISCO' from 'Eurostat' https://ec.europa.eu/eurostat/web/gisco and 'CartoBase ANE' from 'Instituto Geográfico Nacional' https://www.ign.es/. Includes tools to download and process static map tiles and a 'leaflet' plugin for Spanish public administration tile providers.
Author(s)
Maintainer: Diego Hernangómez diego.hernangomezherrero@gmail.com (ORCID) [copyright holder]
Authors:
Diego Hernangómez diego.hernangomezherrero@gmail.com (ORCID) [copyright holder]
Other contributors:
Eurostat (ROR) [copyright holder]
Instituto Geográfico Nacional (ROR) [copyright holder]
Francisco J. Goerlich (ORCID) [contributor]
See Also
Useful links:
Report bugs at https://github.com/rOpenSpain/mapSpain/issues
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 |
options |
tile options |
Value
modified map object
Source
https://dieghernan.github.io/leaflet-providersESP/, a plugin for leaflet, v1.3.3.
See Also
Static map tiles and imagery:
esp_get_tiles(),
esp_make_provider()
Examples
library(leaflet)
leafmap <- leaflet(width = "100%", height = "60vh") |>
setView(lat = 40.4166, lng = -3.7038400, zoom = 10) |>
addTiles(group = "Default (OSM)") |>
addProviderEspTiles(
provider = "IDErioja.Claro",
group = "IDErioja Claro"
) |>
addProviderEspTiles(
provider = "RedTransporte.Carreteras",
group = "Carreteras"
) |>
addLayersControl(
baseGroups = c("IDErioja Claro", "Default (OSM)"),
overlayGroups = "Carreteras",
options = layersControlOptions(collapsed = FALSE)
)
leafmap
Check access to SIANE data resources
Description
Check whether R has access to resources at https://github.com/rOpenSpain/mapSpain/tree/sianedata.
Usage
esp_check_access()
Value
Logical scalar, TRUE if accessible and FALSE otherwise.
See Also
Examples
esp_check_access()
Clear your mapSpain cache directory
Description
Use this function with caution. It clears your cached data and configuration, specifically:
Deletes the mapSpain configuration directory (
tools::R_user_dir("mapSpain", "config")).Deletes the
cache_dirdirectory and its contents.Clears the value stored in
Sys.getenv("MAPSPAIN_CACHE_DIR").
Usage
esp_clear_cache(config = FALSE, cached_data = TRUE, verbose = FALSE)
Arguments
config |
Logical. If |
cached_data |
Logical. If |
verbose |
A logical value. If |
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
Cache management utilities:
esp_set_cache_dir()
Examples
# Do not run this. It would modify your current state.
## Not run:
my_cache <- esp_detect_cache_dir()
# Set an example cache.
ex <- file.path(tempdir(), "example", "cache")
esp_set_cache_dir(ex, verbose = FALSE)
# Restore the initial cache.
esp_clear_cache(verbose = TRUE)
esp_set_cache_dir(my_cache)
identical(my_cache, esp_detect_cache_dir())
## End(Not run)
Spanish subdivision codes and names
Description
A tibble object used internally to translate codes and names for different Spanish subdivisions. This tibble provides a hierarchical representation of Spain's subdivisions, including NUTS 1, Autonomous Communities and Cities (equivalent to NUTS 2), provinces and province-level NUTS 3 units. See the note below for coverage details.
Format
A tibble with 59 rows and columns:
- nuts1.code
NUTS 1 code.
- nuts1.name
NUTS 1 name.
- nuts1.name.alt
NUTS 1 alternative name.
- nuts1.shortname.es
NUTS 1 short (common) name (Spanish).
- codauto
INE code of the Autonomous Community or City.
- iso2.ccaa.code
ISO2 code of the Autonomous Community or City.
- nuts2.code
NUTS 2 code.
- ine.ccaa.name
INE name of the Autonomous Community or City.
- iso2.ccaa.name.es
ISO2 name of the Autonomous Community or City (Spanish).
- iso2.ccaa.name.ca
ISO2 name of the Autonomous Community or City (Catalan).
- iso2.ccaa.name.gl
ISO2 name of the Autonomous Community or City (Galician).
- iso2.ccaa.name.eu
ISO2 name of the Autonomous Community or City (Basque).
- nuts2.name
NUTS 2 name.
- cldr.ccaa.name.en
CLDR name of the Autonomous Community or City (English).
- cldr.ccaa.name.es
CLDR name of the Autonomous Community or City (Spanish).
- cldr.ccaa.name.ca
CLDR name of the Autonomous Community or City (Catalan).
- cldr.ccaa.name.ga
CLDR name of the Autonomous Community or City (Galician).
- cldr.ccaa.name.eu
CLDR name of the Autonomous Community or City (Basque).
- ccaa.shortname.en
Short (common) name of the subdivision (English).
- ccaa.shortname.es
Short (common) name of the subdivision (Spanish).
- ccaa.shortname.ca
Short (common) name of the subdivision (Catalan).
- ccaa.shortname.ga
Short (common) name of the subdivision (Galician).
- ccaa.shortname.eu
Short (common) name of the subdivision (Basque).
- cpro
INE code of the province.
- iso2.prov.code
ISO2 code of the province.
- nuts.prov.code
NUTS code of the province.
- ine.prov.name
INE name of the province.
- iso2.prov.name.es
ISO2 name of the province (Spanish).
- iso2.prov.name.ca
ISO2 name of the province (Catalan).
- iso2.prov.name.ga
ISO2 name of the province (Galician).
- iso2.prov.name.eu
ISO2 name of the province (Basque).
- cldr.prov.name.en
CLDR name of the province (English).
- cldr.prov.name.es
CLDR name of the province (Spanish).
- cldr.prov.name.ca
CLDR name of the province (Catalan).
- cldr.prov.name.ga
CLDR name of the province (Galician).
- cldr.prov.name.eu
CLDR name of the province (Basque).
- prov.shortname.en
Short (common) name of the province (English).
- prov.shortname.es
Short (common) name of the province (Spanish).
- prov.shortname.ca
Short (common) name of the province (Catalan).
- prov.shortname.ga
Short (common) name of the province (Galician).
- prov.shortname.eu
Short (common) name of the province (Basque).
- nuts3.code
NUTS 3 code.
- nuts3.name
NUTS 3 name.
- nuts3.shortname.es
NUTS 3 short (common) name.
Note
Although NUTS 2 aligns with the first subdivision level of Spain (Autonomous Communities and Cities), NUTS 3 does not correspond to the second subdivision level of Spain (provinces). NUTS 3 provides dedicated codes for major islands, whereas provinces do not.
Ceuta and Melilla have special status as Autonomous Cities but are represented at the Autonomous Communities and Cities level with a single province, like Madrid, Asturias or Murcia, in this database.
Source
-
INE: Instituto Nacional de Estadística, https://www.ine.es/.
-
Eurostat (NUTS): https://ec.europa.eu/eurostat/web/nuts/overview.
-
CLDR: https://www.unicode.org/cldr/charts/48/subdivisionNames/index.html
See Also
Included package datasets:
esp_nuts_2024,
esp_tiles_providers,
pobmun25
Examples
data("esp_codelist")
esp_codelist
Convert and translate Spanish subdivision names and codes
Description
Convert Spanish subdivision names or identifiers between different coding schemes such as NUTS, ISO2 and province codes, 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 that contains the codes or names to be converted. |
origin, destination |
Character string. Coding scheme of origin and
destination. One of |
lang |
Character string. Target language code. Available values are
|
all |
Logical. If |
Details
This function uses internal dictionaries together with countrycode
to map between schemes. When origin == destination == "text" the input is
returned unchanged. Mixing names from different administrative levels, for
example Autonomous Community or City and province, may produce NA values
for some entries.
Value
esp_dict_region_code() returns a character vector with converted
subdivision identifiers or names. If a value cannot be matched, the
corresponding element will be NA and a warning is emitted via
cli::cli_alert_warning().
esp_dict_translate() translates a vector of names from one language to
another. If all = FALSE, it returns a character vector with the translated
name for each element of sourcevar. If all = TRUE, it returns a named
list where each element contains all available translations for the
corresponding input value.
Examples
vals <- c("Errioxa", "Coruna", "Gerona", "Madrid")
esp_dict_region_code(vals)
esp_dict_region_code(vals, destination = "nuts")
esp_dict_region_code(vals, destination = "cpro")
esp_dict_region_code(vals, destination = "iso2")
# From ISO2 to other codes.
iso2vals <- c("ES-M", "ES-S", "ES-SG")
esp_dict_region_code(iso2vals, origin = "iso2")
esp_dict_region_code(iso2vals,
origin = "iso2",
destination = "nuts"
)
esp_dict_region_code(iso2vals,
origin = "iso2",
destination = "cpro"
)
# Mixing levels.
valsmix <- c("Centro", "Andalucia", "Seville", "Menorca")
esp_dict_region_code(valsmix, destination = "nuts")
esp_dict_region_code(valsmix, destination = "codauto")
esp_dict_region_code(valsmix, destination = "iso2")
vals <- c("La Rioja", "Sevilla", "Madrid", "Jaen", "Orense", "Baleares")
esp_dict_translate(vals)
esp_dict_translate(vals, lang = "es")
esp_dict_translate(vals, lang = "ca")
esp_dict_translate(vals, lang = "eu")
esp_dict_translate(vals, lang = "ga")
esp_dict_translate(vals, lang = "ga", all = TRUE)
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 |
moveCAN |
A logical |
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
Details
The style parameter controls the geometry returned:
-
"box": a rectangular boundary returned as aLINESTRING. -
"poly": a slightly expanded rectangle returned as a filledPOLYGON. -
"left"/"right": decorativeLINESTRINGvariants that follow the western or eastern side of the islands respectively.
Value
An sf object: a POLYGON (when style = "poly") or a
LINESTRING (other styles).
Source
Coordinates of esp_get_can_provinces() derived from CartoBase ANE
(se89_mult_admin_provcan_l.shp).
See Also
Helpers for Canary Islands insets and displacement:
esp_move_can()
Examples
provs <- esp_get_prov()
box <- esp_get_can_box()
line <- esp_get_can_provinces()
library(ggplot2)
ggplot(provs) +
geom_sf() +
geom_sf(data = box, linewidth = 0.15) +
geom_sf(data = line, linewidth = 0.15) +
theme_linedraw()
# Displacing the Canary Islands by a custom offset.
displace <- c(15, 0)
provs_disp <- esp_get_prov(moveCAN = displace)
box_disp <- esp_get_can_box(style = "left", moveCAN = displace)
line_disp <- esp_get_can_provinces(moveCAN = displace)
ggplot(provs_disp) +
geom_sf() +
geom_sf(data = box_disp, linewidth = 0.15) +
geom_sf(data = line_disp, linewidth = 0.15) +
theme_linedraw()
# Example using the polygon style together with other layers.
library(giscoR)
res <- "20"
countries <- gisco_get_countries(
res = res, epsg = "4326",
country = c("France", "Portugal", "Andorra", "Morocco", "Argelia")
)
can_box <- esp_get_can_box(
style = "poly", epsg = "4326",
moveCAN = c(12.5, 0)
)
ccaa <- esp_get_ccaa(res = res, epsg = "4326", moveCAN = c(12.5, 0))
ggplot(countries) +
geom_sf(fill = "#DFDFDF") +
geom_sf(data = can_box, fill = "#C7E7FB", linewidth = 1) +
geom_sf(data = ccaa, fill = "#FDFBEA") +
coord_sf(xlim = c(-10, 4.3), ylim = c(34.6, 44)) +
theme(
panel.background = element_rect(fill = "#C7E7FB"),
panel.grid = element_blank()
)
City where the municipal public authorities are based from 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 use format
|
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
region |
Optional. A vector of region names, NUTS or ISO codes
(see |
munic |
Character string. A name or |
moveCAN |
A logical |
rawcols |
Logical. If |
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 City, or NUTS 1), all municipalities of that level are 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:
Goerlich, F. J. & Pérez Vázquez, P. (2025). Base de datos histórica de contornos municipales de España -LAU2boundaries4Spain- [Data set]. Zenodo. doi:10.5281/zenodo.15345101, https://www.uv.es/goerlich/Ivie/LAU2boundaries4Spain.html.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Political and administrative boundary datasets:
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()
Datasets sourced from CartoBase ANE (Atlas Nacional de España):
esp_get_ccaa_siane(),
esp_get_countries_siane(),
esp_get_munic_siane(),
esp_get_prov_siane(),
esp_get_spain_siane(),
esp_siane_bulk_download()
Municipality-level datasets:
esp_get_munic(),
esp_get_munic_siane()
Examples
# Compare municipality centroids against esp_get_capimun().
# Get the municipality boundary.
area <- esp_get_munic_siane(munic = "Valladolid", epsg = 3857)
# Area in km2.
print(paste0(round(as.double(sf::st_area(area)) / 1000000, 2), " km2"))
# Extract the centroid.
centroid <- sf::st_centroid(area)
centroid$type <- "Centroid"
# Compare with capimun.
capimun <- esp_get_capimun(munic = "Valladolid", epsg = 3857)
capimun$type <- "Capimun"
# Join both point geometries.
points <- dplyr::bind_rows(centroid, capimun)
# Check on a plot.
library(ggplot2)
ggplot(points) +
geom_sf(data = area, fill = NA, color = "blue") +
geom_sf(data = points, aes(fill = type), size = 5, shape = 21) +
scale_fill_manual(values = c("green", "red")) +
labs(title = "Centroid vs. capimun")
Autonomous Communities and Cities of Spain from GISCO
Description
Get Autonomous Communities and Cities of Spain at a specified scale.
Usage
esp_get_ccaa(ccaa = NULL, moveCAN = TRUE, ...)
Arguments
ccaa |
Character string. A vector of names, codes or both for
Autonomous Communities and Cities, or |
moveCAN |
A logical |
... |
Arguments passed on to
|
Details
When using ccaa you can use and mix names and NUTS codes (levels 1 or 2),
ISO codes (corresponding to level 2) or codauto (see esp_codelist).
Ceuta and Melilla are included at the Autonomous Communities and Cities
level in this function.
When calling a NUTS 1 level, all Autonomous Communities and Cities of that level are added.
Value
A sf object.
Note
Please check the download and usage provisions on
giscoR::gisco_attributions().
Source
https://gisco-services.ec.europa.eu/distribution/v2/.
Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.
See Also
Political and administrative boundary datasets:
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 sourced from 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 Autonomous Communities and Cities.
random_ccaa <- esp_get_ccaa(ccaa = c(
"Euskadi",
"Catalunya",
"ES-EX",
"Canarias",
"ES52",
"01"
))
ggplot(random_ccaa) +
geom_sf(aes(fill = codauto), show.legend = FALSE) +
geom_sf_label(aes(label = codauto), alpha = 0.3) +
coord_sf(crs = 3857)
# All Autonomous Communities and Cities of a NUTS 1 region plus one.
mixed <- esp_get_ccaa(ccaa = c("La Rioja", "Noroeste"))
ggplot(mixed) +
geom_sf()
# Combine with giscoR to get countries.
library(giscoR)
library(sf)
res <- 20 # Use the same resolution.
europe <- gisco_get_countries(resolution = res)
ccaa <- esp_get_ccaa(moveCAN = FALSE, resolution = res)
ggplot(europe) +
geom_sf(fill = "#DFDFDF", color = "#656565") +
geom_sf(data = ccaa, fill = "#FDFBEA", color = "#656565") +
coord_sf(
xlim = c(23, 74) * 10e4,
ylim = c(14, 55) * 10e4,
crs = 3035
) +
theme(panel.background = element_rect(fill = "#C7E7FB"))
Autonomous Communities and Cities of Spain from SIANE
Description
Get Autonomous Communities and Cities of Spain at a specified scale.
Usage
esp_get_ccaa_siane(
ccaa = NULL,
year = Sys.Date(),
epsg = 4258,
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
resolution = c(3, 6.5, 10),
moveCAN = TRUE,
rawcols = FALSE
)
Arguments
ccaa |
Character string. A vector of names, codes or both for
Autonomous Communities and Cities, or |
year |
Character string or number. Release year. It must use format
|
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
resolution |
Character string or number. Resolution of the geospatial data. One of:
|
moveCAN |
A logical |
rawcols |
Logical. If |
Details
When using ccaa you can use and mix names and NUTS codes (levels 1 or 2),
ISO codes (corresponding to level 2) or codauto (see esp_codelist).
Ceuta and Melilla are included at the Autonomous Communities and Cities
level in this function.
When calling a NUTS 1 level, all Autonomous Communities and Cities of that level are added.
Value
A sf object.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Political and administrative boundary datasets:
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()
Datasets sourced from CartoBase ANE (Atlas Nacional de España):
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 resolution.
ccaas_low <- esp_get_ccaa_siane(
rawcols = TRUE, moveCAN = FALSE,
resolution = 10, epsg = 3035
)
library(ggplot2)
ggplot(ccaas_low) +
geom_sf(aes(fill = nuts1.name)) +
scale_fill_viridis_d(option = "cividis")
Comarcas of Spain
Description
Get comarcas of Spain. Comarcas are traditional informal territorial divisions comprising several municipalities that share geographical, economic or cultural traits, typically with poorly defined limits.
Usage
esp_get_comarca(
region = NULL,
comarca = NULL,
moveCAN = TRUE,
type = c("INE", "IGN", "AGR", "LIV"),
epsg = 4258,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE
)
Arguments
region |
Character string. A vector of names, codes or both for
provinces, or |
comarca |
Character string. A name or |
moveCAN |
A logical |
type |
Character string. One of |
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
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 City, or NUTS 1), all comarcas of that level are added.
Value
A sf object.
About comarcas
Comarcas (English equivalent: district, county, area or zone) do not always have a formal legal status. They correspond mainly to natural areas (valleys, river basins and similar areas), historical regions or ancient kingdoms.
In the case of Spain, comarcas only have an administrative character legally recognized in Catalonia, the Basque Country, Navarra (named merindades instead), the region of El Bierzo (Castilla y Leon) and Aragon. Galicia, the Principality of Asturias and Andalusia have functional comarcas.
Types
esp_get_comarca() can retrieve several types of comarcas, each provided
under different classification criteria.
-
"INE": Comarcas defined by the National Statistics Institute (INE). -
"IGN": Official comarcas, only available for some Autonomous Communities and Cities, provided by the National Geographic Institute. -
"AGR": Agrarian comarcas defined by the Ministry of Agriculture, Fisheries and Food (MAPA). -
"LIV": Livestock comarcas defined by the Ministry of Agriculture, Fisheries and Food (MAPA).
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
Political and administrative boundary datasets:
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 from 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 use format
|
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
country |
Character vector of country codes. It can be a vector of
country names, ISO3 country codes or ISO2 country codes. See also
|
Value
A sf object.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
giscoR::gisco_get_countries().
Political and administrative boundary datasets:
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()
Datasets sourced from CartoBase ANE (Atlas Nacional de España):
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
Load an 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 two accessors. esp_get_grid_BDN() extracts
country-wide regular grids with resolutions of 5 x 5 or 10 x 10 kilometers
for mainland Spain or the Canary Islands. esp_get_grid_BDN_ccaa() extracts
1 x 1 kilometer resolution grids for individual Autonomous Communities and
Cities.
These grids are useful for biodiversity analysis, environmental monitoring, and spatial statistical applications.
esp_get_grid_BDN_ccaa() provides higher-resolution 1 x 1 kilometer grids
for specific Autonomous Communities and Cities, useful for regional analysis
with finer spatial detail.
Usage
esp_get_grid_BDN(
resolution = c(10, 5),
type = c("main", "canary"),
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE
)
esp_get_grid_BDN_ccaa(
ccaa,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE
)
Arguments
resolution |
Numeric. Resolution of the grid in kilometers. Must be one of:
|
type |
Character. The geographic scope of the grid:
|
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
ccaa |
Character string. A vector of names, codes or both for
Autonomous Communities and Cities. See Details on |
Details
The BDN provides standardized geographic grids for Spain that follow the
Nature Data Bank's specifications. The data are downloaded from the
sianedata/MITECO/dist data branch and is regularly updated.
Value
A sf object.
Source
Data sourced from the Banco de Datos de la Naturaleza (BDN). See the repository structure: https://github.com/rOpenSpain/mapSpain/tree/sianedata/MITECO/dist
For more information about BDN grids and other resources, visit: https://www.miteco.gob.es/es/biodiversidad/servicios/banco-datos-naturaleza/informacion-disponible/bdn-cart-aux-descargas-ccaa.html.
See Also
Geographical grid datasets:
esp_get_grid_ESDAC(),
esp_get_grid_MTN()
Examples
# Load a 10 x 10 km grid for mainland Spain.
grid <- esp_get_grid_BDN(resolution = 10, type = "main")
# Visualize the grid.
library(ggplot2)
ggplot(grid) +
geom_sf(fill = NA, color = "steelblue") +
theme_light() +
labs(title = "BDN Geographic Grid: 10x10 km Spain")
Get sf POLYGON of the national geographic grids from EEA
Description
This function is defunct because the source file is no longer available.
Usage
esp_get_grid_EEA(
resolution = 100,
type = "main",
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE
)
Arguments
resolution |
Resolution of the grid in kilometers. Can be |
type |
Character. The geographic scope of the grid:
|
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
Value
A sf POLYGON.
Source
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 kilometers. Can be |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
Value
A sf POLYGON.
Source
References
Panagos P., Van Liedekerke M., Jones A., Montanarella L., "European Soil Data Centre: Response to European policy support and public data requirements", (2012) Land Use Policy, 29 (2), pp. 329-338. doi:10.1016/j.landusepol.2011.07.003
European Soil Data Centre (ESDAC), esdac.jrc.ec.europa.eu, European Commission, Joint Research Centre.
See Also
Geographical grid datasets:
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. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
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 distributed through the sianedata/MTN data branch (see
https://github.com/rOpenSpain/mapSpain/tree/sianedata/MTN).
See Also
Geographical grid datasets:
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
boundaries of the provinces or Autonomous Communities and Cities of Spain.
Usage
esp_get_hex_prov(prov = NULL)
esp_get_hex_ccaa(ccaa = NULL)
esp_get_grid_prov(prov = NULL)
esp_get_grid_ccaa(ccaa = NULL)
Arguments
prov, ccaa |
Character. A vector of names, codes or both for provinces
and Autonomous Communities and Cities, or |
Details
Hexbin (or grid) maps have an advantage over traditional choropleth maps. In choropleths, regions with larger polygons tend to appear more prominent simply because of their size, which introduces visual bias. With hexbin maps, each region is represented equally, reducing this bias.
You can use and mix names, ISO codes, "codauto" or "cpro" codes (see
esp_codelist) and NUTS codes of different levels.
When using a code corresponding to a higher level (for example,
esp_get_prov("Andalucia")), all the corresponding units of that level are
provided (in this case, all the provinces of Andalusia).
Results are provided in EPSG:4258. Use sf::st_transform()
to change the projection.
Value
A sf object.
See Also
Political and administrative boundary datasets:
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: Autonomous Communities and Cities")
hexprov <- esp_get_hex_prov()
ggplot(hexprov) +
geom_sf(data = esp) +
geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
geom_sf_text(aes(label = label), check_overlap = TRUE) +
theme_void() +
labs(title = "Hexbin: Provinces")
gridccaa <- esp_get_grid_ccaa()
ggplot(gridccaa) +
geom_sf(data = esp) +
geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
geom_sf_text(aes(label = label), check_overlap = TRUE) +
theme_void() +
labs(title = "Grid: Autonomous Communities and Cities")
gridprov <- esp_get_grid_prov()
ggplot(gridprov) +
geom_sf(data = esp) +
geom_sf(aes(fill = codauto), alpha = 0.3, show.legend = FALSE) +
geom_sf_text(aes(label = label), check_overlap = TRUE) +
theme_void() +
labs(title = "Grid: Provinces")
River basin districts of Spain from SIANE
Description
River basin districts are the areas of land and sea, made up of one or more neighbouring river basins together with their associated groundwaters and coastal waters.
Usage
esp_get_hydrobasin(
epsg = 4258,
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
resolution = c(3, 6.5, 10),
domain = c("land", "landsea")
)
Arguments
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
resolution |
Character string or number. Resolution of the geospatial data. One of:
|
domain |
Character string. Type of river basin district. Possible
values are |
Details
Metadata available on https://github.com/rOpenSpain/mapSpain/tree/sianedata/.
Value
A sf object.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Natural feature datasets:
esp_get_hypsobath(),
esp_get_landwater
Examples
hydroland <- esp_get_hydrobasin(domain = "land")
hydrolandsea <- esp_get_hydrobasin(domain = "landsea")
library(ggplot2)
ggplot(hydroland) +
geom_sf(data = hydrolandsea, fill = "skyblue4", alpha = 0.4) +
geom_sf(fill = "skyblue", alpha = 0.5) +
geom_sf_text(aes(label = rotulo),
size = 2, check_overlap = TRUE,
fontface = "bold",
family = "serif"
) +
coord_sf(
crs = 3857,
xlim = c(-9.5, 4.5),
ylim = c(35, 44)
) +
theme_void()
Hypsometry and bathymetry of Spain from SIANE
Description
Dataset representing the hypsometry and bathymetry of Spain.
-
Hypsometry represents the elevation and depth of features of the Earth's surface relative to mean sea level.
-
Bathymetry is the measurement of the depth of water in oceans, rivers, or lakes.
Usage
esp_get_hypsobath(
epsg = 4258,
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
resolution = c(3, 6.5),
spatialtype = c("area", "line")
)
Arguments
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
resolution |
Character string or number. Resolution of the geospatial data. One of:
|
spatialtype |
Character string. Spatial type of the output. Use
|
Details
Metadata available on https://github.com/rOpenSpain/mapSpain/tree/sianedata/.
Value
A sf object.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Natural feature datasets:
esp_get_hydrobasin(),
esp_get_landwater
Examples
# This code produces a plot and takes a few seconds to run.
library(ggplot2)
hypsobath <- esp_get_hypsobath()
# Tints from Wikipedia.
# https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Maps/Conventions/
# Topographic_maps
levels <- sort(unique(hypsobath$val_inf))
# Create the manual palette.
br_bath <- length(levels[levels < 0])
br_terrain <- length(levels) - br_bath
pal <- c(
tidyterra::hypso.colors(br_bath, "wiki-2.0_bathy"),
tidyterra::hypso.colors(br_terrain, "wiki-2.0_hypso")
)
# Plot the Canary Islands.
ggplot(hypsobath) +
geom_sf(aes(fill = as.factor(val_inf)),
color = NA
) +
coord_sf(
xlim = c(-18.6, -13),
ylim = c(27, 29.5)
) +
scale_fill_manual(values = pal) +
guides(fill = guide_legend(
title = "Elevation",
direction = "horizontal",
label.position = "bottom",
title.position = "top",
nrow = 1
)) +
theme(legend.position = "bottom")
# Plot mainland Spain.
ggplot(hypsobath) +
geom_sf(aes(fill = as.factor(val_inf)),
color = NA
) +
coord_sf(
xlim = c(-9.5, 4.4),
ylim = c(35.8, 44)
) +
scale_fill_manual(values = pal) +
guides(fill = guide_legend(
title = "Elevation",
reverse = TRUE,
keyheight = 0.8
))
Rivers and wetlands of Spain from SIANE
Description
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 cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
resolution |
|
spatialtype |
|
moveCAN |
A logical |
name |
Character string or |
Details
Metadata available on https://github.com/rOpenSpain/mapSpain/tree/sianedata/.
Value
A sf object.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Natural feature datasets:
esp_get_hydrobasin(),
esp_get_hypsobath()
Examples
# Use of regex.
regex1 <- esp_get_rivers(name = "Tajo|Segura")
unique(regex1$rotulo)
regex2 <- esp_get_rivers(name = "Tajo$| Segura")
unique(regex2$rotulo)
# See the difference.
# Rivers in Spain.
iberian <- giscoR::gisco_get_countries(
country = c("ES", "PT", "FR"), resolution = 3
)
main_rivers <- esp_get_rivers() |>
dplyr::filter(t_rio == 1)
library(ggplot2)
ggplot(iberian) +
geom_sf() +
geom_sf(data = main_rivers, color = "skyblue", linewidth = 2) +
coord_sf(
xlim = c(-10, 5),
ylim = c(35, 44)
)
# Wetlands in South-West Andalucia.
and <- esp_get_prov(c("Huelva", "Sevilla", "Cadiz"))
wetlands <- esp_get_wetlands()
wetlands_south <- sf::st_filter(wetlands, and)
ggplot(and) +
geom_sf() +
geom_sf(
data = wetlands_south, fill = "skyblue",
color = "skyblue", alpha = 0.5
)
Municipalities of Spain from GISCO
Description
Get boundaries of municipalities in Spain.
Usage
esp_get_munic(
year = 2024,
epsg = 4258,
cache = deprecated(),
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
region = NULL,
munic = NULL,
moveCAN = TRUE,
ext = "gpkg"
)
Arguments
year |
Year character string or number. Release year of the file. See
|
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
|
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
region |
Optional. A vector of region names, NUTS or ISO codes
(see |
munic |
Character string. A name or |
moveCAN |
A logical |
ext |
Character. Extension of the file (default |
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 City, or NUTS 1), all municipalities of that level are added.
Value
A sf object.
Note
Please check the download and usage provisions on
giscoR::gisco_attributions().
Source
https://gisco-services.ec.europa.eu/distribution/v2/.
Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units.
See Also
Political and administrative boundary datasets:
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()
Municipality-level datasets:
esp_get_capimun(),
esp_get_munic_siane()
Datasets sourced from 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 municipalities.
spanish_laplad <- esp_get_munic(
year = 2023,
region = c(
"Cuenca", "Teruel",
"Zaragoza", "Guadalajara",
"Soria", "Burgos",
"La Rioja"
)
)
breaks <- sort(c(0, 5, 10, 50, 100, 200, 500, 1000, Inf))
spanish_laplad$dens_breaks <- cut(spanish_laplad$POP_DENS_2023, breaks,
dig.lab = 20
)
cut_labs <- prettyNum(breaks, big.mark = " ")[-1]
cut_labs[length(breaks)] <- "> 1000"
library(ggplot2)
ggplot(spanish_laplad) +
geom_sf(aes(fill = dens_breaks), color = "grey30", linewidth = 0.1) +
scale_fill_manual(
values = hcl.colors(length(breaks) - 1, "Spectral"), na.value = "black",
name = "people per sq. kilometer",
labels = cut_labs,
guide = guide_legend(
direction = "horizontal",
nrow = 1
)
) +
theme_void() +
labs(
title = "The Spanish Lapland",
caption = giscoR::gisco_attributions()
) +
theme(
text = element_text(colour = "white"),
plot.background = element_rect(fill = "grey2"),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5, face = "bold"),
plot.caption = element_text(
color = "grey60", hjust = 0.5, vjust = 0,
margin = margin(t = 5, b = 10)
),
legend.position = "bottom",
legend.title.position = "top",
legend.text.position = "bottom",
legend.key.height = unit(0.5, "lines"),
legend.key.width = unit(1, "lines")
)
Municipalities of Spain from SIANE
Description
Get boundaries of municipalities in Spain.
Usage
esp_get_munic_siane(
year = Sys.Date(),
epsg = 4258,
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
resolution = c(3, 6.5, 10),
region = NULL,
munic = NULL,
moveCAN = TRUE,
rawcols = FALSE
)
Arguments
year |
Character string or number. Release year. It must use format
|
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
resolution |
Character string or number. Resolution of the geospatial data. One of:
|
region |
Optional. A vector of region names, NUTS or ISO codes
(see |
munic |
Character string. A name or |
moveCAN |
A logical |
rawcols |
Logical. If |
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 City, or NUTS 1), all municipalities of that level are 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:
Goerlich, F. J. & Pérez Vázquez, P. (2025). Base de datos histórica de contornos municipales de España -LAU2boundaries4Spain- [Data set]. Zenodo. doi:10.5281/zenodo.15345101, https://www.uv.es/goerlich/Ivie/LAU2boundaries4Spain.html.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Political and administrative boundary datasets:
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()
Datasets sourced from CartoBase ANE (Atlas Nacional de España):
esp_get_capimun(),
esp_get_ccaa_siane(),
esp_get_countries_siane(),
esp_get_prov_siane(),
esp_get_spain_siane(),
esp_siane_bulk_download()
Municipality-level datasets:
esp_get_capimun(),
esp_get_munic()
Examples
# Municipalities that have changed in the past: three snapshots.
munis2005 <- esp_get_munic_siane(year = 2005, rawcols = TRUE)
munis2015 <- esp_get_munic_siane(year = 2015, rawcols = TRUE)
munis2024 <- esp_get_munic_siane(year = 2024, rawcols = TRUE)
# Manipulate data.
library(dplyr)
allmunis_unique <- bind_rows(munis2005, munis2015, munis2024) |>
distinct()
id_all <- allmunis_unique |>
sf::st_drop_geometry() |>
group_by(id_ine, name) |>
count() |>
ungroup() |>
arrange(desc(n)) |>
slice_head(n = 1) |>
glimpse()
library(ggplot2)
allmunis_unique |>
filter(id_ine == id_all$id_ine) |>
ggplot() +
geom_sf(aes(fill = as.factor(fecha_alta)),
alpha = 0.7,
show.legend = FALSE
) +
scale_fill_viridis_d() +
facet_wrap(~fecha_alta) +
labs(
title = id_all$name,
subtitle = "Boundary changes over time",
fill = ""
)
Territorial Spanish units for statistics (NUTS) dataset
Description
The GISCO statistical unit dataset represents NUTS (Nomenclature of Territorial Units for Statistics) and statistical regions using multipart polygon, polyline and point topology. The NUTS geographical information is completed by attribute tables and a set of cartographic help lines to better visualize multipart polygonal regions.
NUTS is a hierarchical system divided into three levels:
NUTS 1: major socioeconomic regions.
NUTS 2: basic regions for the application of regional policies.
NUTS 3: small regions for specific diagnoses.
There is also a NUTS 0 level, which usually corresponds to the national boundaries.
Usage
esp_get_nuts(
year = 2024,
epsg = 4258,
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
resolution = 1,
spatialtype = c("RG", "LB"),
region = NULL,
nuts_level = c("all", "0", "1", "2", "3"),
moveCAN = TRUE,
ext = "gpkg"
)
Arguments
year |
Year character string or number. Release year of the file. See
|
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
resolution |
A character string or numeric value with the geospatial data resolution. One of:
|
spatialtype |
Character string. Type of geometry to be returned. Options available are:
|
region |
Optional. A vector of region names, NUTS or ISO codes
(see |
nuts_level |
A character string with the NUTS level. One of |
moveCAN |
A logical |
ext |
Character. Extension of the file (default |
Details
The NUTS nomenclature is a hierarchical classification of statistical regions and subdivides the EU economic territory into regions of three different levels (NUTS 1, 2 and 3, moving respectively from larger to smaller territorial units). NUTS 1 is the most aggregated level. An additional country level (NUTS 0) is also available for countries where the nation at statistical level does not coincide with the administrative boundaries.
The NUTS classification has been officially established through Commission Delegated Regulation 2019/1755. An unofficial NUTS-like classification has been defined for the EFTA countries, candidate countries and potential candidates based on a bilateral agreement between Eurostat and the respective statistical agencies.
Value
A sf object.
Note
Please check the download and usage provisions on
giscoR::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().
Political and administrative boundary datasets:
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()
NUTS boundary datasets:
esp_get_spain()
Datasets sourced from 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 = "NUTS 1: Displacing Canary Islands",
caption = giscoR::gisco_attributions()
)
nuts1_alt <- esp_get_nuts(nuts_level = 1, moveCAN = c(15, 0))
ggplot(nuts1_alt) +
geom_sf() +
labs(
title = "NUTS 1: Displacing Canary Islands",
subtitle = "to the right",
caption = giscoR::gisco_attributions()
)
nuts1_orig <- esp_get_nuts(nuts_level = 1, moveCAN = FALSE)
ggplot(nuts1_orig) +
geom_sf() +
labs(
title = "NUTS 1",
subtitle = "Canary Islands in their true location",
caption = giscoR::gisco_attributions()
)
and_orient <- esp_get_nuts(region = c(
"Almeria", "Granada",
"Jaen", "Malaga"
))
ggplot(and_orient) +
geom_sf()
random_regions <- esp_get_nuts(region = c("ES1", "ES300", "ES51"))
ggplot(random_regions) +
geom_sf() +
labs(title = "Random Regions")
mixing_codes <- esp_get_nuts(region = c("ES4", "ES-PV", "Valencia"))
ggplot(mixing_codes) +
geom_sf() +
labs(title = "Mixing Codes")
Provinces of Spain from GISCO
Description
Get provinces of Spain at a specified scale.
Usage
esp_get_prov(prov = NULL, moveCAN = TRUE, ...)
Arguments
prov |
A vector of names, codes or both for provinces, or |
moveCAN |
A logical |
... |
Arguments passed on to
|
Details
When using prov you can use and mix names and NUTS codes (levels 1, 2 or
3), ISO codes (corresponding to level 2 or 3) or "cpro" (see
esp_codelist).
Ceuta and Melilla are considered provinces in this dataset.
When calling a higher level (Autonomous Community or City, or NUTS 1), all provinces of that level are added.
Value
A sf object.
Note
Please check the download and usage provisions on
giscoR::gisco_attributions().
Source
https://gisco-services.ec.europa.eu/distribution/v2/.
Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.
See Also
Political and administrative boundary datasets:
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 sourced from 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 one addition.
mix <- esp_get_prov(prov = c(
"Noroeste",
"Castilla y Leon", "La Rioja"
))
mix$ccaa <- esp_dict_region_code(
mix$codauto,
origin = "codauto"
)
ggplot(mix) +
geom_sf(aes(fill = ccaa), alpha = 0.5) +
scale_fill_discrete(type = hcl.colors(5, "Temps")) +
theme_classic()
# Available ISO codes.
allprovs <- esp_get_prov()
ggplot(allprovs) +
geom_sf(fill = NA) +
geom_sf_text(aes(label = iso2.prov.code),
check_overlap = TRUE,
fontface = "bold"
) +
coord_sf(crs = 3857) +
theme_void()
Provinces of Spain from SIANE
Description
Get provinces of Spain at a specified scale.
Usage
esp_get_prov_siane(
prov = NULL,
year = Sys.Date(),
epsg = 4258,
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
resolution = c(3, 6.5, 10),
moveCAN = TRUE,
rawcols = FALSE
)
Arguments
prov |
A vector of names, codes or both for provinces, or |
year |
Character string or number. Release year. It must use format
|
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
resolution |
Character string or number. Resolution of the geospatial data. One of:
|
moveCAN |
A logical |
rawcols |
Logical. If |
Details
When using prov you can use and mix names and NUTS codes (levels 1, 2 or
3), ISO codes (corresponding to level 2 or 3) or "cpro" (see
esp_codelist).
Ceuta and Melilla are considered provinces in this dataset.
When calling a higher level (Autonomous Community or City, or NUTS 1), all provinces of that level are added.
Value
A sf object.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Political and administrative boundary datasets:
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()
Datasets sourced from CartoBase ANE (Atlas Nacional de España):
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 from 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 cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
spatialtype |
|
Value
A sf object.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Transport infrastructure datasets:
esp_get_roads()
Examples
provs <- esp_get_prov()
ccaa <- esp_get_ccaa()
# Railways.
rails <- esp_get_railway()
# Stations.
stations <- esp_get_stations()
# Map.
library(ggplot2)
ggplot(provs) +
geom_sf(fill = "grey99", color = "grey50") +
geom_sf(data = ccaa, fill = NA) +
geom_sf(
data = rails, aes(color = t_ffcc_desc),
show.legend = FALSE,
linewidth = 1.5
) +
geom_sf(
data = stations,
color = "red", alpha = 0.5
) +
scale_colour_viridis_d() +
facet_wrap(~t_ffcc_desc) +
theme_minimal()
Roads of Spain from SIANE
Description
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 cache downloaded files. Default is |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
moveCAN |
A logical |
Value
A sf object.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Transport infrastructure datasets:
esp_get_railway()
Examples
country <- esp_get_spain()
roads <- esp_get_roads()
library(ggplot2)
ggplot(country) +
geom_sf(fill = "grey90") +
geom_sf(data = roads, aes(color = t_ctra_desc), show.legend = "line") +
scale_color_manual(
values = c("#003399", "#003399", "#ff0000", "#ffff00")
) +
guides(color = guide_legend(direction = "vertical")) +
theme_minimal() +
labs(color = "Road type") +
theme(legend.position = "bottom")
Simplified map of provinces and Autonomous Communities and Cities of Spain
Description
Simplified map with the boundaries of the provinces or Autonomous Communities of Spain, as provided by the INE (Instituto Nacional de Estadística).
Usage
esp_get_simpl_prov(
prov = NULL,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE
)
esp_get_simpl_ccaa(
ccaa = NULL,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE
)
Arguments
prov, ccaa |
Character. A vector of names, codes or both for provinces
and Autonomous Communities and Cities, or |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
Details
Results are provided without CRS, as provided by the source.
You can use and mix names, ISO codes, "codauto" or "cpro" codes (see
esp_codelist) and NUTS codes of different levels.
When using a code corresponding to a higher level (for example,
esp_get_prov("Andalucia")), all the corresponding units of that level are
provided (in this case, all the provinces of Andalusia).
Value
A sf object.
Source
INE: PC-Axis files.
See Also
Political and administrative boundary datasets:
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 = "Autonomous Communities and Cities")
# Provinces of a single Autonomous Community or City.
and_simple <- esp_get_simpl_prov("Andalucia")
ggplot(and_simple) +
geom_sf()
# Autonomous Communities and Cities.
ccaa_simp <- esp_get_simpl_ccaa()
ggplot(ccaa_simp) +
geom_sf() +
geom_sf_text(aes(label = ine.ccaa.name), check_overlap = TRUE)
Boundaries of Spain from GISCO
Description
Returns the boundaries of Spain as a single sf POLYGON at a
specified scale.
Usage
esp_get_spain(moveCAN = TRUE, ...)
Arguments
moveCAN |
A logical |
... |
Arguments passed on to
|
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
giscoR::gisco_attributions().
Source
https://gisco-services.ec.europa.eu/distribution/v2/.
Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.
See Also
Political and administrative boundary datasets:
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()
NUTS boundary datasets:
esp_get_nuts()
Datasets sourced from 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 from SIANE
Description
Returns the boundaries of Spain as a single sf POLYGON.
Usage
esp_get_spain_siane(moveCAN = TRUE, ...)
Arguments
moveCAN |
A logical |
... |
Arguments passed on to
|
Value
A sf object.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Political and administrative boundary datasets:
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()
Datasets sourced from CartoBase ANE (Atlas Nacional de España):
esp_get_capimun(),
esp_get_ccaa_siane(),
esp_get_countries_siane(),
esp_get_munic_siane(),
esp_get_prov_siane(),
esp_siane_bulk_download()
Examples
original_can <- esp_get_spain_siane(moveCAN = FALSE)
# One row only.
original_can
library(ggplot2)
ggplot(original_can) +
geom_sf(fill = "grey70")
# Less resolution.
moved_can <- esp_get_spain_siane(moveCAN = TRUE, resolution = 10)
ggplot(moved_can) +
geom_sf(fill = "grey70")
Get static map tiles from public administrations of Spain
Description
Get static map tiles based on a spatial object. Maps can be fetched from WMS and WMTS providers.
This function is an implementation of the JavaScript plugin leaflet-providersESP v1.3.3.
esp_get_attributions() gets the attribution of a tile provider defined by
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 |
|
type |
This argument can be one of:
|
zoom |
Character string or number. Only valid for WMTS providers, zoom
level to be downloaded. If |
zoommin |
Character string or number. Delta on default |
crop |
Logical. If |
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 |
transparent |
Logical. Whether to use a transparent background, if supported. |
mask |
Logical. |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
A logical value. If |
options |
A named list containing additional options to pass to the query. |
Details
Zoom levels are described on the OpenStreetMap wiki:
| zoom | area to represent |
| 0 | whole world |
| 3 | large country |
| 5 | state |
| 8 | county |
| 10 | metropolitan area |
| 11 | city |
| 13 | village or suburb |
| 16 | streets |
| 18 | some buildings, trees |
For a complete list of providers, see esp_tiles_providers.
Most WMS/WMTS providers provide tiles on
"EPSG:3857". If the tile looks deformed, try
projecting x first:
x <- sf::st_transform(x, 3857)
Value
A SpatRaster with 3 (RGB) or 4 (RGBA) layers, depending on
the provider. See terra::rast().
Source
https://dieghernan.github.io/leaflet-providersESP/, a plugin for leaflet, v1.3.3.
See Also
Static map tiles and imagery:
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 WMTS provider.
custom_wmts <- esp_make_provider(
id = "cyl_wmts",
q = "https://www.ign.es/wmts/pnoa-ma?",
service = "WMTS",
layer = "OI.OrthoimageCoverage"
)
custom_wmts_tile <- esp_get_tiles(segovia, custom_wmts)
autoplot(custom_wmts_tile, maxcell = Inf) +
geom_sf(data = segovia, fill = NA, color = "white", linewidth = 1)
# Example from https://leaflet-extras.github.io/leaflet-providers/preview/.
cartodb_dark <- list(
id = "CartoDB_DarkMatter",
q = "https://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png"
)
cartodb_dark_tile <- esp_get_tiles(segovia, cartodb_dark,
zoommin = 1,
update_cache = TRUE
)
autoplot(cartodb_dark_tile, maxcell = Inf) +
geom_sf(data = segovia, fill = NA, color = "white", linewidth = 1)
## End(Not run)
Create a custom tile provider
Description
Helper function for esp_get_tiles() that helps to create a custom provider.
Usage
esp_make_provider(id, q, service, layers, ...)
Arguments
id |
An identifier for the user. Used for identifying cached tiles. |
q |
The base URL of the service. |
service |
The type of tile service, either |
layers |
The name of the layer to retrieve. |
... |
Additional arguments to the query, such as |
Details
This function is meant to work with services provided under the OGC Standard.
Note that:
-
mapSpain does not provide advice on the value of
q. Currently, for WMTS requests only services with
tilematrixset=GoogleMapsCompatibleare supported.
Value
A named list with two elements id and q.
See Also
For a list of potential providers from Spain, check the IDEE Directory.
Static map tiles and imagery:
addProviderEspTiles(),
esp_get_tiles()
Examples
## Not run:
custom_wmts <- esp_make_provider(
id = "example",
q = "https://www.ign.es/wmts/ign-base?",
service = "WMTS",
layer = "IGNBaseTodo"
)
x <- esp_get_ccaa("Castilla y León", epsg = 3857)
mytile <- esp_get_tiles(x, type = custom_wmts)
tidyterra::autoplot(mytile) +
ggplot2::geom_sf(data = x, fill = NA)
## End(Not run)
Displace 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
mapSpain objects generated with moveCAN = TRUE.
Usage
esp_move_can(x, moveCAN = TRUE)
Arguments
x |
An |
moveCAN |
A logical |
Details
This helper function makes it easier to represent objects located in the Canary Islands that have been obtained from sources other than mapSpain.
Value
A sf object of the same class and same CRS as x,
displaced accordingly.
Displacing the Canary Islands
While moveCAN is useful for visualization, it will alter the actual
geographic position of the Canary Islands. When using the output for
spatial analysis or tiles (for example, with esp_get_tiles() or
addProviderEspTiles()), set this option to FALSE to get the actual
coordinates instead of the modified ones.
See Also
Helpers for Canary Islands insets and displacement:
esp_get_can_box()
Examples
library(sf)
teide <- data.frame(
name = "Teide Peak",
lon = -16.6437593,
lat = 28.2722883
)
teide_sf <- st_as_sf(teide, coords = c("lon", "lat"), crs = 4326)
# A mapSpain object with moveCAN = TRUE is displaced.
esp <- esp_get_spain(moveCAN = c(13, 0))
library(ggplot2)
ggplot(esp) +
geom_sf() +
geom_sf(data = teide_sf, color = "red") +
labs(
title = "Canary Islands displaced",
subtitle = "But not the external Teide object"
)
# Displace the external object too.
teide_sf_disp <- esp_move_can(teide_sf, moveCAN = c(13, 0))
ggplot(esp) +
geom_sf() +
geom_sf(data = teide_sf_disp, color = "red") +
labs(
title = "Canary Islands displaced",
subtitle = "And also the external Teide object"
)
NUTS 2024 for Spain sf object
Description
This dataset represents Spanish subdivisions at NUTS levels 0, 1, 2 and 3 according to the Nomenclature of Territorial Units for Statistics (NUTS) classification for 2024.
Format
An sf object with MULTIPOLYGON geometries at 1:1 million
resolution in EPSG:4258 projection, containing
86 rows and 10 variables:
NUTS_IDNUTS identifier.
LEVL_CODENUTS level code
(0, 1, 2, 3).CNTR_CODEEurostat country code.
NAME_LATNNUTS name in Latin characters.
NUTS_NAMENUTS name in the local alphabet.
MOUNT_TYPEMountain type, see Details.
URBN_TYPEUrban type, see Details.
COAST_TYPECoastal type, see Details.
geoSame as
NUTS_ID, provided for compatibility with eurostat.geometryGeometry field.
Details
MOUNT_TYPE: Mountain typology:
-
1: More than 50 % of the surface is covered by topographic mountain areas. -
2: More than 50 % of the regional population lives in topographic mountain areas. -
3: More than 50 % of the surface is covered by topographic mountain areas and where more than 50 % of the regional population lives in these mountain areas. -
4: Non-mountain region / other regions. -
0: No classification provided.
URBN_TYPE: Urban-rural typology:
-
1: Predominantly urban region. -
2: Intermediate region. -
3: Predominantly rural region. -
0: No classification provided.
COAST_TYPE: Coastal typology:
-
1: Coastal (on coast). -
2: Coastal (less than 50 % of population living within 50 km of the coastline). -
3: Non-coastal region. -
0: No classification provided.
Source
NUTS_RG_01M_2024_4326.gpkg file.
See Also
Included package datasets:
esp_codelist,
esp_tiles_providers,
pobmun25
Examples
data("esp_nuts_2024")
head(esp_nuts_2024)
Set your mapSpain cache directory
Description
This function stores your cache_dir path on your local machine and loads
it for future sessions. Use Sys.getenv("MAPSPAIN_CACHE_DIR") or
esp_detect_cache_dir() to find the cached path.
Usage
esp_set_cache_dir(
cache_dir = NULL,
overwrite = FALSE,
install = FALSE,
verbose = TRUE
)
esp_detect_cache_dir()
Arguments
cache_dir |
A path to a cache directory. When |
overwrite |
Logical. If |
install |
Logical. If |
verbose |
A logical value. If |
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 their online source without caching using the
option cache = FALSE. Otherwise the source files are downloaded to
your computer. mapSpain implements the following caching options:
For occasional use, rely on the default
tempdir()-based cache (no install).Modify the cache for a single session by setting
esp_set_cache_dir(cache_dir = "a/path/here").For reproducible workflows, install a persistent cache with
esp_set_cache_dir(cache_dir = "a/path/here", install = TRUE), which persists across R sessions.For caching specific files, use the
cache_dirargument in the corresponding function.
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
Cache management utilities:
esp_clear_cache()
Examples
# Do not run this. It would modify your current state.
## Not run:
my_cache <- esp_detect_cache_dir()
# Set an example cache.
ex <- file.path(tempdir(), "example", "cachenew")
esp_set_cache_dir(ex)
esp_detect_cache_dir()
# Restore the initial cache.
esp_set_cache_dir(my_cache)
identical(my_cache, esp_detect_cache_dir())
## End(Not run)
esp_detect_cache_dir()
SIANE bulk download
Description
Download zipped data from SIANE to the cache_dir
and extract the relevant files.
Usage
esp_siane_bulk_download(
cache_dir = NULL,
update_cache = FALSE,
verbose = FALSE
)
Arguments
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
update_cache |
Logical. If |
verbose |
A logical value. If |
Value
An invisible character vector with the full paths of the extracted files. See Examples.
Source
CartoBase ANE (Atlas Nacional de España) provided by Instituto Geográfico Nacional (IGN), http://www.ign.es/web/ign/portal. Years available are 2005 up to today.
Copyright: https://centrodedescargas.cnig.es/CentroDescargas/cartobase-ane
Always acknowledge authorship using the following statements:
When the original digital product is not modified or altered, use one of the following statements:
CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
CartoBase ANE 2006-2024 CC-BY 4.0 Instituto Geográfico Nacional.
When a new product is generated:
Obra derivada de CartoBase ANE 2006-2024 CC-BY 4.0 ign.es.
Data distributed through the sianedata data branch, see
https://github.com/rOpenSpain/mapSpain/tree/sianedata.
See Also
Political and administrative boundary datasets:
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()
Datasets sourced from CartoBase ANE (Atlas Nacional de España):
esp_get_capimun(),
esp_get_ccaa_siane(),
esp_get_countries_siane(),
esp_get_munic_siane(),
esp_get_prov_siane(),
esp_get_spain_siane()
Examples
tmp <- file.path(tempdir(), "testexample")
dest_files <- esp_siane_bulk_download(cache_dir = tmp)
# Read one file.
library(sf)
read_sf(dest_files[1]) |> head()
# Connect the function with the downloaded data.
connect <- esp_get_munic_siane(cache_dir = tmp, verbose = TRUE)
# The message shows that the file is already cached.
# Clean up.
unlink(tmp, force = TRUE, recursive = TRUE)
Public WMS and WMTS providers for Spain
Description
A named list of length 102,
containing URL information from different public WMS and WMTS tile providers
in Spain.
This dataset is an implementation of the JavaScript plugin leaflet-providersESP v1.3.3.
Format
A named list of available providers with the following
structure:
Each list item is named with the provider alias. Each element contains two
nested named lists: static with the parameters required to obtain static
map tiles plus an additional item named attribution, and leaflet with
additional parameters to pass to addProviderEspTiles().
Details
Providers available to be passed to type in esp_get_tiles() are:
-
"IDErioja" -
"IDErioja.Base" -
"IDErioja.Relieve" -
"IDErioja.Claro" -
"IDErioja.Oscuro" -
"IGNBase" -
"IGNBase.Todo" -
"IGNBase.Gris" -
"IGNBase.TodoNoFondo" -
"IGNBase.Orto" -
"MDT" -
"MDT.Elevaciones" -
"MDT.Relieve" -
"MDT.CurvasNivel" -
"MDT.SpotElevation" -
"PNOA" -
"PNOA.MaximaActualidad" -
"PNOA.Mosaico" -
"OcupacionSuelo" -
"OcupacionSuelo.Ocupacion" -
"OcupacionSuelo.Usos" -
"LiDAR" -
"MTN" -
"Geofisica" -
"Geofisica.Terremotos10dias" -
"Geofisica.Terremotos30dias" -
"Geofisica.Terremotos365dias" -
"Geofisica.ObservedEvents" -
"Geofisica.HazardArea" -
"VigilanciaVolcanica" -
"VigilanciaVolcanica.ErupcionesHistoricas" -
"CaminoDeSantiago" -
"CaminoDeSantiago.CaminoFrances" -
"CaminoDeSantiago.CaminosFrancia" -
"CaminoDeSantiago.CaminosGalicia" -
"CaminoDeSantiago.CaminosDelNorte" -
"CaminoDeSantiago.CaminosAndaluces" -
"CaminoDeSantiago.CaminosCentro" -
"CaminoDeSantiago.CaminosEste" -
"CaminoDeSantiago.CaminosCatalanes" -
"CaminoDeSantiago.CaminosSureste" -
"CaminoDeSantiago.CaminosInsulares" -
"CaminoDeSantiago.CaminosPortugueses" -
"Catastro" -
"Catastro.Catastro" -
"Catastro.Parcela" -
"Catastro.CadastralParcel" -
"Catastro.CadastralZoning" -
"Catastro.Address" -
"Catastro.Building" -
"Catastro.BuildingPart" -
"Catastro.AdministrativeBoundary" -
"Catastro.AdministrativeUnit" -
"RedTransporte" -
"RedTransporte.Carreteras" -
"RedTransporte.Ferroviario" -
"RedTransporte.Aerodromo" -
"RedTransporte.AreaServicio" -
"RedTransporte.EstacionesFerroviario" -
"RedTransporte.Puertos" -
"Cartociudad" -
"Cartociudad.CodigosPostales" -
"Cartociudad.Direcciones" -
"NombresGeograficos" -
"UnidadesAdm" -
"UnidadesAdm.Limites" -
"UnidadesAdm.Unidades" -
"Hidrografia" -
"Hidrografia.MasaAgua" -
"Hidrografia.Cuencas" -
"Hidrografia.Subcuencas" -
"Hidrografia.POI" -
"Hidrografia.ManMade" -
"Hidrografia.LineaCosta" -
"Hidrografia.Rios" -
"Hidrografia.Humedales" -
"Militar" -
"Militar.CEGET1M" -
"Militar.CEGETM7814" -
"Militar.CEGETM7815" -
"Militar.CEGETM682" -
"Militar.CECAF1M" -
"ADIF" -
"ADIF.Vias" -
"ADIF.Nodos" -
"ADIF.Estaciones" -
"LimitesMaritimos" -
"LimitesMaritimos.LimitesMaritimos" -
"LimitesMaritimos.LineasBase" -
"Copernicus" -
"Copernicus.Forest" -
"Copernicus.ForestLeaf" -
"Copernicus.WaterWet" -
"Copernicus.SoilSeal" -
"Copernicus.GrassLand" -
"Copernicus.RiparianGreen" -
"Copernicus.RiparianLandCover" -
"Copernicus.Natura2k" -
"Copernicus.UrbanAtlas" -
"ParquesNaturales" -
"ParquesNaturales.Limites" -
"ParquesNaturales.ZonasPerifericas"
Source
https://dieghernan.github.io/leaflet-providersESP/, a plugin for leaflet, v1.3.3.
See Also
Included package datasets:
esp_codelist,
esp_nuts_2024,
pobmun25
Examples
data("esp_tiles_providers")
# Get a single provider.
single <- esp_tiles_providers[["IGNBase.Todo"]]
single$static
single$leaflet
Population of Spain by municipality (2025)
Description
Population of Spain by municipality (2025)
Format
A tibble object with 8,132 rows containing population data by municipality in Spain for 2025.
- cpro
INE code of the province.
- provincia
Name of the province.
- cmun
INE code of the municipality.
- name
Name of the municipality.
- pob25
Total population (2025).
- men
Male population (2025).
- women
Female population (2025).
Source
INE, Instituto Nacional de Estadística. https://www.ine.es/dyngs/INEbase/categoria.htm?c=Estadistica_P&cid=1254734710990.
See Also
Included package datasets:
esp_codelist,
esp_nuts_2024,
esp_tiles_providers
Examples
data("pobmun25")