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.2.0.

esp_getTiles(
  x,
  type = "IDErioja",
  zoom = NULL,
  crop = TRUE,
  res = 512,
  bbox_expand = 0.05,
  transparent = TRUE,
  mask = FALSE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

x

An sf object.

type

Name of the provider. See leaflet.providersESP.df.

zoom

Zoom level. If NULL, it is determined automatically. Only valid for WMTS.

crop

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.

res

Resolution (in pixels) of the final tile. Only valid for WMS.

bbox_expand

A numeric value that indicates the expansion percentage of the bounding box of x.

transparent

Logical. Provides transparent background, if supported. Depends on the selected provider on type.

mask

TRUE if the result should be masked to x.

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.

Source

https://dieghernan.github.io/leaflet-providersESP/ leaflet plugin, v1.2.0.

Value

A RasterBrick is returned, with 3 (RGB) or 4 (RGBA) layers, depending on the provider. .

Details

Zoom levels are described on the OpenStreetMap wiki: https://wiki.openstreetmap.org/wiki/Zoom_levels.

Results of esp_getTiles could be plotted using raster::plotRGB(), tmap::tm_rgb(), etc.

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)

Tiles are cached under the path cache_dir/[type].

See also

Author

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

Examples

# \dontrun{ # This script downloads tiles to your local machine # Run only if you are online library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
Murcia <- esp_get_ccaa("Murcia") Murcia <- st_transform(Murcia, 3857) Tile <- esp_getTiles(Murcia) library(tmap) tm_shape(Tile, raster.downsample = FALSE) + tm_rgb(interpolate = FALSE) + tm_shape(Murcia) + tm_borders()
# }