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 = NULL,
overwrite = FALSE,
verbose = TRUE,
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"). The default format is ".tif" but all GDAL drivers are supported. When a filename is provided, the function uses it as a cache: if the file already exists andoverwrite
is set toFALSE
, the function will directly load the raster from that file instead of re-downloading it.- overwrite
boolean
; if TRUE, the existing raster will be overwritten.- verbose
boolean
; if TRUE, message are added.- interactive
logical
; if TRUE, an interactive menu prompts forapikey
andlayer
argument.
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. See examples below.
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)
} # }