writeRasterToVTK {mkde} | R Documentation |
Write a 2D raster to XDMF XML wrapper and binary data file.
Description
Write the raster to a XDMF files.
Usage
writeRasterToVTK(elev, r.rst, g.rst, b.rst, descr, fname)
Arguments
elev |
A RasterLayer object |
r.rst |
A RasterLayer object for red |
g.rst |
A RasterLayer object for green |
b.rst |
A RasterLayer object for blue |
descr |
String description to be added to header of VTK file |
fname |
The path and base file name for output HDF5 files |
Details
This function writes a raster to VTK format. The raster is colored
according to the RGB values in r.rst
, g.rst
, and
b.rst
, respectively. The RGB balues must be an interger from 0
to 255.
Value
No value is returned
Author(s)
Jeff A. Tracey, PhD
USGS Western Ecological Research Center, San Diego Field Station
jatracey@usgs.gov
James Sheppard, PhD
San Diego Zoo Institute for Conservation Research
jsheppard@sandiegozoo.org
Amit Chourasia, MS
San Diego Supercomputer Center
amit@sdsc.edu
Examples
library(terra)
fpath <- system.file("extdata", "condordem120.RDS", package="mkde")
condordem120 <- terra::readRDS(fpath)
elev.val <- values(condordem120)
elev.min <- min(elev.val, na.rm=TRUE)
elev.max <- max(elev.val, na.rm=TRUE)
# make a color lookup table
cmap <- data.frame(value=c(0.0, 0.25, 0.5, 0.75, 1.0),
R=c(150, 179, 205, 192, 252),
G=c(224, 204, 205, 183, 243),
B=c(94, 147, 168, 147, 226))
cmap$value <- cmap$value*(elev.max - elev.min) + elev.min
# red
f.R <- approxfun(cmap$value, cmap$R)
elev.r <- rast(condordem120)
values(elev.r) <- round(f.R(elev.val))
# green
f.G <- approxfun(cmap$value, cmap$G)
elev.g <- rast(condordem120)
values(elev.g) <- round(f.G(elev.val))
# blue
f.B <- approxfun(cmap$value, cmap$B)
elev.b <- rast(condordem120)
values(elev.b) <- round(f.B(elev.val))
writeRasterToVTK(condordem120, elev.r, elev.g, elev.b, "Elevation for
California condor Example", "condor_dem.vtk")
# Clean up files
unlink("condor_dem.vtk")
[Package mkde version 0.3 Index]