| warp | R Documentation |
Warps a .vec raster onto a target grid, walking the output one tile-row
strip at a time. For each strip the target pixel-centre coordinates are built,
projected into the source coordinate reference system when the two CRSs differ
(delegated to PROJ via sf), mapped through the source geotransform to
fractional source pixels, and sampled from the bounded source window those
coordinates fall in. The output is assembled in memory or streamed straight
back to a new .vec, so the whole output grid is never resident; the source
is read in bounded windows rather than held whole.
warp(
x,
template,
method = c("near", "bilinear", "cubic"),
band = 1L,
path = NULL,
dtype = "f32",
compression = c("fast", "balanced", "max")
)
x |
A |
template |
The target grid: a |
method |
Resampling method: |
band |
Band to warp (1-based). Default 1. |
path |
Optional output |
dtype |
Storage dtype for |
compression |
Compression effort for |
This is the sort / partition tier of the spatial toolbox: each output strip reads the source window it projects onto. For a mild reprojection or a plain resample that window is a thin band; a strong reprojection can make it large, but the output stays streamed throughout.
Sampling follows the GDAL / terra convention (pixel centres at
half-integer coordinates). "near" takes the nearest source cell;
"bilinear" the 2x2 weighted mean; "cubic" the 4x4 cubic convolution
(Catmull-Rom, a = -0.5). A target cell whose sampling kernel reaches outside
the source extent, or touches a nodata cell, comes back NA.
Reprojection happens only when both rasters carry a known EPSG code and the
codes differ; otherwise warp() resamples within a shared CRS and needs no
sf.
When path is NULL, a numeric matrix on the target grid (row 1
northmost) carrying gt, extent, and crs attributes. When path is
given, the written vectra_raster handle (invisibly).
rasterize() to build a raster from streamed vector features,
focal() for moving-window statistics.
z <- outer(1:8, 1:8, function(r, c) r + 2 * c)
f <- tempfile(fileext = ".vec")
vec_write_raster(z, f, dtype = "f64", extent = c(0, 0, 8, 8))
# Resample onto a finer grid over the same extent.
fine <- warp(f, list(extent = c(0, 0, 8, 8), res = 0.5), method = "bilinear")
dim(fine)
unlink(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.