diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..9280a3e 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,3 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +^\.travis.yml$ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2addba5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +# http://docs.travis-ci.com/user/languages/r/ +language: r + +cache: packages + +r: + - release + - devel + +after_success: + - Rscript -e 'covr::coveralls(function_exclusions = c("\\.onLoad"))' + +notifications: + email: + - zozlak@zozlak.org + - sebastian.boeck@boku.ac.at diff --git a/DESCRIPTION b/DESCRIPTION index e9df7ba..12d2da9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,9 +12,15 @@ Imports: curl, httr, jsonlite, + methods, raster, sp +Suggests: + testthat, + knitr, + rmarkdown License: GPL-3 Encoding: UTF-8 LazyData: true RoxygenNote: 5.0.1 +VignetteBuilder: knitr diff --git a/R/S2_do_query.R b/R/S2_do_query.R index 4143ba8..24a39d5 100644 --- a/R/S2_do_query.R +++ b/R/S2_do_query.R @@ -12,6 +12,10 @@ S2_do_query <- function(query, path){ user <- getOption("S2user") password <- getOption("S2password") + + filter <- sapply(query, is.logical) + query[filter] <- as.numeric(query[filter]) + rtrn <- httr::GET('https://s2.boku.eodc.eu', config = httr::authenticate(user, password), path = path, diff --git a/R/S2_download.R b/R/S2_download.R index 996dbbe..3b8d129 100644 --- a/R/S2_download.R +++ b/R/S2_download.R @@ -19,7 +19,7 @@ S2_download <- function(url, destfile, zip = TRUE){ curl::curl_download(url = url, destfile = destfile, quiet = TRUE) - if (isTRUE(zip)) unzip(zipfile = destfile, exdir = dirname(destfile)) + if (isTRUE(zip)) utils::unzip(zipfile = destfile, exdir = dirname(destfile)) return(invisible(NULL)) } diff --git a/R/S2_generate_RGB.R b/R/S2_generate_RGB.R index 7dbec6a..3d87a3c 100644 --- a/R/S2_generate_RGB.R +++ b/R/S2_generate_RGB.R @@ -81,8 +81,8 @@ S2_generate_RGB <- function(granuleId, 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), + username = utils::URLencode(user, reserved = TRUE), + password = utils::URLencode(password, reserved = TRUE), path = "rgb", query = query) diff --git a/R/S2_initialize_user.R b/R/S2_initialize_user.R index 7c3d7e2..3659aaf 100644 --- a/R/S2_initialize_user.R +++ b/R/S2_initialize_user.R @@ -14,7 +14,7 @@ #' @param password character password for 'https://s2.boku.eodc.eu' #' @export -S2_initialize_user <- function(user = "default@foo.bar", password = "default"){ +S2_initialize_user <- function(user = "test@s2.boku.eodc.eu", password = "test"){ options("S2user" = user) options("S2password" = password) } diff --git a/R/jgeom_to_SpatialPolygons.R b/R/jgeom_to_SpatialPolygons.R index 580fe65..e719ed5 100644 --- a/R/jgeom_to_SpatialPolygons.R +++ b/R/jgeom_to_SpatialPolygons.R @@ -18,7 +18,7 @@ jgeom_to_SpatialPolygons <- function(x){ y <- strsplit(y, split = ",") y <- do.call(rbind, y) y <- apply(y, 2, as.numeric) - hull <- chull(y) + hull <- grDevices::chull(y) y <- y[c(hull, hull[1]), ] y <- sp::Polygon(y) y <- sp::Polygons(list(y), ID=1) diff --git a/R/roi_to_jgeom.R b/R/roi_to_jgeom.R index 7eed485..9492495 100644 --- a/R/roi_to_jgeom.R +++ b/R/roi_to_jgeom.R @@ -20,7 +20,7 @@ roi_to_jgeom <- function(roi, round = Inf){ }) } - if ("Spatial" %in% is(roi)){ + if ("Spatial" %in% methods::is(roi)){ if (!raster::isLonLat(roi)){ roi <- sp::spTransform(roi, CRSobj = raster::crs(raster::raster())) } diff --git a/R/spat_to_jgeom.R b/R/spat_to_jgeom.R index f384c8a..ea26969 100644 --- a/R/spat_to_jgeom.R +++ b/R/spat_to_jgeom.R @@ -16,7 +16,7 @@ spat_to_jgeom <- function(spat, round = Inf){ poi_xy <- raster::geom(spat[i, ])[, c("x", "y"), drop = FALSE] - if (nrow(poi_xy) == 1 && "SpatialPoints" %in% is(spat)){ + if (nrow(poi_xy) == 1 && "SpatialPoints" %in% methods::is(spat)){ poi_xy <- data.frame(round(poi_xy, round)) g_type <- "Point" diff --git a/README.md b/README.md new file mode 100644 index 0000000..85f58ff --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# sentinel2 + +Accessing https://s2.boku.eodc.eu Sentinel-2 API made easy. + +## Installation + +* If you do not have the `devtools` package, install it with `install.packages('devtools')`. +* Run `devtools::install_github('IVFL-BOKU/sentinel2') + diff --git a/man/S2_initialize_user.Rd b/man/S2_initialize_user.Rd index 74ab1e0..0163033 100644 --- a/man/S2_initialize_user.Rd +++ b/man/S2_initialize_user.Rd @@ -5,7 +5,7 @@ \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") +S2_initialize_user(user = "test@s2.boku.eodc.eu", password = "test") } \arguments{ \item{user}{character user login you have registered with at diff --git a/tests/run-all.R b/tests/run-all.R new file mode 100644 index 0000000..50c6479 --- /dev/null +++ b/tests/run-all.R @@ -0,0 +1,3 @@ +# https://github.com/hadley/devtools/wiki/Testing +library(testthat) +test_check('sentinel2') diff --git a/tests/testthat/test-S2_query.R b/tests/testthat/test-S2_query.R new file mode 100644 index 0000000..cd58fe0 --- /dev/null +++ b/tests/testthat/test-S2_query.R @@ -0,0 +1,39 @@ +context('S2_query') +S2_initialize_user() + +test_that('S2_query_image() works', { + data = S2_query_image( + atmCorr = FALSE, + band = 'B10', + cloudCovMin = 80, + dateMin = '2016-06-01', + dateMax = '2016-08-31', + utm = '33UXP' + ) + expect_is(data, 'data.frame') + expect_gt(nrow(data), 0) + cols = c("imageId", "productId", "granuleId", "product", "granule", "utm", "orbit", "band", "resolution", "cloudCov", "atmCorr", "date", "format", "processDate", "url") + expect_equal(intersect(names(data), cols), cols) + expect_true(all(as.numeric(data$atmCorr) == 0)) + expect_true(all(data$band == 'B10')) + expect_true(all(data$cloudCov >= 80)) + expect_true(all(data$date >= '2016-06-01')) + expect_true(all(data$date <= '2016-08-31')) + expect_true(all(data$utm == '33UXP')) +}) + +test_that('S2 downloads images', { + if (file.exists('test.jp2')) { + unlink('test.jp2') + } + on.exit({ + if (file.exists('test.jp2')) { + unlink('test.jp2') + } + }) + + data = S2_query_image(imageId = 29392766) + S2_download(data$url, 'test.jp2', FALSE) + expect_true(file.exists('test.jp2')) + expect_true(file.info('test.jp2')$size == 3190469) +})