a plumber2 function to get imagery for a website from a URI (/vsizip//vsicurl/ vsiaz, WMTS: etc etc)
#* @get /tile
#* @serializer image/png
function(query) {
Sys.setenv(
GDAL_CACHEMAX = "2048", # MB for block cache
VSI_CACHE = "TRUE", # Cache remote reads
VSI_CACHE_SIZE = "500000000", # 500MB
GDAL_HTTP_MULTIPLEX = "YES", # HTTP/2 multiplexing
GDAL_HTTP_MAX_RETRY = "3"
)
bbox_raw <- query$bbox
if (is.null(bbox_raw)) {
bbox <- c(-1000000, -1000000, 1000000, 1000000)
} else if (length(bbox_raw) == 4) {
bbox <- as.numeric(bbox_raw)
} else {
bbox <- as.numeric(strsplit(bbox_raw, ",")[[1]])
}
crs <- if (!is.null(query$crs)) query$crs[1] else "EPSG:3031"
source <- if (!is.null(query$source)) query$source[1] else "/data/ibcso-small.tif"
source <- if (!is.null(query$source)) query$source[1] else "/data/ibcso-small.tif"
message("Received source: ", source)
width <- if (!is.null(query$width)) query$width[1] else "256"
height <- if (!is.null(query$height)) query$height[1] else "256"
png_dsn <- tempfile(tmpdir = "/vsimem", fileext = ".png")
#dsn <- sprintf("vrt://%s?scale=true&ot=Byte", source)
dsn <- source
gdalraster::warp(
dsn, png_dsn, t_srs = crs,
cl_arg = c("-ts", width, height, "-te", as.character(bbox), "-r", "bilinear", "-ot", "Byte")
)
vsi <- new(VSIFile, png_dsn)
png_bytes <- vsi$ingest(-1)
vsi$close()
vsi_unlink(png_dsn)
png_bytes
}
here is the current js content, I'm still actively working on what I want this for