Skip to content

Commit

Permalink
Merge pull request #324 from DOI-USGS/hydroloom
Browse files Browse the repository at this point in the history
Hydroloom - tracking PR
  • Loading branch information
dblodgett-usgs authored Sep 30, 2023
2 parents 9c1aadd + 27d35c2 commit 187e1db
Show file tree
Hide file tree
Showing 215 changed files with 2,508 additions and 4,598 deletions.
2 changes: 0 additions & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ inst/doc/*.html
docs
_pkgdown.yml
data-raw
vignettes/rosm.cache
DISCLAIMER.md
code.json
^doc$
^Meta$
.Renviron
tests/testthat/data/03
rosm.cache
pkgdown
.gitlab-ci.yml
.github
Expand Down
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pkgdown
docs
data-raw
rosm.cache
.Renviron
.Rproj.user
.Rhistory
1 change: 0 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
with:
r-version: ${{ matrix.config.r }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck, any::covr
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ pkgdown
cran-comments.md
.Renviron
CRAN-SUBMISSION
temp.R
12 changes: 8 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nhdplusTools
Type: Package
Title: NHDPlus Tools
Version: 0.7.0
Version: 1.0.0
Authors@R: c(person(given = "David",
family = "Blodgett",
role = c("aut", "cre"),
Expand All @@ -18,14 +18,18 @@ Authors@R: c(person(given = "David",
person(given = "Josh",
family = "Erickson",
role = "ctb",
email = "[email protected]"))
email = "[email protected]"),
person(given = "Lauren",
family = "Koenig",
role = "ctb",
comment = c(ORCID = "0000-0002-7790-330X")))
Description: Tools for traversing and working with National Hydrography Dataset Plus (NHDPlus) data. All methods implemented in 'nhdplusTools' are available in the NHDPlus documentation available from the US Environmental Protection Agency <https://www.epa.gov/waterdata/basic-information>.
URL: https://doi-usgs.github.io/nhdplusTools/ https://github.com/doi-usgs/nhdplusTools/
BugReports: https://github.com/doi-usgs/nhdplusTools/issues/
Depends:
R (>= 4.0)
Imports: dplyr, rlang, sf, RANN, units, magrittr, jsonlite, httr, xml2, R.utils, utils, tidyr, methods, rosm, prettymapr, fst, dataRetrieval, tools, zip, pbapply, arrow
Suggests: testthat, knitr, rmarkdown, markdown, ggmap, ggplot2, sp, lwgeom, devtools, codetools, data.table, parallel, s2, gifski, leaflet, httptest
Imports: hydroloom, dplyr, sf, units, magrittr, jsonlite, httr, xml2, R.utils, utils, tidyr, methods, maptiles, mapsf, fst, arrow, dataRetrieval, tools, zip, pbapply, future.apply
Suggests: testthat, knitr, rmarkdown, markdown, ggmap, ggplot2, sp, lwgeom, devtools, codetools, data.table, parallel, s2, gifski, leaflet, httptest, future
License: CC0
Encoding: UTF-8
RoxygenNote: 7.2.3
Expand Down
38 changes: 26 additions & 12 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(calculate_total_drainage_area)
export(disambiguate_flowline_indexes)
export(discover_nhdplus_id)
export(discover_nldi_characteristics)
export(download_nhd)
export(download_nhdplushr)
export(download_nhdplusv2)
export(download_rf1)
Expand Down Expand Up @@ -71,18 +72,15 @@ export(rename_geometry)
export(rescale_catchment_characteristics)
export(rescale_measures)
export(st_compatibalize)
export(stage_national_data)
export(subset_nhdplus)
export(subset_rpu)
export(subset_vpu)
importFrom(RANN,nn2)
importFrom(arrow,open_dataset)
importFrom(arrow,s3_bucket)
importFrom(dplyr,across)
importFrom(dplyr,all_of)
importFrom(dplyr,any_of)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_cols)
importFrom(dplyr,bind_rows)
importFrom(dplyr,collect)
importFrom(dplyr,desc)
Expand All @@ -91,17 +89,13 @@ importFrom(dplyr,everything)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,group_split)
importFrom(dplyr,lag)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,n)
importFrom(dplyr,rename)
importFrom(dplyr,rename_with)
importFrom(dplyr,right_join)
importFrom(dplyr,row_number)
importFrom(dplyr,select)
importFrom(dplyr,starts_with)
importFrom(dplyr,summarise)
importFrom(dplyr,summarize)
importFrom(dplyr,ungroup)
importFrom(fst,metadata_fst)
Expand All @@ -111,33 +105,52 @@ importFrom(httr,POST)
importFrom(httr,RETRY)
importFrom(httr,progress)
importFrom(httr,write_disk)
importFrom(hydroloom,accumulate_downstream)
importFrom(hydroloom,add_levelpaths)
importFrom(hydroloom,add_pathlength)
importFrom(hydroloom,add_pfafstetter)
importFrom(hydroloom,add_streamlevel)
importFrom(hydroloom,add_streamorder)
importFrom(hydroloom,add_toids)
importFrom(hydroloom,disambiguate_indexes)
importFrom(hydroloom,fix_flowdir)
importFrom(hydroloom,get_hydro_location)
importFrom(hydroloom,get_node)
importFrom(hydroloom,get_partial_length)
importFrom(hydroloom,hy)
importFrom(hydroloom,index_points_to_lines)
importFrom(hydroloom,index_points_to_waterbodies)
importFrom(hydroloom,make_fromids)
importFrom(hydroloom,make_index_ids)
importFrom(hydroloom,navigate_connected_paths)
importFrom(hydroloom,navigate_hydro_network)
importFrom(hydroloom,rename_geometry)
importFrom(hydroloom,rescale_measures)
importFrom(hydroloom,sort_network)
importFrom(hydroloom,st_compatibalize)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")
importFrom(magrittr,`%>%`)
importFrom(methods,as)
importFrom(methods,is)
importFrom(pbapply,pbapply)
importFrom(pbapply,pblapply)
importFrom(pbapply,pboptions)
importFrom(rlang,.data)
importFrom(sf,"st_geometry<-")
importFrom(sf,read_sf)
importFrom(sf,st_as_sf)
importFrom(sf,st_as_sfc)
importFrom(sf,st_bbox)
importFrom(sf,st_buffer)
importFrom(sf,st_cast)
importFrom(sf,st_coordinates)
importFrom(sf,st_crs)
importFrom(sf,st_distance)
importFrom(sf,st_drop_geometry)
importFrom(sf,st_filter)
importFrom(sf,st_geometry)
importFrom(sf,st_geometry_type)
importFrom(sf,st_join)
importFrom(sf,st_layers)
importFrom(sf,st_multilinestring)
importFrom(sf,st_nearest_feature)
importFrom(sf,st_reverse)
importFrom(sf,st_sf)
importFrom(sf,st_simplify)
importFrom(sf,st_transform)
Expand All @@ -146,6 +159,7 @@ importFrom(sf,write_sf)
importFrom(stats,weighted.mean)
importFrom(tidyr,contains)
importFrom(tidyr,pivot_wider)
importFrom(tidyr,replace_na)
importFrom(tools,R_user_dir)
importFrom(utils,combn)
importFrom(utils,download.file)
Expand Down
55 changes: 55 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,58 @@
nhdplusTools 1.0.0
==========

## `hydroloom`

v1.0.0 should be backward compatible with v0.7 but deprecation warnings have been added and one previously deprecated function has been removed.

This release evolves `nhdplusTools` to use [`hydroloom`](https://doi-usgs.github.io/hydroloom/articles/hydroloom.html) as a core dependency. `nhdplusTools` now depends on `hydroloom` for all network navigation and indexing functionality that is not specific to the nhdplus data model or specific to a US-context.

Specific functions imported from [`hydroloom`](https://doi-usgs.github.io/hydroloom/articles/hydroloom.html) include:

- hy
- accumulate_downstream
- add_levelpaths
- add_pathlength
- add_pfafstetter
- add_streamlevel
- add_streamorder
- add_toids
- disambiguate_indexes
- fix_flowdir
- get_hydro_location
- get_node
- get_partial_length
- index_points_to_lines
- index_points_to_waterbodies
- make_fromids
- make_index_ids
- navigate_connected_paths
- navigate_hydro_network
- rename_geometry
- rescale_measures
- sort_network
- st_compatibalize

[See the `hydroloom` reference list for details about these functions.](https://doi-usgs.github.io/hydroloom/reference/index.html)

With these functions migrated to hydroloom, a number of `nhdplusTools` functions are now deprecated in favor of the `hyroloom` implementation.

- `make_node_topology()`
- `get_pfaf()`
- `get_path_members()`
- `get_path_lengths()`
- `get_levelpaths()`
- `get_terminal()`
- `make_node_topology()`

In v1.0.0, the `download_nhd()` function was added.

In v1.0.0, the stage_national_data (previously deprecated) function was removed.

nhdplusTools 0.7.1
==========
This release fixes a minor example issue for CRAN checks

nhdplusTools 0.7.0
==========
This release adds three new functions.
Expand Down
94 changes: 32 additions & 62 deletions R/A_nhdplusTools.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ vaa_hydroshare <-
'https://www.hydroshare.org/resource/6092c8a62fac45be97a09bfd0b0bf726/data/contents/nhdplusVAA.fst'

vaa_sciencebase <-
'https://www.sciencebase.gov/catalog/file/get/60c92503d34e86b9389df1c9?name=enhd_nhdplusatts.fst'
'https://www.sciencebase.gov/catalog/file/get/63cb311ed34e06fef14f40a3?name=enhd_nhdplusatts.fst'

nhdplusTools_env <- new.env()

Expand Down Expand Up @@ -249,10 +249,11 @@ default_nhdplus_path <- "../NHDPlusV21_National_Seamless.gdb"

assign("default_nhdplus_path", default_nhdplus_path, envir = nhdplusTools_env)

nhdhr_bucket <- "https://prd-tnm.s3.amazonaws.com/"
nhd_bucket <- "https://prd-tnm.s3.amazonaws.com/"
nhdhr_file_list <- "?prefix=StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/"
nhd_file_list <- "?prefix=StagedProducts/Hydrography/NHD/HU4/GDB/"

assign("nhdhr_bucket", nhdhr_bucket, envir = nhdplusTools_env)
assign("nhd_bucket", nhd_bucket, envir = nhdplusTools_env)
assign("nhdhr_file_list", nhdhr_file_list, envir = nhdplusTools_env)

assign("nhdpt_dat_dir",
Expand Down Expand Up @@ -391,65 +392,6 @@ align_nhdplus_names <- function(x){

}

# TODO: deprecate moved to hydroloom
drop_geometry <- function(x) {
if("sf" %in% class(x)) {
sf::st_drop_geometry(x)
} else {
x
}
}

# TODO: deprecate moved to hydroloom
#' make spatial inputs compatible
#' @description makes sf1 compatible with sf2 by projecting into
#' the projection of 2 and ensuring that the geometry columns are the
#' same name.
#' @param sf1 sf data.frame
#' @param sf2 sf data.frame
#' @export
#' @examples
#'
#' source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
#'
#' (one <- dplyr::select(sample_flines))
#' (two <- sf::st_transform(one, 5070))
#'
#' attr(one, "sf_column") <- "geotest"
#' names(one)[names(one) == "geom"] <- "geotest"
#'
#' st_compatibalize(one, two)
#'
st_compatibalize <- function(sf1, sf2) {

sf1 <- st_transform(sf1, st_crs(sf2))

rename_geometry(sf1, attr(sf2, "sf_column"))

}

# TODO: deprecate moved to hydroloom
#' rename_geometry
#' @description correctly renames the geometry column
#' of a sf object.
#' @param g sf data.table
#' @param name character name to be used for geometry
#' @export
#' @examples
#'
#' (g <- sf::st_sf(a=3, geo = sf::st_sfc(sf::st_point(1:2))))
#' rename_geometry(g, "geometry")
#'
rename_geometry <- function(g, name){
current = attr(g, "sf_column")

names(g)[names(g)==current] = name

attr(g, "sf_column") <- name

g
}

get_cl <- function(cl) {
if(!is.null(cl)) {
if(!requireNamespace("parallel", quietly = TRUE)) {
Expand All @@ -465,3 +407,31 @@ get_cl <- function(cl) {
}
return(cl)
}

#' @importFrom hydroloom st_compatibalize
#' @export
hydroloom::st_compatibalize

#' @importFrom hydroloom rename_geometry
#' @export
hydroloom::rename_geometry

#' @importFrom hydroloom get_node
#' @export
hydroloom::get_node

#' @importFrom hydroloom fix_flowdir
#' @export
hydroloom::fix_flowdir

#' @importFrom hydroloom rescale_measures
#' @export
hydroloom::rescale_measures

#' @importFrom hydroloom get_hydro_location
#' @export
hydroloom::get_hydro_location

#' @importFrom hydroloom get_partial_length
#' @export
hydroloom::get_partial_length
Loading

0 comments on commit 187e1db

Please sign in to comment.