getTiles {cartography} | R Documentation |
Get map tiles based on a spatial object extent. Maps can be fetched from various open map servers.
getTiles(
x,
type = "OpenStreetMap",
zoom = NULL,
crop = FALSE,
verbose = FALSE,
apikey = NA,
cachedir = FALSE,
forceDownload = FALSE
)
x |
an sf object, a simple feature collection or a Spatial*DataFrame. |
type |
the tile server from which to get the map. See Details for providers. For other sources use a list: type = list(src = "name of the source" , q = "tiles address", sub = "subdomains", cit = "how to cite the tiles"). See Examples. |
zoom |
the zoom level. If null, it is determined automatically (see Details). |
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. |
verbose |
if TRUE, tiles filepaths, zoom level and citation are displayed. |
apikey |
Needed for Thunderforest maps. |
cachedir |
name of a directory used to cache tiles. If TRUE, places a 'tile.cache' folder in the working directory. If FALSE, tiles are not cached. |
forceDownload |
if TRUE, cached tiles are downloaded again. |
Zoom levels are described on the OpenStreetMap wiki:
https://wiki.openstreetmap.org/wiki/Zoom_levels.
Full list of providers:
'OpenStreetMap' (or 'osm') | 'Stamen' (or 'stamenbw') | 'Esri' |
'OpenStreetMap.DE' | 'Stamen.Toner' | 'Esri.WorldStreetMap' |
'OpenStreetMap.France' | 'Stamen.TonerBackground' | 'Esri.DeLorme' |
'OpenStreetMap.HOT' (or 'hotstyle') | 'Stamen.TonerHybrid' | 'Esri.WorldTopoMap' |
'Stamen.TonerLines' | 'Esri.WorldImagery' | |
'OpenMapSurfer' | 'Stamen.TonerLabels' | 'Esri.WorldTerrain' |
'OpenMapSurfer.Roads' | 'Stamen.TonerLite' | 'Esri.WorldShadedRelief' |
'OpenMapSurfer.Hybrid' | 'Stamen.Watercolor' (or 'stamenwatercolor') | 'Esri.OceanBasemap' |
'OpenMapSurfer.AdminBounds' | 'Stamen.Terrain' | 'Esri.NatGeoWorldMap' |
'OpenMapSurfer.ElementsAtRisk' | 'Stamen.TerrainBackground' | 'Esri.WorldGrayCanvas' |
'Stamen.TerrainLabels' | ||
'CartoDB' | 'Hydda' | |
'CartoDB.Positron' (or 'cartolight') | 'Thunderforest' | 'Hydda.Full' |
'CartoDB.PositronNoLabels' | 'Thunderforest.OpenCycleMap' | 'Hydda.Base' |
'CartoDB.PositronOnlyLabels' | 'Thunderforest.Transport' | 'Hydda.RoadsAndLabels' |
'CartoDB.DarkMatter' (or 'cartodark') | 'Thunderforest.TransportDark' | |
'CartoDB.DarkMatterNoLabels' | 'Thunderforest.SpinalMap' | 'HikeBike' (or 'hikebike') |
'CartoDB.DarkMatterOnlyLabels' | 'Thunderforest.Landscape' | 'HikeBike.HikeBike' |
'CartoDB.Voyager' | 'Thunderforest.Outdoors' | |
'CartoDB.VoyagerNoLabels' | 'Thunderforest.Pioneer' | 'OpenTopoMap' (or 'opentopomap') |
'CartoDB.VoyagerOnlyLabels' | 'Thunderforest.MobileAtlas' | 'Wikimedia' |
'CartoDB.VoyagerLabelsUnder' | 'Thunderforest.Neighbourhood' | 'OpenStreetMap.MapnikBW' (or 'osmgrayscale') |
A RasterBrick is returned.
https://leaflet-extras.github.io/leaflet-providers/preview/
## Not run:
library(sf)
mtq <- st_read(system.file("gpkg/mtq.gpkg", package="cartography"))
# Download the tiles, extent = Martinique
mtqOSM <- getTiles(x = mtq, type = "osm", crop = TRUE)
# Plot the tiles
tilesLayer(mtqOSM)
# Plot countries
plot(st_geometry(mtq), add=TRUE)
txt <- paste0("\u00A9 OpenStreetMap contributors.",
" Tiles style under CC BY-SA, www.openstreetmap.org/copyright")
mtext(text = txt, side = 1, adj = 0, cex = 0.7, font = 3)
# Download esri tiles
fullserver = paste("https://server.arcgisonline.com/ArcGIS/rest/services",
"Specialty/DeLorme_World_Base_Map/MapServer",
"tile/{z}/{y}/{x}.jpg",
sep = "/"
)
typeosm <- list(
src = 'esri',
q = fullserver,
sub = NA,
cit = 'Tiles; Esri; Copyright: 2012 DeLorme'
)
mtqESRI <- getTiles(x = mtq, type = typeosm, crop = TRUE, verbose = T, zoom = 10)
# Plot the tiles
tilesLayer(mtqESRI)
txt <- typeosm$cit
mtext(text = txt, side = 1, adj = 0, cex = 0.6, font = 3)
## End(Not run)