Skip to content

RS_ReprojectMatch

Reprojects a raster onto a reference raster’s CRS, grid, and extent.

Usage

raster RS_ReprojectMatch(raster: raster, reference: raster)
raster RS_ReprojectMatch(raster: raster, reference: raster, algorithm: string)

Arguments

  • raster (raster)
  • reference (raster)
  • algorithm (string): Resampling algorithm (case-insensitive): NearestNeighbor (the default), Bilinear, Cubic (alias Bicubic), CubicSpline, Lanczos, Average, or Mode.

[!WARNING]

Experimental. This function is experimental; its behavior may change without notice.

Description

RS_ReprojectMatch reprojects raster onto the grid of reference: the output always has the same CRS, extent, resolution, and dimensions as reference, in the spirit of rioxarray’s reproject_match. The reference contributes only its grid — its pixel values are never read.

The input’s band count and order, per-band data type, and nodata are preserved. Pixel values are recomputed by GDAL’s warp using the chosen algorithm (nearest neighbour by default). Cells of the reference grid that the reprojected input does not cover are filled with the input band’s nodata value (or zero when a band has none).

Both rasters must agree on whether they carry a CRS: reprojecting between an unknown CRS and a real one is undefined, so it is an error for exactly one side to have a CRS. When neither has one, the operation is a same-space regrid onto the reference grid.

Int64 and UInt64 input rasters are not supported: GDAL’s warp routes 64-bit integer pixels through a floating working type (a double for nearest/interpolation, a 32-bit float for mode on GDAL \< 3.13), so no resampling method can represent them exactly. Cast to a supported type (for example Int32 or Float64) first.

[!NOTE]

This reads the entire input raster into memory.

Examples

Reprojecting the example raster onto its own grid is an identity, so the output keeps the example’s width (64):

SELECT RS_Width(RS_ReprojectMatch(RS_Example(), RS_Example()));
┌────────────────────────────────────────────────────────┐
│ rs_width(rs_reprojectmatch(rs_example(),rs_example())) │
│                          int64                         │
╞════════════════════════════════════════════════════════╡
│                                                     64 │
└────────────────────────────────────────────────────────┘

The same, choosing bilinear resampling explicitly:

SELECT RS_Height(RS_ReprojectMatch(RS_Example(), RS_Example(), 'Bilinear'));
┌──────────────────────────────────────────────────────────────────────────┐
│ rs_height(rs_reprojectmatch(rs_example(),rs_example(),Utf8("Bilinear"))) │
│                                   int64                                  │
╞══════════════════════════════════════════════════════════════════════════╡
│                                                                       32 │
└──────────────────────────────────────────────────────────────────────────┘