Adds stream paths to the scene, removing the previous stream layer if desired.

render_streams(
  streams,
  water_color = "lightblue",
  width = 1,
  width_column = NULL,
  width_units = c("scene", "meters"),
  densify = TRUE,
  offset = NULL,
  merge = TRUE,
  water_polygons = NULL,
  height = 0.05,
  clear_previous = TRUE,
  verbose = FALSE,
  parallel = TRUE,
  zscale = 1,
  vertical_exaggeration = 1,
  heightmap = NULL,
  ...
)

Arguments

streams

Spatial line data used to draw stream paths. Supports sf, sfc, sfg, SpatialLines, and SpatialLinesDataFrame line inputs.

water_color

Default "lightblue". Stream color.

width

Default 1. Stream width in the units selected by width_units for render_highquality(). The rgl preview uses the converted scene width as its line width.

width_column

Default NULL. Column name in an sf stream object used to set per-feature stream widths. Values must be positive finite numbers and use the same units as width. When supplied, stream merging is disabled to preserve feature attributes.

width_units

Default "scene". Units used by width and width_column. "scene" treats values as scene grid-cell units, preserving the legacy behavior. "meters" converts physical widths to scene units from the cached or supplied spatial extent and CRS.

densify

Default TRUE. Whether to densify stream paths and resample them along the terrain before render_highquality() meshing. Set to FALSE to use the vertices returned by render_path() directly.

offset

Default NULL. Vertical stream centerline offset in elevation units. When NULL, the stream centerline is placed on the sampled surface so the high-quality rectangular stream profile is rendered halfway through the terrain.

merge

Default TRUE. Whether to merge connected stream linework before rendering. This reduces visible caps between adjacent line features in render_highquality().

water_polygons

Default NULL. Optional polygon data defining water areas where streams should not be rendered. Supports sf, sfc, sfg, terra::SpatVector, SpatialPolygons, and SpatialPolygonsDataFrame inputs. Multiple polygons are combined before they are removed from the stream linework. When both inputs have a CRS, the polygons are transformed to the stream CRS before clipping. When only one input has a CRS, an error is returned rather than assuming the coordinate systems match.

height

Default 0.05. Total stream mesh thickness in scene units for render_highquality(). This is independent of width and centered on the sampled stream path, leaving the top surface slightly above the terrain.

clear_previous

Default TRUE. If TRUE, removes the existing stream layer before drawing the new one. A clear-only call returns without rendering a replacement.

verbose

Default FALSE. Whether to show native stream-meshing progress.

parallel

Default TRUE. Whether to build independent stream meshes in parallel with the native job queue.

zscale

Default 1. The ratio between the x and y spacing and the z axis. If omitted and heightmap is a spatial raster, rayshader uses the raster cell resolution.

vertical_exaggeration

Default 1. Multiplier applied to the effective visual relief. If omitted, rayshader uses the cached scene value from plot_3d() or plot_gg() when available; pass explicitly to override for this call.

heightmap

Default NULL. Height matrix or spatial raster for the current scene. If omitted, this is taken from the cached scene set by plot_3d() or plot_gg(). Pass explicitly to override the cached value.

...

Deprecated argument spellings are accepted with a warning and forwarded to their current names.

Value

Invisibly returns the rendered stream coordinates.

Details

See the Mammoth Lakes example in the README for a larger scene with Census stream data and downloaded terrain.

Examples

# A small projected terrain with two streams flowing through a lake.
dem = terra::rast(
  nrows = 48, ncols = 48,
  xmin = 500000, xmax = 500480,
  ymin = 4170000, ymax = 4170480,
  crs = "EPSG:32611"
)
xy = terra::xyFromCell(dem, seq_len(terra::ncell(dem)))
x = (xy[, 1] - 500000) / 480
y = (xy[, 2] - 4170000) / 480
terra::values(dem) = 100 + 20 * (x - 0.5)^2 + 35 * (y - 0.5)^2

# The lake is drawn separately. Clip the blue stream paths at its shoreline.
lake = sf::st_as_sfc(
  "POLYGON ((500175 4170180, 500310 4170180, 500310 4170295, 500175 4170295, 500175 4170180))",
  crs = 32611
)

streams = sf::st_as_sfc(
  c(
    "LINESTRING (500030 4170430, 500120 4170340, 500240 4170240, 500430 4170060)",
    "LINESTRING (500450 4170360, 500340 4170280, 500245 4170240)"
  ),
  crs = 32611
)

lake_level = terra::rasterize(
  terra::vect(lake), dem, field = 101, touches = TRUE
)
dem = shift_terrain(dem, lake, amount = -4)
dem |>
  height_shade() |>
  plot_3d(theta = 35, phi = 40, zoom = 0.92, shadow = FALSE, solid = FALSE)

render_water(water_input = lake_level, water_color = "dodgerblue")
render_streams(streams, water_polygons = lake, water_color = "dodgerblue", offset = 1)
render_highquality(
  width = 320, height = 320, samples = 16,
  light = FALSE, ambient_light = TRUE, water_ior = 1.1
)