View source: R/esp-get-tiles.R
| esp_get_tiles | R Documentation |
Get static map tiles based on a spatial object. Maps can be fetched from WMS and WMTS providers.
This function is an implementation of the JavaScript plugin leaflet-providersESP v1.3.3.
esp_get_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
)
x |
An |
type |
This argument can be one of:
|
zoom |
Character string or number. Only valid for WMTS providers, zoom
level to be downloaded. If |
zoommin |
Character string or number. Delta on default |
crop |
Logical. If |
res |
Character string or number. Only valid for WMS providers. Resolution (in pixels) of the final tile. |
bbox_expand |
Number. Expansion percentage of the bounding box of |
transparent |
Logical. Whether to use a transparent background, if supported. |
mask |
Logical. |
update_cache |
Logical. If |
cache_dir |
Character string. A path to a cache directory. See Caching. |
verbose |
A logical value indicating whether to display informational messages. |
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". If the tile looks deformed, try
projecting x first:
x <- sf::st_transform(x, 3857)
A SpatRaster with 3 (RGB) or 4 (RGBA) layers, depending on
the provider. See terra::rast().
Functions that download data store files in cache_dir. When cache_dir
is NULL, they use the active package cache, which defaults to a temporary
directory. Set update_cache = TRUE to replace an existing cached file.
See Caching strategies in esp_set_cache_dir() to configure a
persistent cache.
https://dieghernan.github.io/leaflet-providersESP/, a plugin for leaflet, v1.3.3.
terra::rast().
esp_tiles_providers.
Static map tiles and imagery:
addProviderEspTiles(),
esp_get_attributions(),
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.