Skip to content

RS_Tile

Returns an array of rasters resulting from the split of the input raster into a grid of fixed-size tiles, one list item per tile with its grid position.

Usage

list RS_Tile(rast: raster, width: integer, height: integer, pad_with_no_data: boolean, no_data_value: double)
list RS_Tile(rast: raster, band_indices: array, width: integer, height: integer, pad_with_no_data: boolean, no_data_value: double)

Arguments

  • rast (raster): Input raster
  • band_indices (array): Array[Int] of 1-based band indices to include in each tile, in the given order.
  • width (integer): Tile width in pixels. Must be >= 1.
  • height (integer): Tile height in pixels. Must be >= 1.
  • pad_with_no_data (boolean): Optional (default false). When true, pad the last partial row/column of tiles to the full tile size with a nodata fill; when false the smaller edge tile is emitted as-is.
  • no_data_value (double): Optional. The value written to padded pixels (only valid with pad_with_no_data = true); defaults to the band’s own nodata value, or the band data type’s minimum if it has none. It is an error if it does not fit the band’s data type.

[!WARNING]

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

Description

RS_Tile cuts a raster into a grid of width x height tiles, returning a list with one item per tile that you UNNEST to get one row per tile.

When no band argument is given, every band is included. band_indices selects an ordered subset of bands. Band indices are 1-based.

Each returned list item is a struct with:

  • x: the tile’s grid column (0-based), counting from the left
  • y: the tile’s grid row (0-based), counting from the top
  • tile: the tile raster, with a geotransform shifted to the tile’s own origin

The grid is ceil(width / tile_width) columns by ceil(height / tile_height) rows. When the raster does not divide evenly, the last column and row of tiles are partial: with pad_with_no_data = false the smaller edge tile is emitted as-is, and with pad_with_no_data = true those tiles are padded to the full tile size with a nodata fill. When the band(s) have no nodata value, no_data_value supplies one.

[!NOTE]

RS_Tile copies the raster: every tile carries its own pixels, so the returned list materializes a full copy of the raster spread across the tiles and held in memory as one list value. A small tile size produces many tiles (a 1 x 1 tile size yields one tile per pixel).

Examples

Tile every band into a 2x2 grid of 32x16 tiles, then UNNEST the list to get one row per tile (counted here so the example output stays small rather than printing every tile raster):

SELECT COUNT(*) AS num_tiles
FROM (SELECT UNNEST(RS_Tile(RS_Example(), 32, 16)) AS tile);
┌───────────┐
│ num_tiles │
│   int64   │
╞═══════════╡
│         4 │
└───────────┘

Tile every band, padding the edge tiles to the full 40x20 size with a nodata fill of 0:

SELECT COUNT(*) AS num_tiles
FROM (SELECT UNNEST(RS_Tile(RS_Example(), 40, 20, true, 0.0)) AS tile);
┌───────────┐
│ num_tiles │
│   int64   │
╞═══════════╡
│         4 │
└───────────┘

Tile an ordered subset of bands:

SELECT COUNT(*) AS num_tiles
FROM (SELECT UNNEST(RS_Tile(RS_Example(), make_array(1, 3), 32, 16)) AS tile);
┌───────────┐
│ num_tiles │
│   int64   │
╞═══════════╡
│         4 │
└───────────┘