R/starsTileServer.R
starsTileServer.Rd
Creates a tile server based on the R6 class plumber::Plumber
.
In can be created both with a stars
grid as well as a function or list of functions.
The main methods are run
and new
.
plumber::Hookable
-> plumber::Plumber
-> starsTileServer
Inherited methods
plumber::Hookable$registerHooks()
plumber::Plumber$addAssets()
plumber::Plumber$addEndpoint()
plumber::Plumber$addFilter()
plumber::Plumber$addGlobalProcessor()
plumber::Plumber$call()
plumber::Plumber$filter()
plumber::Plumber$getApiSpec()
plumber::Plumber$getDebug()
plumber::Plumber$handle()
plumber::Plumber$mount()
plumber::Plumber$onHeaders()
plumber::Plumber$onWSOpen()
plumber::Plumber$openAPIFile()
plumber::Plumber$print()
plumber::Plumber$registerHook()
plumber::Plumber$removeHandle()
plumber::Plumber$route()
plumber::Plumber$run()
plumber::Plumber$serve()
plumber::Plumber$set404Handler()
plumber::Plumber$setApiSpec()
plumber::Plumber$setDebug()
plumber::Plumber$setDocs()
plumber::Plumber$setDocsCallback()
plumber::Plumber$setErrorHandler()
plumber::Plumber$setParsers()
plumber::Plumber$setSerializer()
plumber::Plumber$swaggerFile()
plumber::Plumber$unmount()
new()
This method is used to initialize a new tile server
starsTileServer$new(grid, colorFun = NULL, tileSize = 256, ...)
grid
Either a stars grid, a path pointing towards a gridded file, a function or a list of named functions
colorFun
a color function to use for coloring the map tiles, the function needs to be the same format as leaflet::colorNumeric()
. It is important to specify a color function as it is important to keep the range of the color scale similar between tiles, therefore the minimum and maximum needs to be fixed. It can also be a list of color functions.
tileSize
The size of the tile (generally 256 pixels, and not tested with other sizes)
...
Arguments passed on to the plumber::Plumber, most important is the port
number.
add_tile_endpoint()
Add three endpoints to the tile server, to return both the tiles and the color scale used.
prefix
the name to be used by the server for this tile server
handlerFun
The function that handles the api request and returns the grid
colorFun
The color function to use for example leaflet::colorNumeric()
params
parameters passed on to the new
method of plumber::PlumberEndpoint
m <- matrix(1:20, nrow = 5, ncol = 4)
dim(m) <- c(x = 5, y = 4) # named dim
(s <- stars::st_as_stars(m))
#> stars object with 2 dimensions and 1 attribute
#> attribute(s):
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> A1 1 5.75 10.5 10.5 15.25 20
#> dimension(s):
#> from to offset delta refsys point values x/y
#> x 1 5 0 1 NA FALSE NULL [x]
#> y 1 4 0 1 NA FALSE NULL [y]
sf::st_crs(s) <- 4326
starsTileServer$new(s)
#> # Plumber router with 3 endpoints, 5 filters, and 0 sub-routers.
#> # Use `pr_run()` on this object to start the API.
#> ├──[queryString]
#> ├──[body]
#> ├──[cookieParser]
#> ├──[sharedSecret]
#> ├──[cors]
#> ├──/map
#> │ ├──/A1
#> │ │ ├──/<z:int>
#> │ │ │ ├──/<x:int>
#> │ │ │ │ └──/<y:int> (GET)
#> │ │ ├──/colorfunction (GET)
#> │ │ └──/colorfunctionnoalpha (GET)
#>
# Working directly from a file
grid <- system.file("tif/L7_ETMs.tif", package = "stars")
starsTileServer$new(grid)
#> # Plumber router with 3 endpoints, 5 filters, and 0 sub-routers.
#> # Use `pr_run()` on this object to start the API.
#> ├──[queryString]
#> ├──[body]
#> ├──[cookieParser]
#> ├──[sharedSecret]
#> ├──[cors]
#> ├──/map
#> │ ├──/L7_ETMs.tif
#> │ │ ├──/<z:int>
#> │ │ │ ├──/<x:int>
#> │ │ │ │ └──/<y:int> (GET)
#> │ │ ├──/colorfunction (GET)
#> │ │ └──/colorfunctionnoalpha (GET)
#>
if (FALSE) {
starsTileServer$new(s)$run()
}