| Title: | Create Maps and Visualize Data in 2D and 3D |
|---|---|
| Description: | Uses a combination of raytracing and multiple hill shading methods to produce 2D and 3D data visualizations and maps. Includes water detection and layering functions, programmable color palette generation, several built-in textures for hill shading, 2D and 3D plotting options, a built-in path tracer, 'Wavefront' OBJ file export, and the ability to save 3D visualizations to a 3D printable format. |
| Authors: | Tyler Morgan-Wall [aut, cph, cre] (ORCID: <https://orcid.org/0000-0002-3131-3814>) |
| Maintainer: | Tyler Morgan-Wall <[email protected]> |
| License: | GPL-3 |
| Version: | 0.41.0 |
| Built: | 2026-06-02 00:38:51 UTC |
| Source: | https://github.com/tylermorganwall/rayshader |
Overlays an image (with a transparency layer) on the current map.
add_overlay( hillshade = NULL, overlay = NULL, alphalayer = 1, alphacolor = NULL, alphamethod = "max", color_epsilon = 0.001, rescale_original = FALSE )add_overlay( hillshade = NULL, overlay = NULL, alphalayer = 1, alphacolor = NULL, alphamethod = "max", color_epsilon = 0.001, rescale_original = FALSE )
hillshade |
A three-dimensional RGB array or 2D matrix of shadow intensities. |
overlay |
A three or four dimensional RGB array, where the 4th dimension represents the alpha (transparency) channel.
If the array is 3D, |
alphalayer |
Default |
alphacolor |
Default |
alphamethod |
Default |
color_epsilon |
Default |
rescale_original |
Default |
Hillshade with overlay.
#Combining base R plotting with rayshader's spherical color mapping and raytracing: if(run_documentation()) { montereybay |> sphere_shade() |> add_overlay(height_shade(montereybay),alphalayer = 0.6) |> add_shadow(ray_shade(montereybay,zscale=50)) |> plot_map() } if(run_documentation()) { #Add contours with `generate_contour_overlay()` montereybay |> height_shade() |> add_overlay(generate_contour_overlay(montereybay)) |> add_shadow(ray_shade(montereybay,zscale=50)) |> plot_map() }#Combining base R plotting with rayshader's spherical color mapping and raytracing: if(run_documentation()) { montereybay |> sphere_shade() |> add_overlay(height_shade(montereybay),alphalayer = 0.6) |> add_shadow(ray_shade(montereybay,zscale=50)) |> plot_map() } if(run_documentation()) { #Add contours with `generate_contour_overlay()` montereybay |> height_shade() |> add_overlay(generate_contour_overlay(montereybay)) |> add_shadow(ray_shade(montereybay,zscale=50)) |> plot_map() }
Multiplies a texture array or shadow map by a shadow map.
add_shadow(hillshade, shadowmap, max_darken = 0.7, rescale_original = FALSE)add_shadow(hillshade, shadowmap, max_darken = 0.7, rescale_original = FALSE)
hillshade |
A three-dimensional RGB array or 2D matrix of shadow intensities. |
shadowmap |
A matrix that incidates the intensity of the shadow at that point. 0 is full darkness, 1 is full light. |
max_darken |
Default |
rescale_original |
Default |
Shaded texture map.
#First we plot the sphere_shade() hillshade of `montereybay` with no shadows if(run_documentation()) { montereybay |> sphere_shade(colorintensity=0.5) |> plot_map() } #Raytrace the `montereybay` elevation map and add that shadow to the output of sphere_shade() if(run_documentation()) { montereybay |> sphere_shade(colorintensity=0.5) |> add_shadow(ray_shade(montereybay,sunaltitude=20,zscale=50),max_darken=0.3) |> plot_map() } #Increase the intensity of the shadow map with the max_darken argument. if(run_documentation()) { montereybay |> sphere_shade(colorintensity=0.5) |> add_shadow(ray_shade(montereybay,sunaltitude=20,zscale=50),max_darken=0.1) |> plot_map() } #Decrease the intensity of the shadow map. if(run_documentation()) { montereybay |> sphere_shade(colorintensity=0.5) |> add_shadow(ray_shade(montereybay,sunaltitude=20,zscale=50),max_darken=0.7) |> plot_map() }#First we plot the sphere_shade() hillshade of `montereybay` with no shadows if(run_documentation()) { montereybay |> sphere_shade(colorintensity=0.5) |> plot_map() } #Raytrace the `montereybay` elevation map and add that shadow to the output of sphere_shade() if(run_documentation()) { montereybay |> sphere_shade(colorintensity=0.5) |> add_shadow(ray_shade(montereybay,sunaltitude=20,zscale=50),max_darken=0.3) |> plot_map() } #Increase the intensity of the shadow map with the max_darken argument. if(run_documentation()) { montereybay |> sphere_shade(colorintensity=0.5) |> add_shadow(ray_shade(montereybay,sunaltitude=20,zscale=50),max_darken=0.1) |> plot_map() } #Decrease the intensity of the shadow map. if(run_documentation()) { montereybay |> sphere_shade(colorintensity=0.5) |> add_shadow(ray_shade(montereybay,sunaltitude=20,zscale=50),max_darken=0.7) |> plot_map() }
Adds a layer of water to a map.
add_water(hillshade, watermap, color = "imhof1")add_water(hillshade, watermap, color = "imhof1")
hillshade |
A three-dimensional RGB array. |
watermap |
Matrix indicating whether water was detected at that point. 1 indicates water, 0 indicates no water. |
color |
Default |
#Here we even out a portion of the volcano dataset to simulate water: island_volcano = volcano island_volcano[island_volcano < mean(island_volcano)] = mean(island_volcano) #Setting a minimum area avoids classifying small flat areas as water: if(run_documentation()) { island_volcano |> sphere_shade(texture="imhof3") |> add_water(detect_water(island_volcano, min_area = 400),color="imhof3") |> plot_map() } #We'll do the same thing with the Monterey Bay dataset to fill in the ocean: montbay_water = montereybay montbay_water[montbay_water < 0] = 0 if(run_documentation()) { montereybay |> sphere_shade(texture="imhof4") |> add_water(detect_water(montbay_water),color="imhof4") |> plot_map() }#Here we even out a portion of the volcano dataset to simulate water: island_volcano = volcano island_volcano[island_volcano < mean(island_volcano)] = mean(island_volcano) #Setting a minimum area avoids classifying small flat areas as water: if(run_documentation()) { island_volcano |> sphere_shade(texture="imhof3") |> add_water(detect_water(island_volcano, min_area = 400),color="imhof3") |> plot_map() } #We'll do the same thing with the Monterey Bay dataset to fill in the ocean: montbay_water = montereybay montbay_water[montbay_water < 0] = 0 if(run_documentation()) { montereybay |> sphere_shade(texture="imhof4") |> add_water(detect_water(montbay_water),color="imhof4") |> plot_map() }
Calculates Ambient Occlusion Shadow Map
ambient_shade( heightmap, anglebreaks = 90 * cospi(seq(5, 85, by = 5)/180), sunbreaks = 24, maxsearch = 30, multicore = FALSE, zscale = 1, cache_mask = NULL, shadow_cache = NULL, progbar = interactive(), ... )ambient_shade( heightmap, anglebreaks = 90 * cospi(seq(5, 85, by = 5)/180), sunbreaks = 24, maxsearch = 30, multicore = FALSE, zscale = 1, cache_mask = NULL, shadow_cache = NULL, progbar = interactive(), ... )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced. |
anglebreaks |
Default |
sunbreaks |
Default |
maxsearch |
Default |
multicore |
Default FALSE. If TRUE, multiple cores will be used to compute the shadow matrix. By default, this uses all cores available, unless the user has
set |
zscale |
Default 1. The ratio between the x and y spacing (which are assumed to be equal) and the z axis. |
cache_mask |
Default |
shadow_cache |
Default |
progbar |
Default |
... |
Additional arguments to pass to the |
Shaded texture map.
#Here we produce a ambient occlusion map of the `montereybay` elevation map. if(run_documentation()) { plot_map(ambient_shade(heightmap = montereybay)) } #We can increase the distance to look for surface intersections `maxsearch` #and the density of rays sent out around the point `sunbreaks`. if(run_documentation()) { plot_map(ambient_shade(montereybay, sunbreaks = 24,maxsearch = 100, multicore=TRUE)) } #Create the Red Relief Image Map (RRIM) technique using a custom texture and ambient_shade(), #with an addition lambertian layer added with lamb_shade() to improve topographic clarity. if(run_documentation()) { bigmb = resize_matrix(montereybay, scale=2, method="cubic") bigmb |> sphere_shade(zscale=3, texture = create_texture("red","red","red","red","white")) |> add_shadow(ambient_shade(bigmb, maxsearch = 100, multicore = TRUE,zscale=1),0) |> add_shadow(lamb_shade(bigmb),0.5) |> plot_map() }#Here we produce a ambient occlusion map of the `montereybay` elevation map. if(run_documentation()) { plot_map(ambient_shade(heightmap = montereybay)) } #We can increase the distance to look for surface intersections `maxsearch` #and the density of rays sent out around the point `sunbreaks`. if(run_documentation()) { plot_map(ambient_shade(montereybay, sunbreaks = 24,maxsearch = 100, multicore=TRUE)) } #Create the Red Relief Image Map (RRIM) technique using a custom texture and ambient_shade(), #with an addition lambertian layer added with lamb_shade() to improve topographic clarity. if(run_documentation()) { bigmb = resize_matrix(montereybay, scale=2, method="cubic") bigmb |> sphere_shade(zscale=3, texture = create_texture("red","red","red","red","white")) |> add_shadow(ambient_shade(bigmb, maxsearch = 100, multicore = TRUE,zscale=1),0) |> add_shadow(lamb_shade(bigmb),0.5) |> plot_map() }
Calculates the normal unit vector for every point on the grid.
calculate_normal(heightmap, zscale = 1, progbar = FALSE)calculate_normal(heightmap, zscale = 1, progbar = FALSE)
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced. |
zscale |
Default 1. |
progbar |
Default |
Matrix of light intensities at each point.
#Here we produce a light intensity map of the `volcano` elevation map. #Cache the normal vectors of the volcano dataset if(run_documentation()) { volcanocache = calculate_normal(volcano) } #Use the cached vectors to speed up calculation of `sphere_shade()` on a map. if(run_documentation()) { sphere_shade(volcano,normalvectors = volcanocache) |> plot_map() }#Here we produce a light intensity map of the `volcano` elevation map. #Cache the normal vectors of the volcano dataset if(run_documentation()) { volcanocache = calculate_normal(volcano) } #Use the cached vectors to speed up calculation of `sphere_shade()` on a map. if(run_documentation()) { sphere_shade(volcano,normalvectors = volcanocache) |> plot_map() }
Render shadows from the 3D floating cloud layer on the ground. Use this function
to add shadows to the map with the add_shadow() function.
For realistic results, argument should match those passed to render_clouds(). The exception to this
is attenuation_coef, which can be used to adjust the darkness of the resulting shadows.
cloud_shade( heightmap, start_altitude = 1000, end_altitude = 2000, sun_altitude = 90, sun_angle = 315, time = 0, cloud_cover = 0.5, layers = 10, offset_x = 0, offset_y = 0, scale_x = 1, scale_y = 1, scale_z = 1, frequency = 0.005, fractal_levels = 16, attenuation_coef = 1, seed = 1, zscale = 1 )cloud_shade( heightmap, start_altitude = 1000, end_altitude = 2000, sun_altitude = 90, sun_angle = 315, time = 0, cloud_cover = 0.5, layers = 10, offset_x = 0, offset_y = 0, scale_x = 1, scale_y = 1, scale_z = 1, frequency = 0.005, fractal_levels = 16, attenuation_coef = 1, seed = 1, zscale = 1 )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. This is used by |
start_altitude |
Default |
end_altitude |
Default |
sun_altitude |
Default |
sun_angle |
Default |
time |
Default |
cloud_cover |
Default |
layers |
Default |
offset_x |
Default |
offset_y |
Default |
scale_x |
Default |
scale_y |
Default |
scale_z |
Default |
frequency |
Default |
fractal_levels |
Default |
attenuation_coef |
Default |
seed |
Default |
zscale |
Default |
A 2D shadow matrix.
if(run_documentation()) { #Render clouds with cloud shadows on the ground montereybay |> sphere_shade() |> add_shadow(cloud_shade(montereybay,zscale=50), 0.0) |> plot_3d(montereybay,background="darkred",zscale=50) render_camera(theta=-65, phi = 25, zoom = 0.45, fov = 80) render_clouds(montereybay, zscale=50) render_snapshot() } if(run_documentation()) { #Adjust the light direction for shadows and increase the attenuation for darker clouds montereybay |> sphere_shade() |> add_shadow(cloud_shade(montereybay,zscale=50, sun_altitude=20, attenuation_coef = 3), 0.0) |> plot_3d(montereybay,background="darkred",zscale=50) render_camera(theta=-65, phi = 25, zoom = 0.45, fov = 80) render_clouds(montereybay, zscale=50) render_snapshot() }if(run_documentation()) { #Render clouds with cloud shadows on the ground montereybay |> sphere_shade() |> add_shadow(cloud_shade(montereybay,zscale=50), 0.0) |> plot_3d(montereybay,background="darkred",zscale=50) render_camera(theta=-65, phi = 25, zoom = 0.45, fov = 80) render_clouds(montereybay, zscale=50) render_snapshot() } if(run_documentation()) { #Adjust the light direction for shadows and increase the attenuation for darker clouds montereybay |> sphere_shade() |> add_shadow(cloud_shade(montereybay,zscale=50, sun_altitude=20, attenuation_coef = 3), 0.0) |> plot_3d(montereybay,background="darkred",zscale=50) render_camera(theta=-65, phi = 25, zoom = 0.45, fov = 80) render_clouds(montereybay, zscale=50) render_snapshot() }
Generates a constant color layer.
constant_shade(heightmap, color = "white", alpha = 1)constant_shade(heightmap, color = "white", alpha = 1)
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. |
color |
Default |
alpha |
Default |
RGB array of a single color layer.
if(run_documentation()) { #Shade a red map montereybay |> constant_shade("red") |> add_shadow(lamb_shade(montereybay),0) |> plot_map() } if(run_documentation()) { #Shade a green map montereybay |> constant_shade("green") |> add_shadow(lamb_shade(montereybay),0) |> plot_map() } if(run_documentation()) { #Add a blue tint montereybay |> height_shade() |> add_overlay(constant_shade(montereybay, "dodgerblue", alpha=0.25)) |> add_shadow(lamb_shade(montereybay,zscale=50),0) |> plot_map() } if(run_documentation()) { #Use a blank map on which to draw other data montereybay |> constant_shade() |> add_overlay(generate_line_overlay(monterey_roads_sf, linewidth=5, color="black", attr(montereybay,"extent"), width = 1080, height = 1080), alphalayer=0.8) |> add_water(detect_water(montereybay < 0), "dodgerblue") |> plot_map() }if(run_documentation()) { #Shade a red map montereybay |> constant_shade("red") |> add_shadow(lamb_shade(montereybay),0) |> plot_map() } if(run_documentation()) { #Shade a green map montereybay |> constant_shade("green") |> add_shadow(lamb_shade(montereybay),0) |> plot_map() } if(run_documentation()) { #Add a blue tint montereybay |> height_shade() |> add_overlay(constant_shade(montereybay, "dodgerblue", alpha=0.25)) |> add_shadow(lamb_shade(montereybay,zscale=50),0) |> plot_map() } if(run_documentation()) { #Use a blank map on which to draw other data montereybay |> constant_shade() |> add_overlay(generate_line_overlay(monterey_roads_sf, linewidth=5, color="black", attr(montereybay,"extent"), width = 1080, height = 1080), alphalayer=0.8) |> add_water(detect_water(montereybay < 0), "dodgerblue") |> plot_map() }
Transforms latitude/longitude/altitude coordinates to the reference system used in render_highquality(),
so they can be used to create high quality pathtraced animations by passing the output to the animation_camera_coords
argument in render_highquality().
This function converts the path values to rayshader coordinates (by setting return_coords = TRUE in render_path())
and then subtracts out the rgl y-offset, which can be obtained by calling the internal function rayshader:::get_scene_depth().
convert_path_to_animation_coords( lat, long = NULL, altitude = NULL, extent = NULL, frames = 360, reorder = FALSE, reorder_first_index = 1, reorder_duplicate_tolerance = 0.1, reorder_merge_tolerance = 1, simplify_tolerance = 0, zscale = 1, heightmap = NULL, offset = 5, type = "bezier", offset_lookat = 1, constant_step = TRUE, curvature_adjust = "none", curvature_scale = 30, follow_camera = FALSE, follow_distance = 100, follow_angle = 45, follow_rotations = 0, follow_fixed = FALSE, follow_fixed_offset = c(10, 10, 10), damp_motion = FALSE, damp_magnitude = 0.1, resample_path_evenly = TRUE, ... )convert_path_to_animation_coords( lat, long = NULL, altitude = NULL, extent = NULL, frames = 360, reorder = FALSE, reorder_first_index = 1, reorder_duplicate_tolerance = 0.1, reorder_merge_tolerance = 1, simplify_tolerance = 0, zscale = 1, heightmap = NULL, offset = 5, type = "bezier", offset_lookat = 1, constant_step = TRUE, curvature_adjust = "none", curvature_scale = 30, follow_camera = FALSE, follow_distance = 100, follow_angle = 45, follow_rotations = 0, follow_fixed = FALSE, follow_fixed_offset = c(10, 10, 10), damp_motion = FALSE, damp_magnitude = 0.1, resample_path_evenly = TRUE, ... )
lat |
Vector of latitudes (or other coordinate in the same coordinate reference system as extent). |
long |
Vector of longitudes (or other coordinate in the same coordinate reference system as extent). |
altitude |
Elevation of each point, in units of the elevation matrix (scaled by zscale).
If left |
extent |
Either an object representing the spatial extent of the scene
(either from the |
frames |
Default |
reorder |
Default |
reorder_first_index |
Default |
reorder_duplicate_tolerance |
Default |
reorder_merge_tolerance |
Default |
simplify_tolerance |
Default |
zscale |
Default |
heightmap |
Default |
offset |
Default |
type |
Default |
offset_lookat |
Default |
constant_step |
Default |
curvature_adjust |
Default |
curvature_scale |
Default |
follow_camera |
Default |
follow_distance |
Default |
follow_angle |
Default |
follow_rotations |
Default |
follow_fixed |
Default |
follow_fixed_offset |
Default |
damp_motion |
Default |
damp_magnitude |
Default |
resample_path_evenly |
Default |
... |
Other arguments to pass to |
#Generate a circle in Monterey Bay and fly around on top of it ## Not run: tmp = tempdir() # Recreate your original example but compact, with fewer frames & smaller size. moss_landing_coord = c(36.806807, -121.793332) t = seq(0, 2 * pi, length.out = 360) # fewer frames for speed circle_coords_lat = moss_landing_coord[1] + 0.25 * sin(t) circle_coords_long = moss_landing_coord[2] + 0.25 * cos(t) # Minimal 3D render -> frames extent_mb = attr(montereybay, "extent") sphere_shade(montereybay) |> plot_3d( montereybay, zscale = 50, water = TRUE, shadowcolor = "#40310a", background = "tan", theta = 210, phi = 22, zoom = 0.40, fov = 55 ) render_path( extent = extent_mb, heightmap = montereybay, lat = circle_coords_lat, long = circle_coords_long, zscale = 50, color = "red", antialias = TRUE, offset = 500, linewidth = 2 ) cam = convert_path_to_animation_coords( extent = extent_mb, heightmap = montereybay, lat = circle_coords_lat, long = circle_coords_long, type = "bezier", damp_motion = TRUE, fovs = 80, zscale = 50, offset = 1000, frames = length(t) ) render_highquality( samples = 4, animation_camera_coords = cam, width = 200, height = 200, preview = FALSE, filename = file.path(tmp, "frame"), use_extruded_paths = TRUE ) # Assemble frames -> GIF (pkgdown copies from man/figures) pngs = sprintf("%s/frame%d.png", tmp, seq_along(t)) av::av_encode_video( pngs, framerate = 24 ) ## End(Not run) #Now we use a "follow camera" for a third person view: ## Not run: follow_cam = convert_path_to_animation_coords( extent = extent_mb, heightmap = montereybay, lat = circle_coords_lat, long = circle_coords_long, type = "bezier", damp_motion = TRUE, fovs = 80, zscale = 50, follow_camera = TRUE, offset = 1000, frames = length(t) ) render_highquality( samples = 4, animation_camera_coords = follow_cam, width = 200, height = 200, preview = FALSE, filename = file.path(tmp, "frame"), use_extruded_paths = TRUE ) # See description for video (if on the documentation website) pngs = sprintf("%s/frame%d.png", tmp, seq_along(t)) av::av_encode_video( pngs, framerate = 24 ) ## End(Not run)#Generate a circle in Monterey Bay and fly around on top of it ## Not run: tmp = tempdir() # Recreate your original example but compact, with fewer frames & smaller size. moss_landing_coord = c(36.806807, -121.793332) t = seq(0, 2 * pi, length.out = 360) # fewer frames for speed circle_coords_lat = moss_landing_coord[1] + 0.25 * sin(t) circle_coords_long = moss_landing_coord[2] + 0.25 * cos(t) # Minimal 3D render -> frames extent_mb = attr(montereybay, "extent") sphere_shade(montereybay) |> plot_3d( montereybay, zscale = 50, water = TRUE, shadowcolor = "#40310a", background = "tan", theta = 210, phi = 22, zoom = 0.40, fov = 55 ) render_path( extent = extent_mb, heightmap = montereybay, lat = circle_coords_lat, long = circle_coords_long, zscale = 50, color = "red", antialias = TRUE, offset = 500, linewidth = 2 ) cam = convert_path_to_animation_coords( extent = extent_mb, heightmap = montereybay, lat = circle_coords_lat, long = circle_coords_long, type = "bezier", damp_motion = TRUE, fovs = 80, zscale = 50, offset = 1000, frames = length(t) ) render_highquality( samples = 4, animation_camera_coords = cam, width = 200, height = 200, preview = FALSE, filename = file.path(tmp, "frame"), use_extruded_paths = TRUE ) # Assemble frames -> GIF (pkgdown copies from man/figures) pngs = sprintf("%s/frame%d.png", tmp, seq_along(t)) av::av_encode_video( pngs, framerate = 24 ) ## End(Not run) #Now we use a "follow camera" for a third person view: ## Not run: follow_cam = convert_path_to_animation_coords( extent = extent_mb, heightmap = montereybay, lat = circle_coords_lat, long = circle_coords_long, type = "bezier", damp_motion = TRUE, fovs = 80, zscale = 50, follow_camera = TRUE, offset = 1000, frames = length(t) ) render_highquality( samples = 4, animation_camera_coords = follow_cam, width = 200, height = 200, preview = FALSE, filename = file.path(tmp, "frame"), use_extruded_paths = TRUE ) # See description for video (if on the documentation website) pngs = sprintf("%s/frame%d.png", tmp, seq_along(t)) av::av_encode_video( pngs, framerate = 24 ) ## End(Not run)
Converts the current RGL rayshader scene to a ray_mesh object (see rayvertex package for more information)
convert_rgl_to_raymesh( save_shadow = TRUE, water_attenuation = 0, water_surface_color = TRUE, water_ior = 1 )convert_rgl_to_raymesh( save_shadow = TRUE, water_attenuation = 0, water_surface_color = TRUE, water_ior = 1 )
save_shadow |
Default |
water_attenuation |
Default |
water_surface_color |
Default |
water_ior |
Default |
A ray_mesh object
filename_obj = tempfile(fileext = ".obj") #Save model of volcano if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano, zscale = 2) rm_obj = convert_rgl_to_raymesh() }filename_obj = tempfile(fileext = ".obj") #Save model of volcano if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano, zscale = 2) rm_obj = convert_rgl_to_raymesh() }
Creates a texture map based on 5 user-supplied colors.
create_texture( lightcolor, shadowcolor, leftcolor, rightcolor, centercolor, cornercolors = NULL, old_method = FALSE, darken = 1 )create_texture( lightcolor, shadowcolor, leftcolor, rightcolor, centercolor, cornercolors = NULL, old_method = FALSE, darken = 1 )
lightcolor |
The main highlight color. Corresponds to the top center of the texture map. |
shadowcolor |
The main shadow color. Corresponds to the bottom center of the texture map. This color represents slopes directed directly opposite to the main highlight color. |
leftcolor |
The left fill color. Corresponds to the left center of the texture map. This color represents slopes directed 90 degrees to the left of the main highlight color. |
rightcolor |
The right fill color. Corresponds to the right center of the texture map. This color represents slopes directed 90 degrees to the right of the main highlight color. |
centercolor |
The center color. Corresponds to the center of the texture map. This color represents flat areas. |
cornercolors |
Default |
old_method |
Default |
darken |
Default |
#Here is the `imhof1` palette: create_texture("#fff673","#55967a","#8fb28a","#55967a","#cfe0a9") |> plot_map() #Here is the `unicorn` palette: create_texture("red","green","blue","yellow","white") |> plot_map()#Here is the `imhof1` palette: create_texture("#fff673","#55967a","#8fb28a","#55967a","#cfe0a9") |> plot_map() #Here is the `unicorn` palette: create_texture("red","green","blue","yellow","white") |> plot_map()
Detects bodies of water (of a user-defined minimum size) within an elevation matrix.
detect_water( heightmap, zscale = 1, cutoff = 0.999, min_area = length(heightmap)/400, max_height = NULL, normalvectors = NULL, keep_groups = FALSE, progbar = FALSE )detect_water( heightmap, zscale = 1, cutoff = 0.999, min_area = length(heightmap)/400, max_height = NULL, normalvectors = NULL, keep_groups = FALSE, progbar = FALSE )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All grid points are assumed to be evenly spaced. Alternatively, if heightmap is a logical matrix, each entry specifies whether that point is water or not. |
zscale |
Default |
cutoff |
Default |
min_area |
Default length(heightmap)/400. Minimum area (in units of the height matrix x and y spacing) to be considered a body of water. |
max_height |
Default |
normalvectors |
Default |
keep_groups |
Default |
progbar |
Default |
Matrix indicating whether water was detected at that point. 1 indicates water, 0 indicates no water.
#Here we even out a portion of the volcano dataset to simulate water: island_volcano = volcano island_volcano[island_volcano < mean(island_volcano)] = mean(island_volcano) #Setting a minimum area avoids classifying small flat areas as water: island_volcano |> sphere_shade(texture="imhof3") |> add_water(detect_water(island_volcano, min_area = 400),color="imhof3") |> plot_map()#Here we even out a portion of the volcano dataset to simulate water: island_volcano = volcano island_volcano[island_volcano < mean(island_volcano)] = mean(island_volcano) #Setting a minimum area avoids classifying small flat areas as water: island_volcano |> sphere_shade(texture="imhof3") |> add_water(detect_water(island_volcano, min_area = 400),color="imhof3") |> plot_map()
3D obj model of a flag (sans pole), to be used with render_obj(). Use flag_full_obj() to get the complete
pole, and flag_banner_obj() and flag_pole_obj() to style them separately.
flag_banner_obj()flag_banner_obj()
File location of the included flag OBJ file (saved with a .txt extension)
#Print the location of the flag file flag_banner_obj()#Print the location of the flag file flag_banner_obj()
3D obj model of a flag, to be used with render_obj(). Use flag_full_obj() to get the complete
pole, and flag_banner_obj() and flag_pole_obj() to style them separately.
flag_full_obj()flag_full_obj()
File location of the included flag OBJ file (saved with a .txt extension)
#Print the location of the flag file flag_full_obj()#Print the location of the flag file flag_full_obj()
3D obj model of a flag pole, to be used with render_obj(). Use flag_full_obj() to get the complete
pole, and flag_banner_obj() and flag_pole_obj() to style them separately.
flag_pole_obj()flag_pole_obj()
File location of the included flag OBJ file (saved with a .txt extension)
#Print the location of the flag file flag_pole_obj()#Print the location of the flag file flag_pole_obj()
Using a hillshade and the height map, generates a semi-transparent hillshade to layer onto an existing map.
generate_altitude_overlay( hillshade, heightmap, start_transition, end_transition = NULL, lower = TRUE )generate_altitude_overlay( hillshade, heightmap, start_transition, end_transition = NULL, lower = TRUE )
hillshade |
The hillshade to transition into. |
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All grid points are assumed to be evenly spaced. |
start_transition |
Elevation above which |
end_transition |
Default |
lower |
Default |
4-layer RGB array representing the semi-transparent hillshade.
#Create a bathymetric hillshade if(run_documentation()) { water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) plot_map(bathy_hs) } if(run_documentation()) { #Set everything below 0m to water palette montereybay |> sphere_shade(zscale=10) |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() } #Add snow peaks by setting `lower = FALSE` snow_palette = "white" snow_hs = height_shade(montereybay, texture = snow_palette) if(run_documentation()) { #Set the snow transition region from 500m to 1200m montereybay |> sphere_shade(zscale=10, texture = "desert") |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_overlay(generate_altitude_overlay(snow_hs, montereybay, 500, 1200, lower=FALSE)) |> add_shadow(ambient_shade(montereybay,zscale=50,maxsearch=100),0) |> plot_map() }#Create a bathymetric hillshade if(run_documentation()) { water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) plot_map(bathy_hs) } if(run_documentation()) { #Set everything below 0m to water palette montereybay |> sphere_shade(zscale=10) |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() } #Add snow peaks by setting `lower = FALSE` snow_palette = "white" snow_hs = height_shade(montereybay, texture = snow_palette) if(run_documentation()) { #Set the snow transition region from 500m to 1200m montereybay |> sphere_shade(zscale=10, texture = "desert") |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_overlay(generate_altitude_overlay(snow_hs, montereybay, 500, 1200, lower=FALSE)) |> add_shadow(ambient_shade(montereybay,zscale=50,maxsearch=100),0) |> plot_map() }
This adds the compass
Based on code from "Auxiliary Cartographic Functions in R: North Arrow, Scale Bar, and Label with a Leader Arrow"
generate_compass_overlay( x = 0.85, y = 0.15, size = 0.05, text_size = 1, bearing = 0, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, color1 = NA, color2 = NA, text_color = NA, border_color = "black", border_width = 1, compass_type = c("classic", "split_arrow", "triangle_circle", "split_arrow_ring"), halo_color = NA, halo_expand = 2, halo_alpha = 1, halo_offset = c(0, 0), halo_blur = 0, halo_edge_softness = 0.1 )generate_compass_overlay( x = 0.85, y = 0.15, size = 0.05, text_size = 1, bearing = 0, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, color1 = NA, color2 = NA, text_color = NA, border_color = "black", border_width = 1, compass_type = c("classic", "split_arrow", "triangle_circle", "split_arrow_ring"), halo_color = NA, halo_expand = 2, halo_alpha = 1, halo_offset = c(0, 0), halo_blur = 0, halo_edge_softness = 0.1 )
x |
Default |
y |
Default |
size |
Default |
text_size |
Default |
bearing |
Default |
heightmap |
Default |
width |
Default |
height |
Default |
resolution_multiply |
Default |
color1 |
Default |
color2 |
Default |
text_color |
Default |
border_color |
Default |
border_width |
Default |
compass_type |
Default |
halo_color |
Default |
halo_expand |
Default |
halo_alpha |
Default |
halo_offset |
Default |
halo_blur |
Default |
halo_edge_softness |
Default |
Semi-transparent overlay with a compass.
if(run_documentation()) { #Create the water palette water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) #Generate flat water heightmap mbay = montereybay mbay[mbay < 0] = 0 base_map = mbay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) #Plot a compass base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay)) |> plot_map() } if(run_documentation()) { #Change the position to be over the water base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15)) |> plot_map() } if(run_documentation()) { #Change the type base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, compass_type = "split_arrow")) |> plot_map() } if(run_documentation()) { #Change the type base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, compass_type = "split_arrow_ring")) |> plot_map() } if(run_documentation()) { #Change the type base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, compass_type = "triangle_circle")) |> plot_map() } if(run_documentation()) { #Change the text color for visibility base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, compass_type = "split_arrow", x = 0.15, text_color="white")) |> plot_map() } if(run_documentation()) { #Alternatively, add a halo color to improve contrast base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, compass_type = "split_arrow", halo_color="white", halo_expand = 2)) |> plot_map() } if(run_documentation()) { #Change the color scheme base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, compass_type = "split_arrow", halo_color="white", halo_expand = 2, color1 = "purple", color2 = "red")) |> plot_map() } if(run_documentation()) { #Remove the inner border base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, border_color=NA,compass_type = "split_arrow", halo_color="white", halo_expand = 2, color1 = "darkolivegreen4", color2 = "burlywood3")) |> plot_map() } if(run_documentation()) { #Change the size of the compass and text base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.75, y=0.75, halo_color="white", halo_expand = 2,compass_type = "classic", size=0.075*2, text_size = 1.25)) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.45, y=0.45, halo_color="white", halo_expand = 2,compass_type = "split_arrow_ring", size=0.075)) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, halo_color="white", halo_expand = 2,compass_type = "split_arrow", size=0.075/2, text_size = 0.75)) |> plot_map() } if(run_documentation()) { #Change the bearing of the compass base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, halo_color="white", halo_expand = 2, bearing=30, compass_type = "classic", size=0.075)) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.35, y=0.15, halo_color="white", halo_expand = 2, bearing=15, compass_type = "triangle_circle", size=0.075)) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.35, halo_color="white", halo_expand = 2, bearing=-45, compass_type = "split_arrow_ring", size=0.075)) |> plot_map() } if(run_documentation()) { #Create a drop shadow effect base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, text_color="white", halo_alpha=0.7, halo_blur=3, halo_color="black", halo_expand = 2, halo_offset = c(0.002,-0.002))) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.35, y=0.15, text_color="white", halo_alpha=0.7, halo_blur=3, compass_type = "split_arrow", halo_color="black", halo_expand = 2, halo_offset = c(0.002,-0.002))) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.35, text_color="white", halo_alpha=0.2, halo_blur=8, compass_type = "split_arrow_ring", halo_color="white", halo_expand = 2)) |> plot_map() }if(run_documentation()) { #Create the water palette water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) #Generate flat water heightmap mbay = montereybay mbay[mbay < 0] = 0 base_map = mbay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) #Plot a compass base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay)) |> plot_map() } if(run_documentation()) { #Change the position to be over the water base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15)) |> plot_map() } if(run_documentation()) { #Change the type base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, compass_type = "split_arrow")) |> plot_map() } if(run_documentation()) { #Change the type base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, compass_type = "split_arrow_ring")) |> plot_map() } if(run_documentation()) { #Change the type base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, compass_type = "triangle_circle")) |> plot_map() } if(run_documentation()) { #Change the text color for visibility base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, compass_type = "split_arrow", x = 0.15, text_color="white")) |> plot_map() } if(run_documentation()) { #Alternatively, add a halo color to improve contrast base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, compass_type = "split_arrow", halo_color="white", halo_expand = 2)) |> plot_map() } if(run_documentation()) { #Change the color scheme base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, compass_type = "split_arrow", halo_color="white", halo_expand = 2, color1 = "purple", color2 = "red")) |> plot_map() } if(run_documentation()) { #Remove the inner border base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, border_color=NA,compass_type = "split_arrow", halo_color="white", halo_expand = 2, color1 = "darkolivegreen4", color2 = "burlywood3")) |> plot_map() } if(run_documentation()) { #Change the size of the compass and text base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.75, y=0.75, halo_color="white", halo_expand = 2,compass_type = "classic", size=0.075*2, text_size = 1.25)) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.45, y=0.45, halo_color="white", halo_expand = 2,compass_type = "split_arrow_ring", size=0.075)) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, halo_color="white", halo_expand = 2,compass_type = "split_arrow", size=0.075/2, text_size = 0.75)) |> plot_map() } if(run_documentation()) { #Change the bearing of the compass base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, halo_color="white", halo_expand = 2, bearing=30, compass_type = "classic", size=0.075)) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.35, y=0.15, halo_color="white", halo_expand = 2, bearing=15, compass_type = "triangle_circle", size=0.075)) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.35, halo_color="white", halo_expand = 2, bearing=-45, compass_type = "split_arrow_ring", size=0.075)) |> plot_map() } if(run_documentation()) { #Create a drop shadow effect base_map |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15, text_color="white", halo_alpha=0.7, halo_blur=3, halo_color="black", halo_expand = 2, halo_offset = c(0.002,-0.002))) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.35, y=0.15, text_color="white", halo_alpha=0.7, halo_blur=3, compass_type = "split_arrow", halo_color="black", halo_expand = 2, halo_offset = c(0.002,-0.002))) |> add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.35, text_color="white", halo_alpha=0.2, halo_blur=8, compass_type = "split_arrow_ring", halo_color="white", halo_expand = 2)) |> plot_map() }
Calculates and returns an overlay of contour lines for the current height map.
generate_contour_overlay( heightmap, levels = NA, nlevels = NA, zscale = 1, width = NA, height = NA, resolution_multiply = 1, color = "black", linewidth = 1 )generate_contour_overlay( heightmap, levels = NA, nlevels = NA, zscale = 1, width = NA, height = NA, resolution_multiply = 1, color = "black", linewidth = 1 )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All grid points are assumed to be evenly spaced. |
levels |
Default |
nlevels |
Default |
zscale |
Default |
width |
Default |
height |
Default |
resolution_multiply |
Default |
color |
Default |
linewidth |
Default |
Semi-transparent overlay with contours.
#Add contours to the montereybay dataset if(run_documentation()) { montereybay |> height_shade() |> add_overlay(generate_contour_overlay(montereybay)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() } #Add a different contour color for above and below water, and specify levels manually water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) breaks = seq(range(montereybay)[1],range(montereybay)[2],length.out=50) water_breaks = breaks[breaks < 0] land_breaks = breaks[breaks > 0] if(run_documentation()) { montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_contour_overlay(montereybay, levels = water_breaks, color="white")) |> add_overlay(generate_contour_overlay(montereybay, levels = land_breaks, color="black")) |> plot_map() } if(run_documentation()) { #Increase the resolution of the contour to improve the appearance of lines montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_contour_overlay(montereybay, levels = water_breaks, color="white", height = nrow(montereybay)*2, width = ncol(montereybay)*2)) |> add_overlay(generate_contour_overlay(montereybay, levels = land_breaks, color="black", height = nrow(montereybay)*2, width = ncol(montereybay)*2)) |> plot_map() } if(run_documentation()) { #Increase the number of breaks and the transparency (via add_overlay) montereybay |> height_shade() |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_contour_overlay(montereybay, linewidth=2, nlevels=100, height = nrow(montereybay)*2, color="black", width = ncol(montereybay)*2), alphalayer=0.5) |> plot_map() } if(run_documentation()) { #Manually specify the breaks with levels montereybay |> height_shade() |> add_overlay(generate_contour_overlay(montereybay, linewidth=2, levels = seq(-2000,0,100))) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() }#Add contours to the montereybay dataset if(run_documentation()) { montereybay |> height_shade() |> add_overlay(generate_contour_overlay(montereybay)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() } #Add a different contour color for above and below water, and specify levels manually water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) breaks = seq(range(montereybay)[1],range(montereybay)[2],length.out=50) water_breaks = breaks[breaks < 0] land_breaks = breaks[breaks > 0] if(run_documentation()) { montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_contour_overlay(montereybay, levels = water_breaks, color="white")) |> add_overlay(generate_contour_overlay(montereybay, levels = land_breaks, color="black")) |> plot_map() } if(run_documentation()) { #Increase the resolution of the contour to improve the appearance of lines montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_contour_overlay(montereybay, levels = water_breaks, color="white", height = nrow(montereybay)*2, width = ncol(montereybay)*2)) |> add_overlay(generate_contour_overlay(montereybay, levels = land_breaks, color="black", height = nrow(montereybay)*2, width = ncol(montereybay)*2)) |> plot_map() } if(run_documentation()) { #Increase the number of breaks and the transparency (via add_overlay) montereybay |> height_shade() |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_contour_overlay(montereybay, linewidth=2, nlevels=100, height = nrow(montereybay)*2, color="black", width = ncol(montereybay)*2), alphalayer=0.5) |> plot_map() } if(run_documentation()) { #Manually specify the breaks with levels montereybay |> height_shade() |> add_overlay(generate_contour_overlay(montereybay, linewidth=2, levels = seq(-2000,0,100))) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() }
This uses the car::placeLabel() function to generate labels for the given scene. Either
use an sf object or manually specify the x/y coordinates and label.
generate_label_overlay( labels, extent, x = NULL, y = NULL, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, text_size = 1, color = "black", font = 1, pch = 16, point_size = 1, point_color = NA, offset = c(0, 0), data_label_column = NULL, halo_color = NA, halo_expand = 0, halo_alpha = 1, halo_offset = c(0, 0), halo_blur = 0, halo_edge_softness = 0.1, seed = NA )generate_label_overlay( labels, extent, x = NULL, y = NULL, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, text_size = 1, color = "black", font = 1, pch = 16, point_size = 1, point_color = NA, offset = c(0, 0), data_label_column = NULL, halo_color = NA, halo_expand = 0, halo_alpha = 1, halo_offset = c(0, 0), halo_blur = 0, halo_edge_softness = 0.1, seed = NA )
labels |
A character vector of labels, or an |
extent |
Either an object representing the spatial extent of the scene
(either from the |
x |
Default |
y |
Default |
heightmap |
Default |
width |
Default |
height |
Default |
resolution_multiply |
Default |
text_size |
Default |
color |
Default |
font |
Default |
pch |
Default |
point_size |
Default |
point_color |
Default |
offset |
Default |
data_label_column |
Default |
halo_color |
Default |
halo_expand |
Default |
halo_alpha |
Default |
halo_offset |
Default |
halo_blur |
Default |
halo_edge_softness |
Default |
seed |
Default |
Semi-transparent overlay with labels.
#Add the included `sf` object with roads to the montereybay dataset if(run_documentation()) { #Create the water palette water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) #Set label font par(family = "Arial") #We're plotting the polygon data here for counties around Monterey Bay. We'll first #plot the county names at the polygon centroids. bathy_hs |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_polygon_overlay(monterey_counties_sf, palette = rainbow, extent = attr(montereybay,"extent"), heightmap = montereybay)) |> add_overlay(generate_label_overlay(labels=monterey_counties_sf, color="black", point_size = 1, text_size = 1, data_label_column = "NAME", extent= attr(montereybay,"extent"), heightmap = montereybay, seed=1)) |> plot_map() } if(run_documentation()) { #It's hard to read these values, so we'll add a white halo. bathy_hs |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_polygon_overlay(monterey_counties_sf, palette = rainbow, extent = attr(montereybay,"extent"), heightmap = montereybay)) |> add_overlay(generate_label_overlay(labels=monterey_counties_sf, color="black", point_size = 1, text_size = 1, data_label_column = "NAME", extent= attr(montereybay,"extent"), heightmap = montereybay, halo_color = "white", halo_expand = 3, seed=1)) |> plot_map() } if(run_documentation()) { #Plot the actual town locations, using the manual plotting interface instead of the `sf` object montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_label_overlay(labels=as.character(monterey_counties_sf$NAME), x=as.numeric(as.character(monterey_counties_sf$INTPTLON)), y=as.numeric(as.character(monterey_counties_sf$INTPTLAT)), color="black", point_size = 1, text_size = 1, extent= attr(montereybay,"extent"), heightmap = montereybay, halo_color = "white", halo_expand = 3, seed=1)) |> plot_map() } if(run_documentation()) { #Adding a softer blurred halo montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_label_overlay(labels=as.character(monterey_counties_sf$NAME), x=as.numeric(as.character(monterey_counties_sf$INTPTLON)), y=as.numeric(as.character(monterey_counties_sf$INTPTLAT)), color="black", point_size = 1, text_size = 1, extent= attr(montereybay,"extent"), heightmap = montereybay, halo_color = "white", halo_expand = 3, halo_blur=10, seed=1)) |> plot_map() } if(run_documentation()) { #Changing the seed changes the locations of the labels montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_label_overlay(labels=as.character(monterey_counties_sf$NAME), x=as.numeric(as.character(monterey_counties_sf$INTPTLON)), y=as.numeric(as.character(monterey_counties_sf$INTPTLAT)), color="black", point_size = 1, text_size = 1, extent= attr(montereybay,"extent"), heightmap = montereybay, halo_color = "white", halo_expand = 3, halo_blur=10, seed=2)) |> plot_map() }#Add the included `sf` object with roads to the montereybay dataset if(run_documentation()) { #Create the water palette water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) #Set label font par(family = "Arial") #We're plotting the polygon data here for counties around Monterey Bay. We'll first #plot the county names at the polygon centroids. bathy_hs |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_polygon_overlay(monterey_counties_sf, palette = rainbow, extent = attr(montereybay,"extent"), heightmap = montereybay)) |> add_overlay(generate_label_overlay(labels=monterey_counties_sf, color="black", point_size = 1, text_size = 1, data_label_column = "NAME", extent= attr(montereybay,"extent"), heightmap = montereybay, seed=1)) |> plot_map() } if(run_documentation()) { #It's hard to read these values, so we'll add a white halo. bathy_hs |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_polygon_overlay(monterey_counties_sf, palette = rainbow, extent = attr(montereybay,"extent"), heightmap = montereybay)) |> add_overlay(generate_label_overlay(labels=monterey_counties_sf, color="black", point_size = 1, text_size = 1, data_label_column = "NAME", extent= attr(montereybay,"extent"), heightmap = montereybay, halo_color = "white", halo_expand = 3, seed=1)) |> plot_map() } if(run_documentation()) { #Plot the actual town locations, using the manual plotting interface instead of the `sf` object montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_label_overlay(labels=as.character(monterey_counties_sf$NAME), x=as.numeric(as.character(monterey_counties_sf$INTPTLON)), y=as.numeric(as.character(monterey_counties_sf$INTPTLAT)), color="black", point_size = 1, text_size = 1, extent= attr(montereybay,"extent"), heightmap = montereybay, halo_color = "white", halo_expand = 3, seed=1)) |> plot_map() } if(run_documentation()) { #Adding a softer blurred halo montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_label_overlay(labels=as.character(monterey_counties_sf$NAME), x=as.numeric(as.character(monterey_counties_sf$INTPTLON)), y=as.numeric(as.character(monterey_counties_sf$INTPTLAT)), color="black", point_size = 1, text_size = 1, extent= attr(montereybay,"extent"), heightmap = montereybay, halo_color = "white", halo_expand = 3, halo_blur=10, seed=1)) |> plot_map() } if(run_documentation()) { #Changing the seed changes the locations of the labels montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_label_overlay(labels=as.character(monterey_counties_sf$NAME), x=as.numeric(as.character(monterey_counties_sf$INTPTLON)), y=as.numeric(as.character(monterey_counties_sf$INTPTLAT)), color="black", point_size = 1, text_size = 1, extent= attr(montereybay,"extent"), heightmap = montereybay, halo_color = "white", halo_expand = 3, halo_blur=10, seed=2)) |> plot_map() }
Calculates and returns an overlay of lines for the current height map.
generate_line_overlay( geometry, extent, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, color = "black", linewidth = 1, lty = 1, data_column_width = NULL, offset = c(0, 0) )generate_line_overlay( geometry, extent, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, color = "black", linewidth = 1, lty = 1, data_column_width = NULL, offset = c(0, 0) )
geometry |
An |
extent |
Either an object representing the spatial extent of the scene
(either from the |
heightmap |
Default |
width |
Default |
height |
Default |
resolution_multiply |
Default |
color |
Default |
linewidth |
Default |
lty |
Default |
data_column_width |
Default |
offset |
Default |
Semi-transparent overlay with contours.
#Add the included `sf` object with roads to the montereybay dataset if(run_documentation()) { water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_overlay(generate_line_overlay(monterey_roads_sf, attr(montereybay,"extent"), heightmap = montereybay)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() } if(run_documentation()) { #Change the line width, color, and transparency montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_overlay(generate_line_overlay(monterey_roads_sf, linewidth=3, color="white", attr(montereybay,"extent"), heightmap = montereybay), alphalayer=0.8) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() } if(run_documentation()) { #Manually specify the width and height to improve visual quality of the lines montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_line_overlay(monterey_roads_sf, linewidth=3, color="white", attr(montereybay,"extent"), width = 1080, height = 1080), alphalayer=0.8) |> plot_map() }#Add the included `sf` object with roads to the montereybay dataset if(run_documentation()) { water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_overlay(generate_line_overlay(monterey_roads_sf, attr(montereybay,"extent"), heightmap = montereybay)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() } if(run_documentation()) { #Change the line width, color, and transparency montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_overlay(generate_line_overlay(monterey_roads_sf, linewidth=3, color="white", attr(montereybay,"extent"), heightmap = montereybay), alphalayer=0.8) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() } if(run_documentation()) { #Manually specify the width and height to improve visual quality of the lines montereybay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> add_overlay(generate_line_overlay(monterey_roads_sf, linewidth=3, color="white", attr(montereybay,"extent"), width = 1080, height = 1080), alphalayer=0.8) |> plot_map() }
Calculates and returns an overlay of points for the current map.
generate_point_overlay( geometry, extent, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, pch = 16, color = "black", size = 1, offset = c(0, 0), data_column_width = NULL )generate_point_overlay( geometry, extent, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, pch = 16, color = "black", size = 1, offset = c(0, 0), data_column_width = NULL )
geometry |
An |
extent |
Either an object representing the spatial extent of the scene
(either from the |
heightmap |
Default |
width |
Default |
height |
Default |
resolution_multiply |
Default |
pch |
Default |
color |
Default |
size |
Default |
offset |
Default |
data_column_width |
Default |
Semi-transparent overlay with contours.
#Add the included `sf` object with roads to the montereybay dataset if(run_documentation()) { monterey_city = sf::st_sfc(sf::st_point(c(-121.893611, 36.603056))) montereybay |> height_shade() |> add_overlay(generate_point_overlay(monterey_city, color="red", size=2, attr(montereybay,"extent"), heightmap = montereybay)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() }#Add the included `sf` object with roads to the montereybay dataset if(run_documentation()) { monterey_city = sf::st_sfc(sf::st_point(c(-121.893611, 36.603056))) montereybay |> height_shade() |> add_overlay(generate_point_overlay(monterey_city, color="red", size=2, attr(montereybay,"extent"), heightmap = montereybay)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() }
Transforms an input sf object into an image overlay for the current height map.
generate_polygon_overlay( geometry, extent, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, offset = c(0, 0), data_column_fill = NULL, linecolor = "black", palette = "white", linewidth = 1 )generate_polygon_overlay( geometry, extent, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, offset = c(0, 0), data_column_fill = NULL, linecolor = "black", palette = "white", linewidth = 1 )
geometry |
An |
extent |
Either an object representing the spatial extent of the scene
(either from the |
heightmap |
Default |
width |
Default |
height |
Default |
resolution_multiply |
Default |
offset |
Default |
data_column_fill |
Default |
linecolor |
Default |
palette |
Default |
linewidth |
Default |
Image overlay representing the input polygon data.
#Plot the counties around Monterey Bay, CA if(run_documentation()) { generate_polygon_overlay(monterey_counties_sf, palette = rainbow, extent = attr(montereybay,"extent"), heightmap = montereybay) |> plot_map() } if(run_documentation()) { #These counties include the water, so we'll plot bathymetry data over the polygon #data to only include parts of the polygon that fall on land. water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) generate_polygon_overlay(monterey_counties_sf, palette = rainbow, extent = attr(montereybay,"extent"), heightmap = montereybay) |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, start_transition = 0)) |> plot_map() } if(run_documentation()) { #Add a semi-transparent hillshade and change the palette, and remove the polygon lines montereybay |> sphere_shade(texture = "bw") |> add_overlay(generate_polygon_overlay(monterey_counties_sf, palette = terrain.colors, linewidth=NA, extent = attr(montereybay,"extent"), heightmap = montereybay), alphalayer=0.7) |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, start_transition = 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0) |> plot_map() } if(run_documentation()) { #Map one of the variables in the sf object and use an explicitly defined color palette county_palette = c("087" = "red", "053" = "blue", "081" = "green", "069" = "yellow", "085" = "orange", "099" = "purple") montereybay |> sphere_shade(texture = "bw") |> add_shadow(ray_shade(montereybay,zscale=50),0) |> add_overlay(generate_polygon_overlay(monterey_counties_sf, linecolor="white", linewidth=3, palette = county_palette, data_column_fill = "COUNTYFP", extent = attr(montereybay,"extent"), heightmap = montereybay), alphalayer=0.7) |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, start_transition = 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.5) |> plot_map() }#Plot the counties around Monterey Bay, CA if(run_documentation()) { generate_polygon_overlay(monterey_counties_sf, palette = rainbow, extent = attr(montereybay,"extent"), heightmap = montereybay) |> plot_map() } if(run_documentation()) { #These counties include the water, so we'll plot bathymetry data over the polygon #data to only include parts of the polygon that fall on land. water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) generate_polygon_overlay(monterey_counties_sf, palette = rainbow, extent = attr(montereybay,"extent"), heightmap = montereybay) |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, start_transition = 0)) |> plot_map() } if(run_documentation()) { #Add a semi-transparent hillshade and change the palette, and remove the polygon lines montereybay |> sphere_shade(texture = "bw") |> add_overlay(generate_polygon_overlay(monterey_counties_sf, palette = terrain.colors, linewidth=NA, extent = attr(montereybay,"extent"), heightmap = montereybay), alphalayer=0.7) |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, start_transition = 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0) |> plot_map() } if(run_documentation()) { #Map one of the variables in the sf object and use an explicitly defined color palette county_palette = c("087" = "red", "053" = "blue", "081" = "green", "069" = "yellow", "085" = "orange", "099" = "purple") montereybay |> sphere_shade(texture = "bw") |> add_shadow(ray_shade(montereybay,zscale=50),0) |> add_overlay(generate_polygon_overlay(monterey_counties_sf, linecolor="white", linewidth=3, palette = county_palette, data_column_fill = "COUNTYFP", extent = attr(montereybay,"extent"), heightmap = montereybay), alphalayer=0.7) |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, start_transition = 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.5) |> plot_map() }
This function creates an overlay with a scale bar of a user-specified length.
It uses the coordinates of the map (specified by passing an extent)
and then creates a scale bar at a specified x/y proportion across the map. If the map is not projected
(i.e. is in lat/long coordinates) this function will use the geosphere package to create a
scale bar of the proper length.
generate_scalebar_overlay( extent, length, x = 0.05, y = 0.05, latlong = FALSE, thickness = NA, bearing = 90, unit = "m", flip_ticks = FALSE, labels = NA, text_size = 1, decimals = 0, text_offset = 1, adj = 0.5, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, color1 = "white", color2 = "black", text_color = "black", font = 1, border_color = "black", tick_color = "black", border_width = 1, tick_width = 1, halo_color = NA, halo_expand = 1, halo_alpha = 1, halo_offset = c(0, 0), halo_blur = 0, halo_edge_softness = 0.1 )generate_scalebar_overlay( extent, length, x = 0.05, y = 0.05, latlong = FALSE, thickness = NA, bearing = 90, unit = "m", flip_ticks = FALSE, labels = NA, text_size = 1, decimals = 0, text_offset = 1, adj = 0.5, heightmap = NULL, width = NA, height = NA, resolution_multiply = 1, color1 = "white", color2 = "black", text_color = "black", font = 1, border_color = "black", tick_color = "black", border_width = 1, tick_width = 1, halo_color = NA, halo_expand = 1, halo_alpha = 1, halo_offset = c(0, 0), halo_blur = 0, halo_edge_softness = 0.1 )
extent |
Either an object representing the spatial extent of the scene
(either from the |
length |
The length of the scale bar, in |
x |
Default |
y |
Default |
latlong |
Default |
thickness |
Default |
bearing |
Default |
unit |
Default |
flip_ticks |
Default |
labels |
Default |
text_size |
Default |
decimals |
Default |
text_offset |
Default |
adj |
Default |
heightmap |
Default |
width |
Default |
height |
Default |
resolution_multiply |
Default |
color1 |
Default |
color2 |
Default |
text_color |
Default |
font |
Default |
border_color |
Default |
tick_color |
Default |
border_width |
Default |
tick_width |
Default |
halo_color |
Default |
halo_expand |
Default |
halo_alpha |
Default |
halo_offset |
Default |
halo_blur |
Default |
halo_edge_softness |
Default |
Semi-transparent overlay with a scale bar.
if(run_documentation()) { #Create the water palette water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) #Set scalebar font par(family = "Arial") #Generate flat water heightmap mbay = montereybay mbay[mbay < 0] = 0 base_map = mbay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) #For convenience, the extent of the montereybay dataset is included as an attribute mb_extent = attr(montereybay, "extent") #Add a scalebar base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 40000, heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the text color base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 40000, text_color = "white", heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the length base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 30000, text_color = "white", heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the thickness (default is length/20) base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 30000, text_color = "white", thickness = 30000/10, heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the text offset (given in multiples of thickness) base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 30000, text_color = "white", thickness = 30000/10, text_offset = 0.75, heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the primary and secondary colors, along with the border and tick color base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 30000, text_color = "white", border_color = "white", tick_color = "white", color1 = "darkolivegreen4", color2 = "burlywood3", heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Add a halo base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 40000, halo_color = "white", halo_expand = 1, heightmap = montereybay, font = 2, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the orientation, position, text alignment, and flip the ticks to the other side base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 40000, x = 0.07, bearing=0, adj = 0, flip_ticks = TRUE, halo_color = "white", halo_expand = 1.5, heightmap = montereybay, font = 2, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #64373.8 meters in 40 miles #Create custom labels, change font and text size, remove the border/ticks, and change the color #Here, we specify a width and height to double the resolution of the image (for sharper text) base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 64373.8, x = 0.07, labels = c("0", "20", "40 miles"), thickness=2500, text_size=3, font = 2, text_offset = 0, text_color="white", color2="#bf323b", border_color=NA, tick_color="red", tick_width=0, bearing=0, adj = 0, flip_ticks = TRUE, halo_color="black", halo_blur=3, halo_alpha=0.5, width = ncol(montereybay)*2, height = nrow(montereybay)*2, latlong=TRUE), rescale_original=TRUE) |> plot_map() }if(run_documentation()) { #Create the water palette water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) #Set scalebar font par(family = "Arial") #Generate flat water heightmap mbay = montereybay mbay[mbay < 0] = 0 base_map = mbay |> height_shade() |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(lamb_shade(montereybay,zscale=50),0.3) #For convenience, the extent of the montereybay dataset is included as an attribute mb_extent = attr(montereybay, "extent") #Add a scalebar base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 40000, heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the text color base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 40000, text_color = "white", heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the length base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 30000, text_color = "white", heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the thickness (default is length/20) base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 30000, text_color = "white", thickness = 30000/10, heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the text offset (given in multiples of thickness) base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 30000, text_color = "white", thickness = 30000/10, text_offset = 0.75, heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the primary and secondary colors, along with the border and tick color base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 30000, text_color = "white", border_color = "white", tick_color = "white", color1 = "darkolivegreen4", color2 = "burlywood3", heightmap = montereybay, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Add a halo base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 40000, halo_color = "white", halo_expand = 1, heightmap = montereybay, font = 2, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #Change the orientation, position, text alignment, and flip the ticks to the other side base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 40000, x = 0.07, bearing=0, adj = 0, flip_ticks = TRUE, halo_color = "white", halo_expand = 1.5, heightmap = montereybay, font = 2, latlong=TRUE)) |> plot_map() } if(run_documentation()) { #64373.8 meters in 40 miles #Create custom labels, change font and text size, remove the border/ticks, and change the color #Here, we specify a width and height to double the resolution of the image (for sharper text) base_map |> add_overlay(generate_scalebar_overlay(extent = mb_extent, length = 64373.8, x = 0.07, labels = c("0", "20", "40 miles"), thickness=2500, text_size=3, font = 2, text_offset = 0, text_color="white", color2="#bf323b", border_color=NA, tick_color="red", tick_width=0, bearing=0, adj = 0, flip_ticks = TRUE, halo_color="black", halo_blur=3, halo_alpha=0.5, width = ncol(montereybay)*2, height = nrow(montereybay)*2, latlong=TRUE), rescale_original=TRUE) |> plot_map() }
Using a height map or a boolean matrix, generates a semi-transparent waterline overlay to
layer onto an existing map. This uses the method described by P. Felzenszwalb & D. Huttenlocher in
"Distance Transforms of Sampled Functions" (Theory of Computing, Vol. 8, No. 19, September 2012)
to calculate the distance to the coast. This distance matrix can be returned directly by setting
the return_distance_matrix argument to TRUE.
generate_waterline_overlay( heightmap, color = "white", linewidth = 1, boolean = FALSE, min = 0.001, max = 0.2, breaks = 9, smooth = 0, fade = TRUE, alpha_dist = max, alpha = 1, falloff = 1.3, evenly_spaced = FALSE, zscale = 1, cutoff = 0.999, width = NA, height = NA, resolution_multiply = 1, min_area = length(heightmap)/400, max_height = NULL, return_distance_matrix = FALSE )generate_waterline_overlay( heightmap, color = "white", linewidth = 1, boolean = FALSE, min = 0.001, max = 0.2, breaks = 9, smooth = 0, fade = TRUE, alpha_dist = max, alpha = 1, falloff = 1.3, evenly_spaced = FALSE, zscale = 1, cutoff = 0.999, width = NA, height = NA, resolution_multiply = 1, min_area = length(heightmap)/400, max_height = NULL, return_distance_matrix = FALSE )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point.
If |
color |
Default |
linewidth |
Default |
boolean |
Default |
min |
Default |
max |
Default |
breaks |
Default |
smooth |
Default |
fade |
Default |
alpha_dist |
Default to the value specified in |
alpha |
Default |
falloff |
Default |
evenly_spaced |
Default |
zscale |
Default |
cutoff |
Default |
width |
Default |
height |
Default |
resolution_multiply |
Default |
min_area |
Default |
max_height |
Default |
return_distance_matrix |
Default |
4-layer RGB array representing the waterline overlay.
if(run_documentation()) { #Create a flat body of water for Monterey Bay montbay = montereybay montbay[montbay < 0] = 0 #Generate base map with no lines basemap = montbay |> height_shade() |> add_water(detect_water(montbay), color="dodgerblue") |> add_shadow(texture_shade(montbay, detail=1/3, brightness = 15, contrast = 5),0) |> add_shadow(lamb_shade(montbay,zscale=50),0) plot_map(basemap) } if(run_documentation()) { #Add waterlines basemap |> add_overlay(generate_waterline_overlay(montbay)) |> plot_map() } if(run_documentation()) { #Change minimum line distance: basemap |> add_overlay(generate_waterline_overlay(montbay, min = 0.02)) |> plot_map() } if(run_documentation()) { #Change maximum line distance basemap |> add_overlay(generate_waterline_overlay(montbay, max = 0.4)) |> plot_map() } if(run_documentation()) { #Smooth waterlines basemap |> add_overlay(generate_waterline_overlay(montbay, max = 0.4, smooth=2)) |> plot_map() } if(run_documentation()) { #Increase number of breaks basemap |> add_overlay(generate_waterline_overlay(montbay, breaks = 20, max=0.4)) |> plot_map() } if(run_documentation()) { #Make lines evenly spaced: basemap |> add_overlay(generate_waterline_overlay(montbay, evenly_spaced = TRUE)) |> plot_map() } if(run_documentation()) { #Change variable distance between each line basemap |> add_overlay(generate_waterline_overlay(montbay, falloff=1.5)) |> plot_map() } if(run_documentation()) { #Turn off fading basemap |> add_overlay(generate_waterline_overlay(montbay, fade=FALSE)) |> plot_map() } if(run_documentation()) { #Fill up the entire body of water with lines and make them all 50% transparent basemap |> add_overlay(generate_waterline_overlay(montbay, fade=FALSE, max=1, alpha = 0.5, color="white", evenly_spaced = TRUE, breaks=50)) |> plot_map() }if(run_documentation()) { #Create a flat body of water for Monterey Bay montbay = montereybay montbay[montbay < 0] = 0 #Generate base map with no lines basemap = montbay |> height_shade() |> add_water(detect_water(montbay), color="dodgerblue") |> add_shadow(texture_shade(montbay, detail=1/3, brightness = 15, contrast = 5),0) |> add_shadow(lamb_shade(montbay,zscale=50),0) plot_map(basemap) } if(run_documentation()) { #Add waterlines basemap |> add_overlay(generate_waterline_overlay(montbay)) |> plot_map() } if(run_documentation()) { #Change minimum line distance: basemap |> add_overlay(generate_waterline_overlay(montbay, min = 0.02)) |> plot_map() } if(run_documentation()) { #Change maximum line distance basemap |> add_overlay(generate_waterline_overlay(montbay, max = 0.4)) |> plot_map() } if(run_documentation()) { #Smooth waterlines basemap |> add_overlay(generate_waterline_overlay(montbay, max = 0.4, smooth=2)) |> plot_map() } if(run_documentation()) { #Increase number of breaks basemap |> add_overlay(generate_waterline_overlay(montbay, breaks = 20, max=0.4)) |> plot_map() } if(run_documentation()) { #Make lines evenly spaced: basemap |> add_overlay(generate_waterline_overlay(montbay, evenly_spaced = TRUE)) |> plot_map() } if(run_documentation()) { #Change variable distance between each line basemap |> add_overlay(generate_waterline_overlay(montbay, falloff=1.5)) |> plot_map() } if(run_documentation()) { #Turn off fading basemap |> add_overlay(generate_waterline_overlay(montbay, fade=FALSE)) |> plot_map() } if(run_documentation()) { #Fill up the entire body of water with lines and make them all 50% transparent basemap |> add_overlay(generate_waterline_overlay(montbay, fade=FALSE, max=1, alpha = 0.5, color="white", evenly_spaced = TRUE, breaks=50)) |> plot_map() }
Calculates a color for each point on the surface using a direct elevation-to-color mapping.
height_shade( heightmap, texture = (grDevices::colorRampPalette(c("#6AA85B", "#D9CC9A", "#FFFFFF")))(256), range = NULL )height_shade( heightmap, texture = (grDevices::colorRampPalette(c("#6AA85B", "#D9CC9A", "#FFFFFF")))(256), range = NULL )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. |
texture |
Default |
range |
Default |
RGB array of hillshaded texture mappings.
#Create a direct mapping of elevation to color: montereybay |> height_shade() |> plot_map() #Add a shadow: if(run_documentation()) { montereybay |> height_shade() |> add_shadow(ray_shade(montereybay,zscale=50),0.1) |> plot_map() } #Change the palette: if(run_documentation()) { montereybay |> height_shade(texture = topo.colors(256)) |> add_shadow(ray_shade(montereybay,zscale=50),0.1) |> plot_map() } #Really change the palette (warning: gratuitous use of rainbow palette): if(run_documentation()) { montereybay |> height_shade(texture = rainbow(256)) |> add_shadow(ray_shade(montereybay,zscale=50),0.1) |> plot_map() }#Create a direct mapping of elevation to color: montereybay |> height_shade() |> plot_map() #Add a shadow: if(run_documentation()) { montereybay |> height_shade() |> add_shadow(ray_shade(montereybay,zscale=50),0.1) |> plot_map() } #Change the palette: if(run_documentation()) { montereybay |> height_shade(texture = topo.colors(256)) |> add_shadow(ray_shade(montereybay,zscale=50),0.1) |> plot_map() } #Really change the palette (warning: gratuitous use of rainbow palette): if(run_documentation()) { montereybay |> height_shade(texture = rainbow(256)) |> add_shadow(ray_shade(montereybay,zscale=50),0.1) |> plot_map() }
Calculates local shadow map for a elevation matrix by calculating the dot product between light direction and the surface normal vector at that point. Each point's intensity is proportional to the cosine of the normal vector.
lamb_shade( heightmap, sunaltitude = 45, sunangle = 315, zscale = 1, zero_negative = TRUE )lamb_shade( heightmap, sunaltitude = 45, sunangle = 315, zscale = 1, zero_negative = TRUE )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced. |
sunaltitude |
Default |
sunangle |
Default |
zscale |
Default |
zero_negative |
Default |
Matrix of light intensities at each point.
if(run_documentation()) { #Generate a basic hillshade montereybay |> lamb_shade(zscale=200) |> plot_map() } if(run_documentation()) { #Increase the intensity by decreasing the zscale montereybay |> lamb_shade(zscale=50) |> plot_map() } if(run_documentation()) { #Change the sun direction montereybay |> lamb_shade(zscale=200, sunangle=45) |> plot_map() } if(run_documentation()) { #Change the sun altitude montereybay |> lamb_shade(zscale=200, sunaltitude=60) |> plot_map() }if(run_documentation()) { #Generate a basic hillshade montereybay |> lamb_shade(zscale=200) |> plot_map() } if(run_documentation()) { #Increase the intensity by decreasing the zscale montereybay |> lamb_shade(zscale=50) |> plot_map() } if(run_documentation()) { #Change the sun direction montereybay |> lamb_shade(zscale=200, sunangle=45) |> plot_map() } if(run_documentation()) { #Change the sun altitude montereybay |> lamb_shade(zscale=200, sunaltitude=60) |> plot_map() }
This dataset is an sf object containing polygon data from the U.S. Department of Commerce
with selected geographic and cartographic information from the U.S. Census Bureau's Master
Address File / Topologically Integrated Geographic Encoding and Referencing (MAF/TIGER)
Database (MTDB). This data has been trimmed to only include 26 features in the extent of
the montereybay dataset.
monterey_counties_sfmonterey_counties_sf
An sf object with MULTIPOLYGON geometry.
https://catalog.data.gov/dataset/tiger-line-shapefile-2016-state-california-current-county-subdivision-state-based
# This is the full code (commented out) used to generate this dataset from the original data: #counties = sf::st_read("tl_2016_06_cousub.shp") #monterey_counties_sf = sf::st_crop(counties, attr(montereybay,"extent"))# This is the full code (commented out) used to generate this dataset from the original data: #counties = sf::st_read("tl_2016_06_cousub.shp") #monterey_counties_sf = sf::st_crop(counties, attr(montereybay,"extent"))
This dataset is an sf object containing line data from the U.S. Department of Commerce
with selected roads, TIGER/Line Shapefile, 2015, state, California, Primary and Secondary
Roads State-based Shapefile. This data has been trimmed to only include 330 features in the extent of
the montereybay dataset.
monterey_roads_sfmonterey_roads_sf
An sf object with LINESTRING geometry.
https://www2.census.gov/geo/tiger/TIGER2015/PRISECROADS/tl_2015_06_prisecroads.zip
# This is the full code (commented out) used to generate this dataset from the original data: #counties = sf::st_read("tl_2015_06_prisecroads.shp") #monterey_roads_sf = sf::st_crop(counties, attr(montereybay,"extent"))# This is the full code (commented out) used to generate this dataset from the original data: #counties = sf::st_read("tl_2015_06_prisecroads.shp") #monterey_roads_sf = sf::st_crop(counties, attr(montereybay,"extent"))
This dataset is a downsampled version of a combined topographic and bathymetric elevation matrix representing the Monterey Bay, CA region. Original data from from the NOAA National Map website.
montereybaymontereybay
A matrix with 540 rows and 540 columns. Elevation is in meters, and the spacing between each coordinate is 200 meters (zscale = 200). Water level is 0. Raster extent located in "extent" attribute. CRS located in "CRS" attribute.
https://www.ncei.noaa.gov/metadata/geoportal/rest/metadata/item/gov.noaa.ngdc.mgg.dem:3544/html
# This is the full code (commented out) used to generate this dataset from the original NOAA data: #raster::raster("monterey_13_navd88_2012.nc") #bottom_left = c(y=-122.366765, x=36.179392) #top_right = c(y=-121.366765, x=37.179392) #extent_latlong = sp::SpatialPoints(rbind(bottom_left, top_right), # proj4string=sp::CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")) #monterey_cropped = raster::crop(montbay,extent_latlong) #montbay_mat = raster_to_matrix(montbay_cropped) #montereybay = resize_matrix(montbay_mat,0.05) #attr(montereybay, "extent") = extent_latlong #attr(montereybay, "crs") = crs(monterey_cropped) #attr(montereybay, "crs") = crs(monterey_cropped) #attr(montereybay, "rayshader_data") = TRUE# This is the full code (commented out) used to generate this dataset from the original NOAA data: #raster::raster("monterey_13_navd88_2012.nc") #bottom_left = c(y=-122.366765, x=36.179392) #top_right = c(y=-121.366765, x=37.179392) #extent_latlong = sp::SpatialPoints(rbind(bottom_left, top_right), # proj4string=sp::CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")) #monterey_cropped = raster::crop(montbay,extent_latlong) #montbay_mat = raster_to_matrix(montbay_cropped) #montereybay = resize_matrix(montbay_mat,0.05) #attr(montereybay, "extent") = extent_latlong #attr(montereybay, "crs") = crs(monterey_cropped) #attr(montereybay, "crs") = crs(monterey_cropped) #attr(montereybay, "rayshader_data") = TRUE
Displays the shaded map in 3D with the rgl package.
Note: Calling plot_3d() resets the scene cache for the render_snapshot(), render_depth(), and render_highquality()
plot_3d( hillshade, heightmap, zscale = 1, baseshape = "rectangle", solid = TRUE, soliddepth = "auto", solidcolor = "grey20", solidlinecolor = "grey30", shadow = TRUE, shadowdepth = "auto", shadowcolor = "auto", shadow_darkness = 0.5, shadowwidth = "auto", water = FALSE, waterdepth = 0, watercolor = "dodgerblue", wateralpha = 0.5, waterlinecolor = NULL, waterlinealpha = 1, linewidth = 2, lineantialias = FALSE, soil = FALSE, soil_freq = 0.1, soil_levels = 16, soil_color_light = "#b39474", soil_color_dark = "#8a623b", soil_gradient = 2, soil_gradient_darken = 4, theta = 45, phi = 45, fov = 0, zoom = 1, background = "white", windowsize = 600, precomputed_normals = NULL, triangulate = FALSE, max_error = 0, max_tri = 0, verbose = FALSE, plot_new = TRUE, close_previous = TRUE, clear_previous = TRUE )plot_3d( hillshade, heightmap, zscale = 1, baseshape = "rectangle", solid = TRUE, soliddepth = "auto", solidcolor = "grey20", solidlinecolor = "grey30", shadow = TRUE, shadowdepth = "auto", shadowcolor = "auto", shadow_darkness = 0.5, shadowwidth = "auto", water = FALSE, waterdepth = 0, watercolor = "dodgerblue", wateralpha = 0.5, waterlinecolor = NULL, waterlinealpha = 1, linewidth = 2, lineantialias = FALSE, soil = FALSE, soil_freq = 0.1, soil_levels = 16, soil_color_light = "#b39474", soil_color_dark = "#8a623b", soil_gradient = 2, soil_gradient_darken = 4, theta = 45, phi = 45, fov = 0, zoom = 1, background = "white", windowsize = 600, precomputed_normals = NULL, triangulate = FALSE, max_error = 0, max_tri = 0, verbose = FALSE, plot_new = TRUE, close_previous = TRUE, clear_previous = TRUE )
hillshade |
Hillshade/image to be added to 3D surface map. |
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced. |
zscale |
Default |
baseshape |
Default |
solid |
Default |
soliddepth |
Default |
solidcolor |
Default |
solidlinecolor |
Default |
shadow |
Default |
shadowdepth |
Default |
shadowcolor |
Default |
shadow_darkness |
Default |
shadowwidth |
Default |
water |
Default |
waterdepth |
Default |
watercolor |
Default |
wateralpha |
Default |
waterlinecolor |
Default |
waterlinealpha |
Default |
linewidth |
Default |
lineantialias |
Default |
soil |
Default |
soil_freq |
Default |
soil_levels |
Default |
soil_color_light |
Default |
soil_color_dark |
Default |
soil_gradient |
Default |
soil_gradient_darken |
Default |
theta |
Default |
phi |
Default |
fov |
Default |
zoom |
Default |
background |
Default |
windowsize |
Default |
precomputed_normals |
Default |
triangulate |
Default |
max_error |
Default |
max_tri |
Default |
verbose |
Default |
plot_new |
Default |
close_previous |
Default |
clear_previous |
Default |
#Plotting a spherical texture map of the built-in `montereybay` dataset. if(run_documentation()) { montereybay |> sphere_shade(texture="desert") |> plot_3d(montereybay,zscale=50) render_snapshot() } #With a water layer if(run_documentation()) { montereybay |> sphere_shade(texture="imhof2") |> plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof2", waterlinecolor="white", waterlinealpha=0.5) render_snapshot() } #With a soil texture to the base if(run_documentation()) { montereybay |> sphere_shade(texture="imhof3") |> plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof4", waterlinecolor="white", waterlinealpha=0.5, soil=TRUE) render_camera(theta=225, phi=7, zoom=0.5, fov=67) render_snapshot() } #We can also change the base by setting "baseshape" to "hex" or "circle" if(run_documentation()) { montereybay |> sphere_shade(texture="imhof1") |> plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof1", theta=-45, zoom=0.7, waterlinecolor="white", waterlinealpha=0.5,baseshape="circle") render_snapshot() } if(run_documentation()) { montereybay |> sphere_shade(texture="imhof1") |> plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof1", theta=-45, zoom=0.7, waterlinecolor="white", waterlinealpha=0.5,baseshape="hex") render_snapshot() } #Or we can carve out the region of interest ourselves, by setting those entries to NA #to the elevation map passed into `plot_3d` #Here, we only include the deep bathymetry data by setting all points greater than -10 #in the copied elevation matrix to NA. mb_water = montereybay mb_water[mb_water > -10] = NA if(run_documentation()) { montereybay |> sphere_shade(texture="imhof1") |> plot_3d(mb_water, zscale=50, water = TRUE, watercolor="imhof1", theta=-45, waterlinecolor="white", waterlinealpha=0.5) render_snapshot() }#Plotting a spherical texture map of the built-in `montereybay` dataset. if(run_documentation()) { montereybay |> sphere_shade(texture="desert") |> plot_3d(montereybay,zscale=50) render_snapshot() } #With a water layer if(run_documentation()) { montereybay |> sphere_shade(texture="imhof2") |> plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof2", waterlinecolor="white", waterlinealpha=0.5) render_snapshot() } #With a soil texture to the base if(run_documentation()) { montereybay |> sphere_shade(texture="imhof3") |> plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof4", waterlinecolor="white", waterlinealpha=0.5, soil=TRUE) render_camera(theta=225, phi=7, zoom=0.5, fov=67) render_snapshot() } #We can also change the base by setting "baseshape" to "hex" or "circle" if(run_documentation()) { montereybay |> sphere_shade(texture="imhof1") |> plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof1", theta=-45, zoom=0.7, waterlinecolor="white", waterlinealpha=0.5,baseshape="circle") render_snapshot() } if(run_documentation()) { montereybay |> sphere_shade(texture="imhof1") |> plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof1", theta=-45, zoom=0.7, waterlinecolor="white", waterlinealpha=0.5,baseshape="hex") render_snapshot() } #Or we can carve out the region of interest ourselves, by setting those entries to NA #to the elevation map passed into `plot_3d` #Here, we only include the deep bathymetry data by setting all points greater than -10 #in the copied elevation matrix to NA. mb_water = montereybay mb_water[mb_water > -10] = NA if(run_documentation()) { montereybay |> sphere_shade(texture="imhof1") |> plot_3d(mb_water, zscale=50, water = TRUE, watercolor="imhof1", theta=-45, waterlinecolor="white", waterlinealpha=0.5) render_snapshot() }
Plots a ggplot2 object in 3D by mapping the color or fill aesthetic to elevation.
Currently, this function does not transform lines mapped to color into 3D.
If there are multiple legends/guides due to multiple aesthetics being mapped (e.g. color and shape), the package author recommends that the user pass the order of the guides manually using the ggplot2 function "guides()'. Otherwise, the order may change when processing the ggplot2 object and result in a mismatch between the 3D mapping and the underlying plot.
Using the shape aesthetic with more than three groups is not recommended, unless the user passes in custom, solid shapes. By default in ggplot2, only the first three shapes are solid, which is a requirement to be projected into 3D.
plot_gg( ggobj, ggobj_height = NULL, width = 3, height = 3, height_aes = NULL, invert = FALSE, shadow_intensity = 0.5, units = c("in", "cm", "mm"), scale = 150, pointcontract = 0.7, offset_edges = FALSE, flat_plot_render = FALSE, flat_distance = "auto", flat_transparent_bg = FALSE, flat_direction = "-z", shadow = TRUE, shadowdepth = "auto", shadowcolor = "auto", shadow_darkness = 0.5, background = "white", preview = FALSE, raytrace = TRUE, sunangle = 315, anglebreaks = seq(30, 40, 0.1), multicore = FALSE, lambert = TRUE, triangulate = FALSE, max_error = 0.001, max_tri = 0, verbose = FALSE, emboss_text = 0, emboss_grid = 0, reduce_size = NULL, save_height_matrix = FALSE, save_shadow_matrix = FALSE, saved_shadow_matrix = NULL, monitor_gamma = 1.8, plot = TRUE, ... )plot_gg( ggobj, ggobj_height = NULL, width = 3, height = 3, height_aes = NULL, invert = FALSE, shadow_intensity = 0.5, units = c("in", "cm", "mm"), scale = 150, pointcontract = 0.7, offset_edges = FALSE, flat_plot_render = FALSE, flat_distance = "auto", flat_transparent_bg = FALSE, flat_direction = "-z", shadow = TRUE, shadowdepth = "auto", shadowcolor = "auto", shadow_darkness = 0.5, background = "white", preview = FALSE, raytrace = TRUE, sunangle = 315, anglebreaks = seq(30, 40, 0.1), multicore = FALSE, lambert = TRUE, triangulate = FALSE, max_error = 0.001, max_tri = 0, verbose = FALSE, emboss_text = 0, emboss_grid = 0, reduce_size = NULL, save_height_matrix = FALSE, save_shadow_matrix = FALSE, saved_shadow_matrix = NULL, monitor_gamma = 1.8, plot = TRUE, ... )
ggobj |
ggplot object to projected into 3D. |
ggobj_height |
Default |
width |
Default |
height |
Default |
height_aes |
Default |
invert |
Default |
shadow_intensity |
Default |
units |
Default |
scale |
Default |
pointcontract |
Default |
offset_edges |
Default |
flat_plot_render |
Default |
flat_distance |
Default |
flat_transparent_bg |
Default |
flat_direction |
Default |
shadow |
Default |
shadowdepth |
Default |
shadowcolor |
Default |
shadow_darkness |
Default |
background |
Default |
preview |
Default |
raytrace |
Default |
sunangle |
Default |
anglebreaks |
Default |
multicore |
Default |
lambert |
Default |
triangulate |
Default |
max_error |
Default |
max_tri |
Default |
verbose |
Default |
emboss_text |
Default |
emboss_grid |
Default |
reduce_size |
Default |
save_height_matrix |
Default |
save_shadow_matrix |
Default |
saved_shadow_matrix |
Default |
monitor_gamma |
Default |
plot |
Default |
... |
Additional arguments to be passed to |
Opens a 3D plot in rgl.
library(ggplot2) library(viridis) ggdiamonds = ggplot(diamonds, aes(x, depth)) + stat_density_2d(aes(fill = after_stat(nlevel), color = after_stat(nlevel)), geom = "polygon", n = 200, bins = 50,contour = TRUE) + facet_wrap(clarity~.) + scale_fill_viridis_c(option = "A") + scale_color_viridis_c(option = "A") if(run_documentation()) { plot_gg(ggdiamonds,multicore = TRUE,width=5,height=5,scale=250,windowsize=c(1400,866), zoom = 0.55, phi = 30) render_snapshot() } #Change the camera angle and take a snapshot: if(run_documentation()) { render_camera(zoom=0.5,theta=-30,phi=30) render_snapshot() } #Contours and other lines will automatically be ignored. Here is the volcano dataset: ggvolcano = volcano |> reshape2::melt() |> ggplot() + geom_tile(aes(x=Var1,y=Var2,fill=value)) + geom_contour(aes(x=Var1,y=Var2,z=value),color="black") + scale_x_continuous("X",expand = c(0,0)) + scale_y_continuous("Y",expand = c(0,0)) + scale_fill_gradientn("Z",colours = terrain.colors(10)) + coord_fixed() + theme(legend.position = "none") ggvolcano if(run_documentation()) { plot_gg(ggvolcano, multicore = TRUE, raytrace = TRUE, width = 7, height = 4, scale = 300, windowsize = c(1400, 866), zoom = 0.6, phi = 30, theta = 30) render_snapshot() } if(run_documentation()) { #You can specify the color and height separately using the `ggobj_height()` argument. ggvolcano_surface = volcano |> reshape2::melt() |> ggplot() + geom_contour(aes(x=Var1,y=Var2,z=value),color="black") + geom_contour_filled(aes(x=Var1,y=Var2,z=value))+ scale_x_continuous("X",expand = c(0,0)) + scale_y_continuous("Y",expand = c(0,0)) + coord_fixed() + theme(legend.position = "none") plot_gg(ggvolcano_surface, ggobj_height = ggvolcano, multicore = TRUE, raytrace = TRUE, width = 7, height = 4, scale = 300, windowsize = c(1400, 866), zoom = 0.6, phi = 30, theta = 30) render_snapshot() } #Here, we will create a 3D plot of the mtcars dataset. This automatically detects #that the user used the `color` aesthetic instead of the `fill`. mtplot = ggplot(mtcars) + geom_point(aes(x=mpg,y=disp,color=cyl)) + scale_color_continuous(limits=c(0,8)) #Preview how the plot will look by setting `preview = TRUE`: We also adjust the angle of the light. if(run_documentation()) { plot_gg(mtplot, width=3.5, sunangle=225, preview = TRUE) } if(run_documentation()) { plot_gg(mtplot, width=3.5, multicore = TRUE, windowsize = c(1400,866), sunangle=225, zoom = 0.60, phi = 30, theta = 45) render_snapshot() } #Now let's plot a density plot in 3D. mtplot_density = ggplot(mtcars) + stat_density_2d(aes(x=mpg,y=disp, fill=after_stat(!!str2lang("density"))), geom = "raster", contour = FALSE) + scale_x_continuous(expand=c(0,0)) + scale_y_continuous(expand=c(0,0)) + scale_fill_gradient(low="pink", high="red") mtplot_density if(run_documentation()) { plot_gg(mtplot_density, width = 4,zoom = 0.60, theta = -45, phi = 30, windowsize = c(1400,866)) render_snapshot() } #This also works facetted. mtplot_density_facet = mtplot_density + facet_wrap(~cyl) #Preview this plot in 2D: if(run_documentation()) { plot_gg(mtplot_density_facet, preview = TRUE) } if(run_documentation()) { plot_gg(mtplot_density_facet, windowsize=c(1400,866), zoom = 0.55, theta = -10, phi = 25) render_snapshot() } #That is a little cramped. Specifying a larger width will improve the readability of this plot. if(run_documentation()) { plot_gg(mtplot_density_facet, width = 6, preview = TRUE) } #That's better. Let's plot it in 3D, and increase the scale. if(run_documentation()) { plot_gg(mtplot_density_facet, width = 6, windowsize=c(1400,866), zoom = 0.55, theta = -10, phi = 25, scale=300) render_snapshot() } #We can also render a flat version of the plot alongside (or above/below) the 3D version. if(run_documentation()) { plot_gg(mtplot_density_facet, width = 6, windowsize=c(1400,866), zoom = 0.65, theta = -25, phi = 35, scale=300, flat_plot_render=TRUE, flat_direction = "x") render_snapshot() }library(ggplot2) library(viridis) ggdiamonds = ggplot(diamonds, aes(x, depth)) + stat_density_2d(aes(fill = after_stat(nlevel), color = after_stat(nlevel)), geom = "polygon", n = 200, bins = 50,contour = TRUE) + facet_wrap(clarity~.) + scale_fill_viridis_c(option = "A") + scale_color_viridis_c(option = "A") if(run_documentation()) { plot_gg(ggdiamonds,multicore = TRUE,width=5,height=5,scale=250,windowsize=c(1400,866), zoom = 0.55, phi = 30) render_snapshot() } #Change the camera angle and take a snapshot: if(run_documentation()) { render_camera(zoom=0.5,theta=-30,phi=30) render_snapshot() } #Contours and other lines will automatically be ignored. Here is the volcano dataset: ggvolcano = volcano |> reshape2::melt() |> ggplot() + geom_tile(aes(x=Var1,y=Var2,fill=value)) + geom_contour(aes(x=Var1,y=Var2,z=value),color="black") + scale_x_continuous("X",expand = c(0,0)) + scale_y_continuous("Y",expand = c(0,0)) + scale_fill_gradientn("Z",colours = terrain.colors(10)) + coord_fixed() + theme(legend.position = "none") ggvolcano if(run_documentation()) { plot_gg(ggvolcano, multicore = TRUE, raytrace = TRUE, width = 7, height = 4, scale = 300, windowsize = c(1400, 866), zoom = 0.6, phi = 30, theta = 30) render_snapshot() } if(run_documentation()) { #You can specify the color and height separately using the `ggobj_height()` argument. ggvolcano_surface = volcano |> reshape2::melt() |> ggplot() + geom_contour(aes(x=Var1,y=Var2,z=value),color="black") + geom_contour_filled(aes(x=Var1,y=Var2,z=value))+ scale_x_continuous("X",expand = c(0,0)) + scale_y_continuous("Y",expand = c(0,0)) + coord_fixed() + theme(legend.position = "none") plot_gg(ggvolcano_surface, ggobj_height = ggvolcano, multicore = TRUE, raytrace = TRUE, width = 7, height = 4, scale = 300, windowsize = c(1400, 866), zoom = 0.6, phi = 30, theta = 30) render_snapshot() } #Here, we will create a 3D plot of the mtcars dataset. This automatically detects #that the user used the `color` aesthetic instead of the `fill`. mtplot = ggplot(mtcars) + geom_point(aes(x=mpg,y=disp,color=cyl)) + scale_color_continuous(limits=c(0,8)) #Preview how the plot will look by setting `preview = TRUE`: We also adjust the angle of the light. if(run_documentation()) { plot_gg(mtplot, width=3.5, sunangle=225, preview = TRUE) } if(run_documentation()) { plot_gg(mtplot, width=3.5, multicore = TRUE, windowsize = c(1400,866), sunangle=225, zoom = 0.60, phi = 30, theta = 45) render_snapshot() } #Now let's plot a density plot in 3D. mtplot_density = ggplot(mtcars) + stat_density_2d(aes(x=mpg,y=disp, fill=after_stat(!!str2lang("density"))), geom = "raster", contour = FALSE) + scale_x_continuous(expand=c(0,0)) + scale_y_continuous(expand=c(0,0)) + scale_fill_gradient(low="pink", high="red") mtplot_density if(run_documentation()) { plot_gg(mtplot_density, width = 4,zoom = 0.60, theta = -45, phi = 30, windowsize = c(1400,866)) render_snapshot() } #This also works facetted. mtplot_density_facet = mtplot_density + facet_wrap(~cyl) #Preview this plot in 2D: if(run_documentation()) { plot_gg(mtplot_density_facet, preview = TRUE) } if(run_documentation()) { plot_gg(mtplot_density_facet, windowsize=c(1400,866), zoom = 0.55, theta = -10, phi = 25) render_snapshot() } #That is a little cramped. Specifying a larger width will improve the readability of this plot. if(run_documentation()) { plot_gg(mtplot_density_facet, width = 6, preview = TRUE) } #That's better. Let's plot it in 3D, and increase the scale. if(run_documentation()) { plot_gg(mtplot_density_facet, width = 6, windowsize=c(1400,866), zoom = 0.55, theta = -10, phi = 25, scale=300) render_snapshot() } #We can also render a flat version of the plot alongside (or above/below) the 3D version. if(run_documentation()) { plot_gg(mtplot_density_facet, width = 6, windowsize=c(1400,866), zoom = 0.65, theta = -25, phi = 35, scale=300, flat_plot_render=TRUE, flat_direction = "x") render_snapshot() }
Displays the map in the current device.
plot_map( hillshade, title_text = NA, title_offset = c(20, 20), title_color = "black", title_size = 30, title_font = "sans", title_style = "normal", title_bar_color = NA, title_bar_alpha = 0.5, title_just = "left", ... )plot_map( hillshade, title_text = NA, title_offset = c(20, 20), title_color = "black", title_size = 30, title_font = "sans", title_style = "normal", title_bar_color = NA, title_bar_alpha = 0.5, title_just = "left", ... )
hillshade |
Hillshade to be plotted. |
title_text |
Default |
title_offset |
Default |
title_color |
Default |
title_size |
Default |
title_font |
Default |
title_style |
Default |
title_bar_color |
Default |
title_bar_alpha |
Default |
title_just |
Default |
... |
Additional arguments to pass to the |
#Plotting the Monterey Bay dataset with bathymetry data if(run_documentation()) { water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) #For compass text par(family = "Arial") #Set everything below 0m to water palette montereybay |> sphere_shade(zscale=10) |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() }#Plotting the Monterey Bay dataset with bathymetry data if(run_documentation()) { water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200) bathy_hs = height_shade(montereybay, texture = water_palette) #For compass text par(family = "Arial") #Set everything below 0m to water palette montereybay |> sphere_shade(zscale=10) |> add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_map() }
Turns a raster into a matrix suitable for rayshader.
raster_to_matrix(raster, verbose = interactive())raster_to_matrix(raster, verbose = interactive())
raster |
The input raster. Either a RasterLayer object, a terra SpatRaster object, or a filename. |
verbose |
Default |
#Save montereybay as a raster and open using the filename. if(run_documentation()) { temp_raster_filename = paste0(tempfile(),".tif") raster::writeRaster(raster::raster(t(montereybay)),temp_raster_filename) elmat = raster_to_matrix(temp_raster_filename) elmat |> sphere_shade() |> plot_map() }#Save montereybay as a raster and open using the filename. if(run_documentation()) { temp_raster_filename = paste0(tempfile(),".tif") raster::writeRaster(raster::raster(t(montereybay)),temp_raster_filename) elmat = raster_to_matrix(temp_raster_filename) elmat |> sphere_shade() |> plot_map() }
Calculates shadow map for a elevation matrix by propogating rays from each matrix point to the light source(s), lowering the brightness at each point for each ray that intersects the surface.
ray_shade( heightmap, sunaltitude = 45, sunangle = 315, maxsearch = NULL, lambert = TRUE, zscale = 1, multicore = FALSE, cache_mask = NULL, shadow_cache = NULL, progbar = interactive(), anglebreaks = NULL, ... )ray_shade( heightmap, sunaltitude = 45, sunangle = 315, maxsearch = NULL, lambert = TRUE, zscale = 1, multicore = FALSE, cache_mask = NULL, shadow_cache = NULL, progbar = interactive(), anglebreaks = NULL, ... )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced. |
sunaltitude |
Default |
sunangle |
Default |
maxsearch |
Defaults to the longest possible shadow given the |
lambert |
Default |
zscale |
Default |
multicore |
Default |
cache_mask |
Default |
shadow_cache |
Default |
progbar |
Default |
anglebreaks |
Default |
... |
Additional arguments to pass to the |
Matrix of light intensities at each point.
#First we ray trace the Monterey Bay dataset. #The default angle is from 40-50 degrees azimuth, from the north east. if(run_documentation()) { montereybay |> ray_shade(zscale=50) |> plot_map() } #Change the altitude of the sun to 25 degrees if(run_documentation()) { montereybay |> ray_shade(zscale=50, sunaltitude=25) |> plot_map() } #Remove the lambertian shading to just calculate shadow intensity. if(run_documentation()) { montereybay |> ray_shade(zscale=50, sunaltitude=25, lambert=FALSE) |> plot_map() } #Change the direction of the sun to the South East if(run_documentation()) { montereybay |> ray_shade(zscale=50, sunaltitude=25, sunangle=225) |> plot_map() }#First we ray trace the Monterey Bay dataset. #The default angle is from 40-50 degrees azimuth, from the north east. if(run_documentation()) { montereybay |> ray_shade(zscale=50) |> plot_map() } #Change the altitude of the sun to 25 degrees if(run_documentation()) { montereybay |> ray_shade(zscale=50, sunaltitude=25) |> plot_map() } #Remove the lambertian shading to just calculate shadow intensity. if(run_documentation()) { montereybay |> ray_shade(zscale=50, sunaltitude=25, lambert=FALSE) |> plot_map() } #Change the direction of the sun to the South East if(run_documentation()) { montereybay |> ray_shade(zscale=50, sunaltitude=25, sunangle=225) |> plot_map() }
Reduce Matrix Size (defunct)
reduce_matrix_size(...)reduce_matrix_size(...)
... |
Arguments to pass to |
Reduced matrix.
if(run_documentation()) { montbaysmall = resize_matrix(montereybay, scale=0.5) montbaysmall |> sphere_shade() |> plot_map() }if(run_documentation()) { montbaysmall = resize_matrix(montereybay, scale=0.5) montbaysmall |> sphere_shade() |> plot_map() }
Adds beveled polygon to the scene using the raybevel package. See
the raybevel::generate_beveled_polygon() function for more information.
render_beveled_polygons( polygon, extent, material = "grey", bevel_material = NA, angle = 45, bevel_width = 5, width_raw_units = FALSE, bevel = NA, zscale = 1, bevel_height = 1, base_height = 0, raw_heights = FALSE, raw_offsets = FALSE, heights_relative_to_centroid = TRUE, set_max_height = FALSE, max_height = 10, scale_all_max = TRUE, data_column_top = NULL, data_column_bottom = NULL, heightmap = NULL, scale_data = 1, holes = 0, alpha = 1, lit = TRUE, flat_shading = FALSE, light_altitude = c(45, 30), light_direction = c(315, 225), light_intensity = 1, light_relative = FALSE, clear_previous = FALSE, ... )render_beveled_polygons( polygon, extent, material = "grey", bevel_material = NA, angle = 45, bevel_width = 5, width_raw_units = FALSE, bevel = NA, zscale = 1, bevel_height = 1, base_height = 0, raw_heights = FALSE, raw_offsets = FALSE, heights_relative_to_centroid = TRUE, set_max_height = FALSE, max_height = 10, scale_all_max = TRUE, data_column_top = NULL, data_column_bottom = NULL, heightmap = NULL, scale_data = 1, holes = 0, alpha = 1, lit = TRUE, flat_shading = FALSE, light_altitude = c(45, 30), light_direction = c(315, 225), light_intensity = 1, light_relative = FALSE, clear_previous = FALSE, ... )
polygon |
|
extent |
Either an object representing the spatial extent of the 3D scene
(either from the |
material |
Default |
bevel_material |
Default |
angle |
Default |
bevel_width |
Default |
width_raw_units |
Default |
bevel |
Default |
zscale |
Default |
bevel_height |
Default |
base_height |
Default |
raw_heights |
Default |
raw_offsets |
Default |
heights_relative_to_centroid |
Default |
set_max_height |
Default |
max_height |
Default |
scale_all_max |
Default |
data_column_top |
Default |
data_column_bottom |
Default |
heightmap |
Default |
scale_data |
Default |
holes |
Default |
alpha |
Default |
lit |
Default |
flat_shading |
Default |
light_altitude |
Default |
light_direction |
Default |
light_intensity |
Default |
light_relative |
Default |
clear_previous |
Default |
... |
Additional arguments to pass to |
# This function can also create fake "terrain" from polygons by visualizing the distance # to the nearest edge. if(run_documentation()) { #Render the county borders as polygons in Monterey Bay as terrain montereybay |> sphere_shade(texture = "desert") |> add_shadow(ray_shade(montereybay,zscale = 50)) |> plot_3d(montereybay, water = TRUE, windowsize = 800, watercolor = "dodgerblue", background = "pink") #We will apply a negative buffer to create space between adjacent polygons. You may #have to call `sf::sf_use_s2(FALSE)` before running this code to get it to run. sf::sf_use_s2(FALSE) mont_county_buff = sf::st_simplify(sf::st_buffer(monterey_counties_sf,-0.003), dTolerance=0.001) render_beveled_polygons(mont_county_buff, flat_shading = TRUE, angle = 45 , heightmap = montereybay, bevel_width=2000, material = "red", extent = attr(montereybay,"extent"), bevel_height = 5000, base_height=0, zscale=200) render_camera(theta = 0, phi = 90, zoom = 0.65, fov = 0) render_snapshot() render_camera(theta=194, phi= 35, zoom = 0.5, fov= 80) render_snapshot() } # Changing the color of the beveled top: if(run_documentation()) { render_beveled_polygons(mont_county_buff, flat_shading = TRUE, angle = 45 , heightmap = montereybay, bevel_width=2000, material = "tan", bevel_material = "darkgreen", extent = attr(montereybay,"extent"), clear_previous=TRUE, bevel_height = 5000, base_height=0, zscale=200) } # We can create a nice curved surface by passing in a bevel generated with the # `raybevel::generate_bevel()` function. if(run_documentation()) { render_beveled_polygons(mont_county_buff, flat_shading = TRUE, heightmap = montereybay, bevel = raybevel::generate_bevel("exp",bevel_end = 0.4), #max_height = 10, scale_all_max = TRUE, set_max_height = TRUE, material = rayvertex::material_list(diffuse="red", ambient = "darkred", diffuse_intensity = 0.2, ambient_intensity = 0.1), light_intensity = 1, light_relative = FALSE, extent = attr(montereybay,"extent"), bevel_height = 5000, base_height=0, clear_previous = TRUE, zscale=200) render_snapshot() } # While the bevels all start at the same point in the above example, # they rise to different levels due to being scaled by the maximum internal distance # in the polygon. Setting `scale_all_max = TRUE` ensures the bevels are all scaled to the # same maximum height (in this case, 3000m above the 5000m bevel start height). if(run_documentation()) { render_beveled_polygons(mont_county_buff, flat_shading = TRUE, heightmap = montereybay, bevel = raybevel::generate_bevel("exp",bevel_end = 0.4), max_height = 3000, scale_all_max = TRUE, set_max_height = TRUE, material = rayvertex::material_list(diffuse="red", ambient = "darkred", diffuse_intensity = 0.2, ambient_intensity = 0.1), light_intensity = 1, light_relative = FALSE, extent = attr(montereybay,"extent"), bevel_height = 5000, base_height=0, clear_previous = TRUE, zscale=200) render_snapshot() } # Rendering the polygons with `render_highquality()` if(run_documentation()) { render_highquality() } # We can scale the size of the polygon to a column in the `sf` object as well: # raybevel::generate_bevel() function. We can scale this data down using the `scale_data` # argument. Note that this is applied as well as the `zscale` argument, and that you # must think carefully about your scales and values if trying to represent a meaningful # data visualization with this object. if(run_documentation()) { render_beveled_polygons(mont_county_buff, flat_shading = TRUE, angle = 45, bevel_width=1000, data_column_top = "ALAND", scale_data = 1e-5, heightmap = montereybay, #max_height = 1000, scale_all_max = TRUE, set_max_height = TRUE, material = rayvertex::material_list(diffuse="red"), light_intensity = 1, light_relative = FALSE, extent = attr(montereybay,"extent"), clear_previous = TRUE, zscale=200) render_snapshot() }# This function can also create fake "terrain" from polygons by visualizing the distance # to the nearest edge. if(run_documentation()) { #Render the county borders as polygons in Monterey Bay as terrain montereybay |> sphere_shade(texture = "desert") |> add_shadow(ray_shade(montereybay,zscale = 50)) |> plot_3d(montereybay, water = TRUE, windowsize = 800, watercolor = "dodgerblue", background = "pink") #We will apply a negative buffer to create space between adjacent polygons. You may #have to call `sf::sf_use_s2(FALSE)` before running this code to get it to run. sf::sf_use_s2(FALSE) mont_county_buff = sf::st_simplify(sf::st_buffer(monterey_counties_sf,-0.003), dTolerance=0.001) render_beveled_polygons(mont_county_buff, flat_shading = TRUE, angle = 45 , heightmap = montereybay, bevel_width=2000, material = "red", extent = attr(montereybay,"extent"), bevel_height = 5000, base_height=0, zscale=200) render_camera(theta = 0, phi = 90, zoom = 0.65, fov = 0) render_snapshot() render_camera(theta=194, phi= 35, zoom = 0.5, fov= 80) render_snapshot() } # Changing the color of the beveled top: if(run_documentation()) { render_beveled_polygons(mont_county_buff, flat_shading = TRUE, angle = 45 , heightmap = montereybay, bevel_width=2000, material = "tan", bevel_material = "darkgreen", extent = attr(montereybay,"extent"), clear_previous=TRUE, bevel_height = 5000, base_height=0, zscale=200) } # We can create a nice curved surface by passing in a bevel generated with the # `raybevel::generate_bevel()` function. if(run_documentation()) { render_beveled_polygons(mont_county_buff, flat_shading = TRUE, heightmap = montereybay, bevel = raybevel::generate_bevel("exp",bevel_end = 0.4), #max_height = 10, scale_all_max = TRUE, set_max_height = TRUE, material = rayvertex::material_list(diffuse="red", ambient = "darkred", diffuse_intensity = 0.2, ambient_intensity = 0.1), light_intensity = 1, light_relative = FALSE, extent = attr(montereybay,"extent"), bevel_height = 5000, base_height=0, clear_previous = TRUE, zscale=200) render_snapshot() } # While the bevels all start at the same point in the above example, # they rise to different levels due to being scaled by the maximum internal distance # in the polygon. Setting `scale_all_max = TRUE` ensures the bevels are all scaled to the # same maximum height (in this case, 3000m above the 5000m bevel start height). if(run_documentation()) { render_beveled_polygons(mont_county_buff, flat_shading = TRUE, heightmap = montereybay, bevel = raybevel::generate_bevel("exp",bevel_end = 0.4), max_height = 3000, scale_all_max = TRUE, set_max_height = TRUE, material = rayvertex::material_list(diffuse="red", ambient = "darkred", diffuse_intensity = 0.2, ambient_intensity = 0.1), light_intensity = 1, light_relative = FALSE, extent = attr(montereybay,"extent"), bevel_height = 5000, base_height=0, clear_previous = TRUE, zscale=200) render_snapshot() } # Rendering the polygons with `render_highquality()` if(run_documentation()) { render_highquality() } # We can scale the size of the polygon to a column in the `sf` object as well: # raybevel::generate_bevel() function. We can scale this data down using the `scale_data` # argument. Note that this is applied as well as the `zscale` argument, and that you # must think carefully about your scales and values if trying to represent a meaningful # data visualization with this object. if(run_documentation()) { render_beveled_polygons(mont_county_buff, flat_shading = TRUE, angle = 45, bevel_width=1000, data_column_top = "ALAND", scale_data = 1e-5, heightmap = montereybay, #max_height = 1000, scale_all_max = TRUE, set_max_height = TRUE, material = rayvertex::material_list(diffuse="red"), light_intensity = 1, light_relative = FALSE, extent = attr(montereybay,"extent"), clear_previous = TRUE, zscale=200) render_snapshot() }
Adds 3D polygons with roofs to the current scene, using latitude/longitude or coordinates in the reference system defined by the extent object.
render_buildings( polygon, extent, material = "grey", roof_material = NA, angle = 45, zscale = 1, scale_data = 1, relative_heights = TRUE, heights_relative_to_centroid = FALSE, roof_height = 1, base_height = 0, data_column_top = NULL, data_column_bottom = NULL, heightmap = NULL, holes = 0, alpha = 1, lit = TRUE, flat_shading = FALSE, light_altitude = c(45, 30), light_direction = c(315, 225), light_intensity = 1, light_relative = FALSE, clear_previous = FALSE, ... )render_buildings( polygon, extent, material = "grey", roof_material = NA, angle = 45, zscale = 1, scale_data = 1, relative_heights = TRUE, heights_relative_to_centroid = FALSE, roof_height = 1, base_height = 0, data_column_top = NULL, data_column_bottom = NULL, heightmap = NULL, holes = 0, alpha = 1, lit = TRUE, flat_shading = FALSE, light_altitude = c(45, 30), light_direction = c(315, 225), light_intensity = 1, light_relative = FALSE, clear_previous = FALSE, ... )
polygon |
|
extent |
Either an object representing the spatial extent of the 3D scene
(either from the |
material |
Default |
roof_material |
Default |
angle |
Default |
zscale |
Default |
scale_data |
Default |
relative_heights |
Default |
heights_relative_to_centroid |
Default |
roof_height |
Default |
base_height |
Default |
data_column_top |
Default |
data_column_bottom |
Default |
heightmap |
Default |
holes |
Default |
alpha |
Default |
lit |
Default |
flat_shading |
Default |
light_altitude |
Default |
light_direction |
Default |
light_intensity |
Default |
light_relative |
Default |
clear_previous |
Default |
... |
Additional arguments to pass to |
if(run_documentation()) { # Load and visualize building footprints from Open Street Map library(osmdata) library(sf) library(raster) osm_bbox = c(-121.9472, 36.6019, -121.9179, 36.6385) #Get buildings from OpenStreetMap opq(osm_bbox) |> add_osm_feature("building") |> osmdata_sf() -> osm_data #Get roads from OpenStreetMap opq(osm_bbox) |> add_osm_feature("highway") |> osmdata_sf() -> osm_road #Get extent building_polys = osm_data$osm_polygons osm_dem = elevatr::get_elev_raster(building_polys, z = 11, clip = "bbox") e = extent(building_polys) # Crop DEM, but note that the cropped DEM will have an extent slightly different than what's # specified in `e`. Save that new extent to `new_e`. osm_dem |> crop(e) |> extent() -> new_e osm_dem |> crop(e) |> raster_to_matrix() -> osm_mat #Visualize areas less than one meter as water (approximate tidal range) osm_mat[osm_mat <= 1] = -2 osm_mat |> rayimage::render_resized(mag=4) |> sphere_shade(texture = "desert") |> add_overlay(generate_polygon_overlay(building_polys, extent = new_e, heightmap = osm_mat, linewidth = 6, resolution_multiply = 50), rescale_original = TRUE) |> add_overlay(generate_line_overlay(osm_road$osm_lines, extent = new_e, heightmap = osm_mat, linewidth = 6, resolution_multiply = 50), rescale_original = TRUE) |> plot_3d(osm_mat, water = TRUE, windowsize = 800, watercolor = "dodgerblue", zscale = 10, background = "pink") #Render buildings render_buildings(building_polys, flat_shading = TRUE, angle = 30 , heightmap = osm_mat, material = "white", roof_material = "white", extent = new_e, roof_height = 3, base_height = 0, zscale=10) render_camera(theta=220, phi=22, zoom=0.45, fov=0) render_snapshot() } if(run_documentation()) { #Zoom in to show roof details and render with render_highquality() render_camera(fov=110) render_highquality(camera_location = c(18.22, 0.57, -50.83), camera_lookat = c(20.88, -2.83, -38.87), focal_distance = 13, samples = 16, lightdirection = 45) }if(run_documentation()) { # Load and visualize building footprints from Open Street Map library(osmdata) library(sf) library(raster) osm_bbox = c(-121.9472, 36.6019, -121.9179, 36.6385) #Get buildings from OpenStreetMap opq(osm_bbox) |> add_osm_feature("building") |> osmdata_sf() -> osm_data #Get roads from OpenStreetMap opq(osm_bbox) |> add_osm_feature("highway") |> osmdata_sf() -> osm_road #Get extent building_polys = osm_data$osm_polygons osm_dem = elevatr::get_elev_raster(building_polys, z = 11, clip = "bbox") e = extent(building_polys) # Crop DEM, but note that the cropped DEM will have an extent slightly different than what's # specified in `e`. Save that new extent to `new_e`. osm_dem |> crop(e) |> extent() -> new_e osm_dem |> crop(e) |> raster_to_matrix() -> osm_mat #Visualize areas less than one meter as water (approximate tidal range) osm_mat[osm_mat <= 1] = -2 osm_mat |> rayimage::render_resized(mag=4) |> sphere_shade(texture = "desert") |> add_overlay(generate_polygon_overlay(building_polys, extent = new_e, heightmap = osm_mat, linewidth = 6, resolution_multiply = 50), rescale_original = TRUE) |> add_overlay(generate_line_overlay(osm_road$osm_lines, extent = new_e, heightmap = osm_mat, linewidth = 6, resolution_multiply = 50), rescale_original = TRUE) |> plot_3d(osm_mat, water = TRUE, windowsize = 800, watercolor = "dodgerblue", zscale = 10, background = "pink") #Render buildings render_buildings(building_polys, flat_shading = TRUE, angle = 30 , heightmap = osm_mat, material = "white", roof_material = "white", extent = new_e, roof_height = 3, base_height = 0, zscale=10) render_camera(theta=220, phi=22, zoom=0.45, fov=0) render_snapshot() } if(run_documentation()) { #Zoom in to show roof details and render with render_highquality() render_camera(fov=110) render_highquality(camera_location = c(18.22, 0.57, -50.83), camera_lookat = c(20.88, -2.83, -38.87), focal_distance = 13, samples = 16, lightdirection = 45) }
Changes the position and properties of the camera around the scene. If no values are entered, prints and returns the current values.
render_camera( theta = NULL, phi = NULL, zoom = NULL, fov = NULL, shift_vertical = 0 )render_camera( theta = NULL, phi = NULL, zoom = NULL, fov = NULL, shift_vertical = 0 )
theta |
Defaults to current value. Rotation angle. |
phi |
Defaults to current value. Azimuth angle. Maximum |
zoom |
Defaults to current value. Positive value indicating camera magnification. |
fov |
Defaults to current value. Field of view of the camera. Maximum |
shift_vertical |
Default |
if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale = 50, water = TRUE, waterlinecolor="white") render_snapshot() } #Shift the camera over and add a title if(run_documentation()) { render_camera(theta = -45, phi = 45) render_snapshot(title_text = "Monterey Bay, CA", title_bar_color = "grey50") } #Shift to an overhead view (and change the text/title bar color) if(run_documentation()) { render_camera(theta = 0, phi = 89.9, zoom = 0.9) render_snapshot(title_text = "Monterey Bay, CA", title_color = "white", title_bar_color = "darkgreen") } #Shift to an front view and add a vignette effect if(run_documentation()) { render_camera(theta = -90, phi = 30,zoom = 0.8) render_snapshot(title_text = "Monterey Bay, CA", title_color = "white", title_bar_color = "blue", vignette = TRUE) } #Change the field of view (fov) and make the title bar opaque. if(run_documentation()) { render_camera(theta = -90, phi = 30,zoom = 0.5,fov = 130) render_snapshot(title_text = "Monterey Bay, CA", title_color = "black", title_bar_alpha = 1, title_bar_color = "lightblue", vignette = TRUE) } #Here we render a series of frames to later stitch together into a movie. if(run_documentation()) { phivec = 20 + 70 * 1/(1 + exp(seq(-5, 10, length.out = 180))) phivecfull = c(phivec, rev(phivec)) thetavec = 270 + 45 * sin(seq(0,359,length.out = 360) * pi/180) zoomvechalf = 0.5 + 0.5 * 1/(1 + exp(seq(-5, 10, length.out = 180))) zoomvec = c(zoomvechalf, rev(zoomvechalf)) for(i in 1:360) { render_camera(theta = thetavec[i],phi = phivecfull[i],zoom = zoomvec[i]) #uncomment the next line to save each frame to the working directory #render_snapshot(paste0("frame", i, ".png")) } #Run this command in the command line using ffmpeg to stitch together a video: #ffmpeg -framerate 60 -i frame%d.png -vcodec libx264 raymovie.mp4 #And run this command to convert the video to post to the web: #ffmpeg -i raymovie.mp4 -pix_fmt yuv420p -profile:v baseline -level 3 -vf scale=-2:-2 rayweb.mp4 #Or we can use render_movie() to do this all automatically with type="custom" (uncomment to run): #render_movie(filename = tempfile(fileext = ".mp4"), type = "custom", # theta = thetavec, phi = phivecfull, zoom = zoomvec, fov=0) }if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale = 50, water = TRUE, waterlinecolor="white") render_snapshot() } #Shift the camera over and add a title if(run_documentation()) { render_camera(theta = -45, phi = 45) render_snapshot(title_text = "Monterey Bay, CA", title_bar_color = "grey50") } #Shift to an overhead view (and change the text/title bar color) if(run_documentation()) { render_camera(theta = 0, phi = 89.9, zoom = 0.9) render_snapshot(title_text = "Monterey Bay, CA", title_color = "white", title_bar_color = "darkgreen") } #Shift to an front view and add a vignette effect if(run_documentation()) { render_camera(theta = -90, phi = 30,zoom = 0.8) render_snapshot(title_text = "Monterey Bay, CA", title_color = "white", title_bar_color = "blue", vignette = TRUE) } #Change the field of view (fov) and make the title bar opaque. if(run_documentation()) { render_camera(theta = -90, phi = 30,zoom = 0.5,fov = 130) render_snapshot(title_text = "Monterey Bay, CA", title_color = "black", title_bar_alpha = 1, title_bar_color = "lightblue", vignette = TRUE) } #Here we render a series of frames to later stitch together into a movie. if(run_documentation()) { phivec = 20 + 70 * 1/(1 + exp(seq(-5, 10, length.out = 180))) phivecfull = c(phivec, rev(phivec)) thetavec = 270 + 45 * sin(seq(0,359,length.out = 360) * pi/180) zoomvechalf = 0.5 + 0.5 * 1/(1 + exp(seq(-5, 10, length.out = 180))) zoomvec = c(zoomvechalf, rev(zoomvechalf)) for(i in 1:360) { render_camera(theta = thetavec[i],phi = phivecfull[i],zoom = zoomvec[i]) #uncomment the next line to save each frame to the working directory #render_snapshot(paste0("frame", i, ".png")) } #Run this command in the command line using ffmpeg to stitch together a video: #ffmpeg -framerate 60 -i frame%d.png -vcodec libx264 raymovie.mp4 #And run this command to convert the video to post to the web: #ffmpeg -i raymovie.mp4 -pix_fmt yuv420p -profile:v baseline -level 3 -vf scale=-2:-2 rayweb.mp4 #Or we can use render_movie() to do this all automatically with type="custom" (uncomment to run): #render_movie(filename = tempfile(fileext = ".mp4"), type = "custom", # theta = thetavec, phi = phivecfull, zoom = zoomvec, fov=0) }
Render a 3D floating cloud layer of the map.
Note: Underlying layers with transparency can cause rendering issues in rgl.
render_clouds( heightmap, start_altitude = 1000, end_altitude = 2000, sun_altitude = 10, sun_angle = 315, time = 0, cloud_cover = 0.5, layers = 10, offset_x = 0, offset_y = 0, scale_x = 1, scale_y = 1, scale_z = 1, frequency = 0.005, fractal_levels = 16, attenuation_coef = 1, seed = 1, zscale = 1, baseshape = "rectangle", clear_clouds = FALSE )render_clouds( heightmap, start_altitude = 1000, end_altitude = 2000, sun_altitude = 10, sun_angle = 315, time = 0, cloud_cover = 0.5, layers = 10, offset_x = 0, offset_y = 0, scale_x = 1, scale_y = 1, scale_z = 1, frequency = 0.005, fractal_levels = 16, attenuation_coef = 1, seed = 1, zscale = 1, baseshape = "rectangle", clear_clouds = FALSE )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. This is used by |
start_altitude |
Default |
end_altitude |
Default |
sun_altitude |
Default |
sun_angle |
Default |
time |
Default |
cloud_cover |
Default |
layers |
Default |
offset_x |
Default |
offset_y |
Default |
scale_x |
Default |
scale_y |
Default |
scale_z |
Default |
frequency |
Default |
fractal_levels |
Default |
attenuation_coef |
Default |
seed |
Default |
zscale |
Default |
baseshape |
Default |
clear_clouds |
Default |
Adds a 3D floating cloud layer to the map. No return value.
if(run_documentation()) { #Render a cloud layer over Monterey Bay montereybay |> sphere_shade() |> plot_3d(montereybay,background="brown",zscale=50) #Render some clouds render_clouds(montereybay, zscale=50) render_snapshot() } if(run_documentation()) { #Change the seed for a different set of clouds and add cloud shadows on the ground montereybay |> sphere_shade() |> add_shadow(cloud_shade(montereybay,zscale=50, seed = 2), 0.0) |> plot_3d(montereybay,background="brown",zscale=50) render_camera(theta=-65, phi = 25, zoom = 0.45, fov = 80) render_clouds(montereybay, zscale=50, seed=2, clear_clouds = T) render_snapshot() } if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,background="brown",zscale=50) #Lower the frequency for larger, smoother clouds render_clouds(montereybay, zscale=50, frequency = 0.001, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Increase the frequency for more broken clouds render_clouds(montereybay, zscale=50, frequency = 0.05, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Increase the fractal level for fluffier, bumpier clouds render_clouds(montereybay, zscale=50, fractal_levels = 32, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Decrease the fractal level for more smoother, continuous clouds render_clouds(montereybay, zscale=50, fractal_levels = 4, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Increase the cloud cover render_clouds(montereybay, zscale=50, cloud_cover=0.8, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Decrease the cloud cover render_clouds(montereybay, zscale=50, cloud_cover=0.2, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Change the altitude range of the clouds render_clouds(montereybay,zscale=50,start_altitude=2000,end_altitude = 4000, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Increase the number of layers render_clouds(montereybay, zscale=50,start_altitude=2000,end_altitude = 4000, layers = 20, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Change the sun angle and altitude, and increase the attenuation for darker clouds render_clouds(montereybay,zscale=50,sun_angle=45, sun_altitude= 5, attenuation_coef = 5, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Render the scene with a different baseshape montereybay |> sphere_shade() |> plot_3d(montereybay,background="darkred",zscale=50, baseshape="hex") render_clouds(montereybay,zscale=50, seed=3, baseshape="hex", clear_clouds = T) render_camera(zoom=0.65) render_snapshot() }if(run_documentation()) { #Render a cloud layer over Monterey Bay montereybay |> sphere_shade() |> plot_3d(montereybay,background="brown",zscale=50) #Render some clouds render_clouds(montereybay, zscale=50) render_snapshot() } if(run_documentation()) { #Change the seed for a different set of clouds and add cloud shadows on the ground montereybay |> sphere_shade() |> add_shadow(cloud_shade(montereybay,zscale=50, seed = 2), 0.0) |> plot_3d(montereybay,background="brown",zscale=50) render_camera(theta=-65, phi = 25, zoom = 0.45, fov = 80) render_clouds(montereybay, zscale=50, seed=2, clear_clouds = T) render_snapshot() } if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,background="brown",zscale=50) #Lower the frequency for larger, smoother clouds render_clouds(montereybay, zscale=50, frequency = 0.001, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Increase the frequency for more broken clouds render_clouds(montereybay, zscale=50, frequency = 0.05, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Increase the fractal level for fluffier, bumpier clouds render_clouds(montereybay, zscale=50, fractal_levels = 32, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Decrease the fractal level for more smoother, continuous clouds render_clouds(montereybay, zscale=50, fractal_levels = 4, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Increase the cloud cover render_clouds(montereybay, zscale=50, cloud_cover=0.8, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Decrease the cloud cover render_clouds(montereybay, zscale=50, cloud_cover=0.2, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Change the altitude range of the clouds render_clouds(montereybay,zscale=50,start_altitude=2000,end_altitude = 4000, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Increase the number of layers render_clouds(montereybay, zscale=50,start_altitude=2000,end_altitude = 4000, layers = 20, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Change the sun angle and altitude, and increase the attenuation for darker clouds render_clouds(montereybay,zscale=50,sun_angle=45, sun_altitude= 5, attenuation_coef = 5, clear_clouds = T) render_snapshot() } if(run_documentation()) { #Render the scene with a different baseshape montereybay |> sphere_shade() |> plot_3d(montereybay,background="darkred",zscale=50, baseshape="hex") render_clouds(montereybay,zscale=50, seed=3, baseshape="hex", clear_clouds = T) render_camera(zoom=0.65) render_snapshot() }
Places a compass on the map to specify the North direction.
render_compass( angle = 0, position = "SE", altitude = NULL, zscale = 1, x = NULL, y = NULL, z = NULL, compass_radius = NULL, scale_distance = 1, color_n = "darkred", color_arrow = "grey90", color_background = "grey60", color_bevel = "grey20", position_circular = FALSE, clear_compass = FALSE )render_compass( angle = 0, position = "SE", altitude = NULL, zscale = 1, x = NULL, y = NULL, z = NULL, compass_radius = NULL, scale_distance = 1, color_n = "darkred", color_arrow = "grey90", color_background = "grey60", color_bevel = "grey20", position_circular = FALSE, clear_compass = FALSE )
angle |
Default |
position |
Default |
altitude |
Default |
zscale |
Default |
x |
Default |
y |
Default |
z |
Default |
compass_radius |
Default |
scale_distance |
Default |
color_n |
Default |
color_arrow |
Default |
color_background |
Default |
color_bevel |
Default |
position_circular |
Default |
clear_compass |
Default |
Adds compass to map. No return value.
#Add a North arrow to the map, by default in the bottom right (SE) if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,theta=-45, water=TRUE) render_compass() render_snapshot() } if(run_documentation()) { #Remove the existing symbol with `clear_compass = TRUE` render_compass(clear_compass = TRUE) #Point the N towards the light, at 315 degrees: render_compass(angle = 315) render_snapshot() } if(run_documentation()) { render_compass(clear_compass = TRUE) #We can change the position by specifying a direction (here are three): render_camera(theta=45,phi=45) render_compass(position = "NW") render_compass(position = "E") render_compass(position = "S") render_snapshot() } if(run_documentation()) { render_compass(clear_compass = TRUE) #We can also change the distance away from the edge by setting the `scale_distance` argument. render_compass(position = "NW", scale_distance = 1.4) render_compass(position = "E", scale_distance = 1.4) render_compass(position = "S", scale_distance = 1.4) #Zoom in slightly: render_camera(theta=45,phi=45,zoom=0.7) render_snapshot() } if(run_documentation()) { render_compass(clear_compass = TRUE) #We can also specify the radius directly with `compass_radius`: render_camera(theta=0,phi=45,zoom=1) render_compass(position = "N", scale_distance = 1.5, compass_radius=200) render_compass(position = "E", scale_distance = 1.4, compass_radius=50) render_compass(position = "S", scale_distance = 1.3, compass_radius=25) render_compass(position = "W", scale_distance = 1.2, compass_radius=10) render_snapshot() render_compass(clear_compass = TRUE) } if(run_documentation()) { #We can also adjust the position manually, be specifying all x, y and z arguments. render_camera(theta=-45,phi=45,zoom=0.9) render_compass(x = 150, y = 50, z = 150) render_snapshot() } if(run_documentation()) { # Compass support is also included in render_highquality() render_highquality(min_variance = 0, samples = 16) } if(run_documentation()) { render_compass(clear_compass = TRUE) #We can change the colors in the compass, and also set it a constant distance away with #`position_circular = TRUE`: render_camera(theta=0,phi=45,zoom=0.75) render_compass(position = "N", color_n = "#55967a", color_arrow = "#fff673", color_background = "#cfe0a9", color_bevel = "#8fb28a", position_circular = TRUE) render_compass(position = "NE", color_n = "black", color_arrow = "grey90", color_background = "grey50", color_bevel = "grey20", position_circular = TRUE) render_compass(position = "E", color_n = "red", color_arrow = "blue", color_background = "yellow", color_bevel = "purple", position_circular = TRUE) render_compass(position = "SE", color_n = c(0.7,0.5,0.9), color_arrow = c(0.8,0.8,1), color_background = c(0.2,0.2,1), color_bevel = c(0.6,0.4,0.6), position_circular = TRUE) render_compass(position = "S", color_n = "#ffe3b3", color_arrow = "#6a463a", color_background = "#abaf98", color_bevel = "grey20", position_circular = TRUE) render_compass(position = "SW", color_n = "#ffe3a3", color_arrow = "#f1c3a9", color_background = "#abaf98", color_bevel = "#66615e", position_circular = TRUE) render_compass(position = "W", color_n = "#e9e671", color_arrow = "#cbb387", color_background = "#7c9695", color_bevel = "#cbb387", position_circular = TRUE) render_compass(position = "NW", color_n = c(0.7,0,0), color_arrow = c(0.3,0,0), color_background = c(0.7,0.5,0.5), color_bevel = c(0.2,0,0), position_circular = TRUE) render_snapshot() }#Add a North arrow to the map, by default in the bottom right (SE) if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,theta=-45, water=TRUE) render_compass() render_snapshot() } if(run_documentation()) { #Remove the existing symbol with `clear_compass = TRUE` render_compass(clear_compass = TRUE) #Point the N towards the light, at 315 degrees: render_compass(angle = 315) render_snapshot() } if(run_documentation()) { render_compass(clear_compass = TRUE) #We can change the position by specifying a direction (here are three): render_camera(theta=45,phi=45) render_compass(position = "NW") render_compass(position = "E") render_compass(position = "S") render_snapshot() } if(run_documentation()) { render_compass(clear_compass = TRUE) #We can also change the distance away from the edge by setting the `scale_distance` argument. render_compass(position = "NW", scale_distance = 1.4) render_compass(position = "E", scale_distance = 1.4) render_compass(position = "S", scale_distance = 1.4) #Zoom in slightly: render_camera(theta=45,phi=45,zoom=0.7) render_snapshot() } if(run_documentation()) { render_compass(clear_compass = TRUE) #We can also specify the radius directly with `compass_radius`: render_camera(theta=0,phi=45,zoom=1) render_compass(position = "N", scale_distance = 1.5, compass_radius=200) render_compass(position = "E", scale_distance = 1.4, compass_radius=50) render_compass(position = "S", scale_distance = 1.3, compass_radius=25) render_compass(position = "W", scale_distance = 1.2, compass_radius=10) render_snapshot() render_compass(clear_compass = TRUE) } if(run_documentation()) { #We can also adjust the position manually, be specifying all x, y and z arguments. render_camera(theta=-45,phi=45,zoom=0.9) render_compass(x = 150, y = 50, z = 150) render_snapshot() } if(run_documentation()) { # Compass support is also included in render_highquality() render_highquality(min_variance = 0, samples = 16) } if(run_documentation()) { render_compass(clear_compass = TRUE) #We can change the colors in the compass, and also set it a constant distance away with #`position_circular = TRUE`: render_camera(theta=0,phi=45,zoom=0.75) render_compass(position = "N", color_n = "#55967a", color_arrow = "#fff673", color_background = "#cfe0a9", color_bevel = "#8fb28a", position_circular = TRUE) render_compass(position = "NE", color_n = "black", color_arrow = "grey90", color_background = "grey50", color_bevel = "grey20", position_circular = TRUE) render_compass(position = "E", color_n = "red", color_arrow = "blue", color_background = "yellow", color_bevel = "purple", position_circular = TRUE) render_compass(position = "SE", color_n = c(0.7,0.5,0.9), color_arrow = c(0.8,0.8,1), color_background = c(0.2,0.2,1), color_bevel = c(0.6,0.4,0.6), position_circular = TRUE) render_compass(position = "S", color_n = "#ffe3b3", color_arrow = "#6a463a", color_background = "#abaf98", color_bevel = "grey20", position_circular = TRUE) render_compass(position = "SW", color_n = "#ffe3a3", color_arrow = "#f1c3a9", color_background = "#abaf98", color_bevel = "#66615e", position_circular = TRUE) render_compass(position = "W", color_n = "#e9e671", color_arrow = "#cbb387", color_background = "#7c9695", color_bevel = "#cbb387", position_circular = TRUE) render_compass(position = "NW", color_n = c(0.7,0,0), color_arrow = c(0.3,0,0), color_background = c(0.7,0.5,0.5), color_bevel = c(0.2,0,0), position_circular = TRUE) render_snapshot() }
Adds 3D contours to the current scene, using the heightmap of the 3D surface.
render_contours( heightmap = NULL, zscale = 1, levels = NA, nlevels = NA, linewidth = 1, color = "black", palette = NULL, antialias = FALSE, offset = 0, clear_previous = FALSE )render_contours( heightmap = NULL, zscale = 1, levels = NA, nlevels = NA, linewidth = 1, color = "black", palette = NULL, antialias = FALSE, offset = 0, clear_previous = FALSE )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All grid points are assumed to be evenly spaced. |
zscale |
Default |
levels |
Default |
nlevels |
Default |
linewidth |
Default |
color |
Default |
palette |
Default |
antialias |
Default |
offset |
Default |
clear_previous |
Default |
#Add contours to the montereybay dataset if(run_documentation()) { montereybay |> height_shade() |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_3d(montereybay, theta = -45, zscale=50, zoom=0.9, windowsize=800) render_contours(montereybay, zscale = 50, offset = 100) render_snapshot() } if(run_documentation()) { #Specify the number of levels render_contours(montereybay, zscale = 50, offset = 100, nlevels = 30, clear_previous = TRUE) render_snapshot() } if(run_documentation()) { #Manually specify the breaks with levels render_contours(montereybay, linewidth = 2, offset = 100, zscale = 50, levels = seq(-2000, 0, 100), clear_previous = TRUE) render_snapshot() } if(run_documentation()) { #Use a color palette for the contours volcano |> constant_shade() |> plot_3d(volcano, zscale = 2, solid = FALSE, zoom = 0.8) palette = grDevices::colorRampPalette(c("red", "purple", "pink")) render_contours(volcano, offset = 1, palette = palette, zscale = 2, nlevels = 20) render_snapshot() } if(run_documentation()) { #Render using `render_highquality()` for a neon light effect render_highquality(light = FALSE, samples = 16, line_radius = 0.1, path_material = rayrender::light, ground_size = 0, path_material_args = list(importance_sample = FALSE, color = "purple", intensity = 2)) }#Add contours to the montereybay dataset if(run_documentation()) { montereybay |> height_shade() |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_3d(montereybay, theta = -45, zscale=50, zoom=0.9, windowsize=800) render_contours(montereybay, zscale = 50, offset = 100) render_snapshot() } if(run_documentation()) { #Specify the number of levels render_contours(montereybay, zscale = 50, offset = 100, nlevels = 30, clear_previous = TRUE) render_snapshot() } if(run_documentation()) { #Manually specify the breaks with levels render_contours(montereybay, linewidth = 2, offset = 100, zscale = 50, levels = seq(-2000, 0, 100), clear_previous = TRUE) render_snapshot() } if(run_documentation()) { #Use a color palette for the contours volcano |> constant_shade() |> plot_3d(volcano, zscale = 2, solid = FALSE, zoom = 0.8) palette = grDevices::colorRampPalette(c("red", "purple", "pink")) render_contours(volcano, offset = 1, palette = palette, zscale = 2, nlevels = 20) render_snapshot() } if(run_documentation()) { #Render using `render_highquality()` for a neon light effect render_highquality(light = FALSE, samples = 16, line_radius = 0.1, path_material = rayrender::light, ground_size = 0, path_material_args = list(importance_sample = FALSE, color = "purple", intensity = 2)) }
Adds depth of field to the current RGL scene by simulating a synthetic aperture.
The size of the circle of confusion is determined by the following formula (z_depth is from the image's depth map).
abs(z_depth-focus)*focal_length^2/(f_stop*z_depth*(focus - focal_length))
render_depth( focus = NULL, focallength = 100, fstop = 4, filename = NULL, preview_focus = FALSE, bokehshape = "circle", bokehintensity = 1, bokehlimit = 0.8, rotation = 0, aberration = 0, transparent_water = FALSE, heightmap = NULL, zscale = NULL, title_text = NULL, title_offset = c(20, 20), title_color = "black", title_size = 30, title_font = "sans", title_bar_color = NA, title_bar_alpha = 0.5, title_just = "left", image_overlay = NULL, vignette = FALSE, vignette_color = "black", vignette_radius = 1.3, progbar = interactive(), software_render = FALSE, width = NULL, height = NULL, camera_location = NULL, camera_lookat = c(0, 0, 0), background = "white", text_angle = NULL, text_size = 10, text_offset = c(0, 0, 0), point_radius = 0.5, line_offset = 1e-07, cache_scene = FALSE, reset_scene_cache = FALSE, print_scene_info = FALSE, instant_capture = interactive(), clear = FALSE, bring_to_front = FALSE, ... )render_depth( focus = NULL, focallength = 100, fstop = 4, filename = NULL, preview_focus = FALSE, bokehshape = "circle", bokehintensity = 1, bokehlimit = 0.8, rotation = 0, aberration = 0, transparent_water = FALSE, heightmap = NULL, zscale = NULL, title_text = NULL, title_offset = c(20, 20), title_color = "black", title_size = 30, title_font = "sans", title_bar_color = NA, title_bar_alpha = 0.5, title_just = "left", image_overlay = NULL, vignette = FALSE, vignette_color = "black", vignette_radius = 1.3, progbar = interactive(), software_render = FALSE, width = NULL, height = NULL, camera_location = NULL, camera_lookat = c(0, 0, 0), background = "white", text_angle = NULL, text_size = 10, text_offset = c(0, 0, 0), point_radius = 0.5, line_offset = 1e-07, cache_scene = FALSE, reset_scene_cache = FALSE, print_scene_info = FALSE, instant_capture = interactive(), clear = FALSE, bring_to_front = FALSE, ... )
focus |
Focal point. Defaults to the center of the bounding box. Depth in which to blur, in distance to the camera plane. |
focallength |
Default |
fstop |
Default |
filename |
The filename of the image to be saved. If this is not given, the image will be plotted instead. |
preview_focus |
Default |
bokehshape |
Default |
bokehintensity |
Default |
bokehlimit |
Default |
rotation |
Default |
aberration |
Default |
transparent_water |
Default |
heightmap |
Default |
zscale |
Default |
title_text |
Default |
title_offset |
Default |
title_color |
Default |
title_size |
Default |
title_font |
Default |
title_bar_color |
Default |
title_bar_alpha |
Default |
title_just |
Default |
image_overlay |
Default |
vignette |
Default |
vignette_color |
Default |
vignette_radius |
Default |
progbar |
Default |
software_render |
Default |
width |
Default |
height |
Default |
camera_location |
Default |
camera_lookat |
Default |
background |
Default |
text_angle |
Default |
text_size |
Default |
text_offset |
Default |
point_radius |
Default |
line_offset |
Default |
cache_scene |
Default |
reset_scene_cache |
Default |
print_scene_info |
Default |
instant_capture |
Default |
clear |
Default |
bring_to_front |
Default |
... |
Additional parameters to pass to |
4-layer RGBA array.
if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50, water=TRUE, waterlinecolor="white", zoom=0.3,theta=-135,fov=70, phi=20) #Preview where the focal plane lies render_depth(preview_focus=TRUE) } if(run_documentation()) { #Render the depth of field effect render_depth(focallength = 300) } if(run_documentation()) { #Add a chromatic aberration effect render_depth(focallength = 300, aberration = 0.3) } if(run_documentation()) { #Render the depth of field effect, ignoring water and re-drawing the waterlayer render_depth(preview_focus=TRUE, heightmap = montereybay, zscale=50, focallength=300, transparent_water=TRUE) render_depth(heightmap = montereybay, zscale=50, focallength=300, transparent_water=TRUE) render_camera(theta=45,zoom=0.15,phi=20) } if(run_documentation()) { #Change the bokeh shape and intensity render_depth(focus=900, bokehshape = "circle",focallength=500,bokehintensity=30, title_text = "Circular Bokeh", title_size = 30, title_color = "white", title_bar_color = "black") render_depth(focus=900, bokehshape = "hex",focallength=500,bokehintensity=30, title_text = "Hexagonal Bokeh", title_size = 30, title_color = "white", title_bar_color = "black") } if(run_documentation()) { #Add a title and vignette effect. render_camera(theta=0,zoom=0.7,phi=30) render_depth(focallength = 250, title_text = "Monterey Bay, CA", title_size = 20, title_color = "white", title_bar_color = "black", vignette = TRUE) }if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50, water=TRUE, waterlinecolor="white", zoom=0.3,theta=-135,fov=70, phi=20) #Preview where the focal plane lies render_depth(preview_focus=TRUE) } if(run_documentation()) { #Render the depth of field effect render_depth(focallength = 300) } if(run_documentation()) { #Add a chromatic aberration effect render_depth(focallength = 300, aberration = 0.3) } if(run_documentation()) { #Render the depth of field effect, ignoring water and re-drawing the waterlayer render_depth(preview_focus=TRUE, heightmap = montereybay, zscale=50, focallength=300, transparent_water=TRUE) render_depth(heightmap = montereybay, zscale=50, focallength=300, transparent_water=TRUE) render_camera(theta=45,zoom=0.15,phi=20) } if(run_documentation()) { #Change the bokeh shape and intensity render_depth(focus=900, bokehshape = "circle",focallength=500,bokehintensity=30, title_text = "Circular Bokeh", title_size = 30, title_color = "white", title_bar_color = "black") render_depth(focus=900, bokehshape = "hex",focallength=500,bokehintensity=30, title_text = "Hexagonal Bokeh", title_size = 30, title_color = "white", title_bar_color = "black") } if(run_documentation()) { #Add a title and vignette effect. render_camera(theta=0,zoom=0.7,phi=30) render_depth(focallength = 250, title_text = "Monterey Bay, CA", title_size = 20, title_color = "white", title_bar_color = "black", vignette = TRUE) }
Render a 2D floating overlay over the map.
Note: Multiple layers with transparency can cause rendering issues in rgl.
render_floating_overlay( overlay = NULL, altitude = NULL, heightmap = NULL, zscale = 1, alpha = 1, baseshape = "rectangle", remove_na = TRUE, reorient = TRUE, clear_layers = FALSE, horizontal_offset = c(0, 0), ... )render_floating_overlay( overlay = NULL, altitude = NULL, heightmap = NULL, zscale = 1, alpha = 1, baseshape = "rectangle", remove_na = TRUE, reorient = TRUE, clear_layers = FALSE, horizontal_offset = c(0, 0), ... )
overlay |
Overlay (4D RGBA array) to be rendered on the 3D map. |
altitude |
Altitude to place the overlay. |
heightmap |
The underlying surface. A two-dimensional matrix, where each entry in the matrix is the elevation at that point. |
zscale |
Default |
alpha |
Default |
baseshape |
Default |
remove_na |
Default |
reorient |
Default |
clear_layers |
Default |
horizontal_offset |
Default |
... |
Additional arguments to pass to |
Adds a 3D floating layer to the map. No return value.
if(run_documentation()) { #Render the road network as a floating overlay layer, along with a label annotation and a floating #point annotation if(all(length(find.package("sf", quiet = TRUE)) > 0, length(find.package("magick", quiet = TRUE)) > 0)) { monterey = c(-121.892933,36.603053) monterey_city = sf::st_sfc(sf::st_point(monterey)) #Generate Overlays road_overlay = generate_line_overlay(monterey_roads_sf, attr(montereybay,"extent"), heightmap = montereybay) point_overlay = generate_point_overlay(monterey_city, color="red", size=1, attr(montereybay,"extent"), heightmap = montereybay) #Create 3D plot (water transparency set to 1 because multiple transparency layers can interfere) montereybay |> height_shade() |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_3d(montereybay, water = T, wateralpha = 1, windowsize = 800, watercolor = "lightblue") render_camera(theta=-55,phi=45,zoom=0.8) #Render label render_label(montereybay, lat = monterey[2], long = monterey[1], altitude = 9900, extent = attr(montereybay, "extent"), zscale = 50, text = "Monterey", textcolor = "black", linecolor="darkred") #Render Floating Overlays render_floating_overlay(road_overlay, altitude = 10000,zscale = 50) render_floating_overlay(point_overlay, altitude = 100,zscale = 50) render_snapshot() } }if(run_documentation()) { #Render the road network as a floating overlay layer, along with a label annotation and a floating #point annotation if(all(length(find.package("sf", quiet = TRUE)) > 0, length(find.package("magick", quiet = TRUE)) > 0)) { monterey = c(-121.892933,36.603053) monterey_city = sf::st_sfc(sf::st_point(monterey)) #Generate Overlays road_overlay = generate_line_overlay(monterey_roads_sf, attr(montereybay,"extent"), heightmap = montereybay) point_overlay = generate_point_overlay(monterey_city, color="red", size=1, attr(montereybay,"extent"), heightmap = montereybay) #Create 3D plot (water transparency set to 1 because multiple transparency layers can interfere) montereybay |> height_shade() |> add_shadow(ray_shade(montereybay,zscale=50),0.3) |> plot_3d(montereybay, water = T, wateralpha = 1, windowsize = 800, watercolor = "lightblue") render_camera(theta=-55,phi=45,zoom=0.8) #Render label render_label(montereybay, lat = monterey[2], long = monterey[1], altitude = 9900, extent = attr(montereybay, "extent"), zscale = 50, text = "Monterey", textcolor = "black", linecolor="darkred") #Render Floating Overlays render_floating_overlay(road_overlay, altitude = 10000,zscale = 50) render_floating_overlay(point_overlay, altitude = 100,zscale = 50) render_snapshot() } }
Renders a raytraced version of the displayed rgl scene, using the rayrender package.
User can specify the light direction, intensity, and color, as well as specify the material of the
ground and add additional scene elements.
This function can also generate frames for an animation by passing camera animation information from
either convert_path_to_animation_coords() or rayrender::generate_camera_motion() functions.
render_highquality( filename = NA, samples = 128, sample_method = "sobol_blue", min_variance = 1e-07, light = TRUE, lat = NA, long = NA, datetime = NA, sky_args = list(), lightdirection = 315, lightaltitude = 45, lightsize = NULL, lightintensity = 500, lightcolor = "white", material = rayrender::diffuse(), water_attenuation = 0, water_surface_color = TRUE, water_ior = 1, override_material = FALSE, cache_scene = FALSE, reset_scene_cache = FALSE, width = NULL, height = NULL, text_angle = NULL, text_size = 12, text_offset = c(0, text_size/2, 0), line_radius = 0.5, point_radius = 0.5, smooth_line = FALSE, use_extruded_paths = FALSE, scale_text_angle = NULL, scale_text_size = 12, scale_text_offset = c(0, scale_text_size/2, 0), title_text = NULL, title_offset = c(20, 20), title_color = "black", title_size = 30, title_font = "sans", title_just = "left", title_bar_color = NA, title_bar_alpha = 0.5, ground_material = rayrender::diffuse(), ground_size = 1e+05, scene_elements = NULL, camera_location = NULL, camera_lookat = NULL, camera_interpolate = 1, clear = FALSE, return_scene = FALSE, print_scene_info = FALSE, clamp_value = NA, calculate_consistent_normals = FALSE, load_normals = TRUE, point_material = rayrender::diffuse, point_material_args = list(), path_material = rayrender::diffuse, path_material_args = list(), animation_camera_coords = NULL, plot = is.na(filename), ... )render_highquality( filename = NA, samples = 128, sample_method = "sobol_blue", min_variance = 1e-07, light = TRUE, lat = NA, long = NA, datetime = NA, sky_args = list(), lightdirection = 315, lightaltitude = 45, lightsize = NULL, lightintensity = 500, lightcolor = "white", material = rayrender::diffuse(), water_attenuation = 0, water_surface_color = TRUE, water_ior = 1, override_material = FALSE, cache_scene = FALSE, reset_scene_cache = FALSE, width = NULL, height = NULL, text_angle = NULL, text_size = 12, text_offset = c(0, text_size/2, 0), line_radius = 0.5, point_radius = 0.5, smooth_line = FALSE, use_extruded_paths = FALSE, scale_text_angle = NULL, scale_text_size = 12, scale_text_offset = c(0, scale_text_size/2, 0), title_text = NULL, title_offset = c(20, 20), title_color = "black", title_size = 30, title_font = "sans", title_just = "left", title_bar_color = NA, title_bar_alpha = 0.5, ground_material = rayrender::diffuse(), ground_size = 1e+05, scene_elements = NULL, camera_location = NULL, camera_lookat = NULL, camera_interpolate = 1, clear = FALSE, return_scene = FALSE, print_scene_info = FALSE, clamp_value = NA, calculate_consistent_normals = FALSE, load_normals = TRUE, point_material = rayrender::diffuse, point_material_args = list(), path_material = rayrender::diffuse, path_material_args = list(), animation_camera_coords = NULL, plot = is.na(filename), ... )
filename |
Default |
samples |
Default |
sample_method |
Default |
min_variance |
Default |
light |
Default |
lat |
Default |
long |
Default |
datetime |
Default |
sky_args |
Default empty |
lightdirection |
Default |
lightaltitude |
Default |
lightsize |
Default |
lightintensity |
Default |
lightcolor |
Default |
material |
Default |
water_attenuation |
Default |
water_surface_color |
Default |
water_ior |
Default |
override_material |
Default |
cache_scene |
Default |
reset_scene_cache |
Default |
width |
Defaults to the width of the rgl window. Width of the rendering. |
height |
Defaults to the height of the rgl window. Height of the rendering. |
text_angle |
Default |
text_size |
Default |
text_offset |
Default |
line_radius |
Default |
point_radius |
Default |
smooth_line |
Default |
use_extruded_paths |
Default |
scale_text_angle |
Default |
scale_text_size |
Default |
scale_text_offset |
Default |
title_text |
Default |
title_offset |
Default |
title_color |
Default |
title_size |
Default |
title_font |
Default |
title_just |
Default |
title_bar_color |
Default |
title_bar_alpha |
Default |
ground_material |
Default |
ground_size |
Default |
scene_elements |
Default |
camera_location |
Default |
camera_lookat |
Default |
camera_interpolate |
Default |
clear |
Default |
return_scene |
Default |
print_scene_info |
Default |
clamp_value |
Default |
calculate_consistent_normals |
Default |
load_normals |
Default |
point_material |
Default |
point_material_args |
Default empty |
path_material |
Default |
path_material_args |
Default empty |
animation_camera_coords |
Default |
plot |
Default |
... |
Additional parameters to pass to |
#Render the volcano dataset using pathtracing if(run_documentation()) { volcano %>% sphere_shade() %>% plot_3d(volcano,zscale = 2) render_highquality(min_variance = 0, sample_method = "sobol_blue") } #Change position of light if(run_documentation()) { render_highquality(lightdirection = 45, min_variance = 0, sample_method = "sobol_blue") } #Change vertical position of light if(run_documentation()) { render_highquality(lightdirection = 45, lightaltitude = 10, min_variance = 0, samples = 16) } #Change the ground material if(run_documentation()) { render_highquality(lightdirection = 45, lightaltitude=60, ground_material = rayrender::diffuse(checkerperiod = 30, checkercolor="grey50"), min_variance = 0, samples = 16) } #Add three different color lights and a title if(run_documentation()) { render_highquality(lightdirection = c(0,120,240), lightaltitude=45, lightcolor=c("red","green","blue"), title_text = "Red, Green, Blue", title_bar_color="white", title_bar_alpha=0.8, min_variance = 0, samples = 16) } #Change the camera: if(run_documentation()) { render_camera(theta=-45,phi=60,fov=60,zoom=0.8) render_highquality(lightdirection = c(0), title_bar_color="white", title_bar_alpha=0.8, min_variance = 0, samples = 16) } #Add a shiny metal sphere if(run_documentation()) { render_camera(theta=-45,phi=60,fov=60,zoom=0.8) render_highquality(lightdirection = c(0,120,240), lightaltitude=45, lightcolor=c("red","green","blue"), scene_elements = rayrender::sphere(z=-60,y=0, radius=20,material=rayrender::metal()), min_variance = 0) } #Add a red light to the volcano and change the ambient light to dusk if(run_documentation()) { render_camera(theta=45,phi=45) render_highquality(lightdirection = c(240), lightaltitude=30, lightcolor=c("#5555ff"), scene_elements = rayrender::sphere(z=0,y=15, x=-18, radius=5, material=rayrender::light(color="red",intensity=10)), min_variance = 0, samples = 16) } #Manually change the camera location and direction if(run_documentation()) { render_camera(theta=45,phi=45,fov=90) render_highquality(lightdirection = c(240), lightaltitude=30, lightcolor=c("#5555ff"), camera_location = c(50,10,10), camera_lookat = c(0,15,0), scene_elements = rayrender::sphere(z=0,y=15, x=-18, radius=5, material=rayrender::light(color="red",intensity=10)), min_variance = 0, samples = 16) } # Render the shadow of the Washington Monument with a realistic sky at that datetime # using the `skymodelr` package. run_examples = length(find.package("sf", quiet = TRUE)) && length(find.package("elevatr", quiet = TRUE)) && length(find.package("raster", quiet = TRUE)) && run_documentation() if(run_examples) { library(sf) #Set location of washington monument washington_monument_location = st_point(c(-77.035249, 38.889462)) wm_point = washington_monument_location |> st_point() |> st_buffer(0.01) |> st_sfc(crs = 4326) |> st_transform(st_crs(washington_monument_multipolygonz)) elevation_data = elevatr::get_elev_raster(locations = wm_point, z = 14) scene_bbox = st_bbox(st_buffer(wm_point,300)) cropped_data = raster::crop(elevation_data, scene_bbox) #Use rayshader to convert that raster data to a matrix dc_elevation_matrix = raster_to_matrix(cropped_data) #Remove negative elevation data dc_elevation_matrix[dc_elevation_matrix < 0] = 0 #Plot a 3D map of the national mall dc_elevation_matrix |> height_shade() |> add_shadow(lamb_shade(dc_elevation_matrix), 0) |> plot_3d(dc_elevation_matrix, zscale=3.7, water = TRUE, waterdepth = 1, soliddepth=-50, windowsize = 800) #Zoom in on the monument render_camera(theta=45, phi=0, zoom= 0.03, fov=130) #Render the national monument at solar noon on the solstice rgl::par3d(ignoreExtent = TRUE) render_multipolygonz(washington_monument_multipolygonz, extent = raster::extent(cropped_data), zscale = 4, color = "grey80", heightmap = dc_elevation_matrix) #Render using the built-in (but less accurate) Hosek model. # Here's it's more yellow than it should be, but it's accurate enough for most renders. render_highquality( min_variance = 0, samples = 16, long = -77.035249, lat = 38.889462, iso = 8, clamp_value = 10000, datetime = as.POSIXct("2025-12-21 16:00:00", tz = "EST") ) # Render the more-accurate Praguq model (that requires # supplemental data that will be downloaded on the first call) and # specify a higher resolution environment map via `sky_args` render_highquality( min_variance = 0, samples = 16, long = -77.035249, lat = 38.889462, sky_args = list(hosek = FALSE,resolution=4000), iso = 8, clamp_value = 10000, datetime = as.POSIXct("2025-12-21 16:00:00", tz = "EST") ) }#Render the volcano dataset using pathtracing if(run_documentation()) { volcano %>% sphere_shade() %>% plot_3d(volcano,zscale = 2) render_highquality(min_variance = 0, sample_method = "sobol_blue") } #Change position of light if(run_documentation()) { render_highquality(lightdirection = 45, min_variance = 0, sample_method = "sobol_blue") } #Change vertical position of light if(run_documentation()) { render_highquality(lightdirection = 45, lightaltitude = 10, min_variance = 0, samples = 16) } #Change the ground material if(run_documentation()) { render_highquality(lightdirection = 45, lightaltitude=60, ground_material = rayrender::diffuse(checkerperiod = 30, checkercolor="grey50"), min_variance = 0, samples = 16) } #Add three different color lights and a title if(run_documentation()) { render_highquality(lightdirection = c(0,120,240), lightaltitude=45, lightcolor=c("red","green","blue"), title_text = "Red, Green, Blue", title_bar_color="white", title_bar_alpha=0.8, min_variance = 0, samples = 16) } #Change the camera: if(run_documentation()) { render_camera(theta=-45,phi=60,fov=60,zoom=0.8) render_highquality(lightdirection = c(0), title_bar_color="white", title_bar_alpha=0.8, min_variance = 0, samples = 16) } #Add a shiny metal sphere if(run_documentation()) { render_camera(theta=-45,phi=60,fov=60,zoom=0.8) render_highquality(lightdirection = c(0,120,240), lightaltitude=45, lightcolor=c("red","green","blue"), scene_elements = rayrender::sphere(z=-60,y=0, radius=20,material=rayrender::metal()), min_variance = 0) } #Add a red light to the volcano and change the ambient light to dusk if(run_documentation()) { render_camera(theta=45,phi=45) render_highquality(lightdirection = c(240), lightaltitude=30, lightcolor=c("#5555ff"), scene_elements = rayrender::sphere(z=0,y=15, x=-18, radius=5, material=rayrender::light(color="red",intensity=10)), min_variance = 0, samples = 16) } #Manually change the camera location and direction if(run_documentation()) { render_camera(theta=45,phi=45,fov=90) render_highquality(lightdirection = c(240), lightaltitude=30, lightcolor=c("#5555ff"), camera_location = c(50,10,10), camera_lookat = c(0,15,0), scene_elements = rayrender::sphere(z=0,y=15, x=-18, radius=5, material=rayrender::light(color="red",intensity=10)), min_variance = 0, samples = 16) } # Render the shadow of the Washington Monument with a realistic sky at that datetime # using the `skymodelr` package. run_examples = length(find.package("sf", quiet = TRUE)) && length(find.package("elevatr", quiet = TRUE)) && length(find.package("raster", quiet = TRUE)) && run_documentation() if(run_examples) { library(sf) #Set location of washington monument washington_monument_location = st_point(c(-77.035249, 38.889462)) wm_point = washington_monument_location |> st_point() |> st_buffer(0.01) |> st_sfc(crs = 4326) |> st_transform(st_crs(washington_monument_multipolygonz)) elevation_data = elevatr::get_elev_raster(locations = wm_point, z = 14) scene_bbox = st_bbox(st_buffer(wm_point,300)) cropped_data = raster::crop(elevation_data, scene_bbox) #Use rayshader to convert that raster data to a matrix dc_elevation_matrix = raster_to_matrix(cropped_data) #Remove negative elevation data dc_elevation_matrix[dc_elevation_matrix < 0] = 0 #Plot a 3D map of the national mall dc_elevation_matrix |> height_shade() |> add_shadow(lamb_shade(dc_elevation_matrix), 0) |> plot_3d(dc_elevation_matrix, zscale=3.7, water = TRUE, waterdepth = 1, soliddepth=-50, windowsize = 800) #Zoom in on the monument render_camera(theta=45, phi=0, zoom= 0.03, fov=130) #Render the national monument at solar noon on the solstice rgl::par3d(ignoreExtent = TRUE) render_multipolygonz(washington_monument_multipolygonz, extent = raster::extent(cropped_data), zscale = 4, color = "grey80", heightmap = dc_elevation_matrix) #Render using the built-in (but less accurate) Hosek model. # Here's it's more yellow than it should be, but it's accurate enough for most renders. render_highquality( min_variance = 0, samples = 16, long = -77.035249, lat = 38.889462, iso = 8, clamp_value = 10000, datetime = as.POSIXct("2025-12-21 16:00:00", tz = "EST") ) # Render the more-accurate Praguq model (that requires # supplemental data that will be downloaded on the first call) and # specify a higher resolution environment map via `sky_args` render_highquality( min_variance = 0, samples = 16, long = -77.035249, lat = 38.889462, sky_args = list(hosek = FALSE,resolution=4000), iso = 8, clamp_value = 10000, datetime = as.POSIXct("2025-12-21 16:00:00", tz = "EST") ) }
Adds a marker and label to the current 3D plot
render_label( heightmap, text, lat, long, altitude = NULL, extent = NULL, x = NULL, y = NULL, z = NULL, zscale = 1, relativez = TRUE, offset = 0, clear_previous = FALSE, textsize = 1, dashed = FALSE, dashlength = "auto", linewidth = 3, antialias = FALSE, alpha = 1, textalpha = 1, freetype = TRUE, adjustvec = NULL, family = "sans", fonttype = "standard", linecolor = "black", textcolor = "black" )render_label( heightmap, text, lat, long, altitude = NULL, extent = NULL, x = NULL, y = NULL, z = NULL, zscale = 1, relativez = TRUE, offset = 0, clear_previous = FALSE, textsize = 1, dashed = FALSE, dashlength = "auto", linewidth = 3, antialias = FALSE, alpha = 1, textalpha = 1, freetype = TRUE, adjustvec = NULL, family = "sans", fonttype = "standard", linecolor = "black", textcolor = "black" )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced. |
text |
The label text. |
lat |
A latitude for the text. Must provide an |
long |
A latitude for the text. Must provide an |
altitude |
Default |
extent |
Either an object representing the spatial extent of the scene
(either from the |
x |
Default |
y |
Default |
z |
Default |
zscale |
Default |
relativez |
Default |
offset |
Elevation above the surface (at the label point) to start drawing the line. |
clear_previous |
Default |
textsize |
Default |
dashed |
Default |
dashlength |
Default |
linewidth |
Default |
antialias |
Default |
alpha |
Default |
textalpha |
Default |
freetype |
Default |
adjustvec |
Default |
family |
Default |
fonttype |
Default |
linecolor |
Default |
textcolor |
Default |
if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,water=TRUE, watercolor="#233aa1", zoom=0.9, windowsize = 800) render_snapshot() } santa_cruz = c(36.962957, -122.021033) #We want to add a label to Santa Cruz, so we use the x and y matrix coordinate (x=220 and y=330) if(run_documentation()) { render_label(montereybay,lat = santa_cruz[1], long = santa_cruz[2], extent = attr(montereybay, "extent"), textsize = 2, altitude=12000, zscale=50, text = "Santa Cruz") render_snapshot() } monterey = c(36.603053, -121.892933) #We can also change the linetype to dashed by setting `dashed = TRUE` (additional options allow #the user to control the dash length). You can clear the existing lines by setting #`clear_previous = TRUE`. if(run_documentation()) { render_label(montereybay, lat = monterey[1], long = monterey[2], altitude = 10000, extent = attr(montereybay, "extent"), textsize = 2, zscale = 50, text = "Monterey", textcolor = "white", linecolor="darkred", dashed = TRUE, clear_previous = TRUE) render_snapshot() } canyon = c(36.621049, -122.333912) #By default, z specifies the altitude above that point on the elevation matrix. We can also specify #an absolute height by setting `relativez=FALSE`. if(run_documentation()) { render_label(montereybay,lat=canyon[1], long = canyon[2], altitude = 2000, extent = attr(montereybay,"extent"), textsize = 2, zscale=50,text = "Monterey Canyon", relativez=FALSE) render_snapshot() } #We can also render labels in high quality with `render_highquality()`, specifying a custom #line radius. By default, the labels point towards the camera, but you can fix their angle with #argument `text_angle`. if(run_documentation()) { render_camera(theta=35, phi = 35, zoom = 0.80, fov=60) render_label(montereybay, lat = monterey[1], long = monterey[2], altitude = 10000, extent = attr(montereybay, "extent"), textsize = 2, zscale = 50, text = "Monterey", textcolor = "white", linecolor="darkred", dashed = TRUE, clear_previous = TRUE) render_label(montereybay,lat=canyon[1], long = canyon[2], altitude = 2000, zscale=50, textsize = 2, extent = attr(montereybay,"extent"), textcolor = "white", linecolor="white", text = "Monterey Canyon", relativez=FALSE) render_highquality(samples = 16,text_size = 64, line_radius = 3, text_offset = c(0, 20, 0), lightdirection = 180, min_variance = 0) } if(run_documentation()) { #Fixed text angle render_highquality(samples = 16,text_size = 64, line_radius = 3, text_offset = c(0, 20, 0), lightdirection = 180, text_angle = 0, min_variance = 0) } #We can remove all existing labels by calling `render_label(clear_previous = TRUE)` if(run_documentation()) { render_label(clear_previous = TRUE) render_snapshot() }if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,water=TRUE, watercolor="#233aa1", zoom=0.9, windowsize = 800) render_snapshot() } santa_cruz = c(36.962957, -122.021033) #We want to add a label to Santa Cruz, so we use the x and y matrix coordinate (x=220 and y=330) if(run_documentation()) { render_label(montereybay,lat = santa_cruz[1], long = santa_cruz[2], extent = attr(montereybay, "extent"), textsize = 2, altitude=12000, zscale=50, text = "Santa Cruz") render_snapshot() } monterey = c(36.603053, -121.892933) #We can also change the linetype to dashed by setting `dashed = TRUE` (additional options allow #the user to control the dash length). You can clear the existing lines by setting #`clear_previous = TRUE`. if(run_documentation()) { render_label(montereybay, lat = monterey[1], long = monterey[2], altitude = 10000, extent = attr(montereybay, "extent"), textsize = 2, zscale = 50, text = "Monterey", textcolor = "white", linecolor="darkred", dashed = TRUE, clear_previous = TRUE) render_snapshot() } canyon = c(36.621049, -122.333912) #By default, z specifies the altitude above that point on the elevation matrix. We can also specify #an absolute height by setting `relativez=FALSE`. if(run_documentation()) { render_label(montereybay,lat=canyon[1], long = canyon[2], altitude = 2000, extent = attr(montereybay,"extent"), textsize = 2, zscale=50,text = "Monterey Canyon", relativez=FALSE) render_snapshot() } #We can also render labels in high quality with `render_highquality()`, specifying a custom #line radius. By default, the labels point towards the camera, but you can fix their angle with #argument `text_angle`. if(run_documentation()) { render_camera(theta=35, phi = 35, zoom = 0.80, fov=60) render_label(montereybay, lat = monterey[1], long = monterey[2], altitude = 10000, extent = attr(montereybay, "extent"), textsize = 2, zscale = 50, text = "Monterey", textcolor = "white", linecolor="darkred", dashed = TRUE, clear_previous = TRUE) render_label(montereybay,lat=canyon[1], long = canyon[2], altitude = 2000, zscale=50, textsize = 2, extent = attr(montereybay,"extent"), textcolor = "white", linecolor="white", text = "Monterey Canyon", relativez=FALSE) render_highquality(samples = 16,text_size = 64, line_radius = 3, text_offset = c(0, 20, 0), lightdirection = 180, min_variance = 0) } if(run_documentation()) { #Fixed text angle render_highquality(samples = 16,text_size = 64, line_radius = 3, text_offset = c(0, 20, 0), lightdirection = 180, text_angle = 0, min_variance = 0) } #We can remove all existing labels by calling `render_label(clear_previous = TRUE)` if(run_documentation()) { render_label(clear_previous = TRUE) render_snapshot() }
Renders a movie using the av or gifski packages. Moves the camera around a 3D visualization
using either a standard orbit, or accepts vectors listing user-defined values for each camera parameter. If the latter,
the values must be equal in length to frames (or of length 1, in which the value will be fixed).
Additional arguments are forwarded to render_snapshot() for additional customization arguments (like
adding titles).
render_movie( filename, type = "orbit", frames = 360, fps = 30, phi = 30, theta = 0, zoom = NULL, fov = NULL, width = NULL, height = NULL, audio = NULL, progbar = interactive(), ... )render_movie( filename, type = "orbit", frames = 360, fps = 30, phi = 30, theta = 0, zoom = NULL, fov = NULL, width = NULL, height = NULL, audio = NULL, progbar = interactive(), ... )
filename |
Filename. If not appended with |
type |
Default |
frames |
Default |
fps |
Default |
phi |
Defaults to current view. Azimuth values, in degrees. |
theta |
Default to current view. Theta values, in degrees. |
zoom |
Defaults to the current view. Zoom value, between |
fov |
Defaults to the current view. Field of view values, in degrees. |
width |
Default |
height |
Default |
audio |
Default |
progbar |
Default |
... |
Additional parameters to pass to |
if(interactive()) { filename_movie = tempfile() #By default, the function produces a 12 second orbit at 30 frames per second, at 30 degrees azimuth. montereybay |> sphere_shade(texture="imhof1") |> plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof1", waterlinecolor="white", waterlinealpha=0.5) #Un-comment the following to run: #render_movie(filename = filename_movie) filename_movie = tempfile() #You can change to an oscillating orbit. The magnification is increased and azimuth angle set to 30. #A title has also been added using the title_text argument. #Un-comment the following to run: #render_movie(filename = filename_movie, type = "oscillate", # frames = 60, phi = 30, zoom = 0.8, theta = -90, # title_text = "Monterey Bay: Oscillating") filename_movie = tempfile() #Finally, you can pass your own set of values to the #camera parameters as a vector with type = "custom". phivechalf = 30 + 60 * 1/(1 + exp(seq(-7, 20, length.out = 180)/2)) phivecfull = c(phivechalf, rev(phivechalf)) thetavec = -90 + 45 * sin(seq(0,359,length.out = 360) * pi/180) zoomvec = 0.45 + 0.2 * 1/(1 + exp(seq(-5, 20, length.out = 180))) zoomvecfull = c(zoomvec, rev(zoomvec)) #Un-comment the following to run #render_movie(filename = filename_movie, type = "custom", # frames = 360, phi = phivecfull, zoom = zoomvecfull, theta = thetavec) }if(interactive()) { filename_movie = tempfile() #By default, the function produces a 12 second orbit at 30 frames per second, at 30 degrees azimuth. montereybay |> sphere_shade(texture="imhof1") |> plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof1", waterlinecolor="white", waterlinealpha=0.5) #Un-comment the following to run: #render_movie(filename = filename_movie) filename_movie = tempfile() #You can change to an oscillating orbit. The magnification is increased and azimuth angle set to 30. #A title has also been added using the title_text argument. #Un-comment the following to run: #render_movie(filename = filename_movie, type = "oscillate", # frames = 60, phi = 30, zoom = 0.8, theta = -90, # title_text = "Monterey Bay: Oscillating") filename_movie = tempfile() #Finally, you can pass your own set of values to the #camera parameters as a vector with type = "custom". phivechalf = 30 + 60 * 1/(1 + exp(seq(-7, 20, length.out = 180)/2)) phivecfull = c(phivechalf, rev(phivechalf)) thetavec = -90 + 45 * sin(seq(0,359,length.out = 360) * pi/180) zoomvec = 0.45 + 0.2 * 1/(1 + exp(seq(-5, 20, length.out = 180))) zoomvecfull = c(zoomvec, rev(zoomvec)) #Un-comment the following to run #render_movie(filename = filename_movie, type = "custom", # frames = 360, phi = phivecfull, zoom = zoomvecfull, theta = thetavec) }
Adds MULTIPOLYGONZ will be plotted in the coordinate system set by the user-specified
extent argument as-is.
You can also use save_multipolygonz_to_obj() manually to convert sf objects
render_multipolygonz( sfobj, extent = NULL, zscale = 1, heightmap = NULL, color = "grey50", offset = 0, obj_zscale = TRUE, swap_yz = TRUE, clear_previous = FALSE, baseshape = "rectangle", rgl_tag = "_multipolygon", ... )render_multipolygonz( sfobj, extent = NULL, zscale = 1, heightmap = NULL, color = "grey50", offset = 0, obj_zscale = TRUE, swap_yz = TRUE, clear_previous = FALSE, baseshape = "rectangle", rgl_tag = "_multipolygon", ... )
sfobj |
An sf object with MULTIPOLYGON Z geometry. |
extent |
Either an object representing the spatial extent of the scene
(either from the |
zscale |
Default |
heightmap |
Default |
color |
Default |
offset |
Default |
obj_zscale |
Default |
swap_yz |
Default |
clear_previous |
Default |
baseshape |
Default |
rgl_tag |
Default |
... |
Additional arguments to pass to |
run_examples = length(find.package("sf", quiet = TRUE)) && length(find.package("elevatr", quiet = TRUE)) && length(find.package("raster", quiet = TRUE)) && run_documentation() if(run_examples) { library(sf) #Set location of washington monument washington_monument_location = st_point(c(-77.035249, 38.889462)) wm_point = washington_monument_location |> st_point() |> st_sfc(crs = 4326) |> st_transform(st_crs(washington_monument_multipolygonz)) elevation_data = elevatr::get_elev_raster(locations = wm_point, z = 14) scene_bbox = st_bbox(st_buffer(wm_point,300)) cropped_data = raster::crop(elevation_data, scene_bbox) #Use rayshader to convert that raster data to a matrix dc_elevation_matrix = raster_to_matrix(cropped_data) #Remove negative elevation data dc_elevation_matrix[dc_elevation_matrix < 0] = 0 #Plot a 3D map of the national mall dc_elevation_matrix |> height_shade() |> add_shadow(lamb_shade(dc_elevation_matrix), 0) |> plot_3d(dc_elevation_matrix, zscale=3.7, water = TRUE, waterdepth = 1, soliddepth=-50, windowsize = 800) render_snapshot() } if(run_examples) { #Zoom in on the monument render_camera(theta=150, phi=35, zoom= 0.55, fov=70) #Render the national monument rgl::par3d(ignoreExtent = TRUE) render_multipolygonz(washington_monument_multipolygonz, extent = raster::extent(cropped_data), zscale = 4, color = "grey80", heightmap = dc_elevation_matrix) render_snapshot() } if(run_examples) { #This works with `render_highquality()` render_highquality(min_variance = 0, samples = 16) }run_examples = length(find.package("sf", quiet = TRUE)) && length(find.package("elevatr", quiet = TRUE)) && length(find.package("raster", quiet = TRUE)) && run_documentation() if(run_examples) { library(sf) #Set location of washington monument washington_monument_location = st_point(c(-77.035249, 38.889462)) wm_point = washington_monument_location |> st_point() |> st_sfc(crs = 4326) |> st_transform(st_crs(washington_monument_multipolygonz)) elevation_data = elevatr::get_elev_raster(locations = wm_point, z = 14) scene_bbox = st_bbox(st_buffer(wm_point,300)) cropped_data = raster::crop(elevation_data, scene_bbox) #Use rayshader to convert that raster data to a matrix dc_elevation_matrix = raster_to_matrix(cropped_data) #Remove negative elevation data dc_elevation_matrix[dc_elevation_matrix < 0] = 0 #Plot a 3D map of the national mall dc_elevation_matrix |> height_shade() |> add_shadow(lamb_shade(dc_elevation_matrix), 0) |> plot_3d(dc_elevation_matrix, zscale=3.7, water = TRUE, waterdepth = 1, soliddepth=-50, windowsize = 800) render_snapshot() } if(run_examples) { #Zoom in on the monument render_camera(theta=150, phi=35, zoom= 0.55, fov=70) #Render the national monument rgl::par3d(ignoreExtent = TRUE) render_multipolygonz(washington_monument_multipolygonz, extent = raster::extent(cropped_data), zscale = 4, color = "grey80", heightmap = dc_elevation_matrix) render_snapshot() } if(run_examples) { #This works with `render_highquality()` render_highquality(min_variance = 0, samples = 16) }
Adds 3D OBJ model to the current scene, using latitude/longitude or coordinates in the reference system defined by the extent object. If no altitude is provided, the OBJ will be elevated a constant offset above the heightmap. If the OBJ goes off the edge, the OBJ will be filtered out.
If no latitudes or longitudes are passed in, the OBJ will be plotted in the coordinate system set by the user-specified
extent argument as-is. Use this alongside save_multipolygonz_to_obj() to plot 3D polygons imported from geospatial sources
in the proper location (but for ease of use, use render_multipolygonz() to plot this data directly).
render_obj( filename, extent = NULL, lat = NULL, long = NULL, altitude = NULL, xyz = NULL, zscale = 1, heightmap = NULL, load_material = FALSE, load_normals = TRUE, color = "grey50", offset = 0, obj_zscale = FALSE, swap_yz = NULL, angle = c(0, 0, 0), scale = c(1, 1, 1), clear_previous = FALSE, baseshape = "rectangle", lit = FALSE, light_altitude = c(45, 30), light_direction = c(315, 135), light_intensity = 0.3, light_relative = FALSE, rgl_tag = "", ... )render_obj( filename, extent = NULL, lat = NULL, long = NULL, altitude = NULL, xyz = NULL, zscale = 1, heightmap = NULL, load_material = FALSE, load_normals = TRUE, color = "grey50", offset = 0, obj_zscale = FALSE, swap_yz = NULL, angle = c(0, 0, 0), scale = c(1, 1, 1), clear_previous = FALSE, baseshape = "rectangle", lit = FALSE, light_altitude = c(45, 30), light_direction = c(315, 135), light_intensity = 0.3, light_relative = FALSE, rgl_tag = "", ... )
filename |
Filename for the OBJ file. |
extent |
Either an object representing the spatial extent of the scene
(either from the |
lat |
Vector of latitudes (or other coordinate in the same coordinate reference system as extent). |
long |
Vector of longitudes (or other coordinate in the same coordinate reference system as extent). |
altitude |
Default |
xyz |
Default |
zscale |
Default |
heightmap |
Default |
load_material |
Default |
load_normals |
Default |
color |
Default |
offset |
Default |
obj_zscale |
Default |
swap_yz |
Default |
angle |
Default |
scale |
Default |
clear_previous |
Default |
baseshape |
Default |
lit |
Default |
light_altitude |
Default |
light_direction |
Default |
light_intensity |
Default |
light_relative |
Default |
rgl_tag |
Default |
... |
Additional arguments to pass to |
if(run_documentation()) { #Render the 3D map moss_landing_coord = c(36.806807, -121.793332) montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,water=TRUE, shadowcolor="#40310a", background = "tan", theta=210, phi=22, zoom=0.20, fov=55) t = seq(0,2*pi,length.out=100) circle_coords_lat = moss_landing_coord[1] + 0.3 * sin(t) circle_coords_long = moss_landing_coord[2] + 0.3 * cos(t) #Create a rainbow spectrum of flags render_obj(flag_full_obj(), extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), scale=c(2,2,2), angle=c(0,45,0), zscale=50, color=rainbow(100), smooth = FALSE, clear_previous = TRUE) render_snapshot() } if(run_documentation()) { #Rotate the flag to follow the circle render_obj(flag_full_obj(), extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), scale=c(2,2,2), angle=matrix(c(rep(0,100), seq(0,-360,length.out=101)[-1],rep(0,100)),ncol=3), zscale=50, color=rainbow(100), smooth = FALSE, clear_previous = TRUE) render_snapshot() } if(run_documentation()) { #Style the pole with a different color render_obj(flag_pole_obj(), extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), scale=c(2,2,2), angle=matrix(c(rep(0,100), seq(0,-360,length.out=101)[-1],rep(0,100)),ncol=3), zscale=50, color="grey20", smooth = FALSE, clear_previous = TRUE) render_obj(flag_banner_obj(), extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), scale=c(2,2,2), angle=matrix(c(rep(0,100), seq(0,-360,length.out=101)[-1],rep(0,100)),ncol=3), zscale=50, color=rainbow(100), smooth = FALSE) #And all of these work with `render_highquality()` render_highquality(samples = 16) }if(run_documentation()) { #Render the 3D map moss_landing_coord = c(36.806807, -121.793332) montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,water=TRUE, shadowcolor="#40310a", background = "tan", theta=210, phi=22, zoom=0.20, fov=55) t = seq(0,2*pi,length.out=100) circle_coords_lat = moss_landing_coord[1] + 0.3 * sin(t) circle_coords_long = moss_landing_coord[2] + 0.3 * cos(t) #Create a rainbow spectrum of flags render_obj(flag_full_obj(), extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), scale=c(2,2,2), angle=c(0,45,0), zscale=50, color=rainbow(100), smooth = FALSE, clear_previous = TRUE) render_snapshot() } if(run_documentation()) { #Rotate the flag to follow the circle render_obj(flag_full_obj(), extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), scale=c(2,2,2), angle=matrix(c(rep(0,100), seq(0,-360,length.out=101)[-1],rep(0,100)),ncol=3), zscale=50, color=rainbow(100), smooth = FALSE, clear_previous = TRUE) render_snapshot() } if(run_documentation()) { #Style the pole with a different color render_obj(flag_pole_obj(), extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), scale=c(2,2,2), angle=matrix(c(rep(0,100), seq(0,-360,length.out=101)[-1],rep(0,100)),ncol=3), zscale=50, color="grey20", smooth = FALSE, clear_previous = TRUE) render_obj(flag_banner_obj(), extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), scale=c(2,2,2), angle=matrix(c(rep(0,100), seq(0,-360,length.out=101)[-1],rep(0,100)),ncol=3), zscale=50, color=rainbow(100), smooth = FALSE) #And all of these work with `render_highquality()` render_highquality(samples = 16) }
Adds a 3D path to the current scene, using latitude/longitude or coordinates in the reference system defined by the extent object. If no altitude is provided, the path will be elevated a constant offset above the heightmap. If the path goes off the edge, the nearest height on the heightmap will be used.
render_path( lat, long = NULL, altitude = NULL, groups = NULL, extent = NULL, zscale = 1, heightmap = NULL, resample_evenly = FALSE, resample_n = 360, reorder = FALSE, reorder_first_index = 1, reorder_duplicate_tolerance = 0.1, reorder_merge_tolerance = 1, simplify_tolerance = 0, linewidth = 0.5, color = "black", antialias = FALSE, offset = 5, clear_previous = FALSE, return_coords = FALSE, tag = "path3d" )render_path( lat, long = NULL, altitude = NULL, groups = NULL, extent = NULL, zscale = 1, heightmap = NULL, resample_evenly = FALSE, resample_n = 360, reorder = FALSE, reorder_first_index = 1, reorder_duplicate_tolerance = 0.1, reorder_merge_tolerance = 1, simplify_tolerance = 0, linewidth = 0.5, color = "black", antialias = FALSE, offset = 5, clear_previous = FALSE, return_coords = FALSE, tag = "path3d" )
lat |
Vector of latitudes (or other coordinate in the same coordinate reference system as extent).
Can also be an |
long |
Default |
altitude |
Default |
groups |
Default |
extent |
Either an object representing the spatial extent of the 3D scene
(either from the |
zscale |
Default |
heightmap |
Default |
resample_evenly |
Default |
resample_n |
Default |
reorder |
Default |
reorder_first_index |
Default |
reorder_duplicate_tolerance |
Default |
reorder_merge_tolerance |
Default |
simplify_tolerance |
Default |
linewidth |
Default |
color |
Default |
antialias |
Default |
offset |
Default |
clear_previous |
Default |
return_coords |
Default |
tag |
Default |
if(run_documentation()) { #Starting at Moss Landing in Monterey Bay, we are going to simulate a flight of a bird going #out to sea and diving for food. #First, create simulated lat/long data set.seed(2009) moss_landing_coord = c(36.806807, -121.793332) x_vel_out = -0.001 + rnorm(1000)[1:300]/1000 y_vel_out = rnorm(1000)[1:300]/200 z_out = c(seq(0,2000,length.out = 180), seq(2000,0,length.out=10), seq(0,2000,length.out = 100), seq(2000,0,length.out=10)) bird_track_lat = list() bird_track_long = list() bird_track_lat[[1]] = moss_landing_coord[1] bird_track_long[[1]] = moss_landing_coord[2] for(i in 2:300) { bird_track_lat[[i]] = bird_track_lat[[i-1]] + y_vel_out[i] bird_track_long[[i]] = bird_track_long[[i-1]] + x_vel_out[i] } #Render the 3D map montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,water=TRUE, shadowcolor="#40310a", watercolor="#233aa1", background = "tan", theta=210, phi=22, zoom=0.20, fov=55) #Pass in the extent of the underlying raster (stored in an attribute for the montereybay #dataset) and the latitudes, longitudes, and altitudes of the track. render_path(extent = attr(montereybay,"extent"), lat = unlist(bird_track_lat), long = unlist(bird_track_long), altitude = z_out, zscale=50,color="white", antialias=TRUE) render_snapshot() } if(run_documentation()) { #We'll set the altitude to right above the water to give the tracks a "shadow". render_path(extent = attr(montereybay,"extent"), lat = unlist(bird_track_lat), long = unlist(bird_track_long), altitude = 10, zscale=50, color="black", antialias=TRUE) render_camera(theta=30,phi=35,zoom=0.45,fov=70) render_snapshot() } if(run_documentation()) { #Remove the path: render_path(clear_previous=TRUE) #Finally, we can also plot just GPS coordinates offset from the surface by leaving altitude `NULL` # Here we plot a spiral of values surrounding Moss Landing. This requires the original heightmap. t = seq(0,2*pi,length.out=1000) circle_coords_lat = moss_landing_coord[1] + 0.5 * t/8 * sin(t*6) circle_coords_long = moss_landing_coord[2] + 0.5 * t/8 * cos(t*6) render_path(extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50, color="red", antialias=TRUE,offset=100, linewidth=5) render_camera(theta = 160, phi=33, zoom=0.4, fov=55) render_snapshot() } if(run_documentation()) { #And all of these work with `render_highquality()`. Here, I set `use_extruded_paths = TRUE` #to get thick continuous paths. render_highquality(line_radius=1, min_variance = 0, use_extruded_paths = TRUE, samples = 16) } if(run_documentation()) { #We can also change the material of the objects by setting the `point_material` and #`point_material_args` arguments in `render_highquality()` render_highquality(line_radius=1, min_variance = 0, samples = 16, path_material = rayrender::glossy, use_extruded_paths = TRUE, path_material_args = list(gloss = 0.5, reflectance = 0.2)) } if(run_documentation()) { #For transmissive materials (like `dielectric`), we should specify that the path #should be rendered with an extruded path. We'll use the `attenuation` argument in #the `dielectric` function to specify a realistic glass color. render_path(extent = attr(montereybay,"extent"), heightmap = montereybay, clear_previous = TRUE, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50, color="white", offset=200, linewidth=5) render_highquality(line_radius=1, min_variance = 0, samples = 16, lightsize = 2000, lightintensity = 10, path_material = rayrender::dielectric, use_extruded_paths = TRUE, path_material_args = list(refraction = 1.5, attenuation = c(0.05,0.2,0.2))) }if(run_documentation()) { #Starting at Moss Landing in Monterey Bay, we are going to simulate a flight of a bird going #out to sea and diving for food. #First, create simulated lat/long data set.seed(2009) moss_landing_coord = c(36.806807, -121.793332) x_vel_out = -0.001 + rnorm(1000)[1:300]/1000 y_vel_out = rnorm(1000)[1:300]/200 z_out = c(seq(0,2000,length.out = 180), seq(2000,0,length.out=10), seq(0,2000,length.out = 100), seq(2000,0,length.out=10)) bird_track_lat = list() bird_track_long = list() bird_track_lat[[1]] = moss_landing_coord[1] bird_track_long[[1]] = moss_landing_coord[2] for(i in 2:300) { bird_track_lat[[i]] = bird_track_lat[[i-1]] + y_vel_out[i] bird_track_long[[i]] = bird_track_long[[i-1]] + x_vel_out[i] } #Render the 3D map montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,water=TRUE, shadowcolor="#40310a", watercolor="#233aa1", background = "tan", theta=210, phi=22, zoom=0.20, fov=55) #Pass in the extent of the underlying raster (stored in an attribute for the montereybay #dataset) and the latitudes, longitudes, and altitudes of the track. render_path(extent = attr(montereybay,"extent"), lat = unlist(bird_track_lat), long = unlist(bird_track_long), altitude = z_out, zscale=50,color="white", antialias=TRUE) render_snapshot() } if(run_documentation()) { #We'll set the altitude to right above the water to give the tracks a "shadow". render_path(extent = attr(montereybay,"extent"), lat = unlist(bird_track_lat), long = unlist(bird_track_long), altitude = 10, zscale=50, color="black", antialias=TRUE) render_camera(theta=30,phi=35,zoom=0.45,fov=70) render_snapshot() } if(run_documentation()) { #Remove the path: render_path(clear_previous=TRUE) #Finally, we can also plot just GPS coordinates offset from the surface by leaving altitude `NULL` # Here we plot a spiral of values surrounding Moss Landing. This requires the original heightmap. t = seq(0,2*pi,length.out=1000) circle_coords_lat = moss_landing_coord[1] + 0.5 * t/8 * sin(t*6) circle_coords_long = moss_landing_coord[2] + 0.5 * t/8 * cos(t*6) render_path(extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50, color="red", antialias=TRUE,offset=100, linewidth=5) render_camera(theta = 160, phi=33, zoom=0.4, fov=55) render_snapshot() } if(run_documentation()) { #And all of these work with `render_highquality()`. Here, I set `use_extruded_paths = TRUE` #to get thick continuous paths. render_highquality(line_radius=1, min_variance = 0, use_extruded_paths = TRUE, samples = 16) } if(run_documentation()) { #We can also change the material of the objects by setting the `point_material` and #`point_material_args` arguments in `render_highquality()` render_highquality(line_radius=1, min_variance = 0, samples = 16, path_material = rayrender::glossy, use_extruded_paths = TRUE, path_material_args = list(gloss = 0.5, reflectance = 0.2)) } if(run_documentation()) { #For transmissive materials (like `dielectric`), we should specify that the path #should be rendered with an extruded path. We'll use the `attenuation` argument in #the `dielectric` function to specify a realistic glass color. render_path(extent = attr(montereybay,"extent"), heightmap = montereybay, clear_previous = TRUE, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50, color="white", offset=200, linewidth=5) render_highquality(line_radius=1, min_variance = 0, samples = 16, lightsize = 2000, lightintensity = 10, path_material = rayrender::dielectric, use_extruded_paths = TRUE, path_material_args = list(refraction = 1.5, attenuation = c(0.05,0.2,0.2))) }
Adds 3D datapoints to the current scene, using latitude/longitude or coordinates in the reference system defined by the extent object. If no altitude is provided, the points will be elevated a constant offset above the heightmap. If the points goes off the edge, the nearest height on the heightmap will be used (unless that value is NA, in which the point will be removed).
render_points( lat = NULL, long = NULL, altitude = NULL, extent = NULL, zscale = 1, heightmap = NULL, size = 0.5, color = "black", offset = 5, clear_previous = FALSE )render_points( lat = NULL, long = NULL, altitude = NULL, extent = NULL, zscale = 1, heightmap = NULL, size = 0.5, color = "black", offset = 5, clear_previous = FALSE )
lat |
Vector of latitudes (or other coordinate in the same coordinate reference system as extent). |
long |
Vector of longitudes (or other coordinate in the same coordinate reference system as extent). |
altitude |
Default |
extent |
Either an object representing the spatial extent of the 3D scene
(either from the |
zscale |
Default |
heightmap |
Default |
size |
Default |
color |
Default |
offset |
Default |
clear_previous |
Default |
if(run_documentation()) { #Starting at Moss Landing in Monterey Bay, we are going to simulate a flight of a bird going #out to sea and diving for food. #First, create simulated lat/long data set.seed(2009) moss_landing_coord = c(36.806807, -121.793332) x_vel_out = -0.001 + rnorm(1000)[1:300]/1000 y_vel_out = rnorm(1000)[1:300]/200 z_out = c(seq(0,2000,length.out = 180), seq(2000,0,length.out=10), seq(0,2000,length.out = 100), seq(2000,0,length.out=10)) bird_track_lat = list() bird_track_long = list() bird_track_lat[[1]] = moss_landing_coord[1] bird_track_long[[1]] = moss_landing_coord[2] for(i in 2:300) { bird_track_lat[[i]] = bird_track_lat[[i-1]] + y_vel_out[i] bird_track_long[[i]] = bird_track_long[[i-1]] + x_vel_out[i] } #Render the 3D map montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,water=TRUE, shadowcolor="#40310a", background = "tan", theta=210, phi=22, zoom=0.20, fov=55) #Pass in the extent of the underlying raster (stored in an attribute for the montereybay #dataset) and the latitudes, longitudes, and altitudes of the track. render_points(extent = attr(montereybay,"extent"), lat = unlist(bird_track_lat), long = unlist(bird_track_long), altitude = z_out, zscale=50,color="white") render_snapshot() } if(run_documentation()) { #We'll set the altitude to zero to give the tracks a "shadow" over the water. render_points(extent = attr(montereybay,"extent"), lat = unlist(bird_track_lat), long = unlist(bird_track_long), offset = 0, zscale=50, color="black") render_camera(theta=30,phi=35,zoom=0.45,fov=70) render_snapshot() } if(run_documentation()) { #Remove the points: render_points(clear_previous=TRUE) # Finally, we can also plot just GPS coordinates offset from the surface by leaving altitude `NULL` # Here we plot a circle of values surrounding Moss Landing. This requires the original heightmap. t = seq(0,2*pi,length.out=100) circle_coords_lat = moss_landing_coord[1] + 0.3 * sin(t) circle_coords_long = moss_landing_coord[2] + 0.3 * cos(t) render_points(extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50, color="red", offset=100, size=5) render_camera(theta = 160, phi=33, zoom=0.4, fov=55) render_snapshot() } if(run_documentation()) { #And all of these work with `render_highquality()` render_highquality(point_radius = 1, min_variance = 0, samples = 16) } if(run_documentation()) { #We can also change the material of the objects by setting the `point_material` and #`point_material_args` arguments in `render_highquality()` render_highquality(point_radius = 1, min_variance = 0, samples = 16, point_material = rayrender::glossy, point_material_args = list(gloss = 0.5, reflectance = 0.2)) }if(run_documentation()) { #Starting at Moss Landing in Monterey Bay, we are going to simulate a flight of a bird going #out to sea and diving for food. #First, create simulated lat/long data set.seed(2009) moss_landing_coord = c(36.806807, -121.793332) x_vel_out = -0.001 + rnorm(1000)[1:300]/1000 y_vel_out = rnorm(1000)[1:300]/200 z_out = c(seq(0,2000,length.out = 180), seq(2000,0,length.out=10), seq(0,2000,length.out = 100), seq(2000,0,length.out=10)) bird_track_lat = list() bird_track_long = list() bird_track_lat[[1]] = moss_landing_coord[1] bird_track_long[[1]] = moss_landing_coord[2] for(i in 2:300) { bird_track_lat[[i]] = bird_track_lat[[i-1]] + y_vel_out[i] bird_track_long[[i]] = bird_track_long[[i-1]] + x_vel_out[i] } #Render the 3D map montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,water=TRUE, shadowcolor="#40310a", background = "tan", theta=210, phi=22, zoom=0.20, fov=55) #Pass in the extent of the underlying raster (stored in an attribute for the montereybay #dataset) and the latitudes, longitudes, and altitudes of the track. render_points(extent = attr(montereybay,"extent"), lat = unlist(bird_track_lat), long = unlist(bird_track_long), altitude = z_out, zscale=50,color="white") render_snapshot() } if(run_documentation()) { #We'll set the altitude to zero to give the tracks a "shadow" over the water. render_points(extent = attr(montereybay,"extent"), lat = unlist(bird_track_lat), long = unlist(bird_track_long), offset = 0, zscale=50, color="black") render_camera(theta=30,phi=35,zoom=0.45,fov=70) render_snapshot() } if(run_documentation()) { #Remove the points: render_points(clear_previous=TRUE) # Finally, we can also plot just GPS coordinates offset from the surface by leaving altitude `NULL` # Here we plot a circle of values surrounding Moss Landing. This requires the original heightmap. t = seq(0,2*pi,length.out=100) circle_coords_lat = moss_landing_coord[1] + 0.3 * sin(t) circle_coords_long = moss_landing_coord[2] + 0.3 * cos(t) render_points(extent = attr(montereybay,"extent"), heightmap = montereybay, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50, color="red", offset=100, size=5) render_camera(theta = 160, phi=33, zoom=0.4, fov=55) render_snapshot() } if(run_documentation()) { #And all of these work with `render_highquality()` render_highquality(point_radius = 1, min_variance = 0, samples = 16) } if(run_documentation()) { #We can also change the material of the objects by setting the `point_material` and #`point_material_args` arguments in `render_highquality()` render_highquality(point_radius = 1, min_variance = 0, samples = 16, point_material = rayrender::glossy, point_material_args = list(gloss = 0.5, reflectance = 0.2)) }
Adds 3D polygons to the current scene, using latitude/longitude or coordinates in the reference system defined by the extent object.
render_polygons( polygon, extent, color = "red", top = 1, bottom = NA, data_column_top = NULL, data_column_bottom = NULL, heightmap = NULL, scale_data = 1, parallel = FALSE, holes = 0, alpha = 1, lit = TRUE, light_altitude = c(45, 30), light_direction = c(315, 135), light_intensity = 0.3, light_relative = FALSE, clear_previous = FALSE )render_polygons( polygon, extent, color = "red", top = 1, bottom = NA, data_column_top = NULL, data_column_bottom = NULL, heightmap = NULL, scale_data = 1, parallel = FALSE, holes = 0, alpha = 1, lit = TRUE, light_altitude = c(45, 30), light_direction = c(315, 135), light_intensity = 0.3, light_relative = FALSE, clear_previous = FALSE )
polygon |
|
extent |
Either an object representing the spatial extent of the 3D scene
(either from the |
color |
Default |
top |
Default |
bottom |
Default |
data_column_top |
Default |
data_column_bottom |
Default |
heightmap |
Default |
scale_data |
Default |
parallel |
Default |
holes |
Default |
alpha |
Default |
lit |
Default |
light_altitude |
Default |
light_direction |
Default |
light_intensity |
Default |
light_relative |
Default |
clear_previous |
Default |
if(run_documentation()) { #Render the county borders as polygons in Monterey Bay montereybay |> sphere_shade(texture = "desert") |> add_shadow(ray_shade(montereybay,zscale = 50)) |> plot_3d(montereybay, water = TRUE, windowsize = 800, watercolor = "dodgerblue") render_camera(theta = 140, phi = 55, zoom = 0.85, fov = 30) #We will apply a negative buffer to create space between adjacent polygons. You may #have to call `sf::sf_use_s2(FALSE)` before running this code to get it to run. sf::sf_use_s2(FALSE) mont_county_buff = sf::st_simplify(sf::st_buffer(monterey_counties_sf,-0.003), dTolerance=0.001) render_polygons(mont_county_buff, extent = attr(montereybay,"extent"), top = 10, parallel = FALSE) render_snapshot() } if(run_documentation()) { #We can specify the bottom of the polygons as well. Here I float the polygons above the surface #by specifying the bottom argument. We clear the previous polygons with `clear_previous = TRUE`. render_camera(theta=-60, phi=20, zoom = 0.85, fov=0) render_polygons(mont_county_buff, extent = attr(montereybay,"extent"), bottom = 190, top=200, parallel=FALSE,clear_previous=TRUE) render_snapshot() } if(run_documentation()) { #We can set the height of the data to a column in the sf object: we'll use the land area. #We'll have to scale this value because its max value is 2.6 billion: render_camera(theta=-60, phi=60, zoom = 0.85, fov=30) render_polygons(mont_county_buff, extent = attr(montereybay, "extent"), data_column_top = "ALAND", scale_data = 300/(2.6E9), color = "chartreuse4", clear_previous = TRUE) render_snapshot() } if(run_documentation()) { #This function also works with `render_highquality()` render_highquality(samples = 16, min_variance = 0) }if(run_documentation()) { #Render the county borders as polygons in Monterey Bay montereybay |> sphere_shade(texture = "desert") |> add_shadow(ray_shade(montereybay,zscale = 50)) |> plot_3d(montereybay, water = TRUE, windowsize = 800, watercolor = "dodgerblue") render_camera(theta = 140, phi = 55, zoom = 0.85, fov = 30) #We will apply a negative buffer to create space between adjacent polygons. You may #have to call `sf::sf_use_s2(FALSE)` before running this code to get it to run. sf::sf_use_s2(FALSE) mont_county_buff = sf::st_simplify(sf::st_buffer(monterey_counties_sf,-0.003), dTolerance=0.001) render_polygons(mont_county_buff, extent = attr(montereybay,"extent"), top = 10, parallel = FALSE) render_snapshot() } if(run_documentation()) { #We can specify the bottom of the polygons as well. Here I float the polygons above the surface #by specifying the bottom argument. We clear the previous polygons with `clear_previous = TRUE`. render_camera(theta=-60, phi=20, zoom = 0.85, fov=0) render_polygons(mont_county_buff, extent = attr(montereybay,"extent"), bottom = 190, top=200, parallel=FALSE,clear_previous=TRUE) render_snapshot() } if(run_documentation()) { #We can set the height of the data to a column in the sf object: we'll use the land area. #We'll have to scale this value because its max value is 2.6 billion: render_camera(theta=-60, phi=60, zoom = 0.85, fov=30) render_polygons(mont_county_buff, extent = attr(montereybay, "extent"), data_column_top = "ALAND", scale_data = 300/(2.6E9), color = "chartreuse4", clear_previous = TRUE) render_snapshot() } if(run_documentation()) { #This function also works with `render_highquality()` render_highquality(samples = 16, min_variance = 0) }
Adds 3D raymesh model to the current scene, using latitude/longitude or coordinates in the reference system defined by the extent object. If no altitude is provided, the raymesh will be elevated a constant offset above the heightmap. If the raymesh goes off the edge, the raymesh will be filtered out.
If no latitudes or longitudes are passed in, the raymesh will be plotted in the coordinate system set by the user-specified
extent argument as-is. Use this alongside save_multipolygonz_to_obj() to plot 3D polygons imported from geospatial sources
in the proper location (but for ease of use, use render_multipolygonz() to plot this data directly).
render_raymesh( raymesh, extent = NULL, lat = NULL, long = NULL, altitude = NULL, xyz = NULL, zscale = 1, heightmap = NULL, load_normals = TRUE, change_material = TRUE, color = "grey50", offset = 0, obj_zscale = FALSE, swap_yz = NULL, angle = c(0, 0, 0), scale = c(1, 1, 1), clear_previous = FALSE, baseshape = "rectangle", flat_shading = FALSE, lit = FALSE, light_altitude = c(45, 30), light_direction = c(315, 135), light_intensity = 1, light_relative = FALSE, rgl_tag = "", ... )render_raymesh( raymesh, extent = NULL, lat = NULL, long = NULL, altitude = NULL, xyz = NULL, zscale = 1, heightmap = NULL, load_normals = TRUE, change_material = TRUE, color = "grey50", offset = 0, obj_zscale = FALSE, swap_yz = NULL, angle = c(0, 0, 0), scale = c(1, 1, 1), clear_previous = FALSE, baseshape = "rectangle", flat_shading = FALSE, lit = FALSE, light_altitude = c(45, 30), light_direction = c(315, 135), light_intensity = 1, light_relative = FALSE, rgl_tag = "", ... )
raymesh |
|
extent |
Either an object representing the spatial extent of the scene
(either from the |
lat |
Vector of latitudes (or other coordinate in the same coordinate reference system as extent). |
long |
Vector of longitudes (or other coordinate in the same coordinate reference system as extent). |
altitude |
Default |
xyz |
Default |
zscale |
Default |
heightmap |
Default |
load_normals |
Default |
change_material |
Default |
color |
Default |
offset |
Default |
obj_zscale |
Default |
swap_yz |
Default |
angle |
Default |
scale |
Default |
clear_previous |
Default |
baseshape |
Default |
flat_shading |
Default |
lit |
Default |
light_altitude |
Default |
light_direction |
Default |
light_intensity |
Default |
light_relative |
Default |
rgl_tag |
Default |
... |
Additional arguments to pass to |
if(run_documentation()) { }if(run_documentation()) { }
Resize the rgl Window
render_resize_window(width = NULL, height = NULL)render_resize_window(width = NULL, height = NULL)
width |
Default |
height |
Default |
None
#Resize the rgl window to various sizes if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,zoom=0.6,theta=-90,phi=30) render_resize_window(width = 800, height = 800) render_snapshot() } if(run_documentation()) { render_resize_window(width = 200, height = 200) render_snapshot() } if(run_documentation()) { render_resize_window(width = 800, height = 400) render_snapshot() }#Resize the rgl window to various sizes if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,zoom=0.6,theta=-90,phi=30) render_resize_window(width = 800, height = 800) render_snapshot() } if(run_documentation()) { render_resize_window(width = 200, height = 200) render_snapshot() } if(run_documentation()) { render_resize_window(width = 800, height = 400) render_snapshot() }
Places a scale bar on the map in 3D.
render_scalebar( limits, position = "W", y = NULL, segments = 10, scale_length = 1, label_unit = "", offset = NULL, radius = NULL, color_first = "darkred", color_second = "grey80", color_text = "black", text_switch_side = FALSE, text_x_offset = 0, text_y_offset = 0, text_z_offset = 0, clear_scalebar = FALSE )render_scalebar( limits, position = "W", y = NULL, segments = 10, scale_length = 1, label_unit = "", offset = NULL, radius = NULL, color_first = "darkred", color_second = "grey80", color_text = "black", text_switch_side = FALSE, text_x_offset = 0, text_y_offset = 0, text_z_offset = 0, clear_scalebar = FALSE )
limits |
The distance represented by the scale bar. If a numeric vector greater than length 1, this will specify the breaks along the scale bar to place labels, with the maximum value in limits assumed to be the last label. Must be non-negative. |
position |
Default |
y |
Default |
segments |
Default |
scale_length |
Default |
label_unit |
Default |
offset |
Default |
radius |
Default |
color_first |
Default |
color_second |
Default |
color_text |
Default |
text_switch_side |
Default |
text_x_offset |
Default |
text_y_offset |
Default |
text_z_offset |
Default |
clear_scalebar |
Default |
Displays snapshot of current rgl plot (or saves to disk).
#Add a scale bar to the montereybay dataset, here representing about 80km if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,theta=45, water=TRUE) render_scalebar(limits=c(0, 80), label_unit = "km") render_snapshot() } if(run_documentation()) { #This function works with `render_highquality()` render_highquality(lightdirection = 250, lightaltitude = 40, scale_text_size = 36, samples = 16) render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #We can change the position by specifying a cardinal direction to `position`, and the #color by setting `color_first` and `color_second` render_scalebar(limits=c(0,80), label_unit = "km", position = "N", color_first = "darkgreen", color_second = "lightgreen") render_snapshot() render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #And switch the orientation by setting `text_switch_side = TRUE` render_scalebar(limits=c(0,80), label_unit = "km", position = "N", text_switch_side = TRUE, color_first = "darkgreen", color_second = "lightgreen") render_snapshot() render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #We can add additional breaks by specifying additional distances in `limits` render_scalebar(limits=c(0,40,80), label_unit = "km") render_snapshot() render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #We can also manually specify the height by setting the `y` argument: render_scalebar(limits=c(0,40,80), y=-70, label_unit = "km") render_snapshot() render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #Here we change the total size by specifying a start and end point along the side, #and set the number of colored `segments`: render_scalebar(limits=c(0,20, 40), segments = 4, scale_length = c(0.5,1), label_unit = "km") render_scalebar(limits=c(0,20, 40), segments = 4, position = "N", text_switch_side = TRUE, scale_length = c(0.25,0.75), label_unit = "km") render_snapshot() render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #Change the radius of the scale bar with `radius`. Here, the autopositioning doesn't work well with #the labels, so we provide additional offsets with `text_y_offset` and `text_x_offset` to fix it. render_scalebar(limits=c(0,20, 40), segments = 4, scale_length = c(0.5,1), label_unit = "km", radius=10,text_y_offset=-20,text_x_offset=20) render_snapshot() }#Add a scale bar to the montereybay dataset, here representing about 80km if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,theta=45, water=TRUE) render_scalebar(limits=c(0, 80), label_unit = "km") render_snapshot() } if(run_documentation()) { #This function works with `render_highquality()` render_highquality(lightdirection = 250, lightaltitude = 40, scale_text_size = 36, samples = 16) render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #We can change the position by specifying a cardinal direction to `position`, and the #color by setting `color_first` and `color_second` render_scalebar(limits=c(0,80), label_unit = "km", position = "N", color_first = "darkgreen", color_second = "lightgreen") render_snapshot() render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #And switch the orientation by setting `text_switch_side = TRUE` render_scalebar(limits=c(0,80), label_unit = "km", position = "N", text_switch_side = TRUE, color_first = "darkgreen", color_second = "lightgreen") render_snapshot() render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #We can add additional breaks by specifying additional distances in `limits` render_scalebar(limits=c(0,40,80), label_unit = "km") render_snapshot() render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #We can also manually specify the height by setting the `y` argument: render_scalebar(limits=c(0,40,80), y=-70, label_unit = "km") render_snapshot() render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #Here we change the total size by specifying a start and end point along the side, #and set the number of colored `segments`: render_scalebar(limits=c(0,20, 40), segments = 4, scale_length = c(0.5,1), label_unit = "km") render_scalebar(limits=c(0,20, 40), segments = 4, position = "N", text_switch_side = TRUE, scale_length = c(0.25,0.75), label_unit = "km") render_snapshot() render_scalebar(clear_scalebar = TRUE) } if(run_documentation()) { #Change the radius of the scale bar with `radius`. Here, the autopositioning doesn't work well with #the labels, so we provide additional offsets with `text_y_offset` and `text_x_offset` to fix it. render_scalebar(limits=c(0,20, 40), segments = 4, scale_length = c(0.5,1), label_unit = "km", radius=10,text_y_offset=-20,text_x_offset=20) render_snapshot() }
Either captures the current rgl view and displays, or saves the current view to disk.
render_snapshot( filename, clear = FALSE, title_text = NULL, title_offset = c(20, 20), title_color = "black", title_size = 30, title_font = "sans", title_bar_color = NA, title_bar_alpha = 0.5, title_just = "left", image_overlay = NULL, vignette = FALSE, vignette_color = "black", vignette_radius = 1.3, instant_capture = interactive(), bring_to_front = FALSE, webshot = FALSE, width = NULL, height = NULL, software_render = FALSE, camera_location = NULL, camera_lookat = c(0, 0, 0), background = NULL, text_angle = NULL, text_size = 30, text_offset = c(0, 0, 0), point_radius = 0.5, line_offset = 1e-07, thick_lines = TRUE, line_radius = 0.25, cache_scene = FALSE, reset_scene_cache = FALSE, new_page = TRUE, print_scene_info = FALSE, fsaa = 1, rayvertex_lighting = FALSE, rayvertex_lights = NULL, rayvertex_shadow_map = FALSE, plot = TRUE, ... )render_snapshot( filename, clear = FALSE, title_text = NULL, title_offset = c(20, 20), title_color = "black", title_size = 30, title_font = "sans", title_bar_color = NA, title_bar_alpha = 0.5, title_just = "left", image_overlay = NULL, vignette = FALSE, vignette_color = "black", vignette_radius = 1.3, instant_capture = interactive(), bring_to_front = FALSE, webshot = FALSE, width = NULL, height = NULL, software_render = FALSE, camera_location = NULL, camera_lookat = c(0, 0, 0), background = NULL, text_angle = NULL, text_size = 30, text_offset = c(0, 0, 0), point_radius = 0.5, line_offset = 1e-07, thick_lines = TRUE, line_radius = 0.25, cache_scene = FALSE, reset_scene_cache = FALSE, new_page = TRUE, print_scene_info = FALSE, fsaa = 1, rayvertex_lighting = FALSE, rayvertex_lights = NULL, rayvertex_shadow_map = FALSE, plot = TRUE, ... )
filename |
Filename of snapshot. If missing, will display to current device. |
clear |
Default |
title_text |
Default |
title_offset |
Default |
title_color |
Default |
title_size |
Default |
title_font |
Default |
title_bar_color |
Default |
title_bar_alpha |
Default |
title_just |
Default |
image_overlay |
Default |
vignette |
Default |
vignette_color |
Default |
vignette_radius |
Default |
instant_capture |
Default |
bring_to_front |
Default |
webshot |
Default |
width |
Default |
height |
Default |
software_render |
Default |
camera_location |
Default |
camera_lookat |
Default |
background |
Default |
text_angle |
Default |
text_size |
Default |
text_offset |
Default |
point_radius |
Default |
line_offset |
Default |
thick_lines |
Default |
line_radius |
Default |
cache_scene |
Default |
reset_scene_cache |
Default |
new_page |
Default |
print_scene_info |
Default |
fsaa |
Default |
rayvertex_lighting |
Default |
rayvertex_lights |
Default |
rayvertex_shadow_map |
Default |
plot |
Default |
... |
Additional parameters to pass to |
Displays snapshot of current rgl plot (or saves to disk), as well as invisibly returns an RGBA rayimg array.
if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,zoom=0.6,theta=-90,phi=30) } if(run_documentation()) { render_snapshot() } #Create a title if(run_documentation()) { render_snapshot(title_text = "Monterey Bay, California", title_offset=c(0,20), title_color = "white", title_bar_color = "black", title_font = "Helvetica", title_position = "north") #Add a vignette effect render_camera(zoom=0.8) render_snapshot(title_text = "Monterey Bay, California", title_color = "white", title_bar_color = "darkgreen", vignette = TRUE, title_offset=c(0,20), title_font = "Helvetica", title_position = "north") } #Use software rendering to render a scene with shadow mapping if(run_documentation()) { montereybay |> height_shade() |> plot_3d(montereybay, shadow=FALSE, solidlinecolor = NULL) #No shadows render_snapshot(software_render = TRUE) } if(run_documentation()) { #Now with shadow mapped shadows, calculated in rayvertex render_snapshot(rayvertex_lighting = TRUE, rayvertex_lights = rayvertex::directional_light(intensity = 1.2, direction = c(-1, 1, -1)), rayvertex_shadow_map = TRUE, software_render = TRUE) }if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,zoom=0.6,theta=-90,phi=30) } if(run_documentation()) { render_snapshot() } #Create a title if(run_documentation()) { render_snapshot(title_text = "Monterey Bay, California", title_offset=c(0,20), title_color = "white", title_bar_color = "black", title_font = "Helvetica", title_position = "north") #Add a vignette effect render_camera(zoom=0.8) render_snapshot(title_text = "Monterey Bay, California", title_color = "white", title_bar_color = "darkgreen", vignette = TRUE, title_offset=c(0,20), title_font = "Helvetica", title_position = "north") } #Use software rendering to render a scene with shadow mapping if(run_documentation()) { montereybay |> height_shade() |> plot_3d(montereybay, shadow=FALSE, solidlinecolor = NULL) #No shadows render_snapshot(software_render = TRUE) } if(run_documentation()) { #Now with shadow mapped shadows, calculated in rayvertex render_snapshot(rayvertex_lighting = TRUE, rayvertex_lights = rayvertex::directional_light(intensity = 1.2, direction = c(-1, 1, -1)), rayvertex_shadow_map = TRUE, software_render = TRUE) }
Adds a 3D representation of trees to an existing 3D scene generated with rayshader.
Users can specify the trees' geographical positions using latitude and longitude or the same coordinate reference system as extent.
Different types of tree models can be used, including a basic and a cone-shaped tree. Users can also use their own custom tree model in
OBJ format. The function allows customization of various aspects of the tree, including the color of the crown and the trunk,
the size of the crown (the leafy part of the tree) and the trunk, the overall scale of the tree, and the rotation angle around the x, y, and z axes.
Users can also specify the minimum and maximum height of the trees to be rendered.
render_tree( lat = NULL, long = NULL, extent = NULL, type = "basic", custom_obj_tree = NULL, custom_obj_crown = NULL, custom_obj_trunk = NULL, crown_color = "#22aa22", trunk_color = "#964B00", absolute_height = FALSE, tree_height = NULL, trunk_height_ratio = NULL, crown_width_ratio = NULL, crown_width = NULL, trunk_radius = NULL, tree_zscale = TRUE, min_height = 0, max_height = Inf, zscale = 1, lit = TRUE, heightmap = NULL, baseshape = "rectangle", angle = c(0, 0, 0), clear_previous = FALSE, ... )render_tree( lat = NULL, long = NULL, extent = NULL, type = "basic", custom_obj_tree = NULL, custom_obj_crown = NULL, custom_obj_trunk = NULL, crown_color = "#22aa22", trunk_color = "#964B00", absolute_height = FALSE, tree_height = NULL, trunk_height_ratio = NULL, crown_width_ratio = NULL, crown_width = NULL, trunk_radius = NULL, tree_zscale = TRUE, min_height = 0, max_height = Inf, zscale = 1, lit = TRUE, heightmap = NULL, baseshape = "rectangle", angle = c(0, 0, 0), clear_previous = FALSE, ... )
lat |
Vector of latitudes (or other coordinate in the same coordinate reference system as extent). |
long |
Vector of longitudes (or other coordinate in the same coordinate reference system as extent). |
extent |
Either an object representing the spatial extent of the 3D scene
(either from the |
type |
Default |
custom_obj_tree |
Default |
custom_obj_crown |
Default |
custom_obj_trunk |
Default |
crown_color |
Default |
trunk_color |
Default |
absolute_height |
Default |
tree_height |
Default |
trunk_height_ratio |
Default |
crown_width_ratio |
Default |
crown_width |
Default |
trunk_radius |
Default |
tree_zscale |
Default |
min_height |
Default |
max_height |
Default |
zscale |
Default |
lit |
Default |
heightmap |
Default |
baseshape |
Default |
angle |
Default |
clear_previous |
Default |
... |
Additional arguments to pass to |
if(run_documentation()) { #Let's first start by drawing some trees in a circle around Monterey Bay #We won't scale these to a realistic size (yet) moss_landing_coord = c(36.806807, -121.793332) montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,water=TRUE, shadowcolor="#40310a", background = "tan", theta=210, phi=22, zoom=0.20, fov=55) t = seq(0,2*pi,length.out=20) circle_coords_lat = moss_landing_coord[1] + 0.3 * sin(t) circle_coords_long = moss_landing_coord[2] + 0.3 * cos(t) render_tree(extent = attr(montereybay,"extent"), heightmap = montereybay, tree_zscale = FALSE, tree_height = 30, lit = TRUE, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50) render_snapshot() } if(run_documentation()) { #Change the crown width ratio (compared to the height) render_tree(extent = attr(montereybay,"extent"), heightmap = montereybay, tree_zscale = FALSE, tree_height = 60, crown_width_ratio = 0.5, clear_previous = TRUE, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50) render_snapshot() } if(run_documentation()) { #Change the trunk height and width render_tree(extent = attr(montereybay,"extent"), heightmap = montereybay, tree_zscale = FALSE, tree_height = 40, crown_width_ratio = 2, clear_previous = TRUE, trunk_height_ratio=1/2, trunk_radius = 1.5, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50) render_snapshot() } if(run_documentation()) { #Change the tree type render_tree(extent = attr(montereybay,"extent"), heightmap = montereybay, tree_zscale = FALSE, tree_height = 30, clear_previous = TRUE, type = "cone",trunk_height_ratio = 1/6, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50) render_snapshot() } if(run_documentation()) { #Change the crown color: render_camera(theta = 150, phi = 38, zoom = 0.4, fov = 55) render_tree(extent = attr(montereybay,"extent"), heightmap = montereybay, tree_zscale = FALSE, tree_height = 30, crown_width_ratio = 0.5 + runif(20), crown_color = rainbow(20), clear_previous = TRUE, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50) render_snapshot() } #We will use the lidR package to generate a DEM and detect the crown tops of trees, and #then use rayshader to render 3D tree models scaled to those heights on the map. run_example = length(find.package("lidR", quiet = TRUE)) > 0 && length(find.package("sf", quiet = TRUE)) > 0 && length(find.package("terra", quiet = TRUE)) > 0 && run_documentation() if (run_example) { #Load the example data from the lidR package LASfile = system.file("extdata", "Topography.laz", package="lidR") las = lidR::readLAS(LASfile, filter = "-inside 273450 5274350 273550 5274450") #Convert the lidar point data to a DEM and detect the location of trees from the same data dem = lidR::rasterize_terrain(las, algorithm = lidR::tin()) tree_top_data = lidR::locate_trees(las, lidR::lmf(ws = 5)) tree_locations = sf::st_coordinates(tree_top_data) #Convert DEM to a matrix and extract the extent of the scene dem_matrix = raster_to_matrix(dem) dem_extent = terra::ext(dem) extent_values = dem_extent@pntr$vector #Plot the ground dem_matrix |> height_shade() |> add_shadow(texture_shade(dem_matrix),0.2) |> add_shadow(lamb_shade(dem_matrix),0) |> plot_3d(dem_matrix, windowsize = 800) render_snapshot() } if (run_example) { #The tree locations are given as an absolute height (as opposed to relative to the surface) #so we set `absolute_height = TRUE`. render_tree(lat = tree_locations[,2], long = tree_locations[,1], crown_width_ratio = 0.5, absolute_height = TRUE, tree_height = tree_locations[,3], trunk_height_ratio = 0.2 + 0.1*runif(nrow(tree_locations)), crown_color = "#00aa00", extent = raster::extent(extent_values), heightmap = dem_matrix, clear_previous = TRUE) #Remove existing lights and add our own with rgl rgl::pop3d("lights") rgl::light3d(phi=35,theta=90, viewpoint.rel=F, diffuse="#ffffff", specular="#000000") rgl::light3d(phi=-45,theta=-40, viewpoint.rel=F, diffuse="#aaaaaa", specular="#000000") render_snapshot() } if (run_example) { #Render tree also works with `render_highquality()` render_highquality(lightdirection=c(90,45),lightaltitude=c(90,45), lightcolor=c("dodgerblue","orange"), samples = 32, min_variance = 0) }if(run_documentation()) { #Let's first start by drawing some trees in a circle around Monterey Bay #We won't scale these to a realistic size (yet) moss_landing_coord = c(36.806807, -121.793332) montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50,water=TRUE, shadowcolor="#40310a", background = "tan", theta=210, phi=22, zoom=0.20, fov=55) t = seq(0,2*pi,length.out=20) circle_coords_lat = moss_landing_coord[1] + 0.3 * sin(t) circle_coords_long = moss_landing_coord[2] + 0.3 * cos(t) render_tree(extent = attr(montereybay,"extent"), heightmap = montereybay, tree_zscale = FALSE, tree_height = 30, lit = TRUE, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50) render_snapshot() } if(run_documentation()) { #Change the crown width ratio (compared to the height) render_tree(extent = attr(montereybay,"extent"), heightmap = montereybay, tree_zscale = FALSE, tree_height = 60, crown_width_ratio = 0.5, clear_previous = TRUE, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50) render_snapshot() } if(run_documentation()) { #Change the trunk height and width render_tree(extent = attr(montereybay,"extent"), heightmap = montereybay, tree_zscale = FALSE, tree_height = 40, crown_width_ratio = 2, clear_previous = TRUE, trunk_height_ratio=1/2, trunk_radius = 1.5, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50) render_snapshot() } if(run_documentation()) { #Change the tree type render_tree(extent = attr(montereybay,"extent"), heightmap = montereybay, tree_zscale = FALSE, tree_height = 30, clear_previous = TRUE, type = "cone",trunk_height_ratio = 1/6, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50) render_snapshot() } if(run_documentation()) { #Change the crown color: render_camera(theta = 150, phi = 38, zoom = 0.4, fov = 55) render_tree(extent = attr(montereybay,"extent"), heightmap = montereybay, tree_zscale = FALSE, tree_height = 30, crown_width_ratio = 0.5 + runif(20), crown_color = rainbow(20), clear_previous = TRUE, lat = unlist(circle_coords_lat), long = unlist(circle_coords_long), zscale=50) render_snapshot() } #We will use the lidR package to generate a DEM and detect the crown tops of trees, and #then use rayshader to render 3D tree models scaled to those heights on the map. run_example = length(find.package("lidR", quiet = TRUE)) > 0 && length(find.package("sf", quiet = TRUE)) > 0 && length(find.package("terra", quiet = TRUE)) > 0 && run_documentation() if (run_example) { #Load the example data from the lidR package LASfile = system.file("extdata", "Topography.laz", package="lidR") las = lidR::readLAS(LASfile, filter = "-inside 273450 5274350 273550 5274450") #Convert the lidar point data to a DEM and detect the location of trees from the same data dem = lidR::rasterize_terrain(las, algorithm = lidR::tin()) tree_top_data = lidR::locate_trees(las, lidR::lmf(ws = 5)) tree_locations = sf::st_coordinates(tree_top_data) #Convert DEM to a matrix and extract the extent of the scene dem_matrix = raster_to_matrix(dem) dem_extent = terra::ext(dem) extent_values = dem_extent@pntr$vector #Plot the ground dem_matrix |> height_shade() |> add_shadow(texture_shade(dem_matrix),0.2) |> add_shadow(lamb_shade(dem_matrix),0) |> plot_3d(dem_matrix, windowsize = 800) render_snapshot() } if (run_example) { #The tree locations are given as an absolute height (as opposed to relative to the surface) #so we set `absolute_height = TRUE`. render_tree(lat = tree_locations[,2], long = tree_locations[,1], crown_width_ratio = 0.5, absolute_height = TRUE, tree_height = tree_locations[,3], trunk_height_ratio = 0.2 + 0.1*runif(nrow(tree_locations)), crown_color = "#00aa00", extent = raster::extent(extent_values), heightmap = dem_matrix, clear_previous = TRUE) #Remove existing lights and add our own with rgl rgl::pop3d("lights") rgl::light3d(phi=35,theta=90, viewpoint.rel=F, diffuse="#ffffff", specular="#000000") rgl::light3d(phi=-45,theta=-40, viewpoint.rel=F, diffuse="#aaaaaa", specular="#000000") render_snapshot() } if (run_example) { #Render tree also works with `render_highquality()` render_highquality(lightdirection=c(90,45),lightaltitude=c(90,45), lightcolor=c("dodgerblue","orange"), samples = 32, min_variance = 0) }
Adds water layer to the scene, removing the previous water layer if desired.
render_water( heightmap, waterdepth = 0, watercolor = "lightblue", zscale = 1, wateralpha = 0.5, waterlinecolor = NULL, waterlinealpha = 1, linewidth = 2, remove_water = TRUE )render_water( heightmap, waterdepth = 0, watercolor = "lightblue", zscale = 1, wateralpha = 0.5, waterlinecolor = NULL, waterlinealpha = 1, linewidth = 2, remove_water = TRUE )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced. |
waterdepth |
Default |
watercolor |
Default |
zscale |
Default |
wateralpha |
Default |
waterlinecolor |
Default |
waterlinealpha |
Default |
linewidth |
Default |
remove_water |
Default |
if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50) render_snapshot() } #We want to add a layer of water after the initial render. if(run_documentation()) { render_water(montereybay,zscale=50) render_snapshot() } #Call it again to change the water depth if(run_documentation()) { render_water(montereybay,zscale=50,waterdepth=-1000) render_snapshot() } #Add waterlines if(run_documentation()) { render_camera(theta=-45) render_water(montereybay,zscale=50,waterlinecolor="white") render_snapshot() }if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay,zscale=50) render_snapshot() } #We want to add a layer of water after the initial render. if(run_documentation()) { render_water(montereybay,zscale=50) render_snapshot() } #Call it again to change the water depth if(run_documentation()) { render_water(montereybay,zscale=50,waterdepth=-1000) render_snapshot() } #Add waterlines if(run_documentation()) { render_camera(theta=-45) render_water(montereybay,zscale=50,waterlinecolor="white") render_snapshot() }
Resizes a matrix (preserving contents) by specifying the desired output dimensions or a scaling factor.
resize_matrix( heightmap, scale = 1, width = NULL, height = NULL, method = "bilinear" )resize_matrix( heightmap, scale = 1, width = NULL, height = NULL, method = "bilinear" )
heightmap |
The elevation matrix. |
scale |
Default |
width |
Default |
height |
Default |
method |
Default |
#Reduce the size of the monterey bay dataset by half if(run_documentation()) { montbaysmall = resize_matrix(montereybay, scale=0.5) montbaysmall |> sphere_shade() |> plot_map() } if(run_documentation()) { #Reduce the size of the monterey bay dataset from 540x540 to 100x100 montbaysmall = resize_matrix(montereybay, width = 100, height = 100) montbaysmall |> sphere_shade() |> plot_map() } if(run_documentation()) { #Increase the size of the volcano dataset 3x volcanobig = resize_matrix(volcano, scale=3) volcanobig |> sphere_shade() |> plot_map() } if(run_documentation()) { #Increase the size of the volcano dataset 2x, using cubic interpolation volcanobig = resize_matrix(volcano, scale=3, method="cubic") volcanobig |> sphere_shade() |> plot_map() }#Reduce the size of the monterey bay dataset by half if(run_documentation()) { montbaysmall = resize_matrix(montereybay, scale=0.5) montbaysmall |> sphere_shade() |> plot_map() } if(run_documentation()) { #Reduce the size of the monterey bay dataset from 540x540 to 100x100 montbaysmall = resize_matrix(montereybay, width = 100, height = 100) montbaysmall |> sphere_shade() |> plot_map() } if(run_documentation()) { #Increase the size of the volcano dataset 3x volcanobig = resize_matrix(volcano, scale=3) volcanobig |> sphere_shade() |> plot_map() } if(run_documentation()) { #Increase the size of the volcano dataset 2x, using cubic interpolation volcanobig = resize_matrix(volcano, scale=3, method="cubic") volcanobig |> sphere_shade() |> plot_map() }
This function determines if the examples are being run in pkgdown. It is not meant to be called by the user.
run_documentation()run_documentation()
Boolean value.
# See if the documentation should be run. run_documentation()# See if the documentation should be run. run_documentation()
Writes a stereolithography (STL) file that can be used in 3D printing.
save_3dprint(filename, maxwidth = 125, unit = "mm", rotate = FALSE)save_3dprint(filename, maxwidth = 125, unit = "mm", rotate = FALSE)
filename |
String with the filename. If |
maxwidth |
Default |
unit |
Default |
rotate |
Default |
Writes an STL file to filename. Regardless of the unit displayed, the output STL is in millimeters.
filename_stl = tempfile() #Save the STL file into `filename_stl` if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano,zscale=3) render_snapshot() save_3dprint(filename_stl) } #Save the STL file into `filename_stl`, setting maximum width to 100 mm if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano,zscale=3) render_snapshot() save_3dprint(filename_stl, maxwidth = 100) } #'#Save the STL file into `filename_stl`, setting maximum width to 4 inches if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano,zscale=3) render_snapshot() save_3dprint(filename_stl, maxwidth = 4, unit = "in") } #'#'#Save the STL file into `filename_stl`, setting maximum width (character) to 120mm if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano,zscale=3) render_snapshot() save_3dprint(filename_stl, maxwidth = "120mm") }filename_stl = tempfile() #Save the STL file into `filename_stl` if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano,zscale=3) render_snapshot() save_3dprint(filename_stl) } #Save the STL file into `filename_stl`, setting maximum width to 100 mm if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano,zscale=3) render_snapshot() save_3dprint(filename_stl, maxwidth = 100) } #'#Save the STL file into `filename_stl`, setting maximum width to 4 inches if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano,zscale=3) render_snapshot() save_3dprint(filename_stl, maxwidth = 4, unit = "in") } #'#'#Save the STL file into `filename_stl`, setting maximum width (character) to 120mm if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano,zscale=3) render_snapshot() save_3dprint(filename_stl, maxwidth = "120mm") }
Converts MULTIPOLYGON Z features into a 3D OBJ model
save_multipolygonz_to_obj(sfobj, filename, swap_yz = FALSE)save_multipolygonz_to_obj(sfobj, filename, swap_yz = FALSE)
sfobj |
sf object with MULTIPOLYGON Z geometry, |
filename |
Filename of the OBJ to save the 3D model to. |
swap_yz |
Default |
#Convert the built-in Washington Monument MULTIPOLYGON Z data to an OBJ file obj_temp = tempfile(fileext=".obj") save_multipolygonz_to_obj(washington_monument_multipolygonz, obj_temp, swap_yz=TRUE) #Render with rgl rgl::open3d() render_obj(filename=obj_temp, xyz=matrix(c(0,0,0),ncol=3), color="red") render_camera(theta=30,phi=40)#Convert the built-in Washington Monument MULTIPOLYGON Z data to an OBJ file obj_temp = tempfile(fileext=".obj") save_multipolygonz_to_obj(washington_monument_multipolygonz, obj_temp, swap_yz=TRUE) #Render with rgl rgl::open3d() render_obj(filename=obj_temp, xyz=matrix(c(0,0,0),ncol=3), color="red") render_camera(theta=30,phi=40)
Writes the textured 3D rayshader visualization to an OBJ file.
save_obj( filename, save_texture = TRUE, water_index_refraction = 1, manifold_geometry = FALSE, all_face_fields = FALSE, save_shadow = FALSE )save_obj( filename, save_texture = TRUE, water_index_refraction = 1, manifold_geometry = FALSE, all_face_fields = FALSE, save_shadow = FALSE )
filename |
String with the filename. If |
save_texture |
Default |
water_index_refraction |
Default |
manifold_geometry |
Default |
all_face_fields |
Default |
save_shadow |
Default |
if(interactive()) { filename_obj = tempfile(fileext = ".obj") #Save model of volcano if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano, zscale = 2) save_obj(filename_obj) } #Save model of volcano without texture if(run_documentation()) { save_obj(filename_obj, save_texture = FALSE) } #Make water have realistic index of refraction if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay, zscale = 50) save_obj(filename_obj, water_index_refraction = 1.5) } }if(interactive()) { filename_obj = tempfile(fileext = ".obj") #Save model of volcano if(run_documentation()) { volcano |> sphere_shade() |> plot_3d(volcano, zscale = 2) save_obj(filename_obj) } #Save model of volcano without texture if(run_documentation()) { save_obj(filename_obj, save_texture = FALSE) } #Make water have realistic index of refraction if(run_documentation()) { montereybay |> sphere_shade() |> plot_3d(montereybay, zscale = 50) save_obj(filename_obj, water_index_refraction = 1.5) } }
A wrapper around rayimage::ray_write_image() to write an image to file.
save_png( hillshade, filename, title_text = NA, title_offset = c(20, 20), title_color = "black", title_size = 30, title_font = "sans", title_style = "normal", title_bar_color = NA, title_bar_alpha = 0.5, title_just = "left" )save_png( hillshade, filename, title_text = NA, title_offset = c(20, 20), title_color = "black", title_size = 30, title_font = "sans", title_style = "normal", title_bar_color = NA, title_bar_alpha = 0.5, title_just = "left" )
hillshade |
Array (or matrix) of hillshade to be written. |
filename |
String with the filename. If |
title_text |
Default |
title_offset |
Default |
title_color |
Default |
title_size |
Default |
title_font |
Default |
title_style |
Default |
title_bar_color |
Default |
title_bar_alpha |
Default |
title_just |
Default |
filename_map = tempfile() #Save the map into `filename_map` montereybay |> sphere_shade() |> save_png(filename_map)filename_map = tempfile() #Save the map into `filename_map` montereybay |> sphere_shade() |> save_png(filename_map)
Calculates a color for each point on the surface using the surface normals and hemispherical UV mapping. This uses either a texture map provided by the user (as an RGB array), or a built-in color texture.
sphere_shade( heightmap, sunangle = 315, texture = "imhof1", normalvectors = NULL, colorintensity = 1, zscale = 1, progbar = interactive() )sphere_shade( heightmap, sunangle = 315, texture = "imhof1", normalvectors = NULL, colorintensity = 1, zscale = 1, progbar = interactive() )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced. |
sunangle |
Default |
texture |
Default |
normalvectors |
Default |
colorintensity |
Default |
zscale |
Default |
progbar |
Default |
RGB array of hillshaded texture mappings.
#Basic example: montereybay |> sphere_shade() |> plot_map() #Decrease the color intensity: montereybay |> sphere_shade(colorintensity=0.1) |> plot_map() #Change to a built-in color texture: montereybay |> sphere_shade(texture="desert") |> plot_map() #Change the highlight angle: montereybay |> sphere_shade(texture="desert", sunangle = 45) |> plot_map() #Create our own texture using the `create_texture` function: montereybay |> sphere_shade(zscale=10,texture=create_texture("#E9C68D","#AF7F38", "#674F30","#494D30", "#B3BEA3")) |> plot_map()#Basic example: montereybay |> sphere_shade() |> plot_map() #Decrease the color intensity: montereybay |> sphere_shade(colorintensity=0.1) |> plot_map() #Change to a built-in color texture: montereybay |> sphere_shade(texture="desert") |> plot_map() #Change the highlight angle: montereybay |> sphere_shade(texture="desert", sunangle = 45) |> plot_map() #Create our own texture using the `create_texture` function: montereybay |> sphere_shade(zscale=10,texture=create_texture("#E9C68D","#AF7F38", "#674F30","#494D30", "#B3BEA3")) |> plot_map()
Calculates a shadow for each point on the surface using the method described by Leland Brown in "Texture Shading: A New Technique for Depicting Terrain Relief."
texture_shade( heightmap, detail = 0.5, contrast = 1, brightness = 0, transform = TRUE, dx = 1, dy = 1, pad = 50 )texture_shade( heightmap, detail = 0.5, contrast = 1, brightness = 0, transform = TRUE, dx = 1, dy = 1, pad = 50 )
heightmap |
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. |
detail |
Default |
contrast |
Default |
brightness |
Default |
transform |
Default |
dx |
Default |
dy |
Default |
pad |
Default |
2D matrix of hillshade values.
#Create a direct mapping of elevation to color: if(run_documentation()) { #Plut using default values montereybay |> texture_shade() |> plot_map() } if(run_documentation()) { #Increase the level of detail montereybay |> texture_shade(detail=1) |> plot_map() } if(run_documentation()) { #Decrease the level of detail montereybay |> texture_shade(detail=0) |> plot_map() } if(run_documentation()) { #Increase the level of contrast montereybay |> texture_shade(contrast=3) |> plot_map() } if(run_documentation()) { #Increase the brightness for this level of contrast montereybay |> texture_shade(contrast=5, brightness = 2) |> plot_map() } #Add a texture_shade() layer into a map montbay = montereybay montbay[montbay < 0] = 0 if(run_documentation()) { montbay |> height_shade() |> add_water(detect_water(montbay), color="dodgerblue") |> add_shadow(texture_shade(montbay, detail=1/6, contrast = 4, brightness = 3),0.1) |> add_shadow(lamb_shade(montbay,zscale=50),0) |> plot_map() }#Create a direct mapping of elevation to color: if(run_documentation()) { #Plut using default values montereybay |> texture_shade() |> plot_map() } if(run_documentation()) { #Increase the level of detail montereybay |> texture_shade(detail=1) |> plot_map() } if(run_documentation()) { #Decrease the level of detail montereybay |> texture_shade(detail=0) |> plot_map() } if(run_documentation()) { #Increase the level of contrast montereybay |> texture_shade(contrast=3) |> plot_map() } if(run_documentation()) { #Increase the brightness for this level of contrast montereybay |> texture_shade(contrast=5, brightness = 2) |> plot_map() } #Add a texture_shade() layer into a map montbay = montereybay montbay[montbay < 0] = 0 if(run_documentation()) { montbay |> height_shade() |> add_water(detect_water(montbay), color="dodgerblue") |> add_shadow(texture_shade(montbay, detail=1/6, contrast = 4, brightness = 3),0.1) |> add_shadow(lamb_shade(montbay,zscale=50),0) |> plot_map() }
This dataset is an sf object containing MULTIPOLYGON Z 3D data of the Washington Monument in Washington, DC.
washington_monument_multipolygonzwashington_monument_multipolygonz
An sf object with MULTIPOLYGONZ geometry.
https://opendata.dc.gov/documents/DCGIS::buildings-in-3d/
# See the `render_multipolygonz()` documentation for examples of using this data.# See the `render_multipolygonz()` documentation for examples of using this data.