| Title: | Administrative Boundaries of Spain |
|---|---|
| Description: | Administrative boundaries of Spain at several levels (Autonomous Communities, provinces and municipalities), based on 'GISCO' from 'Eurostat' <https://ec.europa.eu/eurostat/web/gisco> and 'CartoBase ANE' from 'Instituto Geográfico Nacional' <https://www.ign.es/>. It also provides a plugin for the 'leaflet' package and tools to download and process static map tiles. |
| Authors: | Diego Hernangómez [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-8457-4658>), Eurostat [cph] (ROR: <https://ror.org/033d3q980>), Instituto Geográfico Nacional [cph] (ROR: <https://ror.org/03yycdv57>), Francisco J. Goerlich [ctb] (ORCID: <https://orcid.org/0000-0003-1626-525X>) |
| Maintainer: | Diego Hernangómez <[email protected]> |
| License: | GPL-3 |
| Version: | 1.1.0.9000 |
| Built: | 2026-06-05 14:40:15 UTC |
| Source: | https://github.com/rOpenSpain/mapSpain |
Add a tile layer from Spanish public administrations to a leaflet map
addProviderEspTiles( map, provider, layerId = NULL, group = NULL, options = leaflet::providerTileOptions() )addProviderEspTiles( map, provider, layerId = NULL, group = NULL, options = leaflet::providerTileOptions() )
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 |
modified map object
https://dieghernan.github.io/leaflet-providersESP/, a plugin for leaflet, v1.3.3.
leaflet::leaflet(), leaflet::addTiles(), leaflet::addWMSTiles(),
esp_tiles_providers.
Functions for image-based maps and tile providers:
esp_get_tiles(),
esp_make_provider()
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) ) leafmaplibrary(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
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_dir directory and its contents.
Clears the value stored in Sys.getenv("MAPSPAIN_CACHE_DIR").
esp_clear_cache(config = FALSE, cached_data = TRUE, verbose = FALSE)esp_clear_cache(config = FALSE, cached_data = TRUE, verbose = FALSE)
config |
Logical. If |
cached_data |
Logical. If |
verbose |
logical. If |
This is an aggressive function intended to reset your installation as if you had never installed or used mapSpain.
Invisible. This function is called for its side effects.
Cache management utilities:
esp_set_cache_dir()
# 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)# 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)
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 levels. See the note below for coverage details.
A tibble with 59 rows and columns:
NUTS 1 code.
NUTS 1 name.
NUTS 1 alternative name.
NUTS 1 short (common) name (Spanish).
INE code of the Autonomous Community.
ISO2 code of the Autonomous Community.
NUTS 2 code.
INE name of the Autonomous Community.
ISO2 name of the Autonomous Community (Spanish).
ISO2 name of the Autonomous Community (Catalan).
ISO2 name of the Autonomous Community (Galician).
ISO2 name of the Autonomous Community (Basque).
NUTS 2 name.
CLDR name of the Autonomous Community (English).
CLDR name of the Autonomous Community (Spanish).
CLDR name of the Autonomous Community (Catalan).
CLDR name of the Autonomous Community (Galician).
CLDR name of the Autonomous Community (Basque).
Short (common) name of the Autonomous Community (English).
Short (common) name of the Autonomous Community (Spanish).
Short (common) name of the Autonomous Community (Catalan).
Short (common) name of the Autonomous Community (Galician).
Short (common) name of the Autonomous Community (Basque).
INE code of the province.
ISO2 code of the province.
NUTS code of the province.
INE name of the province.
ISO2 name of the province (Spanish).
ISO2 name of the province (Catalan).
ISO2 name of the province (Galician).
ISO2 name of the province (Basque).
CLDR name of the province (English).
CLDR name of the province (Spanish).
CLDR name of the province (Catalan).
CLDR name of the province (Galician).
CLDR name of the province (Basque).
Short (common) name of the province (English).
Short (common) name of the province (Spanish).
Short (common) name of the province (Catalan).
Short (common) name of the province (Galician).
Short (common) name of the province (Basque).
NUTS 3 code.
NUTS 3 name.
NUTS 3 short (common) name.
Although NUTS2 aligns with the first subdivision level of Spain (Autonomous Communities), 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.
INE: Instituto Nacional de Estadistica: 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
Included package datasets:
esp_nuts_2024,
esp_tiles_providers,
pobmun25
data("esp_codelist") esp_codelistdata("esp_codelist") esp_codelist
Convert Spanish subdivision names or identifiers between different coding schemes such as NUTS, ISO2 and province codes, or obtain human-readable names.
esp_dict_region_code(sourcevar, origin = "text", destination = "text") esp_dict_translate(sourcevar, lang = "en", all = FALSE)esp_dict_region_code(sourcevar, origin = "text", destination = "text") esp_dict_translate(sourcevar, lang = "en", all = FALSE)
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 |
lang |
Character string. Target language code, available values:
|
all |
Logical. If |
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.
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, a character vector with the translated name for each
element of sourcevar.
If all = TRUE, a named list is returned where each element contains
all available translations for the corresponding input value.
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)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)
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.
esp_get_can_box( style = c("right", "left", "box", "poly"), moveCAN = TRUE, epsg = 4258 ) esp_get_can_provinces(moveCAN = TRUE, epsg = "4258")esp_get_can_box( style = c("right", "left", "box", "poly"), moveCAN = TRUE, epsg = 4258 ) esp_get_can_provinces(moveCAN = TRUE, epsg = "4258")
style |
Character string. One of |
moveCAN |
A logical |
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
The style parameter controls the geometry returned:
"box": a rectangular boundary returned as a LINESTRING.
"poly": a slightly expanded rectangle returned as a filled POLYGON.
"left" / "right": decorative LINESTRING variants that follow
the western or eastern side of the islands respectively.
An sf object: a POLYGON (when style = "poly") or a
LINESTRING (other styles).
Coordinates of esp_get_can_provinces() derived from CartoBase ANE
(se89_mult_admin_provcan_l.shp).
Helpers for Canary Islands insets and displacement:
esp_move_can()
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() )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() )
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().
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 )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 )
year |
Character string or number. Release year, it must be in
formats |
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to do caching. Default is |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
region |
Optional. A vector of region names, NUTS or ISO codes
(see |
munic |
Character string. A name or |
moveCAN |
A logical |
rawcols |
Logical. Setting this to |
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 municipalities of that level will be added.
A sf object.
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.
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:
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
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.
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:
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()
# 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")# 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")
Returns Autonomous Communities of Spain at a specified scale.
esp_get_ccaa(ccaa = NULL, moveCAN = TRUE, ...)esp_get_ccaa(ccaa = NULL, moveCAN = TRUE, ...)
ccaa |
Character string. A vector of names, codes or both for
Autonomous Communities, or |
moveCAN |
A logical |
... |
Arguments passed on to
|
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.
A sf object.
Please check the download and usage provisions on
giscoR::gisco_attributions().
https://gisco-services.ec.europa.eu/distribution/v2/.
Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.
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()
ccaa <- esp_get_ccaa() library(ggplot2) ggplot(ccaa) + geom_sf() # Random Autonomous Communities 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 of a NUTS1 region 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 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"))ccaa <- esp_get_ccaa() library(ggplot2) ggplot(ccaa) + geom_sf() # Random Autonomous Communities 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 of a NUTS1 region 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 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"))
Returns Autonomous Communities of Spain at a specified scale.
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 )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 )
ccaa |
Character string. A vector of names, codes or both for
Autonomous Communities, or |
year |
Character string or number. Release year, it must be in
formats |
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to do caching. Default is |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
resolution |
Character string or number. Resolution of the geospatial data. One of:
|
moveCAN |
A logical |
rawcols |
Logical. Setting this to |
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.
A sf object.
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:
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
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.
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:
esp_get_capimun(),
esp_get_countries_siane(),
esp_get_munic_siane(),
esp_get_prov_siane(),
esp_get_spain_siane(),
esp_siane_bulk_download()
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")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")
Returns Comarcas of Spain. Comarcas are traditional informal territorial divisions, comprising several municipalities sharing geographical, economic or cultural traits, typically with poorly defined limits.
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 )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 )
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. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
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.
A sf object.
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), in the region of El Bierzo (Castilla y Leon) and Aragon. Galicia, the Principality of Asturias and Andalusia have functional comarcas.
esp_get_comarca() can retrieve several types of comarcas, each one
provided under different classification criteria.
"INE": Comarcas defined by the National Statistics Institute (INE).
"IGN": Official comarcas, only available in some Autonomous Communities,
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).
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.
INE: PC_Axis files, IGN, Ministry of Agriculture, Fisheries and Food (MAPA).
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()
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")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")
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.
esp_get_countries_siane( year = Sys.Date(), epsg = 4258, cache = TRUE, update_cache = FALSE, cache_dir = NULL, verbose = FALSE, country = NULL )esp_get_countries_siane( year = Sys.Date(), epsg = 4258, cache = TRUE, update_cache = FALSE, cache_dir = NULL, verbose = FALSE, country = NULL )
year |
Character string or number. Release year, it must be in
formats |
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to do caching. Default is |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
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 |
A sf object.
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:
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
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.
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:
esp_get_capimun(),
esp_get_ccaa_siane(),
esp_get_munic_siane(),
esp_get_prov_siane(),
esp_get_spain_siane(),
esp_siane_bulk_download()
cntries <- esp_get_countries_siane() library(ggplot2) ggplot(cntries) + geom_sf()cntries <- esp_get_countries_siane() library(ggplot2) ggplot(cntries) + geom_sf()
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:
esp_get_grid_BDN() extracts country-wide regular grids with resolutions
of 5x5 or 10x10 kilometers (mainland Spain or Canary Islands).
esp_get_grid_BDN_ccaa() extracts 1x1 kilometer resolution grids for
individual Autonomous Communities.
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.
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 )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 )
resolution |
Numeric. Resolution of the grid in kilometers. Must be one of:
|
type |
Character. The geographic scope of the grid:
|
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
ccaa |
Character string. A vector of names, codes or both for
Autonomous Communities. See Details on |
The BDN provides standardized geographic grids for Spain that follow the
Nature Data Bank's specifications. The data is downloaded from the
sianedata/MITECO/dist data branch and is regularly updated.
A sf object.
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.
Geographical grid datasets:
esp_get_grid_ESDAC(),
esp_get_grid_MTN()
# 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")# 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")
Loads a sf POLYGON with the geographic grids of Spain as
provided by the European Soil Data Centre (ESDAC).
esp_get_grid_ESDAC( resolution = c(10, 1), update_cache = FALSE, cache_dir = NULL, verbose = FALSE )esp_get_grid_ESDAC( resolution = c(10, 1), update_cache = FALSE, cache_dir = NULL, verbose = FALSE )
resolution |
Numeric. Resolution of the grid in kilometers. Can be |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
A sf POLYGON.
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.
Geographical grid datasets:
esp_get_grid_BDN(),
esp_get_grid_MTN()
## 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)## 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)
Loads a sf POLYGON with the geographic grids of Spain.
esp_get_grid_MTN( grid = "MTN25_ETRS89_Peninsula_Baleares_Canarias", update_cache = FALSE, cache_dir = NULL, verbose = FALSE )esp_get_grid_MTN( grid = "MTN25_ETRS89_Peninsula_Baleares_Canarias", update_cache = FALSE, cache_dir = NULL, verbose = FALSE )
grid |
Name of the grid to be loaded. See Details. |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
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 |
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.
A sf POLYGON.
IGN data distributed through the sianedata/MTN data branch (see
https://github.com/rOpenSpain/mapSpain/tree/sianedata/MTN).
Geographical grid datasets:
esp_get_grid_BDN(),
esp_get_grid_ESDAC()
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")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")
sf hexbin or squared POLYGON of SpainLoads a hexbin map (sf object) or a map of squares with the
boundaries of the provinces or Autonomous Communities of Spain.
esp_get_hex_prov(prov = NULL) esp_get_hex_ccaa(ccaa = NULL) esp_get_grid_prov(prov = NULL) esp_get_grid_ccaa(ccaa = NULL)esp_get_hex_prov(prov = NULL) esp_get_hex_ccaa(ccaa = NULL) esp_get_grid_prov(prov = NULL) esp_get_grid_ccaa(ccaa = NULL)
prov, ccaa
|
Character. A vector of names, codes or both for provinces
and Autonomous Communities, or |
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 (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.
A sf object.
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()
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") 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") 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")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") 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") 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 are the areas of land and sea, made up of one or more neighbouring river basins together with their associated groundwaters and coastal waters.
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") )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") )
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to do caching. Default is |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
resolution |
Character string or number. Resolution of the geospatial data. One of:
|
domain |
Character string. Type of river basin district. Possible
values are |
Metadata available on https://github.com/rOpenSpain/mapSpain/tree/sianedata/.
A sf object.
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:
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
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.
Natural feature datasets:
esp_get_hypsobath(),
esp_get_landwater
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()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()
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.
esp_get_hypsobath( epsg = 4258, cache = TRUE, update_cache = FALSE, cache_dir = NULL, verbose = FALSE, resolution = c(3, 6.5), spatialtype = c("area", "line") )esp_get_hypsobath( epsg = 4258, cache = TRUE, update_cache = FALSE, cache_dir = NULL, verbose = FALSE, resolution = c(3, 6.5), spatialtype = c("area", "line") )
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to do caching. Default is |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
resolution |
Character string or number. Resolution of the geospatial data. One of:
|
spatialtype |
Character string. Spatial type of the output. Use
|
Metadata available on https://github.com/rOpenSpain/mapSpain/tree/sianedata/.
A sf object.
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:
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
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.
Natural feature datasets:
esp_get_hydrobasin(),
esp_get_landwater
# 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 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 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 ))# 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 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 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 ))
Object representing rivers, lagoons, reservoirs and wetlands of Spain.
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 )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 )
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to do caching. Default is |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
resolution |
|
spatialtype |
|
moveCAN |
A logical |
name |
Character string or |
Metadata available on https://github.com/rOpenSpain/mapSpain/tree/sianedata/.
A sf object.
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:
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
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.
Natural feature datasets:
esp_get_hydrobasin(),
esp_get_hypsobath()
# 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 )# 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 )
This dataset shows boundaries of municipalities in Spain.
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" )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" )
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. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. 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 |
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 municipalities of that level will be added.
A sf object.
Please check the download and usage provisions on
giscoR::gisco_attributions().
https://gisco-services.ec.europa.eu/distribution/v2/.
Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units.
giscoR::gisco_get_lau(), giscoR::gisco_get_communes().
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()
# 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") )# 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") )
This dataset shows boundaries of municipalities in Spain.
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 )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 )
year |
Character string or number. Release year, it must be in
formats |
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to do caching. Default is |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. 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. Setting this to |
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 municipalities of that level will be added.
A sf object.
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.
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:
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
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.
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:
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()
# 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 = "Changes on boundaries over time", fill = "" )# 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 = "Changes on boundaries over time", fill = "" )
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:
NUTS 1: major socio-economic regions
NUTS 2: basic regions for the application of regional policies
NUTS 3: small regions for specific diagnoses.
Also, there is a NUTS 0 level, which usually corresponds to the national boundaries.
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" )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" )
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 do caching. Default is |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
resolution |
character string or number. Resolution of the geospatial data. 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 |
character string. NUTS level. One of |
moveCAN |
A logical |
ext |
Character. Extension of the file (default |
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.
A sf object.
Please check the download and usage provisions on
giscoR::gisco_attributions().
https://gisco-services.ec.europa.eu/distribution/v2/.
Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.
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()
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")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")
Returns provinces of Spain at a specified scale.
esp_get_prov(prov = NULL, moveCAN = TRUE, ...)esp_get_prov(prov = NULL, moveCAN = TRUE, ...)
prov |
A vector of names, codes or both for provinces, or |
moveCAN |
A logical |
... |
Arguments passed on to
|
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.
A sf object.
Please check the download and usage provisions on
giscoR::gisco_attributions().
https://gisco-services.ec.europa.eu/distribution/v2/.
Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.
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()
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()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()
Returns provinces of Spain at a specified scale.
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 )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 )
prov |
A vector of names, codes or both for provinces, or |
year |
Character string or number. Release year, it must be in
formats |
epsg |
Character string or number. Projection of the map: 4-digit EPSG code. One of:
|
cache |
Logical. Whether to do caching. Default is |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
resolution |
Character string or number. Resolution of the geospatial data. One of:
|
moveCAN |
A logical |
rawcols |
Logical. Setting this to |
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.
A sf object.
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:
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
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.
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:
esp_get_capimun(),
esp_get_ccaa_siane(),
esp_get_countries_siane(),
esp_get_munic_siane(),
esp_get_spain_siane(),
esp_siane_bulk_download()
library(ggplot2) esp_get_ccaa_siane() |> dplyr::glimpse() |> ggplot() + geom_sf()library(ggplot2) esp_get_ccaa_siane() |> dplyr::glimpse() |> ggplot() + geom_sf()
Loads a sf LINESTRING or POINT object representing the
nodes and railway lines of Spain.
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 )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 )
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 |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
spatialtype |
|
A sf object.
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:
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
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.
Transport infrastructure datasets:
esp_get_roads()
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()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()
Object representing the main roads of Spain.
esp_get_roads( year = Sys.Date(), epsg = "4258", cache = TRUE, update_cache = FALSE, cache_dir = NULL, verbose = FALSE, moveCAN = TRUE )esp_get_roads( year = Sys.Date(), epsg = "4258", cache = TRUE, update_cache = FALSE, cache_dir = NULL, verbose = FALSE, moveCAN = TRUE )
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 |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
moveCAN |
A logical |
A sf object.
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:
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
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.
Transport infrastructure datasets:
esp_get_railway()
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")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 with the boundaries of the provinces or Autonomous communities of Spain, as provided by the INE (Instituto Nacional de Estadistica).
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 )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 )
prov, ccaa
|
Character. A vector of names, codes or both for provinces
and Autonomous Communities, or |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
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).
A sf object.
INE: PC_Axis files
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()
prov_simp <- esp_get_simpl_prov() library(ggplot2) ggplot(prov_simp) + geom_sf(aes(fill = ine.ccaa.name)) + labs(fill = "Autonomous Communities") # Provinces of a single Autonomous Community. and_simple <- esp_get_simpl_prov("Andalucia") ggplot(and_simple) + geom_sf() # Autonomous Communities. ccaa_simp <- esp_get_simpl_ccaa() ggplot(ccaa_simp) + geom_sf() + geom_sf_text(aes(label = ine.ccaa.name), check_overlap = TRUE)prov_simp <- esp_get_simpl_prov() library(ggplot2) ggplot(prov_simp) + geom_sf(aes(fill = ine.ccaa.name)) + labs(fill = "Autonomous Communities") # Provinces of a single Autonomous Community. and_simple <- esp_get_simpl_prov("Andalucia") ggplot(and_simple) + geom_sf() # Autonomous Communities. ccaa_simp <- esp_get_simpl_ccaa() ggplot(ccaa_simp) + geom_sf() + geom_sf_text(aes(label = ine.ccaa.name), check_overlap = TRUE)
Returns the boundaries of Spain as a single sf POLYGON at a
specified scale.
esp_get_spain(moveCAN = TRUE, ...)esp_get_spain(moveCAN = TRUE, ...)
moveCAN |
A logical |
... |
Arguments passed on to
|
Dataset derived from NUTS data provided by GISCO. Check esp_get_nuts() for
details.
A sf POLYGON object.
Please check the download and usage provisions on
giscoR::gisco_attributions().
https://gisco-services.ec.europa.eu/distribution/v2/.
Copyright: https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units.
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()
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")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")
Returns the boundaries of Spain as a single sf POLYGON.
esp_get_spain_siane(moveCAN = TRUE, ...)esp_get_spain_siane(moveCAN = TRUE, ...)
moveCAN |
A logical |
... |
Arguments passed on to
|
A sf object.
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:
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
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.
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:
esp_get_capimun(),
esp_get_ccaa_siane(),
esp_get_countries_siane(),
esp_get_munic_siane(),
esp_get_prov_siane(),
esp_siane_bulk_download()
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")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 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.
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)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)
x |
|
type |
This argument can be either:
|
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. Provides transparent background, if supported. |
mask |
Logical. |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
verbose |
logical. If |
options |
A named list containing additional options to pass to the query. |
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)
A SpatRaster with 3 (RGB) or 4 (RGBA) layers, depending on
the provider. See terra::rast().
https://dieghernan.github.io/leaflet-providersESP/, a plugin for leaflet, v1.3.3.
terra::rast(), esp_tiles_providers
Functions for image-based maps and tile providers:
addProviderEspTiles(),
esp_make_provider()
## 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)## 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)
Helper function for esp_get_tiles() that helps to create a custom provider.
esp_make_provider(id, q, service, layers, ...)esp_make_provider(id, q, service, layers, ...)
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 |
layers |
The name of the layer to retrieve. |
... |
Additional arguments to the query, like |
This function is meant to work with services provided as of the OGC Standard.
Note that:
mapSpain will not provide advice on the argument q to be
provided.
Currently, on WMTS requests only services with
tilematrixset=GoogleMapsCompatible are supported.
A named list with two elements id and q.
For a list of potential providers from Spain check IDEE Directory.
Functions for image-based maps and tile providers:
addProviderEspTiles(),
esp_get_tiles()
## 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)## 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)
sf object located in the Canary IslandsHelper 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.
esp_move_can(x, moveCAN = TRUE)esp_move_can(x, moveCAN = TRUE)
x |
An |
moveCAN |
A logical |
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.
A sf object of the same class and same CRS as x
but displaced accordingly.
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 (for example, 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.
Helpers for Canary Islands insets and displacement:
esp_get_can_box()
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" )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" )
sf objectThis 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.
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.
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.
NUTS_RG_01M_2024_4326.gpkg file.
Included package datasets:
esp_codelist,
esp_tiles_providers,
pobmun25
data("esp_nuts_2024") head(esp_nuts_2024)data("esp_nuts_2024") head(esp_nuts_2024)
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.
esp_set_cache_dir( cache_dir = NULL, overwrite = FALSE, install = FALSE, verbose = TRUE ) esp_detect_cache_dir()esp_set_cache_dir( cache_dir = NULL, overwrite = FALSE, install = FALSE, verbose = TRUE ) esp_detect_cache_dir()
cache_dir |
A path to a cache directory. When |
overwrite |
Logical. If |
install |
Logical. If |
verbose |
logical. If |
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").
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.
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_dir argument 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.
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.
Cache management utilities:
esp_clear_cache()
# 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()# 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()
Download zipped data from SIANE to the cache_dir
and extract the relevant ones.
esp_siane_bulk_download( cache_dir = NULL, update_cache = FALSE, verbose = FALSE )esp_siane_bulk_download( cache_dir = NULL, update_cache = FALSE, verbose = FALSE )
cache_dir |
Character string. A path to a cache directory. See
Caching strategies section in |
update_cache |
Logical. Should the cached file be refreshed? Default
is |
verbose |
logical. If |
A (invisible) character vector with the full path of the files extracted. See Examples.
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:
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
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.
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:
esp_get_capimun(),
esp_get_ccaa_siane(),
esp_get_countries_siane(),
esp_get_munic_siane(),
esp_get_prov_siane(),
esp_get_spain_siane()
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 file is already cached :) # Clean unlink(tmp, force = TRUE, recursive = TRUE)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 file is already cached :) # Clean unlink(tmp, force = TRUE, recursive = TRUE)
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.
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.
leaflet with additional parameters to pass to addProviderEspTiles().
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"
https://dieghernan.github.io/leaflet-providersESP/, a plugin for leaflet, v1.3.3.
Included package datasets:
esp_codelist,
esp_nuts_2024,
pobmun25
data("esp_tiles_providers") # Get a single provider single <- esp_tiles_providers[["IGNBase.Todo"]] single$static single$leafletdata("esp_tiles_providers") # Get a single provider single <- esp_tiles_providers[["IGNBase.Todo"]] single$static single$leaflet
Population of Spain by municipality (2025)
A tibble object with 8,132 rows containing population data by municipality in Spain for 2025.
INE code of the province.
Name of the province.
INE code of the municipality.
Name of the municipality.
Total population (2025).
Male population (2025).
Female population (2025).
INE: Instituto Nacional de Estadistica https://www.ine.es/dyngs/INEbase/categoria.htm?c=Estadistica_P&cid=1254734710990.
Included package datasets:
esp_codelist,
esp_nuts_2024,
esp_tiles_providers
data("pobmun25")data("pobmun25")