Skip to content

WMS examples

Michael Sumner edited this page Oct 14, 2022 · 1 revision
## remotes::install_github("hypertidy/vapour")
## remotes::install_github("hypertidy/whatarelief")

library(vapour)
## I obtained this string by doing
## gdalinfo WMS:https://imagery.pasda.psu.edu/arcgis/services/pasda/PhillyLULC/MapServer/WmsServer?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=0&

wms <- 'WMS:https://imagery.pasda.psu.edu/arcgis/services/pasda/PhillyLULC/MapServer/WmsServer?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=1&SRS=EPSG:4326&BBOX=-75.284169,39.861285,-74.954036,40.143799'
## this is like gdalinfo, but just a list of details
info <- vapour_raster_info(wms)
library(whatarelief)  ## a helper to read data or colours from raster sources
ex <- info$extent  ## use the whole extent
dm <- c(1024, 1024) ## choose a size (otherwise, the default is massive info$dimension)
## get the imagery (this is just a matrix of pixels)
im <- imagery(source = wms, extent = ex, dimension = dm, projection = info$projection)
#img <- imagery(extent = ex, dimension = dm, projection = info$projection)
ximage::ximage(im, extent = ex)
## convert to terra
#library(terra)
#r <- rast(im)
#ext(r) <- ext(ex)
#crs(r) <- info$projection
#plotRGB(r, alpha = 150, add = T)
Clone this wiki locally