From 5bf5420632a6e12a5c7fd8426b10b6b326797e5f Mon Sep 17 00:00:00 2001 From: Sebastian Boeck Date: Tue, 8 Nov 2016 21:22:38 +0100 Subject: [PATCH] fills repo --- DESCRIPTION | 21 ++++-- NAMESPACE | 14 +++- R/S2_buy_granule.R | 18 ++++++ R/S2_check_access.R | 58 +++++++++++++++++ R/S2_do_query.R | 25 ++++++++ R/S2_download.R | 29 +++++++++ R/S2_generate_RGB.R | 109 ++++++++++++++++++++++++++++++++ R/S2_initialize_user.R | 20 ++++++ R/S2_put_ROI.R | 55 ++++++++++++++++ R/S2_query_angle.R | 55 ++++++++++++++++ R/S2_query_granule.R | 57 +++++++++++++++++ R/S2_query_image.R | 64 +++++++++++++++++++ R/S2_query_job.R | 53 ++++++++++++++++ R/S2_query_product.R | 47 ++++++++++++++ R/S2_vrt_L2Agranule.R | 50 +++++++++++++++ R/jgeom_to_SpatialPolygons.R | 36 +++++++++++ R/roi_to_jgeom.R | 38 +++++++++++ R/spat_to_jgeom.R | 38 +++++++++++ R/xy_to_jgeom.R | 38 +++++++++++ R/zzz.R | 9 +++ man/S2_buy_granule.Rd | 15 +++++ man/S2_check_access.Rd | 20 ++++++ man/S2_do_query.Rd | 20 ++++++ man/S2_download.Rd | 22 +++++++ man/S2_generate_RGB.Rd | 48 ++++++++++++++ man/S2_initialize_user.Rd | 27 ++++++++ man/S2_put_ROI.Rd | 33 ++++++++++ man/S2_query_angle.Rd | 49 ++++++++++++++ man/S2_query_granule.Rd | 52 +++++++++++++++ man/S2_query_image.Rd | 59 +++++++++++++++++ man/S2_query_job.Rd | 47 ++++++++++++++ man/S2_query_product.Rd | 41 ++++++++++++ man/S2_vrt_L2Agranule.Rd | 28 ++++++++ man/jgeom_to_SpatialPolygons.Rd | 23 +++++++ man/roi_to_jgeom.Rd | 26 ++++++++ man/spat_to_jgeom.Rd | 21 ++++++ man/xy_to_jgeom.Rd | 26 ++++++++ 37 files changed, 1384 insertions(+), 7 deletions(-) create mode 100644 R/S2_buy_granule.R create mode 100644 R/S2_check_access.R create mode 100644 R/S2_do_query.R create mode 100644 R/S2_download.R create mode 100644 R/S2_generate_RGB.R create mode 100644 R/S2_initialize_user.R create mode 100644 R/S2_put_ROI.R create mode 100644 R/S2_query_angle.R create mode 100644 R/S2_query_granule.R create mode 100644 R/S2_query_image.R create mode 100644 R/S2_query_job.R create mode 100644 R/S2_query_product.R create mode 100644 R/S2_vrt_L2Agranule.R create mode 100644 R/jgeom_to_SpatialPolygons.R create mode 100644 R/roi_to_jgeom.R create mode 100644 R/spat_to_jgeom.R create mode 100644 R/xy_to_jgeom.R create mode 100644 R/zzz.R create mode 100644 man/S2_buy_granule.Rd create mode 100644 man/S2_check_access.Rd create mode 100644 man/S2_do_query.Rd create mode 100644 man/S2_download.Rd create mode 100644 man/S2_generate_RGB.Rd create mode 100644 man/S2_initialize_user.Rd create mode 100644 man/S2_put_ROI.Rd create mode 100644 man/S2_query_angle.Rd create mode 100644 man/S2_query_granule.Rd create mode 100644 man/S2_query_image.Rd create mode 100644 man/S2_query_job.Rd create mode 100644 man/S2_query_product.Rd create mode 100644 man/S2_vrt_L2Agranule.Rd create mode 100644 man/jgeom_to_SpatialPolygons.Rd create mode 100644 man/roi_to_jgeom.Rd create mode 100644 man/spat_to_jgeom.Rd create mode 100644 man/xy_to_jgeom.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 0c9e06d..e9df7ba 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,9 +1,20 @@ Package: sentinel2 -Title: What the Package Does (one line, title case) +Title: Tools to access Sentinel-2 data pre-processed by IVFL, BOKU Vienna Version: 0.0.0.9000 -Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre")) -Description: What the package does (one paragraph). -Depends: R (>= 3.2.2) -License: What license is it under? +Authors@R: person("Sebastian", "Boeck", email = "sebastian.boeck@boku.ac.at", role = c("aut", "cre")) +Description: Tools to conveniently query and access pre-processed Sentinel-2 + data. Registration to 'https://s2.boku.eodc.eu' is required for most operations. + Please consult the 'https://s2.boku.eodc.eu' (, i.e. the 'FAQ' and 'wiki' + pages), if you are unclear on how to use this package. +Depends: + R (>= 3.2.2) +Imports: + curl, + httr, + jsonlite, + raster, + sp +License: GPL-3 Encoding: UTF-8 LazyData: true +RoxygenNote: 5.0.1 diff --git a/NAMESPACE b/NAMESPACE index 884a631..d153f00 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,12 @@ -# Generated by roxygen2: fake comment so roxygen2 overwrites silently. -exportPattern("^[^\\.]") +# Generated by roxygen2: do not edit by hand + +export(S2_buy_granule) +export(S2_check_access) +export(S2_generate_RGB) +export(S2_initialize_user) +export(S2_put_ROI) +export(S2_query_angle) +export(S2_query_granule) +export(S2_query_image) +export(S2_query_job) +export(S2_query_product) diff --git a/R/S2_buy_granule.R b/R/S2_buy_granule.R new file mode 100644 index 0000000..341cdee --- /dev/null +++ b/R/S2_buy_granule.R @@ -0,0 +1,18 @@ +#' Buy a granule at 'https://s2.boku.eodc.eu' +#' +#' Buy granule using granuleId +#' +#' @param granuleId character the granuleId +#' @export + + +S2_buy_granule <- function(granuleId){ + user <- getOption("S2user") + password <- getOption("S2password") + rtrn <- httr::PUT('https://s2.boku.eodc.eu', + config = httr::authenticate(user, password), + path = list('granule', granuleId)) + jsonlite::fromJSON(httr::content(rtrn, as = 'text')) + return(invisible(rtrn)) +} + diff --git a/R/S2_check_access.R b/R/S2_check_access.R new file mode 100644 index 0000000..6335e2e --- /dev/null +++ b/R/S2_check_access.R @@ -0,0 +1,58 @@ +#' (Very basic) check if server/database can be accessed +#' +#' Checks accessibility of server / database and does basic checking of +#' user credentials +#' +#' @param verbose logical +#' @return logical \code{TRUE} if access to server was successfull and user +#' credentials seem to be valid, FALSE if 'anything' went wrong +#' @export + +S2_check_access <- function(verbose = TRUE){ + user <- getOption("S2user") + password <- getOption("S2password") + srvrsp <- httr::GET('https://s2.boku.eodc.eu/user/current', + config = httr::authenticate(user, password)) + + if (httr::status_code(srvrsp) == 200){ + if (httr::content(srvrsp)$userId == user){ + + if (isTRUE(verbose)){ + cat(sprintf("Logged in to 'https://s2.boku.eodc.eu' as %s\n", user)) + } + return(TRUE) + + } else if (httr::content(srvrsp)$userId == "public"){ + + if (user == "default" && password == "default"){ + if (isTRUE(verbose)){ + warning("Not logged in at 'https://s2.boku.eodc.eu' -> limited access to database:\n", + "please supply 'user' and 'password' via 'S2_initialize_user()'\n", + "see '?S2_intialize_user' for details!") + } + return(FALSE) + + } else { + + if (isTRUE(verbose)){ + warning("Not logged in to s2.boku.eodc.eu -> access to database limited:\n", + "please check credentials and use 'S2_initialize_user()' to\n", + "supply a valid 'user' and 'password'\n", + "see '?S2_intialize_user' or visit 'https://s2.boku.eodc.eu' for details!") + } + return(FALSE) + + } + } + } else { + + if (isTRUE(verbose)){ + warning(sprintf("Unable to access server! Status code %s returned", + httr::status_code(srvrsp))) + } + return(FALSE) + + } + +} + diff --git a/R/S2_do_query.R b/R/S2_do_query.R new file mode 100644 index 0000000..4143ba8 --- /dev/null +++ b/R/S2_do_query.R @@ -0,0 +1,25 @@ +#' Send a query to 'https://s2.boku.eodc.eu' +#' +#' Query database and return response as data.frame +#' +#' @param query list of named arguments 'known' to the database. Typically +#' created using e.g. 'S2_query_granule' +#' @param path character altering the query url with respect to the desired +#' output. One of "product", "granule", "image", "qiData", "angle", "roi", +#' "job", "rgb". + + +S2_do_query <- function(query, path){ + user <- getOption("S2user") + password <- getOption("S2password") + rtrn <- httr::GET('https://s2.boku.eodc.eu', + config = httr::authenticate(user, password), + path = path, + query = query) + rtrn <- jsonlite::fromJSON(httr::content(rtrn, as = 'text')) + return(rtrn) +} + + +# query <- S2_query_granule(utm = "33UWP", atmCorr = 1) +# S2_do_query(query, path='granule') diff --git a/R/S2_download.R b/R/S2_download.R new file mode 100644 index 0000000..996dbbe --- /dev/null +++ b/R/S2_download.R @@ -0,0 +1,29 @@ +#' S2_download helper function +#' +#' Simple helper function to zip download and unzip i.e. a 'granule' in a single +#' step +#' +#' @param url character (valid) url to download file from. +#' @param destfile character download destination. If \code{zip = TRUE}, the +#' ending '.zip' will be attached to destfile (, if it is not already). +#' @param zip logical if \code{TRUE}, the url will be downloaded as zip archive +#' and (automatically) unzipped in the parent directory of 'destfile' +#' @return NULL + +S2_download <- function(url, destfile, zip = TRUE){ + + if (isTRUE(zip)){ + url <- paste0(url, "?format=application/zip") + if (!grepl("[.]zip$", destfile)) destfile <- paste0(destfile, ".zip") + } + + curl::curl_download(url = url, destfile = destfile, quiet = TRUE) + + if (isTRUE(zip)) unzip(zipfile = destfile, exdir = dirname(destfile)) + + return(invisible(NULL)) +} + + + + diff --git a/R/S2_generate_RGB.R b/R/S2_generate_RGB.R new file mode 100644 index 0000000..7dbec6a --- /dev/null +++ b/R/S2_generate_RGB.R @@ -0,0 +1,109 @@ +#' Generate RGB image and download +#' +#' Generates 8-bit/channel composite image (see 'https://s2.boku.eodc.eu/wiki/' +#' for details) +#' +#' @param granuleId integer the granuleId for which to create the RGB composite +#' @param destfile character path to the output file. If destfile is a path to +#' an existing directory, a filename will be automatically generated. If NULL, +#' the file will be saved to the current working directory. If a filename is +#' supplied, it will have to have a '.tif' extension. +#' @param resolution integer desired (minimum) resolution, typically 10, 20 or 60. +#' @param atmCorr 0 (default) or 1, if atmospherically corrected bands should be +#' used +#' @param r character red band, e.g. "B08" +#' @param g character green band, e.g. "B04" +#' @param b character blue band, e.g. "B03" +#' @param ra see wiki +#' @param ga see wiki +#' @param ba see wiki +#' @param rb see wiki +#' @param gb see wiki +#' @param bb see wiki +#' @param overwrite logical, should existing files be overwritten? +#' @return NULL +#' @export + +S2_generate_RGB <- function(granuleId, + destfile = NULL, + resolution = 10, + atmCorr = 0, + r = "B08", + g = "B04", + b = "B03", + ra = 20, + ga = 20, + ba = 20, + rb = 20, + gb = 20, + bb = 20, + overwrite = FALSE){ + + query <- S2_query_image(granuleId = granuleId, atmCorr = atmCorr) + respo <- S2_do_query(query, path = "image") + + if (length(respo) == 0 && atmCorr == 0){ + + warning("Unable to process 'granuleId ", granuleId, "'. Not found in database!") + return(invisible(NULL)) + + } else if (length(respo) == 0 && atmCorr == 1){ + + warning("Unable to process 'granuleId ", granuleId, "'. Maybe its not (yet) ", + "atmospherically corrected!\n") + return(invisible(NULL)) + + } + + imageIds <- integer(3) + for (i in seq_len(3)){ + sel <- respo[respo$band == c(r, g, b)[i] & respo$resolution >= resolution, , drop=FALSE] + sel <- sel[order(sel$resolution)[1], , drop=FALSE] + + if (is.na(sel$url)){ + warning("Access to image denied. You seem to lack permission to download file!") + return(invisible(NULL)) + } + + imageIds[i] <- sel[, "imageId"] + } + + query <- list(r = imageIds[1], + g = imageIds[2], + b = imageIds[3], + ra = ra, + ga = ga, + ba = ba, + rb = rb, + gb = gb, + bb = bb) + + user <- getOption("S2user") + password <- getOption("S2password") + rtrn <- httr::modify_url('https://s2.boku.eodc.eu', + username = URLencode(user, reserved = TRUE), + password = URLencode(password, reserved = TRUE), + path = "rgb", + query = query) + + + if (is.null(destfile)){ + destfile <- sprintf("granuleId_%s_r_%s_g_%s_b_%s_atmCorr_%s.tif", + granuleId, r, g, b, atmCorr) + } + + if (dir.exists(destfile)){ + destfile <- sprintf("%s/granuleId_%s_r_%s_g_%s_b_%s_atmCorr_%s.tif", + destfile, granuleId, r, g, b, atmCorr) + } + + if (file.exists(destfile) & !isTRUE(overwrite)){ + warning(destfile, " already exists! Use 'overwrite=TRUE'") + return(invisible(NULL)) + } + + curl::curl_download(url = rtrn, destfile = destfile) + return(invisible(NULL)) +} + + diff --git a/R/S2_initialize_user.R b/R/S2_initialize_user.R new file mode 100644 index 0000000..7c3d7e2 --- /dev/null +++ b/R/S2_initialize_user.R @@ -0,0 +1,20 @@ +#' Function used to set 'user' and 'password' login credentials for the current +#' R session +#' +#' S2_initialize_user stores 'user' and 'password' usign \code{options()}. +#' Functions in package 'S2boku' (that require authentication) will retrieve +#' the credentials using 'getOption()'. This will avoid passing login +#' credentials multiple times in a single session and allows the user +#' for permanent configuration in '.Rprofile'. +#' +#' @note Requires a valid registration to 'https://s2.boku.eodc.eu' to gain +#' access to database functionality where authentication is mandatory. +#' @param user character user login you have registered with at +#' 'https://s2.boku.eodc.eu' +#' @param password character password for 'https://s2.boku.eodc.eu' +#' @export + +S2_initialize_user <- function(user = "default@foo.bar", password = "default"){ + options("S2user" = user) + options("S2password" = password) +} diff --git a/R/S2_put_ROI.R b/R/S2_put_ROI.R new file mode 100644 index 0000000..1b51fb5 --- /dev/null +++ b/R/S2_put_ROI.R @@ -0,0 +1,55 @@ +#' Creates new or update existing regions of interest +#' +#' Place/Update roi for processing Sentinel-2 data +#' +#' @param geometry SpatialPoints, SpatialPolygons or path to a shapefile on disk +#' @param regionId character a new or existing region name +#' @param cloudCovMax integer cloud coverage treshold for a given region +#' @param dateMin character, date 'YYYY-MM-DD' beginning of the region's time span +#' @param dateMax character, date 'YYYY-MM-DD' end of the region's time span +#' @param indicators character vector of indicator names to be computed for a +#' given region (e.g. \code{c("LAI", "FAPAR")}) +#' @param srid integer geometry projection SRID (e.g. 4326 for WGS-84) +#' @return side effect of putting the roi supplied via 'geometry' to +#' 's2.boku.eodc.eu' +#' @export + + +S2_put_ROI <- function(geometry, + regionId = NULL, + cloudCovMax = 50, + indicators = NULL, + dateMin = NULL, + dateMax = NULL, + srid = 4326){ + + if (is.null(dateMin) || is.null(dateMax)){ + stop("Please supply 'dateMin' and 'dateMax' in format 'YYYY-MM-DD") + } + + if (is.null(regionId)){ + stop("'regionId' not specified!", + "\n-> If you want to update an existing 'roi', please supply valid 'regionId'", + "\n-> If you like to create a new 'regionId' enter desired name") + } + + geometry <- roi_to_jgeom(geometry) + + body_l <- list(cloudCovMax = cloudCovMax, + dateMin = dateMin, + dateMax = dateMax, + geometry = geometry, + srid = srid) + + body_l <- body_l[!sapply(body_l , is.null)] + + user <- getOption("S2user") + password <- getOption("S2password") + rtrn <- httr::PUT('https://s2.boku.eodc.eu', + config = httr::authenticate(user, password), + path = list("roi", regionId), + body = body_l) + + return(rtrn) + +} diff --git a/R/S2_query_angle.R b/R/S2_query_angle.R new file mode 100644 index 0000000..0972aa8 --- /dev/null +++ b/R/S2_query_angle.R @@ -0,0 +1,55 @@ +#' Prepare a list to query database for 'angle' +#' +#' Implements the query options for 'angle' found in the wiki +#' @param angleType see wiki +#' @param band see wiki +#' @param broken see wiki +#' @param dateMin see wiki +#' @param dateMax see wiki +#' @param geometry see wiki +#' @param granule see wiki +#' @param granuleId see wiki +#' @param orbitNo see wiki +#' @param product see wiki +#' @param productId see wiki +#' @param retGeometry see wiki +#' @param utm see wiki +#' @param dateSingle see wiki +#' @param ... further arguments, none implemented +#' @return list of query arguments +#' @export + +S2_query_angle <- function(angleType = NULL, + band = NULL, + broken = 0, + dateMax = Sys.Date(), + dateMin = as.Date(dateMax) - 365, + geometry = NULL, + granule = NULL, + granuleId = NULL, + orbitNo = NULL, + product = NULL, + productId = NULL, + retGeometry = 0, + utm = NULL, + dateSingle = NULL, + ...){ + + # check inputs --------------------------------------------------------------- + if (!is.null(dateSingle)){ + dateMin <- dateSingle + dateMax <- dateSingle + dateSingle <- NULL + } + + if (!is.null(geometry)) geometry <- roi_to_jgeom(geometry) + + # make named query list ------------------------------------------------------ + query <- c(as.list(environment()), list(...)) + query <- query[!sapply(query, is.null)] + + # return query list ---------------------------------------------------------- + rtrn <- S2_do_query(query = query, path = 'angle') + return(rtrn) +} + diff --git a/R/S2_query_granule.R b/R/S2_query_granule.R new file mode 100644 index 0000000..1330d3a --- /dev/null +++ b/R/S2_query_granule.R @@ -0,0 +1,57 @@ +#' Prepare a list to query database for 'granule' +#' +#' Implements the query options for granule found in the wiki +#' @param atmCorr see wiki +#' @param broken see wiki +#' @param cloudCovMin see wiki +#' @param cloudCovMax see wiki +#' @param dateMax see wiki +#' @param dateMin see wiki +#' @param geometry see wiki +#' @param granule see wiki +#' @param granuleId see wiki +#' @param orbitNo see wiki +#' @param product see wiki +#' @param productId see wiki +#' @param retGeometry see wiki +#' @param utm see wiki +#' @param dateSingle see wiki +#' @param ... further arguments, none implemented +#' @return list of query arguments +#' @export + +S2_query_granule <- function(atmCorr = NULL, + broken = 0, + cloudCovMin = 0, + cloudCovMax = 100, + dateMax = Sys.Date(), + dateMin = as.Date(dateMax) - 365, + geometry = NULL, + granule = NULL, + granuleId = NULL, + orbitNo = NULL, + product = NULL, + productId = NULL, + retGeometry = 0, + utm = NULL, + dateSingle = NULL, + ...){ + + # check inputs --------------------------------------------------------------- + if (!is.null(dateSingle)){ + dateMin <- dateSingle + dateMax <- dateSingle + dateSingle <- NULL + } + + if (!is.null(geometry)) geometry <- roi_to_jgeom(geometry) + + # make named query list ------------------------------------------------------ + query <- c(as.list(environment()), list(...)) + query <- query[!sapply(query, is.null)] + + # return query list ---------------------------------------------------------- + rtrn <- S2_do_query(query = query, path = 'granule') + return(rtrn) +} + diff --git a/R/S2_query_image.R b/R/S2_query_image.R new file mode 100644 index 0000000..dc4213b --- /dev/null +++ b/R/S2_query_image.R @@ -0,0 +1,64 @@ +#' Prepare a list to query database for 'image' +#' +#' Implements the query options for 'images' found in the wiki +#' +#' @param atmCorr see wiki +#' @param broken see wiki +#' @param band see wiki +#' @param cloudCovMin see wiki +#' @param cloudCovMax see wiki +#' @param dateMax see wiki +#' @param dateMin see wiki +#' @param geometry see wiki +#' @param granule see wiki +#' @param granuleId see wiki +#' @param imageId see wiki +#' @param orbitNo see wiki +#' @param product see wiki +#' @param productId see wiki +#' @param resolution see wiki +#' @param retGeometry see wiki +#' @param utm see wiki +#' @param dateSingle see wiki +#' @param ... further arguments, none implemented +#' @return list of query arguments +#' @export + +S2_query_image <- function(atmCorr = NULL, + band = NULL, + broken = 0, + cloudCovMin = 0, + cloudCovMax = 100, + dateMax = Sys.Date(), + dateMin = as.Date(dateMax) - 365, + geometry = NULL, + granule = NULL, + granuleId = NULL, + imageId = NULL, + orbitNo = NULL, + product = NULL, + productId = NULL, + resolution = NULL, + retGeometry = 0, + utm = NULL, + dateSingle = NULL, + ...){ + + # check inputs --------------------------------------------------------------- + if (!is.null(dateSingle)){ + dateMin <- dateSingle + dateMax <- dateSingle + dateSingle <- NULL + } + + if (!is.null(geometry)) geometry <- roi_to_jgeom(geometry) + + # make named query list ------------------------------------------------------ + query <- c(as.list(environment()), list(...)) + query <- query[!sapply(query, is.null)] + + # return query list ---------------------------------------------------------- + rtrn <- S2_do_query(query = query, path = 'image') + return(rtrn) +} + diff --git a/R/S2_query_job.R b/R/S2_query_job.R new file mode 100644 index 0000000..8aa122f --- /dev/null +++ b/R/S2_query_job.R @@ -0,0 +1,53 @@ +#' Prepare a list to query database for 'job' +#' +#' Implements the query options for 'job' found in the wiki +#' @param dateMax see wiki +#' @param dateMin see wiki +#' @param ended see wiki +#' @param failed see wiki +#' @param geometry see wiki +#' @param jobId see wiki +#' @param granule see wiki +#' @param granuleId see wiki +#' @param product see wiki +#' @param productId see wiki +#' @param retGeometry see wiki +#' @param started see wiki +#' @param dateSingle see wiki +#' @param ... further arguments, none implemented +#' @return list of query arguments +#' @export + +S2_query_job <- function(dateMax = Sys.Date(), + dateMin = as.Date(dateMax) - 365, + ended = 1, + failed = 0, + geometry = NULL, + jobId = NULL, + granule = NULL, + granuleId = NULL, + product = NULL, + productId = NULL, + retGeometry = 0, + started = NULL, + dateSingle = NULL, + ...){ + + # check inputs --------------------------------------------------------------- + if (!is.null(dateSingle)){ + dateMin <- dateSingle + dateMax <- dateSingle + dateSingle <- NULL + } + + if (!is.null(geometry)) geometry <- roi_to_jgeom(geometry) + + # make named query list ------------------------------------------------------ + query <- c(as.list(environment()), list(...)) + query <- query[!sapply(query, is.null)] + + # return query list ---------------------------------------------------------- + rtrn <- S2_do_query(query = query, path = 'job') + return(rtrn) +} + diff --git a/R/S2_query_product.R b/R/S2_query_product.R new file mode 100644 index 0000000..5824279 --- /dev/null +++ b/R/S2_query_product.R @@ -0,0 +1,47 @@ +#' Prepare a list to query database for 'product' +#' +#' Implements the query options for 'product' found in the wiki +#' @param atmCorr see wiki +#' @param dateMax see wiki +#' @param dateMin see wiki +#' @param geometry see wiki +#' @param orbitDir see wiki +#' @param orbitNo see wiki +#' @param product see wiki +#' @param productId see wiki +#' @param retGeometry see wiki +#' @param dateSingle see wiki +#' @param ... further arguments, none implemented +#' @return list of query arguments +#' @export + +S2_query_product <- function(atmCorr = NULL, + dateMax = Sys.Date(), + dateMin = as.Date(dateMax) - 365, + geometry = NULL, + orbitDir = NULL, + orbitNo = NULL, + product = NULL, + productId = NULL, + retGeometry = 0, + dateSingle = NULL, + ...){ + + # check inputs --------------------------------------------------------------- + if (!is.null(dateSingle)){ + dateMin <- dateSingle + dateMax <- dateSingle + dateSingle <- NULL + } + + if (!is.null(geometry)) geometry <- roi_to_jgeom(geometry) + + # make named query list ------------------------------------------------------ + query <- c(as.list(environment()), list(...)) + query <- query[!sapply(query, is.null)] + + # return query list ---------------------------------------------------------- + rtrn <- S2_do_query(query = query, path = 'product') + return(rtrn) +} + diff --git a/R/S2_vrt_L2Agranule.R b/R/S2_vrt_L2Agranule.R new file mode 100644 index 0000000..d80a955 --- /dev/null +++ b/R/S2_vrt_L2Agranule.R @@ -0,0 +1,50 @@ +#' Create a virtual raster from a (Level 2A) Sentinel-2 Granule +#' +#' Creates a '.vrt' raster from a granule directory +#' @note Requires a valid 'GDAL' install (and properly configured '$PATH' variable). +#' Suppose a granule is complete (containing L2A files at 10m, 20m and 60m resolution), +#' the resulting '.vrt' stack will contain bands in the following order: +#' B01 (60m), B02 (10m), B03 (10m), B04 (10m), B05 (20m), B06 (20m), B07 (20m), +#' B08 (10m), B09 (60m), B11 (20m) and B12 (20m). +#' For details, please consult the ESA Sentinel-2 product specifications documentation. +#' @param granule character path to a 'granule' +#' @param verbose logical if \code{TRUE} show warnings +#' @return NULL, side effect of creating a '.vrt' file. + + +S2_vrt_L2Agranule <- function(granule, verbose = FALSE){ + if (nchar(Sys.which("gdalbuildvrt")) != 0){ + + if (isTRUE(verbose)){ + warning("Unable to find 'gdalbuildvrt' -> virtual raster creation skipped!") + } + return(invisible(NULL)) + + } else { + + jp2_10m <- list.files(granule, pattern = "_B[0-9]{2}_10m.jp2$", + recursive = TRUE, full.names = TRUE) + jp2_20m <- list.files(granule, pattern = "_B[0-9]{2}_20m.jp2$", + recursive = TRUE, full.names = TRUE) + jp2_60m <- list.files(granule, pattern = "_B[0-9]{2}_60m.jp2$", + recursive = TRUE, full.names = TRUE) + + + bnd_10m <- regmatches(jp2_10m, m = regexpr(pattern = "_B[0-9]{2}_", jp2_10m)) + bnd_20m <- regmatches(jp2_20m, m = regexpr(pattern = "_B[0-9]{2}_", jp2_20m)) + bnd_60m <- regmatches(jp2_60m, m = regexpr(pattern = "_B[0-9]{2}_", jp2_60m)) + + bnd_stk <- c(jp2_10m, + jp2_20m[!bnd_20m %in% bnd_10m], + jp2_60m[!bnd_60m %in% c(bnd_10m, bnd_20m)]) + + # create the virtual raster ---------------------------------------------- + bnd_stk <- bnd_stk[order(basename(bnd_stk))] + + system(sprintf('gdalbuildvrt -resolution "highest" -separate %s.vrt %s', + file.path(granule, basename(granule)), + paste(bnd_stk, sep = " ", collapse = " "), sep = " ")) + + } + return(invisible(NULL)) +} diff --git a/R/jgeom_to_SpatialPolygons.R b/R/jgeom_to_SpatialPolygons.R new file mode 100644 index 0000000..580fe65 --- /dev/null +++ b/R/jgeom_to_SpatialPolygons.R @@ -0,0 +1,36 @@ +#' Converts json geometry to SpatialPolygons +#' +#' Turn a json geometry as returned by a database query using 'retGeometry = 1' +#' into a SpatialPolygons object +#' +#' @note The geometry is first replaced by its convex hull for simplification! +#' @param x character json geometry as returned by a database query with +#' 'retGeometry = 1' +#' @return SpatialPolygons object of the geometry supplied via x + +jgeom_to_SpatialPolygons <- function(x){ + rtrn <- vector(mode = "list", length = length(x)) + for (i in seq_along(x)){ + ptrn <- "\\[[0-9]+[.]?[0-9]*,[0-9]+[.]?[0-9]*\\]" + y <- unlist(strsplit(x[i], split = '"coordinates":'))[2] + y <- unlist(regmatches(y, m = gregexpr(pattern = ptrn, text = y))) + y <- substr(y, start = 2, stop = nchar(y) - 1) + y <- strsplit(y, split = ",") + y <- do.call(rbind, y) + y <- apply(y, 2, as.numeric) + hull <- chull(y) + y <- y[c(hull, hull[1]), ] + y <- sp::Polygon(y) + y <- sp::Polygons(list(y), ID=1) + y <- sp::SpatialPolygons(list(y), proj4string = raster::crs(raster::raster())) + + rtrn[[i]] <- y + } + if (length(rtrn) == 1){ + rtrn <- unlist(rtrn) + } else { + rtrn <- do.call(raster::bind, rtrn) + } + + return(rtrn) +} diff --git a/R/roi_to_jgeom.R b/R/roi_to_jgeom.R new file mode 100644 index 0000000..7eed485 --- /dev/null +++ b/R/roi_to_jgeom.R @@ -0,0 +1,38 @@ +#' Convert a region of interest to a json geometry +#' +#' @param roi a region of interest supplied as a vector/matrix of named ('x', 'y') +#' coordinates or a SpatialPoints object or a SpatialPolygons object or a path +#' to a shapefile on disk or a json geometry character string +#' @param round number of digits to round coordinates to +#' @note Coordinates are assumed to be projected (WGS-84, 4326). Spatial objects +#' will be reprojected as necessary +#' @return character, a json geometry string + + +roi_to_jgeom <- function(roi, round = Inf){ + + if (is.character(roi) && length(grep("^\\{[[:print:]]*\\}$", roi)) == 0){ + roi <- tryCatch(raster::shapefile(roi), + error = function(cond){ + message("Can't load 'shapefile' from:\n", roi) + message(cond) + return(NULL) + }) + } + + if ("Spatial" %in% is(roi)){ + if (!raster::isLonLat(roi)){ + roi <- sp::spTransform(roi, CRSobj = raster::crs(raster::raster())) + } + roi_geom <- spat_to_jgeom(spat = roi, round = round) + } else if (all(c("x", "y") %in% colnames(rbind(roi)))){ + roi_geom <- xy_to_jgeom(xy = roi, round = round) + } else if (length(grep("^\\{[[:print:]]*\\}$", roi)) != 0){ + roi_geom <- roi + } else { + stop("'roi' not recognized!") + } + + return(roi_geom) + +} diff --git a/R/spat_to_jgeom.R b/R/spat_to_jgeom.R new file mode 100644 index 0000000..f384c8a --- /dev/null +++ b/R/spat_to_jgeom.R @@ -0,0 +1,38 @@ +#' Convert SpatialPoints/PatialPolygons to json geometry +#' +#' Turn a SpatialPoints/PatialPolygons object into a json geometry string +#' +#' @param spat a spatial object of class SpatialPolygons or SpatialPoints +#' @param round number of digits to round coordinates to +#' @return list of json geometries, where length of the list is the number of +#' points or polygons in spat +#' + +spat_to_jgeom <- function(spat, round = Inf){ + + rtrn <- vector(mode = 'list', length = length(spat)) + + for (i in seq_along(spat)){ + + poi_xy <- raster::geom(spat[i, ])[, c("x", "y"), drop = FALSE] + + if (nrow(poi_xy) == 1 && "SpatialPoints" %in% is(spat)){ + + poi_xy <- data.frame(round(poi_xy, round)) + g_type <- "Point" + poi_xy <- with(poi_xy, paste(x, y, sep = ",")) + + } else if (nrow(poi_xy) > 1){ + + g_type <- "Polygon" + + poi_xy <- data.frame(apply(round(poi_xy, round), 2, as.character)) + poi_xy <- with(poi_xy, paste(sprintf("[%s,%s]", x, y), collapse=",")) + poi_xy <- sprintf("[%s]", poi_xy) + } + + rtrn[[i]] <- sprintf('{"type":"%s","coordinates":[%s]}', + g_type, poi_xy) + } + return(rtrn) +} diff --git a/R/xy_to_jgeom.R b/R/xy_to_jgeom.R new file mode 100644 index 0000000..f3e37a7 --- /dev/null +++ b/R/xy_to_jgeom.R @@ -0,0 +1,38 @@ +#' Convert xy coordinates to json geometry +#' +#' Turn a xy coordinates vector (1 point) or matrix (multiple points) into a +#' json geometry string +#' @note Elements of vector/columns of matrix must be named 'x' and 'y' +#' @param xy named vector matrix of 'x' and 'y' coordinates assumed to be projected +#' (4326, WGS-84) +#' @param round number of digits to round coordinates to +#' @return a json geometry string of type 'Point', if only one xy pair is +#' supplied, of type 'Polygon' otherwise +#' + +xy_to_jgeom <- function(xy, round = Inf){ + + poi_xy <- data.frame(rbind(xy)) + + stopifnot(all(c("x", "y") %in% colnames(poi_xy))) + + if (nrow(poi_xy) == 1){ + + poi_xy <- data.frame(round(poi_xy, round)) + g_type <- "Point" + poi_xy <- with(poi_xy, paste(x, y, sep = ",")) + + } else if (nrow(poi_xy) > 1){ + + g_type <- "Polygon" + + poi_xy <- data.frame(apply(round(poi_xy, round), 2, as.character)) + poi_xy <- with(poi_xy, paste(sprintf("[%s,%s]", x, y), collapse=",")) + poi_xy <- sprintf("[%s]", poi_xy) + + } + + rtrn <- sprintf('{"type":"%s","coordinates":[%s]}', g_type, poi_xy) + return(rtrn) + +} diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..3b290d7 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,9 @@ +#' .onLoad setup credentials +#' +#' Setup login credentials on package start, if not retrieved already (e.g. from +#' .Rprofile). + +.onLoad <- function(libname, pkgname){ + if (is.null(getOption("S2user"))) options("S2user" = "default") + if (is.null(getOption("S2password"))) options("S2password" = "default") +} diff --git a/man/S2_buy_granule.Rd b/man/S2_buy_granule.Rd new file mode 100644 index 0000000..6ac474e --- /dev/null +++ b/man/S2_buy_granule.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_buy_granule.R +\name{S2_buy_granule} +\alias{S2_buy_granule} +\title{Buy a granule at 'https://s2.boku.eodc.eu'} +\usage{ +S2_buy_granule(granuleId) +} +\arguments{ +\item{granuleId}{character the granuleId} +} +\description{ +Buy granule using granuleId +} + diff --git a/man/S2_check_access.Rd b/man/S2_check_access.Rd new file mode 100644 index 0000000..111b907 --- /dev/null +++ b/man/S2_check_access.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_check_access.R +\name{S2_check_access} +\alias{S2_check_access} +\title{(Very basic) check if server/database can be accessed} +\usage{ +S2_check_access(verbose = TRUE) +} +\arguments{ +\item{verbose}{logical} +} +\value{ +logical \code{TRUE} if access to server was successfull and user + credentials seem to be valid, FALSE if 'anything' went wrong +} +\description{ +Checks accessibility of server / database and does basic checking of + user credentials +} + diff --git a/man/S2_do_query.Rd b/man/S2_do_query.Rd new file mode 100644 index 0000000..6b86db8 --- /dev/null +++ b/man/S2_do_query.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_do_query.R +\name{S2_do_query} +\alias{S2_do_query} +\title{Send a query to 'https://s2.boku.eodc.eu'} +\usage{ +S2_do_query(query, path) +} +\arguments{ +\item{query}{list of named arguments 'known' to the database. Typically +created using e.g. 'S2_query_granule'} + +\item{path}{character altering the query url with respect to the desired +output. One of "product", "granule", "image", "qiData", "angle", "roi", +"job", "rgb".} +} +\description{ +Query database and return response as data.frame +} + diff --git a/man/S2_download.Rd b/man/S2_download.Rd new file mode 100644 index 0000000..28f358e --- /dev/null +++ b/man/S2_download.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_download.R +\name{S2_download} +\alias{S2_download} +\title{S2_download helper function} +\usage{ +S2_download(url, destfile, zip = TRUE) +} +\arguments{ +\item{url}{character (valid) url to download file from.} + +\item{destfile}{character download destination. If \code{zip = TRUE}, the +ending '.zip' will be attached to destfile (, if it is not already).} + +\item{zip}{logical if \code{TRUE}, the url will be downloaded as zip archive +and (automatically) unzipped in the parent directory of 'destfile'} +} +\description{ +Simple helper function to zip download and unzip i.e. a 'granule' in a single + step +} + diff --git a/man/S2_generate_RGB.Rd b/man/S2_generate_RGB.Rd new file mode 100644 index 0000000..146ab9d --- /dev/null +++ b/man/S2_generate_RGB.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_generate_RGB.R +\name{S2_generate_RGB} +\alias{S2_generate_RGB} +\title{Generate RGB image and download} +\usage{ +S2_generate_RGB(granuleId, destfile = NULL, resolution = 10, atmCorr = 0, + r = "B08", g = "B04", b = "B03", ra = 20, ga = 20, ba = 20, + rb = 20, gb = 20, bb = 20, overwrite = FALSE) +} +\arguments{ +\item{granuleId}{integer the granuleId for which to create the RGB composite} + +\item{destfile}{character path to the output file. If destfile is a path to +an existing directory, a filename will be automatically generated. If NULL, +the file will be saved to the current working directory. If a filename is +supplied, it will have to have a '.tif' extension.} + +\item{resolution}{integer desired (minimum) resolution, typically 10, 20 or 60.} + +\item{atmCorr}{0 (default) or 1, if atmospherically corrected bands should be +used} + +\item{r}{character red band, e.g. "B08"} + +\item{g}{character green band, e.g. "B04"} + +\item{b}{character blue band, e.g. "B03"} + +\item{ra}{see wiki} + +\item{ga}{see wiki} + +\item{ba}{see wiki} + +\item{rb}{see wiki} + +\item{gb}{see wiki} + +\item{bb}{see wiki} + +\item{overwrite}{logical, should existing files be overwritten?} +} +\description{ +Generates 8-bit/channel composite image (see 'https://s2.boku.eodc.eu/wiki/' + for details) +} + diff --git a/man/S2_initialize_user.Rd b/man/S2_initialize_user.Rd new file mode 100644 index 0000000..74ab1e0 --- /dev/null +++ b/man/S2_initialize_user.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_initialize_user.R +\name{S2_initialize_user} +\alias{S2_initialize_user} +\title{Function used to set 'user' and 'password' login credentials for the current + R session} +\usage{ +S2_initialize_user(user = "default@foo.bar", password = "default") +} +\arguments{ +\item{user}{character user login you have registered with at +'https://s2.boku.eodc.eu'} + +\item{password}{character password for 'https://s2.boku.eodc.eu'} +} +\description{ +S2_initialize_user stores 'user' and 'password' usign \code{options()}. + Functions in package 'S2boku' (that require authentication) will retrieve + the credentials using 'getOption()'. This will avoid passing login + credentials multiple times in a single session and allows the user + for permanent configuration in '.Rprofile'. +} +\note{ +Requires a valid registration to 'https://s2.boku.eodc.eu' to gain + access to database functionality where authentication is mandatory. +} + diff --git a/man/S2_put_ROI.Rd b/man/S2_put_ROI.Rd new file mode 100644 index 0000000..ab0c571 --- /dev/null +++ b/man/S2_put_ROI.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_put_ROI.R +\name{S2_put_ROI} +\alias{S2_put_ROI} +\title{Creates new or update existing regions of interest} +\usage{ +S2_put_ROI(geometry, regionId = NULL, cloudCovMax = 50, indicators = NULL, + dateMin = NULL, dateMax = NULL, srid = 4326) +} +\arguments{ +\item{geometry}{SpatialPoints, SpatialPolygons or path to a shapefile on disk} + +\item{regionId}{character a new or existing region name} + +\item{cloudCovMax}{integer cloud coverage treshold for a given region} + +\item{indicators}{character vector of indicator names to be computed for a +given region (e.g. \code{c("LAI", "FAPAR")})} + +\item{dateMin}{character, date 'YYYY-MM-DD' beginning of the region's time span} + +\item{dateMax}{character, date 'YYYY-MM-DD' end of the region's time span} + +\item{srid}{integer geometry projection SRID (e.g. 4326 for WGS-84)} +} +\value{ +side effect of putting the roi supplied via 'geometry' to + 's2.boku.eodc.eu' +} +\description{ +Place/Update roi for processing Sentinel-2 data +} + diff --git a/man/S2_query_angle.Rd b/man/S2_query_angle.Rd new file mode 100644 index 0000000..0901685 --- /dev/null +++ b/man/S2_query_angle.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_query_angle.R +\name{S2_query_angle} +\alias{S2_query_angle} +\title{Prepare a list to query database for 'angle'} +\usage{ +S2_query_angle(angleType = NULL, band = NULL, broken = 0, + dateMax = Sys.Date(), dateMin = as.Date(dateMax) - 365, geometry = NULL, + granule = NULL, granuleId = NULL, orbitNo = NULL, product = NULL, + productId = NULL, retGeometry = 0, utm = NULL, dateSingle = NULL, ...) +} +\arguments{ +\item{angleType}{see wiki} + +\item{band}{see wiki} + +\item{broken}{see wiki} + +\item{dateMax}{see wiki} + +\item{dateMin}{see wiki} + +\item{geometry}{see wiki} + +\item{granule}{see wiki} + +\item{granuleId}{see wiki} + +\item{orbitNo}{see wiki} + +\item{product}{see wiki} + +\item{productId}{see wiki} + +\item{retGeometry}{see wiki} + +\item{utm}{see wiki} + +\item{dateSingle}{see wiki} + +\item{...}{further arguments, none implemented} +} +\value{ +list of query arguments +} +\description{ +Implements the query options for 'angle' found in the wiki +} + diff --git a/man/S2_query_granule.Rd b/man/S2_query_granule.Rd new file mode 100644 index 0000000..f40d343 --- /dev/null +++ b/man/S2_query_granule.Rd @@ -0,0 +1,52 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_query_granule.R +\name{S2_query_granule} +\alias{S2_query_granule} +\title{Prepare a list to query database for 'granule'} +\usage{ +S2_query_granule(atmCorr = NULL, broken = 0, cloudCovMin = 0, + cloudCovMax = 100, dateMax = Sys.Date(), dateMin = as.Date(dateMax) - + 365, geometry = NULL, granule = NULL, granuleId = NULL, + orbitNo = NULL, product = NULL, productId = NULL, retGeometry = 0, + utm = NULL, dateSingle = NULL, ...) +} +\arguments{ +\item{atmCorr}{see wiki} + +\item{broken}{see wiki} + +\item{cloudCovMin}{see wiki} + +\item{cloudCovMax}{see wiki} + +\item{dateMax}{see wiki} + +\item{dateMin}{see wiki} + +\item{geometry}{see wiki} + +\item{granule}{see wiki} + +\item{granuleId}{see wiki} + +\item{orbitNo}{see wiki} + +\item{product}{see wiki} + +\item{productId}{see wiki} + +\item{retGeometry}{see wiki} + +\item{utm}{see wiki} + +\item{dateSingle}{see wiki} + +\item{...}{further arguments, none implemented} +} +\value{ +list of query arguments +} +\description{ +Implements the query options for granule found in the wiki +} + diff --git a/man/S2_query_image.Rd b/man/S2_query_image.Rd new file mode 100644 index 0000000..a5aa91b --- /dev/null +++ b/man/S2_query_image.Rd @@ -0,0 +1,59 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_query_image.R +\name{S2_query_image} +\alias{S2_query_image} +\title{Prepare a list to query database for 'image'} +\usage{ +S2_query_image(atmCorr = NULL, band = NULL, broken = 0, cloudCovMin = 0, + cloudCovMax = 100, dateMax = Sys.Date(), dateMin = as.Date(dateMax) - + 365, geometry = NULL, granule = NULL, granuleId = NULL, + imageId = NULL, orbitNo = NULL, product = NULL, productId = NULL, + resolution = NULL, retGeometry = 0, utm = NULL, dateSingle = NULL, + ...) +} +\arguments{ +\item{atmCorr}{see wiki} + +\item{band}{see wiki} + +\item{broken}{see wiki} + +\item{cloudCovMin}{see wiki} + +\item{cloudCovMax}{see wiki} + +\item{dateMax}{see wiki} + +\item{dateMin}{see wiki} + +\item{geometry}{see wiki} + +\item{granule}{see wiki} + +\item{granuleId}{see wiki} + +\item{imageId}{see wiki} + +\item{orbitNo}{see wiki} + +\item{product}{see wiki} + +\item{productId}{see wiki} + +\item{resolution}{see wiki} + +\item{retGeometry}{see wiki} + +\item{utm}{see wiki} + +\item{dateSingle}{see wiki} + +\item{...}{further arguments, none implemented} +} +\value{ +list of query arguments +} +\description{ +Implements the query options for 'images' found in the wiki +} + diff --git a/man/S2_query_job.Rd b/man/S2_query_job.Rd new file mode 100644 index 0000000..d0b45ec --- /dev/null +++ b/man/S2_query_job.Rd @@ -0,0 +1,47 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_query_job.R +\name{S2_query_job} +\alias{S2_query_job} +\title{Prepare a list to query database for 'job'} +\usage{ +S2_query_job(dateMax = Sys.Date(), dateMin = as.Date(dateMax) - 365, + ended = 1, failed = 0, geometry = NULL, jobId = NULL, + granule = NULL, granuleId = NULL, product = NULL, productId = NULL, + retGeometry = 0, started = NULL, dateSingle = NULL, ...) +} +\arguments{ +\item{dateMax}{see wiki} + +\item{dateMin}{see wiki} + +\item{ended}{see wiki} + +\item{failed}{see wiki} + +\item{geometry}{see wiki} + +\item{jobId}{see wiki} + +\item{granule}{see wiki} + +\item{granuleId}{see wiki} + +\item{product}{see wiki} + +\item{productId}{see wiki} + +\item{retGeometry}{see wiki} + +\item{started}{see wiki} + +\item{dateSingle}{see wiki} + +\item{...}{further arguments, none implemented} +} +\value{ +list of query arguments +} +\description{ +Implements the query options for 'job' found in the wiki +} + diff --git a/man/S2_query_product.Rd b/man/S2_query_product.Rd new file mode 100644 index 0000000..01249ea --- /dev/null +++ b/man/S2_query_product.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_query_product.R +\name{S2_query_product} +\alias{S2_query_product} +\title{Prepare a list to query database for 'product'} +\usage{ +S2_query_product(atmCorr = NULL, dateMax = Sys.Date(), + dateMin = as.Date(dateMax) - 365, geometry = NULL, orbitDir = NULL, + orbitNo = NULL, product = NULL, productId = NULL, retGeometry = 0, + dateSingle = NULL, ...) +} +\arguments{ +\item{atmCorr}{see wiki} + +\item{dateMax}{see wiki} + +\item{dateMin}{see wiki} + +\item{geometry}{see wiki} + +\item{orbitDir}{see wiki} + +\item{orbitNo}{see wiki} + +\item{product}{see wiki} + +\item{productId}{see wiki} + +\item{retGeometry}{see wiki} + +\item{dateSingle}{see wiki} + +\item{...}{further arguments, none implemented} +} +\value{ +list of query arguments +} +\description{ +Implements the query options for 'product' found in the wiki +} + diff --git a/man/S2_vrt_L2Agranule.Rd b/man/S2_vrt_L2Agranule.Rd new file mode 100644 index 0000000..0e46306 --- /dev/null +++ b/man/S2_vrt_L2Agranule.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/S2_vrt_L2Agranule.R +\name{S2_vrt_L2Agranule} +\alias{S2_vrt_L2Agranule} +\title{Create a virtual raster from a (Level 2A) Sentinel-2 Granule} +\usage{ +S2_vrt_L2Agranule(granule, verbose = FALSE) +} +\arguments{ +\item{granule}{character path to a 'granule'} + +\item{verbose}{logical if \code{TRUE} show warnings} +} +\value{ +NULL, side effect of creating a '.vrt' file. +} +\description{ +Creates a '.vrt' raster from a granule directory +} +\note{ +Requires a valid 'GDAL' install (and properly configured '$PATH' variable). + Suppose a granule is complete (containing L2A files at 10m, 20m and 60m resolution), + the resulting '.vrt' stack will contain bands in the following order: + B01 (60m), B02 (10m), B03 (10m), B04 (10m), B05 (20m), B06 (20m), B07 (20m), + B08 (10m), B09 (60m), B11 (20m) and B12 (20m). + For details, please consult the ESA Sentinel-2 product specifications documentation. +} + diff --git a/man/jgeom_to_SpatialPolygons.Rd b/man/jgeom_to_SpatialPolygons.Rd new file mode 100644 index 0000000..02a66e2 --- /dev/null +++ b/man/jgeom_to_SpatialPolygons.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/jgeom_to_SpatialPolygons.R +\name{jgeom_to_SpatialPolygons} +\alias{jgeom_to_SpatialPolygons} +\title{Converts json geometry to SpatialPolygons} +\usage{ +jgeom_to_SpatialPolygons(x) +} +\arguments{ +\item{x}{character json geometry as returned by a database query with +'retGeometry = 1'} +} +\value{ +SpatialPolygons object of the geometry supplied via x +} +\description{ +Turn a json geometry as returned by a database query using 'retGeometry = 1' + into a SpatialPolygons object +} +\note{ +The geometry is first replaced by its convex hull for simplification! +} + diff --git a/man/roi_to_jgeom.Rd b/man/roi_to_jgeom.Rd new file mode 100644 index 0000000..eae913e --- /dev/null +++ b/man/roi_to_jgeom.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/roi_to_jgeom.R +\name{roi_to_jgeom} +\alias{roi_to_jgeom} +\title{Convert a region of interest to a json geometry} +\usage{ +roi_to_jgeom(roi, round = Inf) +} +\arguments{ +\item{roi}{a region of interest supplied as a vector/matrix of named ('x', 'y') +coordinates or a SpatialPoints object or a SpatialPolygons object or a path +to a shapefile on disk or a json geometry character string} + +\item{round}{number of digits to round coordinates to} +} +\value{ +character, a json geometry string +} +\description{ +Convert a region of interest to a json geometry +} +\note{ +Coordinates are assumed to be projected (WGS-84, 4326). Spatial objects + will be reprojected as necessary +} + diff --git a/man/spat_to_jgeom.Rd b/man/spat_to_jgeom.Rd new file mode 100644 index 0000000..a45be0d --- /dev/null +++ b/man/spat_to_jgeom.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/spat_to_jgeom.R +\name{spat_to_jgeom} +\alias{spat_to_jgeom} +\title{Convert SpatialPoints/PatialPolygons to json geometry} +\usage{ +spat_to_jgeom(spat, round = Inf) +} +\arguments{ +\item{spat}{a spatial object of class SpatialPolygons or SpatialPoints} + +\item{round}{number of digits to round coordinates to} +} +\value{ +list of json geometries, where length of the list is the number of + points or polygons in spat +} +\description{ +Turn a SpatialPoints/PatialPolygons object into a json geometry string +} + diff --git a/man/xy_to_jgeom.Rd b/man/xy_to_jgeom.Rd new file mode 100644 index 0000000..e999b09 --- /dev/null +++ b/man/xy_to_jgeom.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/xy_to_jgeom.R +\name{xy_to_jgeom} +\alias{xy_to_jgeom} +\title{Convert xy coordinates to json geometry} +\usage{ +xy_to_jgeom(xy, round = Inf) +} +\arguments{ +\item{xy}{named vector matrix of 'x' and 'y' coordinates assumed to be projected +(4326, WGS-84)} + +\item{round}{number of digits to round coordinates to} +} +\value{ +a json geometry string of type 'Point', if only one xy pair is + supplied, of type 'Polygon' otherwise +} +\description{ +Turn a xy coordinates vector (1 point) or matrix (multiple points) into a + json geometry string +} +\note{ +Elements of vector/columns of matrix must be named 'x' and 'y' +} +