From ebae2b02d239bbfa171b8f5a0d28e5475700748d Mon Sep 17 00:00:00 2001 From: Mike Mahoney Date: Mon, 18 Jan 2021 14:14:05 -0500 Subject: [PATCH] Style and update NEWS for 0.2.1 --- NEWS.md | 10 ++++++++++ R/classes.R | 1 - R/get_bbox.R | 16 +++++++++------- R/hit_api.R | 3 ++- R/merge_rasters.R | 2 +- tests/testthat/test-4-merge_rasters.R | 17 +++++++++-------- tests/testthat/test-get_bbox.R | 1 - tests/testthat/test-utils.R | 5 +++-- tests/testthat/test-vector_to_overlay.R | 1 - 9 files changed, 34 insertions(+), 22 deletions(-) diff --git a/NEWS.md b/NEWS.md index 837a9b4..5a6f44b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# terrainr 0.2.1 +* Improvements and bug fixes: + * The `transportation` endpoint has moved servers, and is now handled by the + same function that handles DEMs and orthoimages +* Internal changes: + * The main branch of `terrainr` is now `main` + * Tests run on a schedule on Monday/Wednesday/Friday mornings, to alert to + endpoint changes + * Restyled code + # terrainr 0.2.0 * Breaking changes: * `merge_rasters` loses the argument `merge_raster`. For the "georeference diff --git a/R/classes.R b/R/classes.R index bf3c7f6..0db1c54 100644 --- a/R/classes.R +++ b/R/classes.R @@ -79,7 +79,6 @@ terrainr_coordinate_pair <- function(coords, coord_units = c( lat <- coords[[1]] lng <- coords[[2]] } else { - names(coords) <- tolower(names(coords)) if (all(names(coords) %in% c(latitude_names, longitude_names))) { diff --git a/R/get_bbox.R b/R/get_bbox.R index bf11eb9..b10866e 100644 --- a/R/get_bbox.R +++ b/R/get_bbox.R @@ -35,8 +35,8 @@ #' @md # nolint start get_bbox <- function(data = NULL, lat = NULL, lng = NULL, na.rm = NULL) { -# lintr complains about na.rm but I want to mimic base R -# nolint end + # lintr complains about na.rm but I want to mimic base R + # nolint end UseMethod("get_bbox") } @@ -44,7 +44,7 @@ get_bbox <- function(data = NULL, lat = NULL, lng = NULL, na.rm = NULL) { #' @export # nolint start get_bbox.sf <- function(data, lat, lng, na.rm) { -# nolint end + # nolint end coords <- as.data.frame(sf::st_coordinates(data)) terrainr::get_coord_bbox(lat = coords$Y, lng = coords$X, na.rm = na.rm) } @@ -55,16 +55,18 @@ get_bbox.sf <- function(data, lat, lng, na.rm) { get_bbox.RasterLayer <- function(data, lat, lng, na.rm) { # nolint end coords <- raster::extent(data) - terrainr::get_coord_bbox(lat = c(coords@ymin, coords@ymax), - lng = c(coords@xmin, coords@xmax), - na.rm = na.rm) + terrainr::get_coord_bbox( + lat = c(coords@ymin, coords@ymax), + lng = c(coords@xmin, coords@xmax), + na.rm = na.rm + ) } #' @rdname get_bbox #' @export # nolint start get_coord_bbox <- function(data = NULL, lat, lng, na.rm = NULL) { -# nolint end + # nolint end if (!is.null(data)) { lat <- tryCatch(lat, error = function(e) rlang::ensym(lat)) lng <- tryCatch(lng, error = function(e) rlang::ensym(lng)) diff --git a/R/hit_api.R b/R/hit_api.R index 25120af..2de46e6 100644 --- a/R/hit_api.R +++ b/R/hit_api.R @@ -152,7 +152,8 @@ hit_national_map_api <- function(bbox, res <- httr::GET(url, query = c(bbox_arg, query_arg)) body <- tryCatch(httr::content(res, type = "application/json"), error = function(e) { - tryCatch({ + tryCatch( + { res <- httr::GET(url, query = c(bbox_arg, query_arg)) httr::content(res, type = "application/json") }, diff --git a/R/merge_rasters.R b/R/merge_rasters.R index 2ebd786..7e9ecc7 100644 --- a/R/merge_rasters.R +++ b/R/merge_rasters.R @@ -182,8 +182,8 @@ merge_rasters <- function(input_rasters, total_extent, output_image, overwrite = overwrite - ) ) + ) invisible( utils::capture.output( gdalUtils::mosaic_rasters( diff --git a/tests/testthat/test-4-merge_rasters.R b/tests/testthat/test-4-merge_rasters.R index 451a749..23c51e8 100644 --- a/tests/testthat/test-4-merge_rasters.R +++ b/tests/testthat/test-4-merge_rasters.R @@ -39,8 +39,9 @@ test_that("merge_raster files are identical no matter the filename", { # assign the output tile filenames... tmptif <- vector("list") temp_tiles <- get_tiles(first_tile, - services = c("elevation", "ortho"), - georeference = FALSE) + services = c("elevation", "ortho"), + georeference = FALSE + ) tmptif[[1]] <- temp_tiles[[1]] tmptif[[2]] <- get_tiles(second_tile)[[1]] @@ -57,16 +58,16 @@ test_that("merge_raster files are identical no matter the filename", { ) merge_orth <- tempfile(fileext = ".tiff") - merge_rasters(temp_tiles[[1]], - tempfile(fileext = ".tif"), - temp_tiles[[2]], - merge_orth) + merge_rasters( + temp_tiles[[1]], + tempfile(fileext = ".tif"), + temp_tiles[[2]], + merge_orth + ) stored_raster <- raster::raster("testdata/merge_rasters_test.tif") test_raster <- raster::raster(merge_orth) expect_equal(stored_raster@crs, test_raster@crs) expect_equal(stored_raster@extent, test_raster@extent) - }) - diff --git a/tests/testthat/test-get_bbox.R b/tests/testthat/test-get_bbox.R index 83db95e..e502b81 100644 --- a/tests/testthat/test-get_bbox.R +++ b/tests/testthat/test-get_bbox.R @@ -56,5 +56,4 @@ test_that("raster s3 method definitions work", { get_bbox(raster::raster("testdata/3DEP.tif")), tolerance = 0.00001 ) - }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 61c3ff3..a3abc68 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -24,6 +24,7 @@ test_that("distance conversions make sense", { 1000 ) expect_equal(terrainr::convert_distance(100, "feet"), - terrainr::convert_distance(1200, "inches"), - tolerance = 0.001) + terrainr::convert_distance(1200, "inches"), + tolerance = 0.001 + ) }) diff --git a/tests/testthat/test-vector_to_overlay.R b/tests/testthat/test-vector_to_overlay.R index 4cd7a9c..98036a7 100644 --- a/tests/testthat/test-vector_to_overlay.R +++ b/tests/testthat/test-vector_to_overlay.R @@ -88,4 +88,3 @@ test_that("vector_to_overlay generates the same tiles", { png::readPNG("testdata/vto_poly.png") ) }) -