Skip to content

Commit f303d10

Browse files
committed
updated doocumentation
1 parent bcb15e1 commit f303d10

38 files changed

Lines changed: 772 additions & 596 deletions

Example_Data/rmd_netdelin.dbf

462 KB
Binary file not shown.

Example_Data/rmd_netdelin.prj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

Example_Data/rmd_netdelin.shp

2.68 MB
Binary file not shown.

Example_Data/rmd_netdelin.shx

17 KB
Binary file not shown.

SNT_QuickReference.xlsx

8.33 KB
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
\BOOKMARK [1][-]{Rfn.cat.Rul.shp.1}{cat\137shp}{}% 1
2+
\BOOKMARK [1][-]{Rfn.net.Rul.calc.1}{net\137calc}{}% 2
3+
\BOOKMARK [1][-]{Rfn.net.Rul.cat.1}{net\137cat}{}% 3
4+
\BOOKMARK [1][-]{Rfn.net.Rul.clim.1}{net\137clim}{}% 4
5+
\BOOKMARK [1][-]{Rfn.net.Rul.comid.1}{net\137comid}{}% 5
6+
\BOOKMARK [1][-]{Rfn.net.Rul.conflu.1}{net\137conflu}{}% 6
7+
\BOOKMARK [1][-]{Rfn.net.Rul.delin.1}{net\137delin}{}% 7
8+
\BOOKMARK [1][-]{Rfn.net.Rul.flow.1}{net\137flow}{}% 8
9+
\BOOKMARK [1][-]{Rfn.net.Rul.hort.1}{net\137hort}{}% 9
10+
\BOOKMARK [1][-]{Rfn.net.Rul.lc.1}{net\137lc}{}% 10
11+
\BOOKMARK [1][-]{Rfn.net.Rul.nhdplus.1}{net\137nhdplus}{}% 11
12+
\BOOKMARK [1][-]{Rfn.net.Rul.sample.1}{net\137sample}{}% 12
13+
\BOOKMARK [1][-]{Rfn.net.Rul.segid.1}{net\137segid}{}% 13
14+
\BOOKMARK [1][-]{Rfn.net.Rul.sinu.1}{net\137sinu}{}% 14
15+
\BOOKMARK [0][-]{index.0}{Index}{}% 15

StreamNetworkTools/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: StreamNetworkTools
2-
Title: Chracterizing Topology and Planform Geometry of NHDPlusV2 Stream Networks
2+
Title: Characterizing Topology and Planform Geometry of NHDPlusV2 Stream Networks
33
Version: 1.0.0.000
44
Authors@R: person("Darin", "Kopp", email = "darinkopp@gmail.com", role = c("aut", "cre"))
55
Description: An R package to derive covariates from the NHDPlusV2 dataset and faciliate continental scale analyses of river networks.

StreamNetworkTools/R/cat_shp.R

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
#' Catchment Shape
22
#'
3-
#' Calculates metrics related to catchment \code{Value}
3+
#' Calculates metrics related to catchment shape very slowly.
44
#'
5-
#' Requires netcat object (see \code{\link{net_cat}})
5+
#' @param netcat output from \code{\link{net_cat}}
66
#'
7-
#' @param netcat output from \code{net_delin}
8-
#'
9-
#' @return a \code{data.frame}: \code{group.comid} of network root node; \code{net.comid}
10-
#' network flowline comid; and basin.len which is basin lenght
7+
#' @return \code{data.frame}: \code{group.comid} root COMID of network;
8+
#' \code{net.comid} COMID upstream of root COMID, indexes catchments;
9+
#' \code{$basin_len} length of basin, longest distance between two catchment
10+
#' vertices; \code{$basin_area} area of catchment; \code{$basin_width}
11+
#' basin_area / basin_len
1112
#'
1213
#' @examples
13-
#' g <- cat_shp(netcat = c, vpu = "01", nhdplus_path = getwd())
14+
#' # identify NHDPlusV2 COMID
15+
#' a <- net_sample(nhdplus_path = getwd(), vpu = "01", ws_order = 6, n = 5)
16+
#' # delineate stream network
17+
#' b <- net_delin(group_comid = as.character(a[,"COMID"]), nhdplus_path = getwd(), vpu = "01")
18+
#' #identify catchments
19+
#' c <- net_cat(netdelin = b, vpu = "01", nhdplus_path = getwd(), dissolve = "N")
20+
#' calculate basin shape
21+
#' d <- cat_shp(netcat = c, vpu = "01", nhdplus_path = getwd())
1422
#'
1523
#' @export
1624

1725
cat_shp<-function(netcat){
18-
# project to albers
19-
obj <- st_transform(netcat$sf_obj, 5070)
26+
# project to albers
27+
obj <- st_transform(netcat$sf_obj, 5070)
2028

2129
distance.func <- function(polygon){
2230
polygon <- st_sfc(polygon)
@@ -28,14 +36,14 @@ basin_len <- units::set_units(unlist(dist),"meters")
2836
basin_area <- st_area(obj)
2937
basin_width <- basin_area / basin_len
3038
group.comid <- as.character(obj$group.comid)
31-
out <- data.frame(group.comid,
32-
basin_len,
33-
basin_area,
34-
basin_width)
39+
out <- data.frame(group.comid, basin_len, basin_area, basin_width)
40+
3541
if(any(names(obj) == "net.comid")){
3642
net.comid <- as.character(obj$net.comid)
3743
out <- data.frame(out, net.comid)
3844
}
3945

46+
out <- out[,c("group.comid", "net.comid", "basin_len", "basin_area", "basin_width")]
47+
4048
return(out)
4149
}

StreamNetworkTools/R/net_calc.r

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
#' Network Topology
1+
#' Network Topology Metrics
22
#'
3-
#' Calculates metrics related to stream network topology see \code{Value}
3+
#' Calculates stream network topology metrics
44
#'
55
#' Requires /NHDPlusAttributes directory (see \code{\link{net_nhdplus}})
66
#'
7-
#' Warning: "Check drain.dia. Incomplete headwater path 5848788 at COMID 5848656
8-
#' in network 5848066 perhaps due to waterbody" may indicate that
9-
#' drain.dia is flawed by the presence of a waterbody in the network
7+
#' Length and area measures are scaled by M values
108
#'
119
#' @param netdelin output from \code{net_delin}
12-
#' @param vpu vector processing unit
13-
#' @param nhdplus_path directory containing NHDPlusV2 \code{\link{net_nhdplus}}
10+
#' @param vpu NHDPlusV2 Vector Processing Unit
11+
#' @param nhdplus_path Directory for NHDPlusV2 files (\code{\link{net_nhdplus}})
1412
#'
15-
#' @return a \code{data.frame}: \code{COMID} of network root node; \code{vpu}
16-
#' vector processing unit; \code{maxelev} max elevation of network flowline (cm);
17-
#' \code{minelev} min elevation of network flowline (cm); \code{releif}
18-
#' (\code{maxelev} - \code{minelev}); \code{drain.dia} drainage diameter
19-
#' (longest flowpath in network); \code{head.h2o} number of terminal nodes
20-
#' (i.e. headwaters); \code{trib.jun} number of tributary junctions
21-
#' (\code{head.h2o} - 1); \code{AREASQKM} drainage area (km^2);
22-
#' \code{LENGTHKM} total lenght of network flowlines; \code{drain.den}
23-
#' drainage density (\code{LENGTHKM} / \code{AREASQKM}); \code{WS.ord}
24-
#' strahler order for root node; \code{reach.cnt} number of valley segments
25-
#' (edges); \code{diver.cnt} count of divergent flow paths
13+
#' @return \code{data.frame}: \code{$group.comid} stream network root COMID;
14+
#' \code{$vpu} NHDPlusV2 vector processing unit;\code{M} Position of sampling
15+
#' point on COMID, as proportion of COMID from upstream end; \code{WS.ord}
16+
#' strahler order for root node;\code{$head.h2o} number of headwater reaches;
17+
#' \code{$trib.jun} number of tributary junctions; \code{reach.cnt} number of
18+
#' reaches in network; \code{diver.cnt} count of divergent flow paths;
19+
#' \code{$AREASQKM} drainage area (km^2); \code{$LENGTHKM} total lenght of
20+
#' network flowlines (km); \code{drain.den} drainage density (\code{LENGTHKM}
21+
#' / \code{AREASQKM})
2622
#'
2723
#' @examples
28-
#' g <- net_calc(netdelin = c, vpu = "01", nhdplus_path = getwd())
29-
#'
24+
#' # identify NHDPlusV2 COMID
25+
#' a <- net_sample(nhdplus_path = getwd(), vpu = "01", ws_order = 6, n = 5)
26+
#' # delineate stream network
27+
#' b <- net_delin(group_comid = as.character(a[,"COMID"]), nhdplus_path = getwd(), vpu = "01")
28+
#' calculate topology summary
29+
#' c <- net_calc(netdelin = b, vpu = "01", nhdplus_path = getwd())
3030
#' @export
3131

3232
net_calc <- function(netdelin, vpu, nhdplus_path){
@@ -96,7 +96,7 @@ net_calc <- function(netdelin, vpu, nhdplus_path){
9696
c("net.id", "net.comid", "group.comid")]
9797

9898
diver.cnt <- aggregate(div.rm[, "group.comid"],
99-
by = list(div.rm[,"net.id"], div.rm[, "group.comid"]),
99+
by = list(div.rm[,"net.id"]),
100100
length)
101101

102102
names(diver.cnt) <- c("net.id", "diver.cnt")
@@ -142,5 +142,7 @@ net_calc <- function(netdelin, vpu, nhdplus_path){
142142
merge(x, y, by = "net.id", all.x = T),
143143
list(data.out, WS.ord,head.h2o, reach.cnt, diver.cnt, cat.area))#, relief))
144144

145+
names(data.out)[2] <- "group.comid"
146+
145147
return(data.out)
146148
}

StreamNetworkTools/R/net_cat.r

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,93 @@
1-
#' Identify NHDPlus Catchment
1+
#' NHDPlus Catchment
22
#'
3-
#' Extracts NHDPlus flowline catchments with optional dissolve
3+
#' Identifies catchments associated with network COMID
44
#'
5-
#' Ploygons can be used to associate landscape attributes not included with
6-
#' NHDPlus
5+
#' catchment ploygons can be used to associate landscape attributes to NHDPlusV2
6+
#' flowlines (COMID).
77
#'
88
#' Requires NHDPlusCatchment directory
99
#'
10-
#' Some comid's do not have matching catchment (featureID) and some catchments
11-
#' do not have matching comid's (see
12-
#' \url{http://www.horizon-systems.com/NHDPlus/NHDPlusV2_documentation.php})
10+
#' see
11+
#' (\url{http://www.horizon-systems.com/NHDPlus/NHDPlusV2_documentation.php})
12+
#' for information about Watershed boundary dataset and its use in NHDPlusV2
13+
#' Only catchments matching network COMID are returned in sf object
1314
#'
1415
#' @param netdelin output form \code{link{net_delin}}
15-
#' @param vpu the vector processing unit
16-
#' @param nhdplus_path the directory containing NHDPlus data see(\code{net_nhdplus})
17-
#' @param dissolve collapse subcatchments to create a single network catchmet \code{(Y/N)}
16+
#' @param vpu NHDPlusV2 Vector Processing Unit
17+
#' @param nhdplus_path Directory containing NHDPlusV2 see (\code{net_nhdplus})
18+
#' @param dissolve dissolve catchments \code{(Y/N)}
1819
#'
19-
#' @return named list: \code{$sf_obj} is simple features object and \code{$na_cat} records
20-
#' comid's without catchment
20+
#' @return named list: \code{$sf_obj} is simple features object;
21+
#' \code{$group.comid} root COMID of network; \code{$net.comid} COMID upstream
22+
#' of root COMID; \code{vpu} NHDPlusV2 Vector Processing Unit. \code{$na_cat}
23+
#' contains comids without catchment \code{$na_cat} records comid's without
24+
#' catchment (see Details)
2125
#'
2226
#' @examples
23-
#' d <- net_cat(netdelin = c, vpu = "01", nhdplus_path = getwd(), dissolve = "Y")
24-
#' plot(st_geometry(d$sf_obj))
27+
#' #' # identify NHDPlusV2 COMID
28+
#' a <- net_sample(nhdplus_path = getwd(), vpu = "01", ws_order = 6, n = 5)
29+
#' # delineate stream network
30+
#' b <- net_delin(group_comid = as.character(a[,"COMID"]), nhdplus_path = getwd(), vpu = "01")
31+
#' C <- net_cat(netdelin = b, vpu = "01", nhdplus_path = getwd(), dissolve = "N")
32+
#' #plot catchments
33+
#' plot(st_geometry(c$sf_obj))
34+
#' #write sf object as shapefile
35+
#' sf::write(c$sf_obj, paste(getwd(),"c.shp",sep = ""))
2536
#' @export
2637

2738
net_cat <- function(netdelin, vpu, nhdplus_path, dissolve){
2839

2940
dir.spatial <- grep(paste(vpu, "/NHDPlusCatchment", sep = ""),
3041
list.dirs(nhdplus_path, full.names = T),
3142
value = T)
32-
dir.spatial <- dir.spatial[grep("NHDPlusCatchment/",dir.spatial,invert=T)]
43+
dir.spatial <- dir.spatial[grep("NHDPlusCatchment/", dir.spatial, invert = T)]
3344
catch <- sf::st_read(dir.spatial, layer = "Catchment")
34-
names(catch)[c(1, 2)] <- toupper(names(catch)[c(1,2)])
45+
names(catch)[c(1, 2)] <- toupper(names(catch)[c(1, 2)])
3546
#some networks do not have matching catchements
36-
na.cat <- data.frame(vpu = character(),
37-
group.comid = character(),
38-
net.comid = character())
47+
na.cat <- data.frame(vpu = character(), group.comid = character(), net.comid = character())
3948
ids <- netdelin$Network
4049
count <- 1
4150

4251
for (i in unique(ids[ ,"group.comid"])){
4352
group.comid <- as.character(i)
4453
net.comid <- as.character(ids[ids[ ,"group.comid"] == i, "net.comid"])
4554
cat_comid <- dim(catch[catch$FEATUREID %in% net.comid, "FEATUREID"])[1]
46-
na_len<-length(net.comid[net.comid %in% catch$FEATUREID == F])
47-
na.cat<-rbind(na.cat,
48-
data.frame(net.comid = net.comid[net.comid %in% catch$FEATUREID == F],
49-
group.comid = rep(group.comid,na_len),
50-
vpu = rep(vpu,na_len)))
55+
na_len <- length(net.comid[net.comid %in% catch$FEATUREID == F])
56+
na.cat <- rbind(na.cat, data.frame(net.comid = net.comid[net.comid %in% catch$FEATUREID == F],
57+
group.comid = rep(group.comid, na_len),
58+
vpu = rep(vpu, na_len)))
5159
if (cat_comid > 0){
5260
if (count == 1) {
5361
save.shp <- catch[catch$FEATUREID %in% net.comid, "FEATUREID"]
54-
net.ids<-save.shp$FEATUREID
62+
net.ids <- save.shp$FEATUREID
5563
save.shp <- lwgeom::st_make_valid(save.shp)
5664
geom <- sf::st_geometry(save.shp)
57-
save.shp <- sf::st_sf(geom,
58-
data.frame(group.comid = rep(group.comid, cat_comid),
59-
net.comid=net.ids,
65+
save.shp <- sf::st_sf(geom, data.frame(group.comid = rep(group.comid, cat_comid),
66+
net.comid = net.ids,
6067
vpu = rep(vpu, cat_comid)))
6168
} else {
6269
temp <- catch[catch$FEATUREID %in% net.comid, "FEATUREID"]
6370
net.ids <- temp$FEATUREID
6471
temp <- lwgeom::st_make_valid(temp)
6572
geom <- sf::st_geometry(temp)
66-
temp <- sf::st_sf(geom,
67-
data.frame(group.comid = rep(group.comid, cat_comid),
68-
net.comid=net.ids,
73+
temp <- sf::st_sf(geom, data.frame(group.comid = rep(group.comid, cat_comid),
74+
net.comid = net.ids,
6975
vpu = rep(vpu, cat_comid)))
7076
save.shp <- rbind(save.shp, temp)
7177
}
7278
count <- count + 1
7379
} else {
74-
net.comid<-NA
80+
net.comid <- NA
7581
na.cat <- rbind(na.cat, cbind(vpu, group.comid, net.comid))
7682
}
7783
}
78-
if (dissolve=="Y"){
84+
85+
if (dissolve == "Y"){
7986
save.shp <- dplyr::group_by(save.shp, group.comid)
8087
save.shp <- dplyr::summarise(save.shp, subcat_count = length(vpu))
8188
save.shp <- sf::st_cast(save.shp)
8289
}
90+
8391
out.list <- list(sf_obj = save.shp, na_cat = na.cat)
8492
return(out.list)
8593
}

0 commit comments

Comments
 (0)