You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

nhdplusTools中get_split_catchment无法完整描绘汇水流域问题

问题:nhdplusTools包中get_split_catchment()无法获取出口点上游完整流域

使用R包nhdplusTools中的get_split_catchment()函数从出口点(pour point)描绘汇水流域时,函数能正确识别出口点对应的COMID,但遇到上游下一个COMID时就停止运行,无法获取出口点上游的完整流域范围。

复现代码

library(tidyverse)
library(nhdplusTools)
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE

# 1. 定义起始出口点 ----
start_point <- st_sfc(st_point(c(-78.3361152, 38.9767759)), crs = 4269)

# 将点匹配到最近的NHDPlus水流线
trace <- get_raindrop_trace(start_point)

snap_point <- st_sfc(st_point(trace$intersection_point[[1]]),
                     crs = 4326)

# 2. 获取匹配点对应的NHDPlus COMID ----
start_comid <- discover_nhdplus_id(snap_point)

# 3. 导航并提取上游支流水流线 ----
flowline <- navigate_nldi(list(featureSource = "comid", 
                               featureID = start_comid), 
                          mode = "upstreamTributaries", 
                          distance_km = 1000)

# 4. 下载并筛选水流线对应的NHDPlus数据 ----
subset_file <- tempfile(fileext = ".gpkg")
subset <- subset_nhdplus(comids = as.integer(flowline$UT$nhdplus_comid),
                         output_file = subset_file,
                         nhdplus_data = "download", 
                         flowline_only = FALSE,
                         return_data = TRUE, overwrite = TRUE)
#> All intersections performed in latitude/longitude.
#> Reading NHDFlowline_Network
#> Writing NHDFlowline_Network
#> Reading CatchmentSP
#> Writing CatchmentSP
flowline <- subset$NHDFlowline_Network

# 定义起始COMID的NLDI特征列表 ----
nldi_nwis <- list(featureSource = "comid", featureID = start_comid)

# 5. 为匹配点描绘流域 ----
basin <- get_split_catchment(snap_point, upstream = TRUE)
basin <- basin[2,3]

# 6. 可视化流域 ----
ggplot() +
  geom_sf(data = flowline, color = "blue", size = 1) +
  geom_sf(data = basin, fill = NA, color = "red", size = 1) +
  geom_sf(data = start_point, color = "green", size = 3, shape = 21, fill = "green") +
  theme_bw() +
  theme(axis.text = element_text(size = 14, color = 'black'))

可视化结果

可视化结果中,红色区域为描绘的流域,绿色点是出口点,蓝色线条为水流线:
流域可视化图

环境信息

sessionInfo()
#> R version 4.4.1 (2024-06-14 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 22631)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.utf8 
#> [2] LC_CTYPE=English_United States.utf8   
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C                           
#> [5] LC_TIME=English_United States.utf8    
#> 
#> time zone: America/New_York
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] sf_1.0-16          nhdplusTools_1.2.1 lubridate_1.9.3    forcats_1.0.0     
#>  [5] stringr_1.5.1      dplyr_1.1.4        purrr_1.0.2        readr_2.1.5       
#>  [9] tidyr_1.3.1        tibble_3.2.1       ggplot2_3.5.1      tidyverse_2.0.0   
#> 
#> loaded via a namespace (and not attached):
#>  [1] gtable_0.3.5         xfun_0.45            tzdb_0.4.0          
#>  [4] vctrs_0.6.5          tools_4.4.1          generics_0.1.3      
#>  [7] curl_5.2.1           parallel_4.4.1       proxy_0.4-27        
#> [10] fansi_1.0.6          pkgconfig_2.0.3      KernSmooth_2.23-24  
#> [13] data.table_1.15.4    assertthat_0.2.1     lifecycle_1.0.4     
#> [16] farver_2.1.2         compiler_4.4.1       munsell_0.5.1       
#> [19] fst_0.9.8            htmltools_0.5.8.1    class_7.3-22        
#> [22] yaml_2.3.9           pillar_1.9.0         classInt_0.4-10     
#> [25] hydroloom_1.0.2      cachem_1.1.0         wk_0.9.2            
#> [28] zip_2.3.1            tidyselect_1.2.1     digest_0.6.36       
#> [31] stringi_1.8.4        arrow_16.1.0         fastmap_1.2.0       
#> [34] grid_4.4.1           colorspace_2.1-0     cli_3.6.3           
#> [37] magrittr_2.0.3       utf8_1.2.4           e1071_1.7-14        
#> [40] withr_3.0.0          scales_1.3.0         bit64_4.0.5         
#> [43] timechange_0.3.0     rmarkdown_2.27       httr_1.4.7          
#> [46] dataRetrieval_2.7.15 bit_4.0.5            RANN_2.6.1          
#> [49] hms_1.1.3            fstcore_0.9.18       memoise_2.0.1       
#> [52] pbapply_1.7-2        evaluate_0.24.0      knitr_1.48          
#> [55] s2_1.1.7             rlang_1.1.4          Rcpp_1.0.12         
#> [58] glue_1.7.0           DBI_1.2.3            xml2_1.3.6          
#> [61] reprex_2.1.1         rstudioapi_0.16.0    jsonlite_1.8.8      
#> [64] R6_2.5.1             fs_1.6.4             units_0.8-5

内容的提问来源于stack exchange,提问作者tassones

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 09:12:33