Skip to content

Commit

Permalink
added epsg code modifications to argument type 'bounding-box' (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
flahn committed Jan 14, 2022
1 parent 9998f01 commit befdf8f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions R/argument_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test-argument-bounding-box.R
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit befdf8f

Please sign in to comment.