Adds road paths to the scene and eagerly builds their reusable
high-quality meshes. Roads can be previewed as rgl lines or as the same mesh
geometry consumed by render_highquality(). Road chains that cannot be
represented by either mesh method are omitted with a warning while the
remaining meshes continue rendering. Pavement is raised by 0.055 elevation
units (5.5 cm for meter elevations), converted using the effective zscale.
A small scene-precision margin prevents coplanar top surfaces in large scenes.
Pavement thickness stays at 0.11 elevation units independently of that margin.
render_roads(
roads,
road_color = "#303030",
width = NULL,
width_column = NULL,
densify = TRUE,
offset = 0,
offset_transition = 0,
layer = NULL,
layer_height = 5.5,
merge = TRUE,
lane_texture = TRUE,
lane_texture_file = NULL,
lane_dash_length = 3,
lane_gap_length = 10,
lane_texture_length = NULL,
lane_texture_mapping = c("auto", "fixed"),
lanes = 2,
lane_width = 3,
lane_color = "#eeeade",
centerline_color = "#eeeade",
edge_line_color = "#d6ad3d",
lane_line_width = 0.035,
lane_dash_fraction = NULL,
clear_previous = TRUE,
preview = c("line", "mesh"),
verbose = FALSE,
parallel = TRUE,
maximum_grade = 0.15,
continuation_grade_tolerance = 0.14,
zscale = 1,
vertical_exaggeration = 1,
heightmap = NULL,
terrain_grading = FALSE,
bridge = NULL,
...
)Spatial line data used to draw road paths. Supports sf,
sfc, sfg, SpatialLines, and SpatialLinesDataFrame line inputs.
Default "#303030". sRGB road surface color.
Default NULL, which derives road width from lanes and
lane_width. If supplied, road width in scene grid-cell units for
render_highquality(). The rgl preview uses the same value as line width.
Default NULL. Column name in an sf road object used
to set per-feature road widths. Values must be positive finite numbers and
use the same units as width. When supplied, road merging is disabled to
preserve feature attributes.
Default TRUE. Whether to densify road paths and resample
them along the terrain before render_highquality() meshing. Set to FALSE
to use the vertices returned by render_path() directly.
Default 0. Additional vertical road base offset in elevation
units above the sampled surface.
Default 0. Length in scene/world units over which
each end of a road transitions between the sampled surface and offset.
Positive values use the terrain height at the path midpoint plus offset as
a constant deck height, with a quadratic Bezier ramp at each end. If a road
is shorter than twice this distance, each ramp is shortened to half the road
length.
Default NULL. An unquoted or character column name in an sf
road object containing OpenStreetMap-style layer values. When omitted, uses
the layer column if present; explicit NULL disables this lookup. Missing values are
treated as implicit layer 0, except affirmative bridge or elevated
location metadata infer effective layer 1 and affirmative tunnel or
underground location metadata infer effective layer -1. Inferred values
remain distinguishable from explicit OSM layer tags in diagnostics.
tunnel = "building_passage" describes a covered passage through a building;
it does not imply a below-ground layer or exemption from terrain clearance.
Explicit underground location metadata still takes precedence.
Roads are grouped by exact physical events and conservative endpoint
continuations. A sparse quadratic profile solve enforces crossing clearance,
physical grade and grade-rate limits, junction height continuity, and
selected through-road grade compatibility. Surface roads retain a sampled
terrain reference, elevated spans use endpoint support chords, and roads with
explicit tunnel or underground metadata use a bounded terrain-relative
reference. Untagged negative layers are not independently activated as
tunnels. Ambiguous endpoint matches that would create a contradictory
clearance cycle are excluded. Using layer or bridge disables merge and requires
the suggested sf, igraph, Matrix, and osqp packages. Terrain-floor
constraints use the unmodified DEM across the road width, independently of
the smoothed fitting reference. Curved profiles are tessellated before meshing
so rendered decks preserve the solved heights between source road vertices.
Default 5.5. Either a single positive spacing in
elevation units between locally ordered layers, or an unquoted or character
column name containing each feature's positive separation above the lower
road at an intersection. Column heights override constant layer spacing.
Default TRUE. Whether to merge connected road linework before
rendering. This reduces visible joins between adjacent line features in
render_highquality().
Default TRUE. If TRUE, render_highquality() uses a
generated repeating texture on the top road surface for lane markings.
Default NULL. Optional path to a custom road lane
texture. When supplied, it is used instead of the generated texture and
lane_texture is treated as TRUE.
Default 3. Painted dash length in scene/world units
for generated dashed lane markings. The default approximates a 10 foot dash
as 3 meters.
Default 10. Gap length in scene/world units for
generated dashed lane markings. The default approximates a 30 foot gap as
10 meters.
Default NULL, which uses
lane_dash_length + lane_gap_length. Scene-unit length covered by one
repetition of the road lane texture.
Default "auto". If "auto", each road path is
assigned a texture repetition count based on its world-unit length and
lane_texture_length. If "fixed", all road paths use lane_texture_length
directly.
Default 2. Number of lanes used when generating the default
lane texture and, when width = NULL, deriving the road width. May also be
an unquoted or character column name in an sf road object. OSM-style
compound values use their first positive integer. Missing values first use
lanes:forward plus lanes:backward, then fall back to one lane for links
and one-way roads or two lanes for other roads.
Default 3. Lane width in scene/world units used when
width = NULL. The derived road width is
lane_width * (lanes + 2). The generated lane texture leaves one lane width
total outside the edge lines, split between both sides.
Default "#eeeade". sRGB color for dashed lane divider
markings.
Default "#eeeade". sRGB color for the center
divider.
Default "#d6ad3d". sRGB color for solid edge
markings.
Default 0.035. Lane marking width as a fraction of
the road width in the generated texture.
Default NULL, which uses
lane_dash_length / (lane_dash_length + lane_gap_length). Fraction of each
texture repetition occupied by a dash for dashed lane markings.
Default TRUE. If TRUE, removes the existing road
layer before drawing the new one. A clear-only call returns without rendering
a replacement.
Default "line". Whether roads are drawn in rgl as lightweight
"line" previews or as their cached "mesh" geometry. The mesh is the exact
high-quality geometry. Lines are raised slightly above the pavement surface
for visibility in rgl; this display offset does not affect rendered or
exported road geometry.
Default FALSE. Whether to display progress during road
profile preparation, solving, and mesh construction.
Default TRUE. Whether to use multiple native threads while
sampling road terrain contacts and building the cached road meshes.
Default 0.15. Maximum absolute longitudinal road
grade. Positive infinity removes the grade bound.
Default 0.14. Maximum absolute grade
mismatch at selected road continuations. Continuation height remains exact.
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.
Default FALSE. Cut the displayed terrain locally
beneath road pavement instead of lifting roads over adjacent DEM banks.
With layer, surface junctions are held at or below their sampled ground
elevation and their approaches are flattened while retaining crossing
clearance and grade limits. Explicit tunnels retain their terrain cover.
This replaces the scene surface with a regular terrain grid and updates the
cached heightmap; it does not modify the input raster or matrix.
Default NULL. An unquoted or character column name containing
bridge status. When omitted, uses the bridge column if present; explicit
NULL disables this lookup. Accepts logical values or OSM tags: missing,
empty, "no", "false", and "0" mean no bridge; affirmative tags such as
"yes" and "viaduct" identify bridges. Bridge status activates the profile
solver even without a layer column or an intersecting road. Explicit layer
values retain their ordering; missing bridge layers infer layer 1, while
ordinary missing layers remain 0. Pass layer = NULL, bridge = NULL to
disable automatic structure profiles and use terrain-following roads.
Deprecated argument spellings are accepted with a warning and forwarded to their current names.
Invisibly returns the rendered road coordinates. When layer or
bridge metadata is used, the result has terrain_following, profile_diagnostics, and
mesh_topology attributes describing the sparse profile solve and selected
physical mesh continuations.
With terrain_grading = TRUE, graded_heightmap contains the modified terrain.