Get static map tiles based on a spatial object. Maps can be fetched from various open map servers.
This function is a implementation of the javascript plugin leaflet-providersESP v1.3.0.
esp_getTiles(
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
)An sf or sfc object.
Name of the provider. See leaflet.providersESP.df.
Zoom level. If NULL, it is determined automatically. If set,
it overrides zoommin. Only valid for WMTS tiles. On a single point it
applies a buffer to the point and on zoom = NULL the function set a zoom
level of 18. See Details.
Delta on default zoom. The default value is designed to
download fewer tiles than you probably want. Use 1 or 2 to
increase the resolution.
TRUE if results should be cropped to the specified x extent,
FALSE otherwise. If x is an sf object with one POINT, crop is set
to FALSE.
Resolution (in pixels) of the final tile. Only valid for WMS.
A numeric value that indicates the expansion percentage
of the bounding box of x.
Logical. Provides transparent background, if supported.
Depends on the selected provider on type.
TRUE if the result should be masked to x.
A logical whether to update cache. Default is FALSE.
When set to TRUE it would force a fresh download of the source file.
A path to a cache directory. See About caching.
Logical, displays information. Useful for debugging,
default is FALSE.
A named list containing additional options to pass to the query.
A SpatRaster is returned, with 3 (RGB) or 4 (RGBA) layers, depending on
the provider. See terra::rast().
.
You can set your cache_dir with esp_set_cache_dir().
Sometimes cached files may be corrupt. On that case, try re-downloading
the data setting update_cache = TRUE.
If you experience any problem on download, try to download the
corresponding .geojson file by any other method and save it on your
cache_dir. Use the option verbose = TRUE for debugging the API 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 leaflet.providersESP.df.
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)
Other imagery utilities:
addProviderEspTiles(),
layer_spatraster(),
leaflet.providersESP.df
# NOT RUN {
# This script downloads tiles to your local machine
# Run only if you are online
Murcia <- esp_get_ccaa_siane("Murcia", epsg = 3857)
Tile <- esp_getTiles(Murcia)
library(ggplot2)
ggplot(Murcia) +
layer_spatraster(Tile) +
geom_sf(fill = NA)
# }
Run the code above in your browser using DataLab