Package 'hillshader'

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

Help Index


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 rayshader shader(s) to sequentially apply. Defaults to ray_shade.

filename

Character. If set, the result if written as a raster file. Defaults to NULL.

...

Additional parameters to be passed to the either shader functions or to raster::writeRaster.

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 rayshader operation

raster

The original raster from which matrix is derived. Can be an Extent object.

crs

If an Extent object is passed to the raster option, the corresponding coordinate reference system information.

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 raster::writeRaster.

...

Additional arguments passed to raster::writeRaster.

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
 )