USEPA / StreamCatTools

R package to work with the StreamCat API within R and access the full suite of StreamCat catchment and watershed scale metrics for all NHDPlusV2 stream reaches and catchments.
https://usepa.github.io/StreamCatTools/
Creative Commons Zero v1.0 Universal
30 stars 6 forks source link

Distance US / DS along COMID #15

Open mhweber opened 2 years ago

mhweber commented 2 years ago

Suggestion from Leah Ettema:

Just an idea for StreamCatTools R package: It would be great if there could be a function that provides some measure of where a sampling point is on the COMID in order to help the user screen for correct COMMID. If the sampling point is at the very US end, maybe the COMID upstream of sampling point COMID is the more appropriate landuse/catchment data to use. Maybe it could be something like distance of the sampling point to the US end of the COMID divided by total length of COMID.

jbousquin commented 2 years ago

Wrote this a couple years ago to add the distance from an sf point to the catchment outflow point. I want to say there is an fline upper node as well that could be compared to it instead of having to get the upstream fline. I'd be cautious of comparing this euclidean distance to the fline length though. I haven't dug into the recent release of nhdplusTools, I remember back ~11/2/21 D. Blodgett tweeted something about adding navigation from a point along a network (may or may not relate at all).

distance_catchment_outlet<- function(point, fline) {
  #Note: this should only be used on positive pathlength
  #     point and fline must have matching comid
  if(point$comid == fline$comid){
    end = get_node(fline, "end")
    st_distance(point, end)
  } else {
    FALSE
    #TODO: BREAK LOUDLY
  }
}
mhweber commented 2 years ago

Thanks Justin - I've been using navigate_nldi from nhdplusTools for other projects - I know Dave has been updating features in nhdplusTools and I added some functionality recently - I'll check and see if specific functionality exists in nhdplusTools already and if not incorporate your suggestion into a package function - thanks!