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,
  ...
)

Arguments

roads

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

road_color

Default "#303030". sRGB road surface color.

width

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.

width_column

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.

densify

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.

offset

Default 0. Additional vertical road base offset in elevation units above the sampled surface.

offset_transition

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.

layer

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.

layer_height

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.

merge

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

lane_texture

Default TRUE. If TRUE, render_highquality() uses a generated repeating texture on the top road surface for lane markings.

lane_texture_file

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.

lane_dash_length

Default 3. Painted dash length in scene/world units for generated dashed lane markings. The default approximates a 10 foot dash as 3 meters.

lane_gap_length

Default 10. Gap length in scene/world units for generated dashed lane markings. The default approximates a 30 foot gap as 10 meters.

lane_texture_length

Default NULL, which uses lane_dash_length + lane_gap_length. Scene-unit length covered by one repetition of the road lane texture.

lane_texture_mapping

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.

lanes

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.

lane_width

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.

lane_color

Default "#eeeade". sRGB color for dashed lane divider markings.

centerline_color

Default "#eeeade". sRGB color for the center divider.

edge_line_color

Default "#d6ad3d". sRGB color for solid edge markings.

lane_line_width

Default 0.035. Lane marking width as a fraction of the road width in the generated texture.

lane_dash_fraction

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.

clear_previous

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

preview

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.

verbose

Default FALSE. Whether to display progress during road profile preparation, solving, and mesh construction.

parallel

Default TRUE. Whether to use multiple native threads while sampling road terrain contacts and building the cached road meshes.

maximum_grade

Default 0.15. Maximum absolute longitudinal road grade. Positive infinity removes the grade bound.

continuation_grade_tolerance

Default 0.14. Maximum absolute grade mismatch at selected road continuations. Continuation height remains exact.

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.

terrain_grading

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.

bridge

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.

Value

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.