MapRegionalSources: Map regional irrigation source connection as spatial lines

View source: R/function_MapRegionalSources.R

MapRegionalSourcesR Documentation

Map regional irrigation source connection as spatial lines

Description

By default, this function creates an sf object which contains regional irrigation connections between source and target HYPE sub-catchments. However, this function can also be used to create interactive Leaflet maps.

Usage

MapRegionalSources(
  data,
  map,
  map.subid.column = 1,
  group.column = NULL,
  group.colors = NULL,
  digits = 3,
  progbar = FALSE,
  map.type = "default",
  plot.scale = TRUE,
  plot.searchbar = FALSE,
  weight = 0.5,
  opacity = 1,
  fillColor = "#4d4d4d",
  fillOpacity = 0.25,
  line.weight = 5,
  line.opacity = 1,
  seed = NULL,
  darken = 0,
  font.size = 10,
  file = "",
  vwidth = 1424,
  vheight = 1000,
  html.name = ""
)

Arguments

data

Dataframe, containing a column SUBID and a column REGSRCID (not case-sensitive), which identify irrigation target and source sub-catchments, respectively. Typically a HYPE 'MgmtData.txt' file, imported with ReadMgmtData.

map

A sf, SpatialPointsDataFrame, or SpatialPolygonsDataFrame object providing sub-catchment locations as points or polygons. Typically an imported SUBID center-point shape file or geopackage. If provided polygon data, then the polygon centroids will be calculated and used as the point locations (See sf::st_centroid()). Spatial data import requires additional packages, e.g. sf.

map.subid.column

Integer, index of the column in map holding SUBIDs (sub-catchment IDs).

group.column

Integer, optional index of the column in data providing grouping of connections to allow toggling of groups in Leaflet maps. Default NULL will produce maps without grouping.

group.colors

Named list providing colors for connection groups in Leaflet maps. List names represent the names of the groups in the group.column of data, and list values represent the colors. Example: groups.colors = list("GROUP 1" = "black", "GROUP 2" = "red"). If a group is not included in group.colors, then random colors will be assigned to the connections in the group. Default NULL will produce maps using random colors for all groups.

digits

Integer, number of digits to which irrigation connection lengths are rounded to.

progbar

Logical, display a progress bar while calculating.

map.type

Map type keyword string. Choose either "default" for the default static plots or "leaflet" for interactive Leaflet maps.

plot.scale

Logical, include a scale bar on Leaflet maps.

plot.searchbar

Logical, if TRUE, then a search bar will be included on Leaflet maps. See leaflet.extras::addSearchFeatures().

weight

Numeric, weight of subbasin boundary lines in Leaflet maps. Used if map contains polygon data. See leaflet::addPolygons().

opacity

Numeric, opacity of subbasin boundary lines in Leaflet maps. Used if map contains polygon data. See leaflet::addPolygons().

fillColor

String, color of subbasin polygons in Leaflet maps. Used if map contains polygon data. See leaflet::addPolygons().

fillOpacity

Numeric, opacity of subbasin polygons in Leaflet maps. Used if map contains polygon data. See leaflet::addPolygons().

line.weight

Numeric, weight of connection lines in Leaflet maps. See leaflet::addPolylines().

line.opacity

Numeric, opacity of connection lines in Leaflet maps. See leaflet::addPolylines().

seed

Integer, seed number to to produce repeatable color palette.

darken

Numeric specifying the amount of darkening applied to the random color palette. Negative values will lighten the palette. See distinctColorPalette.

font.size

Numeric, font size (px) for subbasin labels in Leaflet maps.

file

Save a Leaflet map to an image file by specifying the path to the desired output file using this argument. File extension must be specified. See mapview::mapshot(). You may need to run webshot::install_phantomjs() the first time you save a map to an image file.

vwidth

Numeric, width of the exported Leaflet map image in pixels. See webshot::webshot().

vheight

Numeric, height of the exported Leaflet map image in pixels. See webshot::webshot().

html.name

Save a Leaflet map to an interactive HTML file by specifying the path to the desired output file using this argument. File extension must be specified. See htmlwidgets::saveWidget().

Details

MapRegionalSources can return static plots or interactive Leaflet maps depending on value provided for the argument map.type. By default, MapRegionalSources creates an sf object from HYPE SUBID centerpoints using a table of SUBID pairs. Regional irrigation sources in HYPE are transfers from outlet lakes or rivers in a source sub-catchment to the soil storage of irrigated SLC classes (Soil, Land use, Crop) in a target sub-catchment. If map.type is set to "leaflet", then MapRegionalSources returns an object of class leaflet.

Value

For default static maps, MapRegionalSources returns an sf object containing columns SUBID (irrigation target sub-catchment), REGSRCID (irrigation source sub-catchment), and Length_[unit] (distance between sub-catchments) where 'unit' is the actual length unit of the distances. The projection of the returned object is always identical to the projection of argument map. For interactive Leaflet maps, PlotMapOutput returns an object of class leaflet. If map contains polygon data, then the interactive map will include the polygons as a background layer.

Examples

# Import subbasin centroids and subbasin polygons (to use as background)
require(sf)
te1 <- st_read(dsn = system.file("demo_model", "gis",
"Nytorp_centroids.gpkg", package = "HYPEtools"))
te2 <- st_read(dsn = system.file("demo_model", "gis",
"Nytorp_map.gpkg", package = "HYPEtools"))
# Create dummy MgmtData file with irrigation links
te3 <- data.frame(SUBID = c(3594, 63794), REGSRCID = c(40556, 3486))

# Plot regional irrigation links between subbasins with subbasin outlines as background
MapRegionalSources(data = te3, map = te1, map.subid.column = 25)
plot(st_geometry(te2), add = TRUE, border = 2)



rcapell/HYPEtools documentation built on Feb. 28, 2024, 2:29 p.m.