Skip to content

Commit 3eb8c8f

Browse files
committed
return vector from hydroseq, remove docs
1 parent 1b42ab6 commit 3eb8c8f

66 files changed

Lines changed: 33 additions & 14299 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ S3method(dbplyr_edition,OGRSQLConnection)
66
S3method(st_as_sf,tbl_OGRSQLConnection)
77
export(OGRSQL)
88
export(accumulate_downstream)
9-
export(add_hydroseq)
109
export(as_ogr)
1110
export(collect)
11+
export(get_hydroseq)
1212
export(st_as_sf)
1313
exportClasses(OGRSQLConnection)
1414
exportClasses(OGRSQLDriver)

R/network_properties.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' input row. The network must be a DAG (no cycles). This is an O(E) pass after
66
#' a single topological sort and is fast on large hydro networks.
77
#'
8-
#' @param x A data frame (or tibble) containing at least the identifier column
8+
#' @param x A data frame, tibble, or sf object containing at least the identifier column
99
#' given by `id`, the downstream pointer column given by `toid`, and the
1010
#' attribute column named in `attr`.
1111
#' @param id Character scalar. Column name in `x` with unique node identifiers.
@@ -95,7 +95,7 @@ accumulate_downstream <- function(x, id = "flowpath_id", toid = "flowpath_toid
9595

9696
#' Compute and add the hydrosequence to a directed acyclic network.
9797
#'
98-
#' @param topology A data frame (or tibble) containing at least the identifier column
98+
#' @param x A data frame (or tibble) containing at least the identifier column
9999
#' given by `id` and the downstream pointer column given by `toid`.
100100
#' @param id Character scalar. Column name in `topology` with unique node identifiers.
101101
#' Defaults to `"flowpath_id"`.
@@ -109,14 +109,14 @@ accumulate_downstream <- function(x, id = "flowpath_id", toid = "flowpath_toid
109109
#' @importFrom igraph dfs graph_from_data_frame
110110
#' @export
111111

112-
add_hydroseq <- function(topology, id = "flowpath_id", toid = "flowpath_toid", colname = "hydroseq") {
112+
get_hydroseq <- function(x, id = "flowpath_id", toid = "flowpath_toid") {
113113
# Create a _transposed_ network, where traversing the network
114114
# is equivalent to traversing the hydrological network upstream.
115115
#
116116
# This assumes the outlets of this network all connect to an
117117
# ephemeral "0" node (forming a rooted tree network).
118118

119-
edgelist <- as.data.frame(topology)[, c(toid, id)]
119+
edgelist <- as.data.frame(x)[, c(toid, id)]
120120
names(edgelist) <- c("id", "toid")
121121
edgelist$id[is.na(edgelist$id)] <- "0"
122122

@@ -147,8 +147,7 @@ add_hydroseq <- function(topology, id = "flowpath_id", toid = "flowpath_toid", c
147147
names(result) <- c(id, toid, "hydroseq")
148148

149149
# Arrange into input order
150-
topology[[colname]] <- result$hydroseq[match(topology[[id]], result[[id]])]
151-
topology
150+
result$hydroseq[match(x[[id]], result[[id]])]
152151
}
153152

154153

README.Rmd

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ You can install the development version of `hfutils` from [GitHub](https://githu
3535
remotes::install_github("lynker-spatial/hfutils")
3636
```
3737

38-
```{r}
38+
```{r,message=FALSE}
3939
library(hfutils)
4040
library(dplyr)
4141
```
@@ -47,26 +47,27 @@ library(dplyr)
4747
#### Basic connection: Dataset
4848

4949
```{r, eval = TRUE}
50-
hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg')
50+
gpkg <- '/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg'
51+
hfutils::as_ogr(gpkg)
5152
```
5253

5354
#### Basic connection: Layer
5455

5556
```{r, eval = TRUE}
56-
hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg', "divides")
57+
hfutils::as_ogr(gpkg, "divides")
5758
```
5859

5960
#### Lazy Eval
6061

6162
```{r, eval = TRUE}
62-
hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg', "divides") |>
63+
hfutils::as_ogr(gpkg, "divides") |>
6364
select(divide_id, areasqkm)
6465
```
6566

6667
#### sf extraction
6768

6869
```{r, eval = TRUE}
69-
hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg', "divides") |>
70+
hfutils::as_ogr(gpkg, "divides") |>
7071
filter(vpuid == "01") |>
7172
st_as_sf()
7273
```
@@ -82,7 +83,7 @@ hfutils::as_ogr('/vsis3/lynker-spatial/hydrofabric/v2.2/conus/conus_nextgen.gpkg
8283
```{r}
8384
## Accumulate Downstream
8485
system.time({
85-
da <- hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg',
86+
da <- hfutils::as_ogr(gpkg,
8687
'flowpaths') |>
8788
filter(vpuid == "01") |>
8889
st_as_sf() |>
@@ -92,14 +93,14 @@ head(da)
9293
9394
## Hydrosequence
9495
system.time({
95-
hs <- hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg',
96+
hs <- hfutils::as_ogr(gpkg,
9697
'flowpaths') |>
9798
filter(vpuid == "01") |>
9899
st_as_sf() |>
99-
add_hydroseq()
100+
get_hydroseq()
100101
})
101102
102-
head(hs$hydroseq)
103+
head(hs)
103104
```
104105

105106
### Questions?

README.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ remotes::install_github("lynker-spatial/hfutils")
2828
``` r
2929
library(hfutils)
3030
library(dplyr)
31-
#>
32-
#> Attaching package: 'dplyr'
33-
#> The following objects are masked from 'package:stats':
34-
#>
35-
#> filter, lag
36-
#> The following objects are masked from 'package:base':
37-
#>
38-
#> intersect, setdiff, setequal, union
3931
```
4032

4133
## Basic Use
@@ -45,7 +37,8 @@ library(dplyr)
4537
#### Basic connection: Dataset
4638

4739
``` r
48-
hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg')
40+
gpkg <- '/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg'
41+
hfutils::as_ogr(gpkg)
4942
#> [1] "divides" "flowpaths" "hydrolocations" "pois"
5043
#> [5] "network"
5144
#> <OGRSQLConnection>
@@ -56,7 +49,7 @@ hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg')
5649
#### Basic connection: Layer
5750

5851
``` r
59-
hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg', "divides")
52+
hfutils::as_ogr(gpkg, "divides")
6053
#> # Source: table<"divides"> [?? x 6]
6154
#> # Database: OGRSQLConnection
6255
#> divide_id vpuid areasqkm has_flowpath flowpath_id geom
@@ -77,7 +70,7 @@ hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg', "di
7770
#### Lazy Eval
7871

7972
``` r
80-
hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg', "divides") |>
73+
hfutils::as_ogr(gpkg, "divides") |>
8174
select(divide_id, areasqkm)
8275
#> # Source: SQL [?? x 2]
8376
#> # Database: OGRSQLConnection
@@ -99,7 +92,7 @@ hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg', "di
9992
#### sf extraction
10093

10194
``` r
102-
hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg', "divides") |>
95+
hfutils::as_ogr(gpkg, "divides") |>
10396
filter(vpuid == "01") |>
10497
st_as_sf()
10598
#> Simple feature collection with 67880 features and 5 fields
@@ -141,29 +134,29 @@ hfutils::as_ogr('/vsis3/lynker-spatial/hydrofabric/v2.2/conus/conus_nextgen.gpkg
141134
``` r
142135
## Accumulate Downstream
143136
system.time({
144-
da <- hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg',
137+
da <- hfutils::as_ogr(gpkg,
145138
'flowpaths') |>
146139
filter(vpuid == "01") |>
147140
st_as_sf() |>
148141
accumulate_downstream(attr = "areasqkm")})
149142
#> user system elapsed
150-
#> 0.836 0.506 1.368
143+
#> 0.821 0.464 1.285
151144

152145
head(da)
153146
#> [1] 15.66720 11.12805 4.44600 6.52365 4.53420 335.51145
154147

155148
## Hydrosequence
156149
system.time({
157-
hs <- hfutils::as_ogr('/Users/mikejohnson/hydrofabric/v3.0/reference_fabric.gpkg',
150+
hs <- hfutils::as_ogr(gpkg,
158151
'flowpaths') |>
159152
filter(vpuid == "01") |>
160153
st_as_sf() |>
161-
add_hydroseq()
154+
get_hydroseq()
162155
})
163156
#> user system elapsed
164-
#> 1.004 0.462 1.468
157+
#> 1.008 0.460 1.470
165158

166-
head(hs$hydroseq)
159+
head(hs)
167160
#> [1] 804 22722 22724 22723 22725 28137
168161
```
169162

docs/404.html

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)