RS_Resample¶
Resamples a raster onto a new pixel grid — a new width/height, a new pixel size, and/or a snapped origin — in the same CRS.
Usage¶
raster RS_Resample(raster: raster, reference_raster: raster, use_scale: boolean, algorithm: string)
raster RS_Resample(raster: raster, width_or_scale: double, height_or_scale: double, use_scale: boolean, algorithm: string)
raster RS_Resample(raster: raster, width_or_scale: double, height_or_scale: double, grid_x: double, grid_y: double, use_scale: boolean, algorithm: string)
Arguments¶
- raster (raster): The input raster to resample.
- width_or_scale (double): Output width in pixels when
use_scaleis false (a fractional value is an error), or the target x pixel size (scaleX) whenuse_scaleis true. - height_or_scale (double): Output height in pixels when
use_scaleis false (a fractional value is an error), or the target y pixel size (scaleY, negative for a north-up raster) whenuse_scaleis true. - grid_x (double): X coordinate of the grid the output origin snaps to.
- grid_y (double): Y coordinate of the grid the output origin snaps to.
- use_scale (boolean): When false,
width_or_scale/height_or_scaleare output pixel dimensions and the world extent is preserved; when true, they are the target pixel size. - algorithm (string): Resampling algorithm (case-insensitive):
NearestNeighbor(the default),Bilinear,Cubic(aliasBicubic),CubicSpline,Lanczos,Average, orMode. - reference_raster (raster): A raster whose grid — dimensions (or
pixel size, when
use_scaleis true) and origin — defines the output grid. Must share the input’s CRS.
[!WARNING]
Experimental. This function is experimental; its behavior may change without notice.
Description¶
RS_Resample changes a raster’s pixel grid while keeping its band count
and order and per-band nodata. Pixel values are recomputed by GDAL with
the chosen algorithm (nearest neighbour by default). The output stays
in the input’s CRS — RS_Resample never reprojects (use
RS_ReprojectMatch for that).
RS_Resample has three positional overloads:
RS_Resample(raster, width_or_scale, height_or_scale, use_scale, algorithm)— whenuse_scaleis false,width_or_scale/height_or_scaleare the output pixel dimensions (a fractional value is an error) and the world extent is preserved. Whenuse_scaleis true they are the target pixel size (scaleX,scaleY, withscaleYnegative for a north-up raster); the pixel size is kept exact and the extent grows by up to one pixel so it tiles into whole pixels. Cells outside the source footprint become nodata.RS_Resample(raster, width_or_scale, height_or_scale, grid_x, grid_y, use_scale, algorithm)— additionally snaps the output origin to the grid anchored at(grid_x, grid_y), expanding outward so the original extent stays covered.RS_Resample(raster, reference_raster, use_scale, algorithm)— takes the target dimensions (or pixel size, whenuse_scale) and the origin grid fromreference_raster, which must share the input’s CRS (it is an error otherwise).
algorithm (case-insensitive) is one of NearestNeighbor (the
default), Bilinear, Cubic (alias Bicubic), CubicSpline,
Lanczos, Average, or Mode.
Dimensions and pixel size use the rows-then-columns intuition of the
raster (height_or_scale/scaleY for rows, width_or_scale/scaleX
for columns). In the extent-preserving dimension form, a skewed or
rotated raster is re-gridded with its footprint preserved (both the
scale and skew terms of each axis scale by the same factor). A scale
change or origin snap on a skewed raster is not supported and errors.
For an N-D raster (bands with extra dimensions such as time), the
resample is a 2-D (y, x) operation broadcast across every non-spatial
plane, so the non-spatial dimensions are preserved and only the (y, x)
extent changes.
[!NOTE]
Extent-growing scale changes and origin snaps read the entire raster into memory.
Examples¶
Downsample the example raster (64 x 32) to half its dimensions:
SELECT RS_Width(RS_Resample(RS_Example(), 32, 16, false, 'NearestNeighbor'));
┌──────────────────────────────────────────────────────────────────────────────┐
│ rs_width(rs_resample(rs_example(),Int64(32),Int64(16),Boolean(false),Utf8("N │
│ earestNeighbor")))… │
╞══════════════════════════════════════════════════════════════════════════════╡
│ 32 │
└──────────────────────────────────────────────────────────────────────────────┘
Upsample to twice its dimensions with bilinear resampling:
SELECT RS_Height(RS_Resample(RS_Example(), 128, 64, false, 'Bilinear'));
┌──────────────────────────────────────────────────────────────────────────────┐
│ rs_height(rs_resample(rs_example(),Int64(128),Int64(64),Boolean(false),Utf8( │
│ "Bilinear")))… │
╞══════════════════════════════════════════════════════════════════════════════╡
│ 64 │
└──────────────────────────────────────────────────────────────────────────────┘