Package 'gdalblock'

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

Help Index


Get block bounding box

Description

Get block bounding box

Usage

block_bbox(x, ...)

Arguments

x

A block object.

i

Block column index (0-based).

j

Block row index (0-based).

Value

Numeric vector c(xmin, ymin, xmax, ymax).


Get block metadata as data frame

Description

Get block metadata as data frame

Usage

block_data(x, ...)

Arguments

x

A block object.

...

Ignored.

i

Block column indices (0-based). If NULL, all columns.

j

Block row indices (0-based). If NULL, all rows.

Value

A data.frame with columns: i, j, xoff, yoff, xsize, ysize, xmin, ymin, xmax, ymax, and geometry (wk::rct).

Examples

## 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

Description

Get block dimensions

Usage

block_dim(x, ...)

Arguments

x

A block object.

i

Block column index (0-based).

j

Block row index (0-based).

Value

Integer vector c(ncol, nrow).


Get block pixel/line index

Description

Get block pixel/line index

Usage

block_index(x, ...)

Arguments

x

A block object.

i

Block column index (0-based).

j

Block row index (0-based).

Value

Integer vector c(xoff, yoff, xsize, ysize).


Get block rectangles as wk::rct

Description

Get block rectangles as wk::rct

Usage

block_rct(x, ...)

Arguments

x

A block object.

...

Ignored.

i

Block column indices (0-based). If NULL, all columns.

j

Block row indices (0-based). If NULL, all rows.

Value

A wk::rct vector of block extents with CRS.

Examples

## 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

Description

Find blocks intersecting a bounding box

Usage

blocks_in_bbox(x, ...)

Arguments

x

A block object.

...

Ignored.

bbox

Numeric vector c(xmin, ymin, xmax, ymax).

data

If TRUE, return full block_data(). If FALSE (default), return wk::rct.

Value

A wk::rct vector or data.frame of intersecting blocks.

Examples

## 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

Description

Find blocks intersecting an extent

Usage

blocks_in_ext(x, ...)

Arguments

x

A block object.

...

Ignored.

ext

Numeric vector c(xmin, xmax, ymin, ymax).

data

If TRUE, return full block_data(). If FALSE (default), return wk::rct.

Value

A wk::rct vector or data.frame of intersecting blocks.

Examples

## Not run: 
b <- block("/path/to/raster.tif")
blocks_in_ext(b, c(100, 500, 200, 600))

## End(Not run)

Plot blocks

Description

Draw rectangles for specified blocks on a new or existing plot.

Usage

plot_block(x, ...)

Arguments

x

A block object.

...

Additional arguments passed to wk::wk_plot().

i

Block column indices (0-based). If NULL, all columns.

j

Block row indices (0-based). If NULL, all rows.

add

Logical; if TRUE, add to existing plot. Default FALSE.

Value

Invisibly returns the wk::rct of plotted blocks.

Examples

## 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)

Plot blocks within a bounding box

Description

Draw rectangles for all blocks that intersect a bounding box.

Usage

plot_block_bbox(x, ...)

Arguments

x

A block object.

...

Additional arguments passed to wk::wk_plot() for block rectangles.

bbox

Numeric vector c(xmin, ymin, xmax, ymax).

add

Logical; if TRUE, add to existing plot. Default FALSE.

plot_bbox

Logical; if TRUE, also draw the query bbox. Default TRUE.

bbox_args

List of arguments passed to graphics::rect() for the bbox rectangle.

Value

Invisibly returns a list with rct (wk::rct) and data (data.frame).


Plot blocks within an extent

Description

Draw rectangles for all blocks that intersect an extent. Uses extent-style coordinate ordering (xmin, xmax, ymin, ymax).

Usage

plot_block_ext(x, ...)

Arguments

x

A block object.

...

Additional arguments passed to wk::wk_plot() for block rectangles.

ext

Numeric vector c(xmin, xmax, ymin, ymax).

add

Logical; if TRUE, add to existing plot. Default FALSE.

plot_ext

Logical; if TRUE, also draw the query extent. Default TRUE.

ext_args

List of arguments passed to graphics::rect() for the extent rectangle.

Value

Invisibly returns a list with rct (wk::rct) and data (data.frame).


block S7 Class

Description

An S7 class for block-based access to GDAL raster datasets.

Usage

read_block(x, ...)

Arguments

x

A block object.

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).

Details

The block class wraps a gdalraster::GDALRaster object and provides convenient access to the block (tile) structure of the dataset.

Properties

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

Methods

  • 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

Value

A block object.

A matrix of raster values.

Examples

## 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