| Title: | Block-Based Access to GDAL Raster Datasets |
|---|---|
| Description: | Provides an S7 class for block-based (tiled) access to raster datasets via GDAL. Wraps 'gdalraster' to expose block structure and efficient block-level reading. |
| Authors: | Michael Sumner [aut, cre] |
| Maintainer: | Michael Sumner <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-11 06:49:21 UTC |
| Source: | https://github.com/hypertidy/gdalblock |
Get block bounding box
block_bbox(x, ...)block_bbox(x, ...)
x |
A |
i |
Block column index (0-based). |
j |
Block row index (0-based). |
Numeric vector c(xmin, ymin, xmax, ymax).
Get block metadata as data frame
block_data(x, ...)block_data(x, ...)
x |
A |
... |
Ignored. |
i |
Block column indices (0-based). If NULL, all columns. |
j |
Block row indices (0-based). If NULL, all rows. |
A data.frame with columns: i, j, xoff, yoff, xsize, ysize, xmin, ymin, xmax, ymax, and geometry (wk::rct).
## Not run: b <- block("/path/to/raster.tif") block_data(b) # all blocks with full metadata block_data(b, 0:2, 0:2) # subset ## End(Not run)## Not run: b <- block("/path/to/raster.tif") block_data(b) # all blocks with full metadata block_data(b, 0:2, 0:2) # subset ## End(Not run)
Get block dimensions
block_dim(x, ...)block_dim(x, ...)
x |
A |
i |
Block column index (0-based). |
j |
Block row index (0-based). |
Integer vector c(ncol, nrow).
Get block pixel/line index
block_index(x, ...)block_index(x, ...)
x |
A |
i |
Block column index (0-based). |
j |
Block row index (0-based). |
Integer vector c(xoff, yoff, xsize, ysize).
Get block rectangles as wk::rct
block_rct(x, ...)block_rct(x, ...)
x |
A |
... |
Ignored. |
i |
Block column indices (0-based). If NULL, all columns. |
j |
Block row indices (0-based). If NULL, all rows. |
A wk::rct vector of block extents with CRS.
## Not run: b <- block("/path/to/raster.tif") block_rct(b) # all blocks block_rct(b, 0, 0) # single block block_rct(b, 0:3, 0:2) # grid of blocks plot(block_rct(b)) # wk plotting ## End(Not run)## Not run: b <- block("/path/to/raster.tif") block_rct(b) # all blocks block_rct(b, 0, 0) # single block block_rct(b, 0:3, 0:2) # grid of blocks plot(block_rct(b)) # wk plotting ## End(Not run)
Find blocks intersecting a bounding box
blocks_in_bbox(x, ...)blocks_in_bbox(x, ...)
x |
A |
... |
Ignored. |
bbox |
Numeric vector c(xmin, ymin, xmax, ymax). |
data |
If TRUE, return full block_data(). If FALSE (default), return wk::rct. |
A wk::rct vector or data.frame of intersecting blocks.
## Not run: b <- block("/path/to/raster.tif") blocks_in_bbox(b, c(100, 200, 500, 600)) blocks_in_bbox(b, c(100, 200, 500, 600), data = TRUE) ## End(Not run)## Not run: b <- block("/path/to/raster.tif") blocks_in_bbox(b, c(100, 200, 500, 600)) blocks_in_bbox(b, c(100, 200, 500, 600), data = TRUE) ## End(Not run)
Find blocks intersecting an extent
blocks_in_ext(x, ...)blocks_in_ext(x, ...)
x |
A |
... |
Ignored. |
ext |
Numeric vector c(xmin, xmax, ymin, ymax). |
data |
If TRUE, return full block_data(). If FALSE (default), return wk::rct. |
A wk::rct vector or data.frame of intersecting blocks.
## Not run: b <- block("/path/to/raster.tif") blocks_in_ext(b, c(100, 500, 200, 600)) ## End(Not run)## Not run: b <- block("/path/to/raster.tif") blocks_in_ext(b, c(100, 500, 200, 600)) ## End(Not run)
Draw rectangles for specified blocks on a new or existing plot.
plot_block(x, ...)plot_block(x, ...)
x |
A |
... |
Additional arguments passed to |
i |
Block column indices (0-based). If NULL, all columns. |
j |
Block row indices (0-based). If NULL, all rows. |
add |
Logical; if |
Invisibly returns the wk::rct of plotted blocks.
## Not run: b <- block("/path/to/raster.tif") plot_block(b) # all blocks plot_block(b, 0:2, 0:1, col = "lightblue") ## End(Not run)## Not run: b <- block("/path/to/raster.tif") plot_block(b) # all blocks plot_block(b, 0:2, 0:1, col = "lightblue") ## End(Not run)
Draw rectangles for all blocks that intersect a bounding box.
plot_block_bbox(x, ...)plot_block_bbox(x, ...)
x |
A |
... |
Additional arguments passed to |
bbox |
Numeric vector c(xmin, ymin, xmax, ymax). |
add |
Logical; if |
plot_bbox |
Logical; if |
bbox_args |
List of arguments passed to |
Invisibly returns a list with rct (wk::rct) and data (data.frame).
Draw rectangles for all blocks that intersect an extent. Uses extent-style coordinate ordering (xmin, xmax, ymin, ymax).
plot_block_ext(x, ...)plot_block_ext(x, ...)
x |
A |
... |
Additional arguments passed to |
ext |
Numeric vector c(xmin, xmax, ymin, ymax). |
add |
Logical; if |
plot_ext |
Logical; if |
ext_args |
List of arguments passed to |
Invisibly returns a list with rct (wk::rct) and data (data.frame).
An S7 class for block-based access to GDAL raster datasets.
read_block(x, ...)read_block(x, ...)
x |
A |
dsn |
A dataset description (file path, URL, or any GDAL-supported URI). |
i |
Block column index (0-based). |
j |
Block row index (0-based). |
band |
Band number (1-based, default 1). |
The block class wraps a gdalraster::GDALRaster object and provides
convenient access to the block (tile) structure of the dataset.
Access properties using @:
dsn: The dataset description/URI
bbox: Bounding box as c(xmin, ymin, xmax, ymax)
dimension: Dimensions as c(ncol, nrow, nbands)
crs: Coordinate reference system (WKT string)
nbands: Number of bands
datatype: Character vector of data types per band
res: Resolution as c(xres, yres)
blocksize: Standard block size as c(width, height)
nblocks: Number of blocks as c(nx, ny)
blocks: List with block structure details
read_block(x, i, j, band): Read block data as matrix
block_dim(x, i, j): Get block dimensions
block_bbox(x, i, j): Get block bounding box
block_index(x, i, j): Get pixel/line offsets
block_rct(x, i, j): Get blocks as wk::rct
block_data(x, i, j): Get blocks as data.frame with full metadata
blocks_in_bbox(x, bbox): Find blocks intersecting a bbox
blocks_in_ext(x, ext): Find blocks intersecting an extent
A block object.
A matrix of raster values.
## Not run: b <- block("/path/to/raster.tif") b@dimension b@blocksize read_block(b, 0, 0) plot(block_rct(b)) ## End(Not run) Read a block of raster data## Not run: b <- block("/path/to/raster.tif") b@dimension b@blocksize read_block(b, 0, 0) plot(block_rct(b)) ## End(Not run) Read a block of raster data