Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nhdplus flowline traversal blocked by virtual stream segments #42

Closed
jsta opened this issue Feb 21, 2018 · 5 comments
Closed

nhdplus flowline traversal blocked by virtual stream segments #42

jsta opened this issue Feb 21, 2018 · 5 comments

Comments

@jsta
Copy link
Contributor

jsta commented Feb 21, 2018

It looks to me like traverse_flowlines using nhdplusv2 does not travel on virtual stream segments while nhdh does travel on them. Specifically, nhdh traverses through wb 155442272 while nhdplusv2 does not travel through (the equivalent) wb 6863055.

Is this intended?

Compare the two chunks below:

setup

library(hydrolinks)
library(purrr)
library(magrittr)

wb_coords <- c(44.00467, -88.43445)

traverse nhd hi-res

dset <- "nhdh"

wb_id <- link_to_waterbodies(wb_coords[1], wb_coords[2], 
                             1, dataset = dset) %>%
         purrr::when(any(names(.) %in% "COMID") 
              ~ .$COMID,
              ~.$PERMANENT_)

nhd_wb <- get_shape_by_id(wb_id, feature_type = "waterbody", dataset = dset)

f_lines <- traverse_flowlines(max_distance = 50, direction = "in", 
                   start = wb_id, 
                   dataset = dset, md5check = FALSE) %>%
  purrr::when(any(names(.) %in% "COMID") 
              ~ .$COMID,
              ~.$PERMANENT_)

upstream_shp <- get_shape_by_id(f_lines, dataset = dset, 
                                feature_type = "flowline")

plot(upstream_shp$geometry)
plot(nhd_wb$geometry, add = TRUE)

nhd

traverse nhdplus

dset <- "nhdplusv2"

wb_id <- link_to_waterbodies(wb_coords[1], wb_coords[2], 
                             1, dataset = dset) %>%
  purrr::when(any(names(.) %in% "COMID") 
              ~ .$COMID,
              ~.$PERMANENT_)

nhd_wb <- get_shape_by_id(wb_id, feature_type = "waterbody", dataset = dset)

f_lines <- traverse_flowlines(max_distance = 50, direction = "in", 
                              start = wb_id, 
                              dataset = dset, md5check = FALSE) %>%
  purrr::when(any(names(.) %in% "COMID") 
              ~ .$COMID,
              ~.$PERMANENT_)

upstream_shp <- get_shape_by_id(f_lines, dataset = dset, 
                                feature_type = "flowline")

plot(upstream_shp$geometry)
plot(nhd_wb$geometry, add = TRUE)

nhdplus

@lawinslow
Copy link
Owner

@rainshapes can you diagnose? This is not intended operation, but may be an artifact in dealing with the different dataset structures.

@lawinslow
Copy link
Owner

@jsta could you give #45 a try with your above issue? This should have fixed your issue (among others). If it does, we'll work on a CRAN release.

@lawinslow
Copy link
Owner

Should be solved in #45

@jsta
Copy link
Contributor Author

jsta commented Mar 12, 2018

Hmm, the example I linked above gives me an error now for both nhdplus and nhdh:

Error in traverse_flowlines(max_distance = 50, direction = "in", start = wb_id, :
Cannot traverse from node 0!

I already rolled my own traversal code for my use case so I'm afraid I will not do much more to diagnose.

@lawinslow
Copy link
Owner

Got it.

For future reference. This is fixed. Reproducible with this code.

library(hydrolinks)
library(purrr)
library(magrittr)

wb_coords <- c(44.00467, -88.43445)
dset <- "nhdh"

wb_id <- link_to_waterbodies(wb_coords[1], wb_coords[2], 
                             1, dataset = dset) %>%
  purrr::when(any(names(.) %in% "comid") 
              ~ .$comid,
              ~.$permanent_)

nhd_wb <- get_shape_by_id(wb_id, feature_type = "waterbody", dataset = dset)


f_lines <- traverse_flowlines(max_distance = 50, direction = "in", 
                              start = wb_id, 
                              dataset = dset, md5check = FALSE) %>%
  purrr::when(any(names(.) %in% "comid") 
              ~ .$comid,
              ~.$permanent_)

upstream_shp <- get_shape_by_id(f_lines, dataset = dset, 
                                feature_type = "flowline")
upstream_wb <- get_shape_by_id(f_lines, dataset = dset, 
                                feature_type = "waterbody")

plot(upstream_shp$geometry)
plot(upstream_wb$geometry, add=TRUE, col='dodgerblue')
plot(nhd_wb$geometry, add = TRUE)

image

dset <- "nhdplusv2"

wb_id <- link_to_waterbodies(wb_coords[1], wb_coords[2], 
                             1, dataset = dset) %>%
  purrr::when(any(names(.) %in% "comid") 
              ~ .$comid,
              ~.$permanent_)

nhd_wb <- get_shape_by_id(wb_id, feature_type = "waterbody", dataset = dset)

f_lines <- traverse_flowlines(max_distance = 50, direction = "in", 
                              start = wb_id, 
                              dataset = dset, md5check = FALSE) %>%
  purrr::when(any(names(.) %in% "comid") 
              ~ .$comid,
              ~.$permanent_)

upstream_shp <- get_shape_by_id(f_lines, dataset = dset, 
                                feature_type = "flowline")
upstream_wb <- get_shape_by_id(f_lines, dataset = dset, 
                               feature_type = "waterbody")

plot(upstream_shp$geometry)
plot(upstream_wb$geometry, add=TRUE, col='dodgerblue')
plot(nhd_wb$geometry, add = TRUE, col='dodgerblue')

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants