Skip to content

Commit

Permalink
fix and test example snap stream measure to point
Browse files Browse the repository at this point in the history
  • Loading branch information
joethorley committed Oct 29, 2024
1 parent d7af69a commit 231582e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
7 changes: 4 additions & 3 deletions R/snap-stream-measure-to-point.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ snap_stream_measure_to_point <- function(x, streams) {
#' \dontrun{
#' watershed <- fwa_add_watershed_to_blk(data.frame(blk = 356308001, rm = 1000))
#' network <- fwa_add_collection_to_polygon(watershed)
#' network <- select(network, blk = blue_line_key)
#' points <- fwa_convert_streams_to_rms(streams, interval = 500) |>
#' fwa_snap_stream_measure_to_point(points)
#' network$blk <- network$blue_line_key
#' streams <- fwa_join_stream_segments(network)
#' points <- fwa_add_rms_to_blk(data.frame(blk = 356308001))
#' fwa_snap_stream_measure_to_point(points, streams)
#' }
fwa_snap_stream_measure_to_point <- function(x, streams, ...) {
chk::chk_s3_class(x, "sf")
Expand Down
7 changes: 4 additions & 3 deletions man/fwa_snap_stream_measure_to_point.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
blk,rm,elevation,stream_measure,distance_to_stream
356308001,0,9.626,0,0
356308001,1000,10.131,1000.003607,3.2269364995865447e-5
356308001,2000,7.5,2000.017171,5.4951725837621686e-5
356308001,3000,9.687,3000.011434,1.3594185026123294e-5
356308001,4000,9.784,4000.014659,2.9565363508967057e-5
356308001,5000,9.784,5000.00998,4.321858460506546e-5
356308001,6000,9.784,6000.008678,6.017606609217237e-5
356308001,7000,9.784,7000.024298,7.254997397455956e-6
356308001,8000,10,8000.020311,5.8045242860341156e-5
356308001,9000,10.5,9000.01751,6.814799015189416e-5
356308001,10000,10.5,10000.030555,8.218122384703171e-6
356308001,11000,10.5,11000.041108,3.279253599904076e-5
356308001,12000,10.5,12000.051979,3.152766857483756e-5
356308001,13000,10.5,13000.075469,5.016752780037244e-5
356308001,14000,10.5,14000.103248,6.298745334744137e-5
356308001,15000,10.5,15000.131712,5.419516181470108e-5
356308001,16000,11.5,16000.133767,2.7711300228008696e-5
356308001,17000,48.016497448,17000.12526,1.0518539207806441e-5
356308001,18000,161.128703037,18000.138751,4.390647233044472e-5
356308001,19000,209.895131406,19000.150674,1.0217588499100131e-5
10 changes: 10 additions & 0 deletions tests/testthat/test-snap-stream-measure-to-point.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ test_that("fwa_snap_stream_measure_to_point", {
expect_identical(nrow(stream_measure_blk_diff), nrow(points))
expect_snapshot_data(stream_measure_blk_diff, "stream_measure_blk_diff")
})

test_that("fwa_snap_stream_measure_to_point example", {
watershed <- fwa_add_watershed_to_blk(data.frame(blk = 356308001, rm = 1000))
network <- fwa_add_collection_to_polygon(watershed)
network$blk <- network$blue_line_key
streams <- fwa_join_stream_segments(network)
points <- fwa_add_rms_to_blk(data.frame(blk = 356308001))
stream_measure <- fwa_snap_stream_measure_to_point(points, streams)
expect_snapshot_data(stream_measure, "stream_measure_example")
})

0 comments on commit 231582e

Please sign in to comment.