Skip to contents

Export river network as shapefile. Reach attributes can be added.

Usage

river_to_shapefile(river, filename, atts = NULL, 
                    EPSG = NULL, ...)

Arguments

river

river object. It must have been aggregated (via aggregate_river).

filename

Character. Output file name. It must contain the ".shp" extension.

atts

Attributes at AG level that can be exported. This should be a character vector, with entries corresponding to the names of fields within the AG sub-list of river. See example.

EPSG

EPSG code. Default is NULL, which does not produce a .prj file (i.e., the shapefile does not contain projection information).

...

Additional arguments to be passed to writeVector (e.g., overwrite = TRUE allows overwriting an existing shapefile).

Value

No output is produced. This function is used for its side effetcs.

Examples

if (FALSE) { # interactive() && traudem::can_register_taudem()
library(terra) # to use "vect"
fp <- system.file("extdata/wigger.tif", package="rivnet")
river <- extract_river(outlet=c(637478,237413), DEM=fp)
river <- aggregate_river(river)

tmpname <- paste0(tempfile(), ".shp")
river_to_shapefile(river, tmpname, overwrite = TRUE)

# read output
vv <- vect(tmpname)
vv
plot(vv)

# \donttest{
# add attributes to shapefile (drainage area, stream order)
river_to_shapefile(river, tmpname,
          atts = c("A", "streamOrder"), # same names as in river$AG
          overwrite = TRUE) 
vv <- vect(tmpname)
vv

# add projection 
river_to_shapefile(river, tmpname, 
          EPSG = 21781, 
          overwrite = TRUE)
vv <- vect(tmpname)
vv          
# }

}