Download a raster layer from IGN Web Mapping Services (WMS).
To do that, it need a location giving by a shape, an apikey
and the name of layer. You can find those information from
IGN website
or with get_apikeys()
and get_layers_metadata()
.
Usage
get_wms_raster(x,
apikey = "altimetrie",
layer = "ELEVATION.ELEVATIONGRIDCOVERAGE",
res = 25,
filename = tempfile(fileext = ".tif"),
crs = 2154,
overwrite = FALSE,
version = "1.3.0",
styles = "",
interactive = FALSE)
Arguments
- x
Object of class
sf
orsfc
. Needs to be located in France.- apikey
character
; API key fromget_apikeys()
or directly from IGN website.- layer
character
; layer name fromget_layers_metadata(apikey, "wms")
or directly from IGN website.- res
numeric
; resolution in the unit of the coordinate system (e.g. meter for 2154). See detail for more information aboutres
.- filename
character
orNULL
; filename or a open connection for writing. (ex : "test.tif" or "~/test.tif"). IfNULL
,layer
is used as filename. Default drivers is ".tif" but all gdal drivers are supported, see details for more info.- crs
numeric
,character
, or object of classsf
orsfc
. It is set to EPSG:2154 by default. Seesf::st_crs()
for more detail.- overwrite
If TRUE, output raster is overwrite.
- version
character
; version of the service used. See details for more info.- styles
character
; rendering style of the layer. Set to "" by default. See details for more info.- interactive
logical
; If TRUE, interactive menu ask forapikey
andlayer
.
Details
res
: Warning, settingres
higher than default layer resolution multiplies the number of pixels without increasing the precision. For example, the download of the BD Alti layer from IGN will be optimal for a resolution of 25m.version
andstyles
arguments are detailed on IGN documentationfilename
: All GDAL supported drivers can be found hereoverwrite
:get_wms raster
always checks thatfilename
does not already exist. If it does, it is imported into R without further downloading unlessoverwrite
is set toTRUE
.
Examples
if (FALSE) {
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, 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(apikey, "wms") # all layers for altimetrie wms
layer <- metadata_table[2,1] # ELEVATION.ELEVATIONGRIDCOVERAGE
# Downloading digital elevation model from IGN
mnt_2154 <- get_wms_raster(penmarch, apikey, layer, res = 25)
# If crs is set to 4326, res is in degrees
mnt_4326 <- get_wms_raster(penmarch, apikey, layer, res = 0.0005, crs = 4326)
# Plotting result
tm_shape(mnt_4326)+
tm_raster()+
tm_shape(penmarch)+
tm_borders(col = "blue", lwd = 3)
}