R/sits_services.R

Defines functions sits_services

Documented in sits_services

#' @title Provides information about the time series services available
#' @name sits_services
#'
#' @description Uses the configuration file to print information
#'     about the services, products and coverages.
#'     WTSS - The Web Time Series Service is a lightweight web service that
#'     allow remote access to satellite image time series
#'     and provides three operations:
#'
#'  1. listCoverages: returns a list of data cubes
#'     available in a server instance.
#'
#'  2. describeCoverage: this operation returns the metadata for a data cube
#'     identified by its name.
#'
#'  3. timeSeries: this operation requests the time series of values of a cube
#'    at a given location.
#'
#' EOCUBES - The EOCubes service is a lightweight link data package
#'  that allows remote access to satellite
#'  image data cubes. It has the following functions:
#'
#'  1. listCubes: returns a list of data cubes
#'     available in a server instance.
#'
#'  2. describeCube: returns the metadata for a given data cube
#'     identified by its name.
#'
#'  3. GetDataCube: creates a metadata description of a data cube.
#' @export
sits_services <- function() {
    services <- sits.env$config$services

    for (s in services) {

        if (s == "WTSS") {
            # find the URL of the WTSS service in the configuration file
            URL  <- .sits_config_server(s)
            # check if the service is running
            wtss_ok <- .sits_wtss_check(URL)
            # if service is running, describe it
            if (wtss_ok) {
                wtss.obj <- suppressMessages(wtss::WTSS(URL))
                assertthat::assert_that(!purrr::is_null(wtss.obj),
                   msg = "sits_cube - WTSS service not responding - check URL")
                cubes     <- wtss.obj$coverages

                cat(paste0("Service: \"", s,"\"\n"))
                for (c_name in cubes) {
                    cat(paste0("   Cube: \"", c_name, "\"\n"))

                    # describe the data cube
                    wtss::describe_coverage(wtss.obj, c_name)
                }
            }
            else
                message(paste0("WTSS service not running: please check config"))
        }
        else if (s == "SATVEG") {
            # check if the service is running
            satveg_ok <- .sits_satveg_check()
            # if service is running, describe it
            if (satveg_ok) {
                q <- "SATVEG-EMBRAPA_cubes"
                cubes <- sits.env$config[[q]]

                for (cb in cubes) {
                    cat(paste0("   Cube: \"", cb, "\"\n"))
                    q1 <- paste0(s, "_bands")
                    bands <- sits.env$config[[q1]][[cb]]
                    cat(paste0("      Bands: \"",
                               paste(bands, collapse = "\", \""), "\"\n"))
                }
            }
            else
                message(paste0("Default SATVEG service not running -
                               please check configuration file"))

        } else if (s == "EOCUBES") {
            # find the URL of the EOCUBES service in the configuration file
            URL  <- .sits_config_server(s)
            # check if the service is running
            eocubes_ok <- .sits_eocubes_check(URL)
            # if service is running, describe it
            if (eocubes_ok) {
                cat(paste0("Service: \"", s,"\"\n"))

                remote.obj   <- EOCubes::remote(name = "eocubes")
                cubes <- names(EOCubes::list_cubes(remote.obj))

                for (cb in cubes) {
                    cat(paste0("   Cube: \"", cb, "\"\n"))
                    cub.obj <- EOCubes::cube(cb, remote.obj)
                    cat(paste0("      Bands: \"",
                        paste(EOCubes::cube_bands(cub.obj),
                              collapse = "\", \""), "\"\n"))
                }
            }
            else
                message(paste0("Default EOCUBES service not running -
                               please check configuration file"))
        }
    }
}
e-sensing/sits.data documentation built on Dec. 26, 2019, 11:02 p.m.