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.

Super classes

plumber::Hookable -> plumber::Plumber -> starsTileServer

Methods

Inherited methods


Method new()

This method is used to initialize a new tile server

Usage

starsTileServer$new(grid, colorFun = NULL, tileSize = 256, ...)

Arguments

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.

Details

If grid is a function it should take a stars grid as the first argument and return the grid with the same topology with values attached. Any other arguments to the function will be part of the API and will be passed to the function as characters.

Returns

An starsTileServer object.


Method add_tile_endpoint()

Add three endpoints to the tile server, to return both the tiles and the color scale used.

Usage

starsTileServer$add_tile_endpoint(prefix, handlerFun, colorFun, params)

Arguments

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


Method get_grid()

return the grid used to initialize the function

Usage

starsTileServer$get_grid()


Method get_attributes()

return the attributes of the stars grid

Usage

starsTileServer$get_attributes()


Method get_dimensions()

return the names of the dimensions of the grid

Usage

starsTileServer$get_dimensions()


Method get_dimension_values_chr()

return the values of a dimension as a character

Usage

starsTileServer$get_dimension_values_chr(x)

Arguments

x

the name of the dimension


Method get_non_spatial_dimensions()

return all non spatial dimensions

Usage

starsTileServer$get_non_spatial_dimensions()


Method clone()

The objects of this class are cloneable with this method.

Usage

starsTileServer$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

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()
}