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
sf
orsfc
, located in France.- layer
character
; layer name obtained fromget_layers_metadata("wms-r")
or the IGN website.- res
numeric
; resolution specified in the units of the coordinate system (e.g., meters for EPSG:2154, degrees for EPSG:4326). See details for more information.- crs
numeric
,character
, or object of classsf
orsfc
; defaults to EPSG:2154. Seesf::st_crs()
for more details.- rgb
boolean
; if set toTRUE
, downloads an RGB image. If set toFALSE
, downloads a single band with floating point values. See details for more information.- filename
character
orNULL
; specifies the filename or an open connection for writing (e.g., "test.tif" or "~/test.tif"). IfNULL
, useslayer
as the filename. The default format is ".tif", but all GDAL drivers are supported.- verbose
boolean
; if TRUE, message are added.- overwrite
boolean
; if TRUE, the existing raster will be overwritten.- interactive
logical
; if TRUE, an interactive menu prompts forapikey
andlayer
.
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
.
Examples
if (FALSE) { # \dontrun{
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)
} # }