get_wms_raster {happign} | R Documentation |
Download WMS raster layer
Description
Download a raster layer from the IGN Web Mapping Services (WMS). Specify a location using a shape and provide the layer name.
Usage
get_wms_raster(x,
layer = "ORTHOIMAGERY.ORTHOPHOTOS",
res = 10,
crs = 2154,
rgb = TRUE,
filename = tempfile(fileext = ".tif"),
verbose = TRUE,
overwrite = FALSE,
interactive = FALSE)
Arguments
x |
Object of class |
layer |
|
res |
|
crs |
|
rgb |
|
filename |
|
verbose |
|
overwrite |
|
interactive |
|
Details
-
res
: Note that settingres
higher than the default resolution of the layer will increase the number of pixels but not the precision of the image. For instance, downloading the BD Alti layer from IGN is optimal at a resolution of 25m. -
rgb
: Rasters are commonly used to download images such as orthophotos. In specific cases like DEMs, however, a value per pixel is essential. -
overwrite
: The functionget_wms_raster
first checks iffilename
already exists. If it does, the file is imported into R without downloading again, unlessoverwrite
is set toTRUE
.
Value
SpatRaster
object from terra
package.
See Also
Examples
## Not run:
library(sf)
library(tmap)
# Shape from the best town in France
penmarch <- read_sf(system.file("extdata/penmarch.shp", package = "happign"))
# For quick testing use interactive = TRUE
raster <- get_wms_raster(x = penmarch, res = 25, interactive = TRUE)
# For specific data, choose apikey with get_apikey() and layer with get_layers_metadata()
apikey <- get_apikeys()[4] # altimetrie
metadata_table <- get_layers_metadata("wms-r", apikey) # all layers for altimetrie wms
layer <- metadata_table[2,1] # ELEVATION.ELEVATIONGRIDCOVERAGE
# Downloading digital elevation model values not image
mnt_2154 <- get_wms_raster(penmarch, layer, res = 1, crs = 2154, rgb = FALSE)
# If crs is set to 4326, res is in degrees
mnt_4326 <- get_wms_raster(penmarch, layer, res = 0.0001, crs = 4326, rgb = FALSE)
# Plotting result
tm_shape(mnt_4326)+
tm_raster()+
tm_shape(penmarch)+
tm_borders(col = "blue", lwd = 3)
## End(Not run)