Skip to contents

Function to return NHDPlusV2 Waterbody COMIDS using either a dataframe with coordinates and a specified CRS or an sf object. The function generates a vector of NHDPlus Waterbody COMID values a user can then pass to lc_get_data function

Usage

lc_get_comid(
  dd = NULL,
  xcoord = NULL,
  ycoord = NULL,
  crsys = NULL,
  buffer = NULL
)

Arguments

dd

Name of data frame object. Can be a simple data frame with coordinate columns in a known CRS or an sf points data frame

xcoord

The x coordinate column if using a raw data frame

ycoord

The y coordinate column if using a raw data frame

crsys

The epsg code if using a raw data frame

buffer

The amount of buffer to use to extend search for a waterbody (simply passed to nhdplusTools::get_waterbodies)

Value

A new sf data frame with a populated 'COMID' column

Author

Marc Weber

Examples

# \donttest{

dd <- data.frame(x = c(-89.198,-114.125,-122.044),
y = c(45.502,47.877,43.730))

comids <- lc_get_comid(dd, xcoord='x',
                       ycoord='y', crsys=4269)
#> Spherical geometry (s2) switched off
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> Spherical geometry (s2) switched on
#> Spherical geometry (s2) switched off
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> Spherical geometry (s2) switched on
#> Spherical geometry (s2) switched off
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> Spherical geometry (s2) switched on

dd <- data.frame(x = c(-89.198,-114.125,-122.044),
y = c(45.502,47.877,43.730)) |> 
   sf::st_as_sf(coords = c('x', 'y'), crs = 4326)
   
comids <- lc_get_comid(dd)
#> Spherical geometry (s2) switched off
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> Spherical geometry (s2) switched on
#> Spherical geometry (s2) switched off
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> Spherical geometry (s2) switched on
#> Spherical geometry (s2) switched off
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> Spherical geometry (s2) switched on
 # }