| Title: | Create Hillshade Relief Maps Using Ray-Tracing | 
| Version: | 0.1.2 | 
| Description: | A set of tools to create georeferenced hillshade relief raster maps using ray-tracing and other advanced hill-shading techniques. It includes a wrapper function to create a georeferenced, ray-traced hillshade map from a digital elevation model, and other functions that can be used in a rayshader pipeline. | 
| License: | GPL (≥ 3) | 
| Encoding: | UTF-8 | 
| LazyData: | true | 
| RoxygenNote: | 7.1.1 | 
| Imports: | methods, raster, rayshader, scales | 
| Depends: | R (≥ 2.10) | 
| Collate: | 'add_shadow_2d.R' 'matrix_to_raster.R' 'write_raster.R' 'utils.R' 'hillshader.R' 'maungawhau.R' 'maungawhau_hr.R' | 
| NeedsCompilation: | no | 
| Packaged: | 2024-01-28 21:17:18 UTC; RoudierP | 
| Author: | Pierre Roudier | 
| Maintainer: | Pierre Roudier <pierre.roudier@gmail.com> | 
| Repository: | CRAN | 
| Date/Publication: | 2024-01-29 10:30:02 UTC | 
Add shadow
Description
Multiplies a texture array or shadow map by a shadow map.
Usage
add_shadow_2d(hillshade, shadowmap, max_darken = 0.7, rescale_original = FALSE)
Arguments
| hillshade | A 2D matrix of shadow intensities. | 
| shadowmap | A matrix that indicates the intensity of the shadow at that point. 0 is full darkness, 1 is full light. | 
| max_darken | Default '0.7'. The lower limit for how much the image will be darkened. 0 is completely black, 1 means the shadow map will have no effect. | 
| rescale_original | Ignored. | 
Value
A shaded map.
Author(s)
Slight modification from Tyler's code in rayshader::add_shadow
Examples
library(rayshader)
# Create elevation matrix
el_mat <- raster_to_matrix(maungawhau)
el_mat %>%
 # Create hillshade layer using
 # ray-tracing
 ray_shade() %>%
 # Add ambient shading
 add_shadow_2d(
   ambient_shade(
     heightmap = el_mat
   )
 )
Hillshader
Description
.
Usage
hillshader(elevation, shader = "ray_shade", filename = NULL, ...)
Arguments
| elevation | Raster, a digital elevation model. | 
| shader | Character. List of  | 
| filename | Character. If set, the result if written as a raster file. Defaults to  | 
| ... | Additional parameters to be passed to the either shader functions or to  | 
Value
Either a RasterLayer of light intensities (hillshade), or writes the result to disk if filename is set.
Author(s)
Pierre Roudier
Examples
# Simple example
library(raster)
hs <- hillshader(maungawhau)
plot(hs)
Matrix to Raster
Description
Turns a matrix into a Raster
Usage
matrix_to_raster(matrix, raster, crs = NULL)
Arguments
| matrix | The input matrix, typically the output of a  | 
| raster | The original raster from which  | 
| crs | If an  | 
Value
a RasterLayer
Author(s)
Pierre Roudier
Elevation Raster for Maungawhau in Tāmaki Mākaurau/Auckland
Description
Elevation data as a raster for Maungawhau, a volcano located in Tāmaki Mākaurau/Auckland.
Usage
maungawhau
Format
A RasterLayer with 87 rows, 61 columns, and 1 band with the elevation data at a 10-m resolution. The data is projected in New Zealand Map Grid (NZMG, EPSG:27200).
Source
Elevation data from datasets::volcano, georeferencing adapted from https://waterdata.usgs.gov/blog/inlmiscmaps/
LiDAR Elevation Raster for Maungawhau in Tāmaki Mākaurau/Auckland
Description
Elevation data as a raster for Maungawhau, a volcano located in Tāmaki Mākaurau/Auckland.
Usage
maungawhau_hr
Format
A RasterLayer with 860 rows, 600 columns, and 1 band with the elevation data at a 1 m resolution. The data is projected in New Zealand Map Grid (NZMG, EPSG:27200).
Source
Elevation data from LINZ Data Service: https://data.linz.govt.nz/layer/53405-auckland-lidar-1m-dem-2013/
Write hillshade to a file
Description
Write an array from a hillshade procedure to a geospatial raster file.
Usage
write_raster(hillshade, elevation, filename, format, ...)
Arguments
| hillshade | A 2D matrix of shadow intensities. | 
| elevation | Original elevation raster. | 
| filename | Character. Output filename. | 
| format | Character. Output file type. Passed to  | 
| ... | Additional arguments passed to  | 
Value
This function is used for the side-effect of writing values to a file.
Author(s)
Pierre Roudier
Examples
library(rayshader)
out_fn <- paste0(tempfile(), ".tif")
# Create elevation matrix
el_mat <- maungawhau %>%
 raster_to_matrix()
 el_mat %>%
 # Create hillshade layer using
 # ray-tracing
 ray_shade() %>%
 # Add ambient shading
 add_shadow_2d(
   ambient_shade(
     heightmap = el_mat
   )
 ) %>%
 write_raster(
   elevation = maungawhau,
   filename = out_fn
 )