plot_nhdplus: Plot NHDPlus

Description Usage Arguments Details Value Examples

View source: R/plot_nhdplus.R

Description

Given a list of outlets, get their basin boundaries and network and return a plot in EPSG:3857 Web Mercator Projection.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
plot_nhdplus(
  outlets = NULL,
  bbox = NULL,
  streamorder = NULL,
  nhdplus_data = NULL,
  gpkg = NULL,
  plot_config = NULL,
  add = FALSE,
  actually_plot = TRUE,
  overwrite = TRUE,
  flowline_only = NULL,
  ...
)

Arguments

outlets

list of nldi outlets. Other inputs are coerced into nldi outlets, see details.

bbox

object of class bbox with a defined crs. See examples.

streamorder

integer only streams of order greater than or equal will be returned

nhdplus_data

geopackage containing source nhdplus data (omit to download)

gpkg

path and file with .gpkg ending. If omitted, no file is written.

plot_config

list containing plot configuration, see details.

add

boolean should this plot be added to an already built map.

actually_plot

boolean actually draw the plot? Use to get data subset only.

overwrite

passed on the subset_nhdplus.

flowline_only

boolean only subset and plot flowlines?

...

parameters passed on to rosm.

Details

plot_nhdplus supports several input specifications. An unexported function "as_outlet" is used to convert the outlet formats as described below.

  1. if outlets is omitted, the bbox input is required and all nhdplus data in the bounding box is plotted.

  2. If outlets is a list of integers, it is assumed to be NHDPlus IDs (comids) and all upstream tributaries are plotted.

  3. if outlets is an integer vector, it is assumed to be all NHDPlus IDs (comids) that should be plotted. Allows custom filtering.

  4. If outlets is a character vector, it is assumed to be NWIS site ids.

  5. if outlets is a list containing only characters, it is assumed to be a list of nldi features and all upstream tributaries are plotted.

  6. if outlets is a data.frame with point geometry, a point in polygon match is performed and upstream with tributaries from the identified catchments is plotted.

The plot_config parameter is a list with names "basin", "flowline" and "outlets". The following shows the defaults that can be altered.

  1. basin list(lwd = 1, col = NA, border = "black")

  2. flowline list(lwd = 1, col = "blue")

  3. outlets

       list(default = list(col = "black", border = NA, pch = 19, cex = 1),
            nwissite = list(col = "grey40", border = NA, pch = 17, cex = 1),
            huc12pp = list(col = "white", border = "black", pch = 22, cex = 1),
            wqp = list(col = "red", border = NA, pch = 20, cex = 1))
            

If adding additional layers to the plot, data must be projected to EPSG:3857 with 'sf::st_transform(x, 3857)' prior to adding to the plot.

Value

data.frame plot data is returned invisibly in NAD83 Lat/Lon.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
options("rgdal_show_exportToProj4_warnings"="none")

plot_nhdplus("05428500")

plot_nhdplus("05428500", streamorder = 2)

plot_nhdplus(list(13293970, 13293750))

source(system.file("extdata/sample_data.R", package = "nhdplusTools"))

plot_nhdplus(list(13293970, 13293750), streamorder = 3, nhdplus_data = sample_data)

plot_nhdplus(list(list("comid", "13293970"),
                  list("nwissite", "USGS-05428500"),
                  list("huc12pp", "070900020603"),
                  list("huc12pp", "070900020602")),
             streamorder = 2,
             nhdplus_data = sample_data)


plot_nhdplus(sf::st_as_sf(data.frame(x = -89.36083,
                                     y = 43.08944),
                          coords = c("x", "y"), crs = 4326),
             streamorder = 2,
             nhdplus_data = sample_data)

plot_nhdplus(list(list("comid", "13293970"),
                  list("nwissite", "USGS-05428500"),
                  list("huc12pp", "070900020603"),
                  list("huc12pp", "070900020602")),
             streamorder = 2,
             nhdplus_data = sample_data,
             plot_config = list(basin = list(lwd = 2),
                                outlets = list(huc12pp = list(cex = 1.5),
                                               comid = list(col = "green"))))

bbox <- sf::st_bbox(c(xmin = -89.43, ymin = 43, xmax = -89.28, ymax = 43.1),
                    crs = "+proj=longlat +datum=WGS84 +no_defs")

fline <- sf::read_sf(sample_data, "NHDFlowline_Network")
comids <- nhdplusTools::get_UT(fline, 13293970)

plot_nhdplus(comids)

#' # With Local Data
plot_nhdplus(bbox = bbox, nhdplus_data = sample_data)

# With downloaded data
plot_nhdplus(bbox = bbox, streamorder = 3)

# Can also plot on top of the previous!
plot_nhdplus(bbox = bbox, nhdplus_data = sample_data,
             plot_config = list(flowline = list(lwd = 0.5)))
plot_nhdplus(comids, nhdplus_data = sample_data, streamorder = 3, add = TRUE,
             plot_config = list(flowline = list(col = "darkblue")))

# Cleanup downloaded open street map cache and temp data dir if desired.
# This is included for CRAN checks primarily.
unlink(nhdplusTools::nhdplusTools_data_dir(), recursive = TRUE)

nhdplusTools documentation built on June 23, 2021, 9:07 a.m.