# NOT RUN {
# Initiate and setup GRASS
dem_path <- system.file("extdata", "nc", "elev_ned_30m.tif", package = "openSTARS")
if(.Platform$OS.type == "windows"){
grass_program_path = "c:/Program Files/GRASS GIS 7.6"
} else {
grass_program_path = "/usr/lib/grass78/"
}
setup_grass_environment(dem = dem_path,
gisBase = grass_program_path,
remove_GISRC = TRUE,
override = TRUE
)
gmeta()
# Load files into GRASS
dem_path <- system.file("extdata", "nc", "elev_ned_30m.tif", package = "openSTARS")
sites_path <- system.file("extdata", "nc", "sites_nc.shp", package = "openSTARS")
streams_path <- system.file("extdata", "nc", "streams.shp", package = "openSTARS")
import_data(dem = dem_path, sites = sites_path, streams = streams_path)
# Derive streams from DEM
derive_streams(burn = 10, accum_threshold = 100, condition = TRUE, clean = TRUE)
# Check and correct complex confluences (there are complex confluences in the
# example date set if the accumulation threshold is low)
cj <- check_compl_confluences()
if(cj){
correct_compl_confluences()
}
# plot
library(sp)
dem <- readRAST('dem', ignore.stderr = TRUE, plugin = FALSE)
streams <- readVECT('streams_v', ignore.stderr = TRUE)
streams_orig <- readVECT('streams_v_o3', ignore.stderr = TRUE)
# zoom to a relevant part of the dem
plot(dem, col = terrain.colors(20), axes = TRUE,
xlim = c(640100,640150), ylim = c(219735,219785))
lines(streams_orig, col = 'red', lwd = 4)
lines(streams, col = 'blue', lty = 2, lwd = 2)
legend("bottomright", col = c("red", "blue"), lty = c(1,2), lwd = c(4,2),
legend = c("original", "corrected"))
plot(streams, col = c("blue", "red")[streams@data$changed+1], lty = 1, lwd = 2)
# }
Run the code above in your browser using DataLab