bary_index {quadmesh} | R Documentation |
Barycentric triangle index for interpolation
Description
This function returns the barycentric weight for a grid of coordinates from a geographic raster.
Usage
bary_index(x, coords = NULL, grid = NULL, ...)
Arguments
x |
a 'RasterLayer' source |
coords |
optional input coordinates |
grid |
target 'RasterLayer', a target regular grid |
... |
ignored |
Details
It's not as fast as raster::projectRaster()
(e.g. projectRaster(x, grid)
) but it
also accepts a coords
argument and so can be used for non-regular raster
reprojection.
'coords' may be 'NULL' or longitude, latitude in a 2-layer raster brick or stack as with
mesh_plot
.
Value
RasterLayer
Examples
library(raster)
p_srs <- "+proj=stere +lat_0=-90 +lat_ts=-71 +datum=WGS84"
polar <- raster(extent(-5e6, 5e6, -5e6, 5e6), crs = p_srs, res = 25000)
etopo <- aggregate(etopo, fact = 4)
index <- bary_index(etopo, grid = polar)
ok <- !is.na(index$idx)
r <- setValues(polar, NA_integer_)
r[ok] <- colSums(matrix(values(etopo)[index$tri[, index$idx[ok]]], nrow = 3) * t(index$p)[, ok])
plot(r)
[Package quadmesh version 0.5.5 Index]