pdf <- FALSE
if(!pdf) {
  knitr::opts_chunk$set(fig.width = 6, fig.asp = 1, dpi = 300, out.width = "90%")
} else {
#output: rmarkdown::html_vignette
#output: rmarkdown::pdf_document
  knitr::opts_chunk$set(fig.width = 6, fig.asp = 1, dpi = 300)
}

Flow plots are simply a way of visualizing what LITAP is doing under the hood.

In the following examples, we will be using the output from complete run on the supplied "testELEV.dbf". You can find the original DEM file in the LITAP extdata folder by using the system.file() function. For more information on the flow_mapper() function see the Getting Started Vignette.

library(LITAP)

# Save output to working directory
flow_mapper(system.file("extdata", "testELEV.dbf", package = "LITAP"),
            out_folder = "./testELEV/", nrow = 90, ncol = 90, clean = TRUE) 

We will load the rds file (R data files) for the final dems and stats file.

dem <- readRDS("./testELEV/flow/dem_fill.rds")
inverted_dem <- readRDS("./testELEV/flow/dem_ilocal.rds")

local_stats <- readRDS("./testELEV/flow/stats_local.rds")

Basic maps

By default, the flow_plot() function displays relief maps, using the terrain() and hillShade() functions from the raster package. Note the outer border of dark grey, this represents unknown cells, as the relief calculations do not work on cells without neighbours.

flow_plot(dem)
if(pdf) cat("\\newpage")

Alternatively, you can plot elevation data directly.

flow_plot(dem, type = "elevation")
if(pdf) cat("\\newpage")

Subsets

You can zoom in on a particular area of interest by specifying row and column limits:

flow_plot(dem, type = "elevation", rlim = c(20, 30), clim = c(35, 45))
if(pdf) cat("\\newpage")

Cell numbering

You can number the cells in a plot with seqno = TRUE:

flow_plot(dem, type = "elevation", rlim = c(20, 30), clim = c(35, 45), 
          seqno = TRUE)
if(pdf) cat("\\newpage")

If you're only interested in certain cells, specify which ones with cells = c() and highlight = TRUE

flow_plot(dem, type = "elevation", rlim = c(20, 30), clim = c(35, 45), 
          seqno = TRUE, cells = c(3187:3193, 3336:3343), highlight = TRUE)
if(pdf) cat("\\newpage")

Flow directions

You can plot individual flow directions with dir = TRUE.

flow_plot(dem, type = "elevation", rlim = c(20, 30), clim = c(35, 45), 
          dir = TRUE)
if(pdf) cat("\\newpage")

In combination with cell numbers

flow_plot(dem, type = "elevation", rlim = c(20, 30), clim = c(35, 45), 
          dir = TRUE, seqno = TRUE)
if(pdf) cat("\\newpage")

Only for certain cells (this will show the entire flow path that a given cell is on)

flow_plot(dem, type = "elevation", rlim = c(20, 30), clim = c(35, 45), 
          dir = TRUE, cells = c(3187:3193, 3336:3343))
if(pdf) cat("\\newpage")

Only for certain cells and show cell numbers

flow_plot(dem, type = "elevation", rlim = c(20, 30), clim = c(35, 45), 
          dir = TRUE, seqno = TRUE, cells = c(3187:3193, 3336:3343))
if(pdf) cat("\\newpage")

Highlight the cells of interest

flow_plot(dem, type = "elevation", rlim = c(20, 30), clim = c(35, 45), 
          dir = TRUE, seqno = TRUE, cells = c(3187:3193, 3336:3343), highlight = TRUE)
if(pdf) cat("\\newpage")

Flow directions by upslope area

You can filter the flow directions to show only those with an upslope area greater than some threshold:

flow_plot(dem, type = "elevation", dir = TRUE, upslope_threshold = 500)
if(pdf) cat("\\newpage")

Comparing different upslope thresholds:

gridExtra::grid.arrange(flow_plot(dem, type = "elevation", dir = TRUE, upslope_threshold = 0) + ggplot2::labs(title = "0") + ggplot2::theme(legend.position = "none"),
                        flow_plot(dem, type = "elevation", dir = TRUE, upslope_threshold = 10) + ggplot2::labs(title = "10") + ggplot2::theme(legend.position = "none"),
                        flow_plot(dem, type = "elevation", dir = TRUE, upslope_threshold = 20) + ggplot2::labs(title = "20") + ggplot2::theme(legend.position = "none"),
                        flow_plot(dem, type = "elevation", dir = TRUE, upslope_threshold = 40) + ggplot2::labs(title = "75") + ggplot2::theme(legend.position = "none"),
                        flow_plot(dem, type = "elevation", dir = TRUE, upslope_threshold = 75) + ggplot2::labs(title = "200") + ggplot2::theme(legend.position = "none"),
                        flow_plot(dem, type = "elevation", dir = TRUE, upslope_threshold = 500) + ggplot2::labs(title = "500") + ggplot2::theme(legend.position = "none"),
                        ncol = 2)
if(pdf) cat("\\newpage")

Ridge Lines

To look at ridge lines, use the inverted dem files

flow_plot(inverted_dem, type = "elevation", dir = TRUE, upslope_threshold = 250)
if(pdf) cat("\\newpage")

Watersheds

You can also highlight watersheds

flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "initial") +
  labs(title = "Initial Watersheds")
if(pdf) cat("\\newpage")

Watershed pits

flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "initial", 
          pits = TRUE)
if(pdf) cat("\\newpage")

Comparing watersheds at different stages of pit removal

gridExtra::grid.arrange(
  flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "initial") + 
    ggplot2::labs(title = "Initial Watersheds") + ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
  flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "local") + 
    ggplot2::labs(title = "Local Watersheds") + ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
  flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "pond") + 
    ggplot2::labs(title = "Pond Watersheds") + ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
  flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "fill") + 
    ggplot2::labs(title = "Fill Watersheds") + ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
  ncol = 2)
if(pdf) cat("\\newpage")

Watersheds by flow paths

flow_plot(db = dem, type = "elevation", shed = TRUE, 
          shed_type = "initial", dir = TRUE)
if(pdf) cat("\\newpage")

Subsets still apply

flow_plot(db = dem, type = "elevation", shed = TRUE, 
          rlim = c(30,60), clim = c(45,75),
          shed_type = "initial", dir = TRUE)

Look at how watersheds combined in the upper right corner

if(!pdf) {
  gridExtra::grid.arrange(
    flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "initial", 
              dir = TRUE, rlim = c(10, 45), clim = c(85, 115)) + 
      ggplot2::labs(title = "Initial Watersheds") + 
      ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
    flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "local",
              dir = TRUE, rlim = c(10, 45), clim = c(85, 115)) + 
      ggplot2::labs(title = "Local Watersheds") + 
      ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
    flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "pond", 
              dir = TRUE, rlim = c(10, 45), clim = c(85, 115)) + 
      ggplot2::labs(title = "Pond Watersheds") + 
      ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
    flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "fill", 
              dir = TRUE, rlim = c(10, 45), clim = c(85, 115)) + 
      ggplot2::labs(title = "Fill Watersheds") + 
      ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
    ncol = 2)
} else {
  gridExtra::grid.arrange(
    flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "initial", 
              dir = TRUE, rlim = c(10, 45), clim = c(85, 115)) + 
      ggplot2::labs(title = "Initial Watersheds") + 
      ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
    flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "local", 
              dir = TRUE, rlim = c(10, 45), clim = c(85, 115)) + 
      ggplot2::labs(title = "Local Watersheds") + 
      ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
    ncol = 1)

  cat("\\newpage")

  gridExtra::grid.arrange(
    flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "pond", 
              dir = TRUE, rlim = c(10, 45), clim = c(85, 115)) + 
      ggplot2::labs(title = "Pond Watersheds") + 
      ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
    flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "fill", 
              dir = TRUE, rlim = c(10, 45), clim = c(85, 115)) + 
      ggplot2::labs(title = "Fill Watersheds") + 
      ggplot2::theme(plot.margin = ggplot2::unit(c(5, 1, 5, 1), "pt")),
    ncol = 1)
}
if(pdf) cat("\\newpage")

Look at pour points

flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "local", 
          stats = local_stats)
if(pdf) cat("\\newpage")

Take a closer look

flow_plot(db = dem, type = "elevation", shed = TRUE, shed_type = "local",
          rlim = c(0, 40), clim = c(110, 150), stats = local_stats)
if(pdf) cat("\\newpage")
unlink("./testELEV", recursive = TRUE)


steffilazerte/LITAP documentation built on Feb. 9, 2022, 8:11 a.m.