
Get static tiles from public administrations of Spain
Source:R/esp-get-tiles.R, R/esp-get-attributions.R
esp_get_tiles.RdGet static map tiles based on a spatial object. Maps can be fetched from various open map servers.
This function is an implementation of the javascript plugin leaflet-providersESP v1.3.3.
esp_get_attributions gets the attribution of a tile provider defined as
the type argument.
Usage
esp_get_tiles(
x,
type = "IDErioja",
zoom = NULL,
zoommin = 0,
crop = TRUE,
res = 512,
bbox_expand = 0.05,
transparent = TRUE,
mask = FALSE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
options = NULL
)
esp_get_attributions(type, options = NULL)Source
https://dieghernan.github.io/leaflet-providersESP/ leaflet plugin, v1.3.3.
Arguments
- x
- type
This argument can be either:
The name of one of the pre-defined providers (see esp_tiles_providers).
A list with two named elements
idandqwith your own arguments. Seeesp_make_provider()and examples.
- zoom
character string or number. Only valid for WMTS providers, zoom level to be downloaded. If
NULL, it is determined automatically. If set, it overrideszoommin. If a singlesfPOINTandzoom = NULL, the function sets a zoom level of 18. See Details.- zoommin
character string or number. Delta on default
zoom. The default value is designed to download fewer tiles than you probably want. Use1or2to increase the resolution.- crop
logical. If
TRUE, the results will be cropped to the specifiedxextent. Ifxis ansfobject with onePOINT,cropis set toFALSE. Seeterra::crop().- res
character string or number. Only valid for WMS providers. Resolution (in pixels) of the final tile.
- bbox_expand
number. Expansion percentage of the bounding box of
x.- transparent
logical. Provides transparent background, if supported.
- mask
logical.
TRUEif the result should be masked tox. Seeterra::mask().- update_cache
logical. Should the cached file be refreshed? Default is
FALSE. When set toTRUE, it will force a new download.- cache_dir
character string. A path to a cache directory. See Caching strategies section in
esp_set_cache_dir().- verbose
logical. If
TRUEdisplays informational messages.- options
A named list containing additional options to pass to the query.
Value
A SpatRaster with 3 (RGB) or 4 (RGBA) layers, depending on
the provider. See terra::rast().
Details
Zoom levels are described on the OpenStreetMap wiki:
| zoom | area to represent |
| 0 | whole world |
| 3 | large country |
| 5 | state |
| 8 | county |
| 10 | metropolitan area |
| 11 | city |
| 13 | village or suburb |
| 16 | streets |
| 18 | some buildings, trees |
For a complete list of providers see esp_tiles_providers.
Most WMS/WMTS providers provide tiles on
"EPSG:3857". In case that the tile looks deformed,
try projecting first x:
x <- sf::st_transform(x, 3857)
See also
terra::rast(), esp_tiles_providers, maptiles::get_tiles()
Other functions for creating maps with images:
addProviderEspTiles(),
esp_make_provider()
Examples
# \dontrun{
# 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)
#>
#> Attaching package: 'tidyterra'
#> The following object is masked from 'package:stats':
#>
#> filter
ggplot(segovia) +
geom_spatraster_rgb(data = tile, maxcell = Inf) +
geom_sf(fill = NA, linewidth = 1)
# Another provider
tile2 <- esp_get_tiles(segovia, type = "MDT")
ggplot(segovia) +
geom_spatraster_rgb(data = tile2, maxcell = Inf) +
geom_sf(fill = NA, linewidth = 1, color = "red")
# A custom WMS provided
custom_wms <- esp_make_provider(
id = "an_id_for_caching",
q = "https://idecyl.jcyl.es/geoserver/ge/wms?",
service = "WMS",
version = "1.3.0",
format = "image/png",
layers = "geolog_cyl_litologia"
)
custom_wms_tile <- esp_get_tiles(segovia, custom_wms)
autoplot(custom_wms_tile, maxcell = Inf) +
geom_sf(data = segovia, fill = NA, color = "red", linewidth = 1)
# A custom WMTS provider
custom_wmts <- esp_make_provider(
id = "cyl_wmts",
q = "https://www.ign.es/wmts/pnoa-ma?",
service = "WMTS",
layer = "OI.OrthoimageCoverage"
)
custom_wmts_tile <- esp_get_tiles(segovia, custom_wmts)
autoplot(custom_wmts_tile, maxcell = Inf) +
geom_sf(data = segovia, fill = NA, color = "white", linewidth = 1)
# Example from https://leaflet-extras.github.io/leaflet-providers/preview/
cartodb_dark <- list(
id = "CartoDB_DarkMatter",
q = "https://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png"
)
cartodb_dark_tile <- esp_get_tiles(segovia, cartodb_dark,
zoommin = 1,
update_cache = TRUE
)
autoplot(cartodb_dark_tile, maxcell = Inf) +
geom_sf(data = segovia, fill = NA, color = "white", linewidth = 1)
# }