Title: | Download and Display Map Tiles |
---|---|
Description: | To create maps from tiles, 'maptiles' downloads, composes and displays tiles from a large number of providers (e.g. 'OpenStreetMap', 'Stadia', 'Esri', 'CARTO', or 'Thunderforest'). |
Authors: | Timothée Giraud [cre, aut] , Diego Hernangómez [ctb] , Robert J. Hijmans [ctb] , Hugh A. Graham [ctb] |
Maintainer: | Timothée Giraud <[email protected]> |
License: | GPL-3 |
Version: | 0.8.0 |
Built: | 2024-11-21 05:51:00 UTC |
Source: | https://github.com/riatelab/maptiles |
Use this function to create new tiles provider.
create_provider(name, url, sub = NA, citation)
create_provider(name, url, sub = NA, citation)
name |
name of the provider. |
url |
url of the provider. The url must contain {x}, {y} and {z} placeholders. It may also contain {s} for sub-domains or {apikey} for API keys (see Examples). |
sub |
sub-domains. |
citation |
attribution text of the provider. |
a list is returned. This list can be used by get_tiles.
statdia_toner <- create_provider( name = "stadia_stamen_toner", url = "https://tiles.stadiamaps.com/tiles/stamen_toner/{z}/{x}/{y}.png?api_key={apikey}", citation = "© Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors" ) opentopomap <- create_provider( name = "otm", url = "https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png", sub = c("a", "b", "c"), citation = "map data: © OpenStreetMap contributors, SRTM | map style: © OpenTopoMap (CC-BY-SA)" ) IGN <- create_provider( name = "orthophoto_IGN", url = paste0( "https://data.geopf.fr/wmts?", "request=GetTile", "&service=WMTS", "&version=1.0.0", "&style=normal", "&tilematrixset=PM_6_18", "&format=image/jpeg", "&layer=ORTHOIMAGERY.ORTHOPHOTOS.BDORTHO", "&tilematrix={z}", "&tilerow={y}", "&tilecol={x}" ), citation = "IGN, BD ORTHO®" ) # Find TileMatrixSet and Style values layer <- "ORTHOIMAGERY.ORTHOPHOTOS.BDORTHO" path <- "https://data.geopf.fr/wmts?" param_info <- "service=wmts&request=GetCapabilities&version=1.0.0" url <- paste0("WMTS:", path, param_info, ",layer=", layer) ## Not run: tmp <- tempfile(fileext = ".xml") sf::gdal_utils( util = "translate", source = url, destination = tmp, options = c("-of", "WMTS") ) readLines(tmp) ## End(Not run)
statdia_toner <- create_provider( name = "stadia_stamen_toner", url = "https://tiles.stadiamaps.com/tiles/stamen_toner/{z}/{x}/{y}.png?api_key={apikey}", citation = "© Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors" ) opentopomap <- create_provider( name = "otm", url = "https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png", sub = c("a", "b", "c"), citation = "map data: © OpenStreetMap contributors, SRTM | map style: © OpenTopoMap (CC-BY-SA)" ) IGN <- create_provider( name = "orthophoto_IGN", url = paste0( "https://data.geopf.fr/wmts?", "request=GetTile", "&service=WMTS", "&version=1.0.0", "&style=normal", "&tilematrixset=PM_6_18", "&format=image/jpeg", "&layer=ORTHOIMAGERY.ORTHOPHOTOS.BDORTHO", "&tilematrix={z}", "&tilerow={y}", "&tilecol={x}" ), citation = "IGN, BD ORTHO®" ) # Find TileMatrixSet and Style values layer <- "ORTHOIMAGERY.ORTHOPHOTOS.BDORTHO" path <- "https://data.geopf.fr/wmts?" param_info <- "service=wmts&request=GetCapabilities&version=1.0.0" url <- paste0("WMTS:", path, param_info, ",layer=", layer) ## Not run: tmp <- tempfile(fileext = ".xml") sf::gdal_utils( util = "translate", source = url, destination = tmp, options = c("-of", "WMTS") ) readLines(tmp) ## End(Not run)
Get the attribution of map tiles.
get_credit(provider)
get_credit(provider)
provider |
provider name or provider object (as produced by create_provider). |
get_credit("OpenStreetMap")
get_credit("OpenStreetMap")
List of builtin providers with their name, URL, subdomains and attribution text.
get_providers()
get_providers()
A list of is returned.
get_providers()
get_providers()
Get map tiles based on a spatial object extent. Maps can be fetched from various map servers.
get_tiles( x, provider = "OpenStreetMap", zoom, crop = FALSE, project = TRUE, verbose = FALSE, apikey, cachedir, forceDownload = FALSE )
get_tiles( x, provider = "OpenStreetMap", zoom, crop = FALSE, project = TRUE, verbose = FALSE, apikey, cachedir, forceDownload = FALSE )
x |
sf, sfc, bbox, SpatRaster, SpatVector or SpatExtent object.
If |
provider |
tile server to get the tiles from. It can be one of the builtin providers (see Details for the list) or a named list produced by create_provider (see Examples). |
zoom |
zoom level (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. |
project |
if TRUE, the output is projected to the crs of x. If FALSE the output uses "EPSG:3857" (Web Mercator). |
verbose |
if TRUE, tiles filepaths, zoom level and attribution are displayed. |
apikey |
API key. Not needed for Thunderforest or Stadia servers if environment variables named "THUNDERFOREST_MAPS" or "STADIA_MAPS" are set. |
cachedir |
name of a folder used to cache tiles. If not set, tiles are cached in a tempdir folder. |
forceDownload |
if TRUE, existing cached tiles may be overwritten. |
Zoom levels are described in the OpenStreetMap wiki:
https://wiki.openstreetmap.org/wiki/Zoom_levels.
Providers:
"OpenStreetMap", "OpenStreetMap.DE", "OpenStreetMap.France",
"OpenStreetMap.HOT", "OpenTopoMap",
"Stadia.StamenToner", "Stadia.StamenTonerBackground",
"Stadia.StamenTonerLines", "Stadia.StamenTonerLabels",
"Stadia.StamenTonerLite",
"Stadia.StamenWatercolor", "Stadia.StamenTerrain",
"Stadia.StamenTerrainBackground",
"Stadia.StamenTerrainLabels",
"Esri.WorldStreetMap",
"Esri.WorldTopoMap", "Esri.WorldImagery", "Esri.WorldTerrain",
"Esri.WorldShadedRelief", "Esri.OceanBasemap", "Esri.NatGeoWorldMap",
"Esri.WorldGrayCanvas",
"CartoDB.Positron", "CartoDB.PositronNoLabels",
"CartoDB.PositronOnlyLabels", "CartoDB.DarkMatter",
"CartoDB.DarkMatterNoLabels",
"CartoDB.DarkMatterOnlyLabels", "CartoDB.Voyager", "CartoDB.VoyagerNoLabels",
"CartoDB.VoyagerOnlyLabels",
"Thunderforest.OpenCycleMap", "Thunderforest.Transport",
"Thunderforest.TransportDark", "Thunderforest.SpinalMap",
"Thunderforest.Landscape",
"Thunderforest.Outdoors", "Thunderforest.Pioneer",
"Thunderforest.MobileAtlas",
"Thunderforest.Neighbourhood"
A SpatRaster is returned.
## Not run: library(sf) library(maptiles) nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) nc_osm <- get_tiles(nc, crop = TRUE, zoom = 6) plot_tiles(nc_osm) # Create a provider from a custom url osm_tiles <- create_provider( name = "osm_tiles", url = "https://tile.openstreetmap.org/{z}/{x}/{y}.png", citation = "© OpenStreetMap contributors." ) # Download tiles and compose raster (SpatRaster) nc_osm2 <- get_tiles( x = nc, provider = osm_tiles, crop = FALSE, zoom = 6, project = FALSE, verbose = TRUE ) # Plot the tiles plot_tiles(nc_osm2) # Add attribution mtext(get_credit(osm_tiles), side = 1, line = -1) ## End(Not run)
## Not run: library(sf) library(maptiles) nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) nc_osm <- get_tiles(nc, crop = TRUE, zoom = 6) plot_tiles(nc_osm) # Create a provider from a custom url osm_tiles <- create_provider( name = "osm_tiles", url = "https://tile.openstreetmap.org/{z}/{x}/{y}.png", citation = "© OpenStreetMap contributors." ) # Download tiles and compose raster (SpatRaster) nc_osm2 <- get_tiles( x = nc, provider = osm_tiles, crop = FALSE, zoom = 6, project = FALSE, verbose = TRUE ) # Plot the tiles plot_tiles(nc_osm2) # Add attribution mtext(get_credit(osm_tiles), side = 1, line = -1) ## End(Not run)
To create maps from tiles, maptiles downloads, composes and displays tiles from a large number of providers (e.g. OpenStreetMap, Stamen, Esri, CARTO, or Thunderforest).
Maintainer: Timothée Giraud [email protected] (ORCID)
Other contributors:
Diego Hernangómez (ORCID) [contributor]
Robert J. Hijmans (ORCID) [contributor]
Hugh A. Graham [contributor]
Useful links:
Plot map tiles.
plot_tiles(x, adjust = FALSE, add = FALSE, ...)
plot_tiles(x, adjust = FALSE, add = FALSE, ...)
x |
a SpatRaster object. |
adjust |
if TRUE, plot the raster without zoom-in or zoom-out in the graphic device: add margins if the raster is smaller than the graphic device, zoom-in if the raster is larger than the graphic device. This feature does not work with an unprojected (lon/lat) raster. |
add |
whether to add the layer to an existing plot (TRUE) or not (FALSE). |
... |
bgalpha, smooth, or other arguments passed to be passed to
|
This function is a wrapper for plotRGB
from the terra package.
## Not run: library(sf) library(maptiles) nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) nc_osm <- get_tiles(nc, crop = TRUE) plot_tiles(nc_osm) ## End(Not run)
## Not run: library(sf) library(maptiles) nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) nc_osm <- get_tiles(nc, crop = TRUE) plot_tiles(nc_osm) ## End(Not run)