From 1ee41a91aba90bccb707555dc3b319b1f16777ad Mon Sep 17 00:00:00 2001 From: jsta Date: Tue, 13 Jul 2021 09:33:29 -0600 Subject: [PATCH] solve solaris proj issue --- R/utils.R | 9 +++++++-- tests/testthat/test-utils.R | 10 ++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/R/utils.R b/R/utils.R index 3911c90..251dec5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -131,8 +131,13 @@ is_spatial <- function(filename) { #' find_vpu(nhdR::gull$sp$NHDWaterbody) #' } find_vpu <- function(pnt) { - pnt <- sf::st_transform(pnt, sf::st_crs(nhdR::vpu_shp)) - vpu <- nhdR::vpu_shp[nhdR::vpu_shp$UnitType == "VPU", ] + # fix for older proj versions (solaris) + # https://stackoverflow.com/a/62268361/3362993 + vpu <- nhdR::vpu_shp + sf::st_crs(vpu$geometry) <- 4326 + + pnt <- sf::st_transform(pnt, sf::st_crs(vpu)) + vpu <- vpu[vpu$UnitType == "VPU", ] if (any(names(pnt) == "UnitID")) { pnt <- pnt[, !(names(pnt) %in% "UnitID")] diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 7cdf008..d421b16 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -5,14 +5,12 @@ test_that("long2UTM works", { }) test_that("find_vpu works with character vpus", { - skip_on_os("solaris") pnt <- sf::st_sfc(sf::st_point(c(-80.8, 26.93))) sf::st_crs(pnt) <- 4326 expect_equal(nhdR:::find_vpu(pnt), "03S") }) test_that("find_vpu works with numeric vpus", { - skip_on_os("solaris") pnt <- sf::st_sfc(sf::st_point(c(-70.56, 43.85))) sf::st_crs(pnt) <- 4326 expect_equal(nhdR:::find_vpu(pnt), "01") @@ -28,7 +26,7 @@ test_that("toUTM works", { # with non-longlat objects expect_equal(sf::st_crs(toUTM(mendota$sp$NHDWaterbody)), - sf::st_crs(mendota$sp$NHDWaterbody)) + sf::st_crs(mendota$sp$NHDWaterbody)) # with objects spanning multiple utm zones big_combined <- rbind( @@ -36,13 +34,13 @@ test_that("toUTM works", { st_transform(sunapee$sp$NHDWaterbody, 4326)) expect_true(get_utm_zone(st_crs(toUTM(gull$sp$NHDWaterbody))) == - "16") + "16") big_combined <- rbind( st_transform(sunapee$sp$NHDWaterbody, 4326), st_transform(gull$sp$NHDWaterbody, 4326)) expect_true(st_crs(toUTM(sunapee$sp$NHDWaterbody)) == - st_crs(toUTM(big_combined))) + st_crs(toUTM(big_combined))) -}) +}) \ No newline at end of file