DOI-USGS / hyRefactor

https://code.usgs.gov/wma/nhgf/reference-fabric/hyrefactor
Creative Commons Zero v1.0 Universal
5 stars 0 forks source link

Over aggregation of flowlines in some regions. #47

Closed dblodgett-usgs closed 2 years ago

dblodgett-usgs commented 2 years ago

I've been chasing this bug and can't quite nail it down.

The issue occurs when this full region 06 refactor set is run through get_catchment_set and does not occur when only one basin is run through.

load("test_get_catchment_sets.rda")
test <- nhdplusTools::get_sorted(flowpath, outlets = 41262)
test <- flowpath
hyRefactor:::get_catchment_sets(test, outlets[outlets$ID %in% test$ID,]) -> fline_sets
fline_sets <- fline_sets[[1]]
mapview::mapview(test[test$ID %in% fline_sets[fline_sets$ID == 27933,]$set[[1]],])

test_get_catchment_sets.zip

dblodgett-usgs commented 2 years ago

Turns out that this is actually an issue with disconnected network that's causing some odd behavior in the aggregation logic. The over-aggregated flowline is actually being generated in error -- I think there should be a way to avoid that behavior. Will investigate.

dblodgett-usgs commented 2 years ago

The reason the behavior only occurs when the whole network is included is that the get_sorted method above removes the disconnected part of the domain. That was just a red herring.

dblodgett-usgs commented 2 years ago

After a variety of investigations, it turns out this is related to an issue in data prep way way upstream of hyRefactor. It was just emerging dwn here.

I found that this was because the burnlineevent layer didn't have a line for that feature and that feature is labeled as a divergence in the original NHD. It is not a divergence in eNHD so is on the main path and I was replacing all divergences with their burn line event (because many of them are trimmed). By replacing with a missing geometry, the feature didn't get written to my reference fabric geopackage and was lost.