From befdf8f043fa89cb6a1e57d65060fc01fe87857e Mon Sep 17 00:00:00 2001 From: "florian.lahn" Date: Fri, 14 Jan 2022 13:29:45 +0100 Subject: [PATCH] added epsg code modifications to argument type 'bounding-box' (#99) --- R/argument_types.R | 12 +++++++++++ tests/testthat/test-argument-bounding-box.R | 24 +++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/testthat/test-argument-bounding-box.R diff --git a/R/argument_types.R b/R/argument_types.R index c5df819a..61866921 100644 --- a/R/argument_types.R +++ b/R/argument_types.R @@ -1216,6 +1216,18 @@ BoundingBox = R6Class( private$required = required private$schema$type = "object" private$schema$subtype = "bounding-box" + }, + setValue = function(value) { + # the value will be a posixct where we just return the time component + if (is.list(value)) { + if ("crs" %in% names(value)) { + crs_value = value[["crs"]] + if (is.character(crs_value) && grepl(tolower(crs_value),pattern = "^epsg:")) { + value[["crs"]] = as.integer(gsub(x = crs_value,replacement = "",pattern = "[^0-9]")) + } + } + } + private$value= value } ), private = list( diff --git a/tests/testthat/test-argument-bounding-box.R b/tests/testthat/test-argument-bounding-box.R new file mode 100644 index 00000000..41df0fda --- /dev/null +++ b/tests/testthat/test-argument-bounding-box.R @@ -0,0 +1,24 @@ +test_that("numeric epsg code works", { + tryCatch({ + code = openeo:::BoundingBox$new() + code$setValue(list(west = 16.06, south = 48.06, east = 16.65, north = 48.35, crs = 3857)) + + msg = code$validate() + expect(length(msg)==0,failure_message = "It doesn't work") + }, error = function(e) { + expect(FALSE,failure_message=e$message) + }) +}) + +test_that("epsg code as string works", { + tryCatch({ + code = openeo:::BoundingBox$new() + code$setValue(list(west = 16.06, south = 48.06, east = 16.65, north = 48.35, crs = "EPSG:3857")) + + msg = code$validate() + expect(length(msg)==0,failure_message = "It doesn't work") + }, error = function(e) { + expect(FALSE,failure_message=e$message) + }) +}) +