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

clean_geometry error before and after node.js install #58

Open
spencer-tassone opened this issue Aug 5, 2024 · 0 comments
Open

clean_geometry error before and after node.js install #58

spencer-tassone opened this issue Aug 5, 2024 · 0 comments

Comments

@spencer-tassone
Copy link

I am trying to use the hyRefactor::clean_geometry function to clean up polygon fragments but I keep getting an error message:

Error : The mapshaper node library must be installed and on your PATH. Install node.js (https://nodejs.org/en/) and then install mapshaper with: npm install -g mapshaper

I have installed node.js and run npm install -g mapshaper but still get the error after restarting R and rerunning the code.

# Clear the workspace and reset graphics ----
rm(list = ls())
dev.off()
#> null device 
#>           1

# Load necessary libraries ----
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
library(ggspatial)
library(rmapshaper)
library(hyRefactor)

# 1. Define the starting point (pour point) ----
start_point <- st_sfc(st_point(c(-78.336, 38.976)), crs = 4269)

## 1a. Snap point to the nearest NHDPlus flowline ----
trace <- get_raindrop_trace(start_point)

## 1b. Use the intersection point as the pour point ----
snap_point <- st_sfc(st_point(trace$intersection_point[[1]]),
                         crs = 4269)

# 2. Retrieve NHDPlus COMID for the snapped point ----
start_comid <- discover_nhdplus_id(snap_point)

# 3. Navigate and extract upstream tributary flowlines ----
flowline <- navigate_nldi(list(featureSource = "comid", 
                               featureID = start_comid), 
                          mode = "upstreamTributaries", 
                          distance_km = 1000)

# 4. Download and subset NHDPlus data for the flowlines ----
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

# Define the NLDI feature list for the starting COMID ----
nldi_nwis <- list(featureSource = "comid", featureID = start_comid)

# 5. Delineate the basin for the snap point ----
basin <- get_split_catchment(snap_point, upstream = TRUE)
basin$ID <- 'Strasburg'
basin <- clean_geometry(basin, ID = "ID")
#> Error : The mapshaper node library must be installed and on your PATH.
#> Install node.js (https://nodejs.org/en/) and then install mapshaper with:
#>     npm install -g mapshaper
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] hyRefactor_0.4.11  rmapshaper_0.5.0   ggspatial_1.1.9    sf_1.0-16         
#>  [5] nhdplusTools_1.2.1 lubridate_1.9.3    forcats_1.0.0      stringr_1.5.1     
#>  [9] dplyr_1.1.4        purrr_1.0.2        readr_2.1.5        tidyr_1.3.1       
#> [13] 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            lattice_0.22-6      
#>  [4] tzdb_0.4.0           vctrs_0.6.5          tools_4.4.1         
#>  [7] generics_0.1.3       curl_5.2.1           parallel_4.4.1      
#> [10] proxy_0.4-27         fansi_1.0.6          pkgconfig_2.0.3     
#> [13] KernSmooth_2.23-24   data.table_1.15.4    assertthat_0.2.1    
#> [16] lifecycle_1.0.4      compiler_4.4.1       munsell_0.5.1       
#> [19] terra_1.7-78         codetools_0.2-20     fst_0.9.8           
#> [22] htmltools_0.5.8.1    class_7.3-22         yaml_2.3.9          
#> [25] pillar_1.9.0         classInt_0.4-10      hydroloom_1.0.2     
#> [28] cachem_1.1.0         wk_0.9.2             rvest_1.0.4         
#> [31] zip_2.3.1            tidyselect_1.2.1     digest_0.6.36       
#> [34] stringi_1.8.4        arrow_16.1.0         fastmap_1.2.0       
#> [37] grid_4.4.1           colorspace_2.1-0     cli_3.6.3           
#> [40] magrittr_2.0.3       utf8_1.2.4           e1071_1.7-14        
#> [43] withr_3.0.0          scales_1.3.0         sp_2.1-4            
#> [46] bit64_4.0.5          timechange_0.3.0     rmarkdown_2.27      
#> [49] httr_1.4.7           dataRetrieval_2.7.15 bit_4.0.5           
#> [52] RANN_2.6.1           hms_1.1.3            fstcore_0.9.18      
#> [55] memoise_2.0.1        pbapply_1.7-2        evaluate_0.24.0     
#> [58] knitr_1.48           V8_4.4.2             s2_1.1.7            
#> [61] rlang_1.1.4          Rcpp_1.0.12          glue_1.7.0          
#> [64] DBI_1.2.3            geojsonsf_2.0.3      xml2_1.3.6          
#> [67] reprex_2.1.1         rstudioapi_0.16.0    jsonlite_1.8.8      
#> [70] R6_2.5.1             fs_1.6.4             units_0.8-5

Created on 2024-08-05 with reprex v2.1.1

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

1 participant