Loads a simple feature (sf) object containing the municipalities boundaries of Spain.

esp_get_munic uses GISCO (Eurostat) as source.

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

esp_get_munic(
  year = "2019",
  epsg = "4258",
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  region = NULL,
  munic = NULL,
  moveCAN = TRUE
)

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

Arguments

year

Release year. See Details for years available.

epsg

projection of the map: 4-digit EPSG code. One of:

  • "4258": ETRS89

  • "4326": WGS84

  • "3035": ETRS89 / ETRS-LAEA

  • "3857": Pseudo-Mercator

cache

A logical whether to do caching. Default is TRUE.

update_cache

A logical whether to update cache. Default is FALSE. When set to TRUE it would force a fresh download of the source .geojson file.

cache_dir

A path to a cache directory. The directory can also be set globally with:

See Details on esp_get_nuts().

verbose

Display information. Useful for debugging, default is FALSE.

region

A vector of names and/or codes for provinces or NULL to get all the municipalities. See Details.

munic

A name or regex expression with the names of the required municipalities. NULL would not produce any filtering.

moveCAN

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

resolution

Resolution of the polygon. Values available are "3", "6.5" or "10".

rawcols

Logical. Setting this to TRUE would add the raw columns of the dataset provided by IGN.

Source

GISCO API

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

Value

A POLYGON object.

Details

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

When calling a superior level (Province, Autonomous Community or NUTS1) , all the municipalities of that level would be added.

On esp_get_munic years available are: 2001, 2004, 2006, 2008, 2010, 2013 and any year between 2016 and 2019.

On esp_get_munic_siane, year could be passed as a single year ("YYYY" format, as end of year) or as a specific date ("YYYY-MM-DD" format). Historical information starts as of 2005.

See also

Author

dieghernan, https://github.com/dieghernan/

Examples

Base <- esp_get_munic(region = c("Castilla y Leon")) SAN <- esp_get_munic( region = c("Castilla y Leon"), munic = c("^San ", "^Santa ") ) library(tmap) tm_shape(Base) + tm_polygons("#FDFBEA", border.col = "#656565", border.alpha = 0.3) + tm_shape(SAN) + tm_polygons("#C12838", border.col = "#656565") + tm_layout( main.title = paste0( "Municipalities named under Saints (San, Santa)", "\nCastilla y Leon, Spain" ), main.title.size = .8 )