wmts: OGC Webmap Tile Server (WMTS)

Description Usage Arguments Details Value Examples

View source: R/wmts.R

Description

Get raster from WMTS

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
wmts(
  x,
  loc,
  buffer = NULL,
  silent = FALSE,
  ...,
  zoom = NULL,
  max_tiles = 9,
  bands = 1:3,
  sds = 1L
)

Arguments

x

WMTS address, either the raw 'WMTSCapabilities.xml' or an expanded GDAL 'WMTS:<url>[],options]' driver data source

loc

something we can get an extent from

buffer

radius in metres (in the case 'loc' is a single point, and is longlat)

silent

suppress messages (default is FALSE)

...

ignored

zoom

override hueristic for zoom level (take care! no safety checks)

max_tiles

max number of tiles for zoom hueristic (default 25)

bands

bands to get (default is 1,2,3 assuming RGB)

sds

which subdataset to read if there are multiple (defaults to 1)

Details

Beware that if 'zoom' is set the 'max_tiles' argument is ignored. Use the function defaults to discover a reasonable zoom level, then re-run with a higher (more pixels) or lower (fewer pixels) zoom level.

Value

raster brick

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
centre <- c(-80.888, 32.332)  ## lonlat
radius <- 4000                ## metres
u <- file.path("https://basemap.nationalmap.gov/arcgis/rest",
               "services/USGSTopo/MapServer/WMTS/1.0.0/WMTSCapabilities.xml")
x <- wmts(u, centre, buffer = radius)
# u1 <- sprintf("WMTS:%s,layer=USGSTopo,tilematrixset=default028mm", u)
# x <- wmts(u1, centre, buffer = radius)
# x <- wmts(u, cbind(0, 0), buffer = 20037508)
raster::plotRGB(x, interpolate = TRUE) ## use interpolate to match to device size
#f <- system.file("gpkg/nc.gpkg", package = "sf", mustWork = TRUE)
#sf <- sf::read_sf(f)
#x <- wmts(u, sf)


#tab <- tibble::as_tibble(raster::as.data.frame(x, xy = TRUE))
#names(tab) <- c("x", "y", "red", "green", "blue")
##tab <- dplyr::filter(tab, !is.na(red))
#
### ... when we have missing values, we should drop them or rgb() will error
#tab$hex <- rgb(tab$red, tab$green, tab$blue, maxColorValue = 255)
#library(ggplot2)
#ggplot(tab, aes(x, y, fill = hex)) +
#   geom_raster(interpolate = TRUE) +
#   coord_equal() +
#   scale_fill_identity()

mdsumner/wmts documentation built on July 24, 2021, 3:06 p.m.