Skip to content

RS_SliceRange

Narrows a dimension to a half-open range, keeping the dimension with reduced size.

Usage

raster RS_SliceRange(rast: raster, dim_name: utf8, start: int, end: int)

Arguments

  • rast (raster): Input raster
  • dim_name (utf8): Name of the dimension to narrow (e.g., ‘time’).
  • start (int): Start index (inclusive, zero-based).
  • end (int): End index (exclusive).

[!WARNING]

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

Description

Narrows a named non-spatial dimension to the half-open range [start, end) on every band that carries it, keeping the dimension in the output with reduced size. For example, narrowing a raster with shape [time=12, y=256, x=256] on 'time' with range [2, 7) produces a raster with shape [time=5, y=256, x=256].

The spatial dimensions (x_dim and y_dim) cannot be narrowed.

Heterogeneous rasters

Bands within a raster can have different dimensionality. Bands that do not carry the named dimension are emitted unchanged (“pass-through”) rather than producing an error. This matches the convention used by RS_Slice, RS_DimToBand, and xarray’s ds.isel.

If no band carries the named dimension, the function errors — that condition usually signals a typo’d dimension name.

Returns an error if start >= end or the range is out of bounds for any band that does carry the dimension.

See also RS_Slice to extract a single index and remove the dimension entirely.

Examples

-- Create a 'band' dimension from RS_Example()'s bands, then narrow it to the
-- half-open range [0, 2), keeping the dimension with reduced size.
SELECT RS_SliceRange(RS_BandToDim(RS_Example(), 'band'), 'band', 0, 2);
┌──────────────────────────────────────────────────────────────────────────────┐
│ rs_slicerange(rs_bandtodim(rs_example(),Utf8("band")),Utf8("band"),Int64(0), │
│                                  Int64(2))…                                  │
╞══════════════════════════════════════════════════════════════════════════════╡
│ [64x32/1] @ [43.08 79.07 203.07999999999998 207.07] skew=(1, 1) / OGC:CRS84  │
└──────────────────────────────────────────────────────────────────────────────┘