% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spatial.R
\name{warp}
\alias{warp}
\title{Resample or reproject a streamed raster onto a target grid}
\usage{
warp(
  x,
  template,
  method = c("near", "bilinear", "cubic"),
  band = 1L,
  path = NULL,
  dtype = "f32",
  compression = c("fast", "balanced", "max")
)
}
\arguments{
\item{x}{A \code{vectra_raster} (from \code{\link[=vec_open_raster]{vec_open_raster()}}) or a path to a \code{.vec}
raster to warp.}

\item{template}{The target grid: a \code{vectra_raster} / \code{.vec} path whose grid
and CRS are borrowed, or a list \code{list(crs =, extent =, res =, dims =)}.
With \code{crs} and \code{res} but no \code{extent}, the target extent is the source's
corners projected into \code{crs}.}

\item{method}{Resampling method: \code{"near"}, \code{"bilinear"}, or \code{"cubic"}.
Default \code{"near"}.}

\item{band}{Band to warp (1-based). Default 1.}

\item{path}{Optional output \code{.vec} path. When given the result is streamed to
disk and the opened \code{\link[=vec_open_raster]{vec_open_raster()}} handle is returned invisibly; when
\code{NULL} the result is returned as an in-memory matrix.}

\item{dtype}{Storage dtype for \code{.vec} output (see \code{\link[=vec_write_raster]{vec_write_raster()}}).
Default \code{"f32"}.}

\item{compression}{Compression effort for \code{.vec} output. Default \code{"fast"}.}
}
\value{
When \code{path} is \code{NULL}, a numeric matrix on the target grid (row 1
northmost) carrying \code{gt}, \code{extent}, and \code{crs} attributes. When \code{path} is
given, the written \code{vectra_raster} handle (invisibly).
}
\description{
Warps a \code{.vec} raster onto a target grid, walking the \emph{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 \pkg{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 \code{.vec}, so the whole output grid is never resident; the source
is read in bounded windows rather than held whole.
}
\details{
This is the \emph{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 / \pkg{terra} convention (pixel centres at
half-integer coordinates). \code{"near"} takes the nearest source cell;
\code{"bilinear"} the 2x2 weighted mean; \code{"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 \code{NA}.

Reprojection happens only when both rasters carry a known EPSG code and the
codes differ; otherwise \code{warp()} resamples within a shared CRS and needs no
\pkg{sf}.
}
\examples{
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)

}
\seealso{
\code{\link[=rasterize]{rasterize()}} to build a raster from streamed vector features,
\code{\link[=focal]{focal()}} for moving-window statistics.
}
