Title: | Create Hillshade Relief Maps Using Ray-Tracing |
---|---|
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. |
Authors: | Pierre Roudier [aut, cre] |
Maintainer: | Pierre Roudier <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.2 |
Built: | 2024-10-26 03:24:51 UTC |
Source: | https://github.com/pierreroudier/hillshader |
Multiplies a texture array or shadow map by a shadow map.
add_shadow_2d(hillshade, shadowmap, max_darken = 0.7, rescale_original = FALSE)
add_shadow_2d(hillshade, shadowmap, max_darken = 0.7, rescale_original = FALSE)
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. |
A shaded map.
Slight modification from Tyler's code in rayshader::add_shadow
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 ) )
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(elevation, shader = "ray_shade", filename = NULL, ...)
hillshader(elevation, shader = "ray_shade", filename = NULL, ...)
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 |
Either a RasterLayer
of light intensities (hillshade), or writes the result to disk if filename
is set.
Pierre Roudier
# Simple example library(raster) hs <- hillshader(maungawhau) plot(hs)
# Simple example library(raster) hs <- hillshader(maungawhau) plot(hs)
Turns a matrix into a Raster
matrix_to_raster(matrix, raster, crs = NULL)
matrix_to_raster(matrix, raster, crs = NULL)
matrix |
The input matrix, typically the output of a |
raster |
The original raster from which |
crs |
If an |
a RasterLayer
Pierre Roudier
Elevation data as a raster for Maungawhau, a volcano located in Tāmaki Mākaurau/Auckland.
maungawhau
maungawhau
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).
Elevation data from datasets::volcano
, georeferencing adapted from https://waterdata.usgs.gov/blog/inlmiscmaps/
Elevation data as a raster for Maungawhau, a volcano located in Tāmaki Mākaurau/Auckland.
maungawhau_hr
maungawhau_hr
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).
Elevation data from LINZ Data Service: https://data.linz.govt.nz/layer/53405-auckland-lidar-1m-dem-2013/
Write an array from a hillshade procedure to a geospatial raster file.
write_raster(hillshade, elevation, filename, format, ...)
write_raster(hillshade, elevation, filename, format, ...)
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 |
This function is used for the side-effect of writing values to a file.
Pierre Roudier
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 )
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 )