Skip to content

RS_Slice

Selects a single index along a dimension, removing that dimension from the output.

Usage

raster RS_Slice(rast: raster, dim_name: utf8, index: int)

Arguments

  • rast (raster): Input raster
  • dim_name (utf8): Name of the dimension to slice (e.g., ‘time’).
  • index (int): Zero-based index along the dimension.

[!WARNING]

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

Description

Extracts a single slice along a named non-spatial dimension, removing that dimension from every band that carries it in the output raster. For example, slicing a raster with shape [time=12, y=256, x=256] on 'time' at index 5 produces a 2D raster with shape [y=256, x=256] containing the data at time step 5.

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

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_DimToBand and xarray’s ds.isel({dim: i}).

For example, with a raster containing an elevation band ([y, x]) and a temperature band ([time, y, x]), RS_Slice(raster, 'time', 5) slices the temperature band and passes the elevation band through unchanged.

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

Returns an error if the index is out of range for any band that does carry the dimension.

See also RS_SliceRange to extract a range of indices while keeping the dimension.

Examples

-- RS_Example() is 2-D, so first create a non-spatial 'band' dimension with
-- RS_BandToDim, then select one index along it (dropping the dimension).
SELECT RS_Slice(RS_BandToDim(RS_Example(), 'band'), 'band', 0);
┌─────────────────────────────────────────────────────────────────────────────┐
│   rs_slice(rs_bandtodim(rs_example(),Utf8("band")),Utf8("band"),Int64(0))   │
│                                    raster                                   │
╞═════════════════════════════════════════════════════════════════════════════╡
│ [64x32/1] @ [43.08 79.07 203.07999999999998 207.07] skew=(1, 1) / OGC:CRS84 │
└─────────────────────────────────────────────────────────────────────────────┘