Skip to content

Commit

Permalink
solve solaris proj issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jsta committed Jul 13, 2021
1 parent 408ae67 commit 1ee41a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 7 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -28,21 +26,21 @@ 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(
st_transform(gull$sp$NHDWaterbody, 4326),
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)))

})
})

0 comments on commit 1ee41a9

Please sign in to comment.