make_chunk_index: Generate an index of chunk offsets and sizes for iterating a...

View source: R/gdal_helpers.R

make_chunk_indexR Documentation

Generate an index of chunk offsets and sizes for iterating a raster

Description

make_chunk_index() returns a matrix of xchunkoff, ychunkoff, xoff, yoff, xsize, ysize, xmin, xmax, ymin and ymax, i.e., indexing of potentially multi-block chunks defined on block boundaries for iterating I/O operations over a raster. The last four columns are geospatial coordinates of the bounding box. Note that class GDALRaster provides a method of the same name that is more convenient to use with a dataset object.

Usage

make_chunk_index(
  raster_xsize,
  raster_ysize,
  block_xsize,
  block_ysize,
  gt = c(0, 1, 0, 0, 0, 1),
  max_pixels = 0
)

Arguments

raster_xsize

Integer value giving the number of raster columns.

raster_ysize

Integer value giving the number of raster rows.

block_xsize

Integer value giving the horizontal size of a raster block in number of pixels.

block_ysize

Integer value giving the vertical size of a raster block in number of pixels.

gt

A numeric vector of length six containing the affine geotransform for the raster (defaults to c(0, 1, 0, 0, 0, 1)). Required only if geospatial bounding boxes of the chunks are needed in the output.

max_pixels

Numeric value (a whole number), optionally carrying the bit64::integer64 class attribute. Specifies the maximum number of pixels per chunk. Can be set to zero to define chunks as the blocks.

Details

The stand-alone function here supports the general case of chunking/tiling a raster layout without using a dataset object. If the max_pixels argument is set to zero, the chunks are raster blocks (the internal tiles in the case of a tiled format). Otherwise, chunks are defined as the maximum number of consecutive whole blocks containing ⁠<= max_pixels⁠, that may span one or multiple whole rows of blocks.

Value

A numeric matrix with number of rows equal to the number of chunks, and named columns: xchunkoff, ychunkoff, xoff, yoff, xsize, ysize, xmin, xmax, ymin, ymax. Offsets are 0-based.

See Also

Methods make_chunk_index(), readChunk() and writeChunk() in class GDALRaster.

Usage example in the web article GDAL Block Cache.

Examples

## chunk as one block
blocks <- make_chunk_index(raster_xsize = 156335, raster_ysize = 101538,
                           block_xsize = 256, block_ysize = 256,
                           gt = c(-2362395, 30, 0, 3267405, 0, -30),
                           max_pixels = 0)

nrow(blocks)

head(blocks)

tail(blocks)

## chunk as 16 consectutive blocks
chunks <- make_chunk_index(raster_xsize = 156335, raster_ysize = 101538,
                           block_xsize = 256, block_ysize = 256,
                           gt = c(-2362395, 30, 0, 3267405, 0, -30),
                           max_pixels = 256 * 256 * 16)

nrow(chunks)

head(chunks)

tail(chunks)

gdalraster documentation built on Nov. 19, 2025, 9:07 a.m.