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,
...
)Spatial line data used to draw stream paths. Supports sf,
sfc, sfg, SpatialLines, and SpatialLinesDataFrame line inputs.
Default "lightblue". Stream color.
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.
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.
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.
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.
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.
Default TRUE. Whether to merge connected stream linework before
rendering. This reduces visible caps between adjacent line features in
render_highquality().
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.
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.
Default TRUE. If TRUE, removes the existing stream
layer before drawing the new one. A clear-only call returns without rendering
a replacement.
Default FALSE. Whether to show native stream-meshing progress.
Default TRUE. Whether to build independent stream meshes in
parallel with the native job queue.
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.
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.
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.
Invisibly returns the rendered stream coordinates.
See the Mammoth Lakes example in the README for a larger scene with Census stream data and downloaded terrain.
# 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
)