| Title: | TIFF Virtualization and Decoding via Rust |
|---|---|
| Description: | Extract byte-range chunk references from cloud-hosted TIFF and COG files without reading pixel data. Uses the Rust 'async-tiff' and 'object_store' crates for async I/O across S3, GCS, Azure, HTTP, and local storage. Returns a data frame of tile offsets and metadata suitable for constructing Kerchunk or Zarr virtual stores. |
| Authors: | Michael Sumner [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-2471-7511>) |
| Maintainer: | Michael Sumner <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0.9004 |
| Built: | 2026-09-26 11:25:50 UTC |
| Source: | https://github.com/hypertidy/rustycogs |
Add extent information xmin,xmax,ymin,ymax to refs table
refs_tiles(x)refs_tiles(x)
x |
file path or url |
dataframe with xmin,xmax,ymin,ymax add to the tiffs_refs output
tiles_to_matrix
vfile <- system.file("extdata/volcano-cog.tif", package = "rustycogs", mustWork = TRUE) refs <- refs_tiles(vfile) dim(refs) str(refs)vfile <- system.file("extdata/volcano-cog.tif", package = "rustycogs", mustWork = TRUE) refs <- refs_tiles(vfile) dim(refs) str(refs)
Returns one row per IFD per file — no tile explosion. Useful for understanding file structure before deciding which tiles to fetch.
Returns one row per IFD per file with no tile explosion. Use this to
understand file structure — how many IFDs (overviews), tile grid dimensions,
dtype, CRS, geotransform — before deciding which tiles to fetch with
tiff_refs() or tiff_read_tiles().
tiff_ifd_info(paths, region = NULL, anon = FALSE, concurrency = 16L) tiff_ifd_info(paths, region = NULL, anon = FALSE, concurrency = 16L)tiff_ifd_info(paths, region = NULL, anon = FALSE, concurrency = 16L) tiff_ifd_info(paths, region = NULL, anon = FALSE, concurrency = 16L)
paths |
Character vector of file paths or URLs. |
region |
Optional AWS region string (e.g. |
anon |
Logical. Use anonymous/unsigned requests. Default |
concurrency |
Integer. Maximum concurrent file scans. Default |
A data.frame with one row per IFD containing image dimensions, tile grid size, dtype, compression, photometric interpretation, predictor, planar configuration, CRS, nodata, and geotransform.
A data frame with one row per IFD and columns: path, ifd,
is_tiled, image_w, image_h, tile_w, tile_h, n_tiles_x,
n_tiles_y, dtype, compression, bits_per_sample,
samples_per_pixel, photometric, predictor,
planar_configuration, crs_epsg, gdal_nodata, scale_x,
scale_y, origin_x, origin_y.
tiff_refs() for the full per-tile data frame
## Not run: tiff_ifd_info("scene.tif") tiff_ifd_info("s3://my-bucket/data.tif", anon = TRUE) ## End(Not run)## Not run: tiff_ifd_info("scene.tif") tiff_ifd_info("s3://my-bucket/data.tif", anon = TRUE) ## End(Not run)
Scans one or more TIFF or COG files and returns a data frame with one row per tile per IFD, containing the byte-range metadata needed to construct Kerchunk or Zarr virtual stores.
tiff_refs(paths, region = NULL, anon = FALSE, concurrency = 16L) tiff_refs(paths, region = NULL, anon = FALSE, concurrency = 16L)tiff_refs(paths, region = NULL, anon = FALSE, concurrency = 16L) tiff_refs(paths, region = NULL, anon = FALSE, concurrency = 16L)
paths |
Character vector of file paths or URLs.
Supported schemes: |
region |
Optional AWS region string (e.g. |
anon |
Logical. Use anonymous/unsigned requests. Default |
concurrency |
Integer. Maximum number of files scanned concurrently.
Default |
A data.frame with columns path, ifd, tile_col, tile_row, offset, length, image_w, image_h, tile_w, tile_h, valid_w, valid_h, dtype, compression, bits_per_sample, samples_per_pixel, crs_epsg, gdal_nodata, planar_configuration, scale_x, scale_y, origin_x, origin_y.
A data frame with columns: path, ifd, tile_col, tile_row,
offset, length, image_w, image_h, tile_w, tile_h, dtype,
compression, bits_per_sample, samples_per_pixel, crs_epsg,
gdal_nodata, planar_configuration, scale_x, scale_y,
origin_x, origin_y.
tiff_ifd_info() for a compact one-row-per-IFD summary,
tiff_read_tiles() to fetch pixel data
## Not run: refs <- tiff_refs("s3://my-bucket/data.tif", anon = TRUE) refs <- tiff_refs(c("file1.tif", "file2.tif"), concurrency = 4L) ## End(Not run)## Not run: refs <- tiff_refs("s3://my-bucket/data.tif", anon = TRUE) refs <- tiff_refs(c("file1.tif", "file2.tif"), concurrency = 4L) ## End(Not run)
Fetch and decode a single tile from a TIFF/COG file.
Fetch and decode a single tile from a TIFF/COG file
tiff_tile(path, ifd_index = 0L, col, row, region = NULL, anon = FALSE) tiff_tile(path, ifd_index = 0L, col, row, region = NULL, anon = FALSE)tiff_tile(path, ifd_index = 0L, col, row, region = NULL, anon = FALSE) tiff_tile(path, ifd_index = 0L, col, row, region = NULL, anon = FALSE)
path |
File path or URL to the TIFF. |
ifd_index |
IFD index (0-based). |
col |
Tile column index (0-based). |
row |
Tile row index (0-based). |
region |
Optional AWS region string. |
anon |
Logical. Use anonymous requests. Default |
A named list with data, dim, dtype.
A named list with:
data: numeric vector of decoded pixel values (row-major)
dim: integer vector c(height, width, bands)
dtype: character dtype string (e.g. "<f4", "<u2")
tile_to_array() to reshape the result, tiff_tiles() for batches
## Not run: tile <- tiff_tile("scene.tif", col = 0L, row = 0L) m <- tile_to_array(tile) ## End(Not run)## Not run: tile <- tiff_tile("scene.tif", col = 0L, row = 0L) m <- tile_to_array(tile) ## End(Not run)
Uses ifd.fetch_tiles() for a single vectorized range request.
Fetches a batch of tiles from a single file in one vectorized request.
More efficient than calling tiff_tile() in a loop. For multi-file
batches use tiff_read_tiles().
tiff_tiles(path, ifd_index = 0L, cols, rows, region = NULL, anon = FALSE) tiff_tiles(path, ifd_index = 0L, cols, rows, region = NULL, anon = FALSE)tiff_tiles(path, ifd_index = 0L, cols, rows, region = NULL, anon = FALSE) tiff_tiles(path, ifd_index = 0L, cols, rows, region = NULL, anon = FALSE)
path |
File path or URL to the TIFF. |
ifd_index |
IFD index (0-based). Default |
cols |
Integer vector of tile column indices (0-based). |
rows |
Integer vector of tile row indices (0-based). Must be the same
length as |
region |
Optional AWS region string. |
anon |
Logical. Use anonymous requests. Default |
A list of tile result lists, each with data, dim, dtype.
A list of tile results, each with data, dim, and dtype
components as described in tiff_tile().
tile_to_array() to reshape individual results,
tiff_read_tiles() for multi-file batches
## Not run: tiles <- tiff_tiles("scene.tif", cols = 0:3, rows = rep(0L, 4)) arrays <- lapply(tiles, tile_to_array) ## End(Not run)## Not run: tiles <- tiff_tiles("scene.tif", cols = 0:3, rows = rep(0L, 4)) arrays <- lapply(tiles, tile_to_array) ## End(Not run)
Reshapes the flat numeric vector returned by tiff_tile(), each element
of tiff_tiles(), or each element of the data column from
tiff_read_tiles() into a matrix (single band) or 3D array (multi-band).
tile_to_array(tile)tile_to_array(tile)
tile |
A tile result list from |
The matrix is filled row-by-row (byrow = TRUE), consistent with the
row-major (C) order returned by async-tiff and expected by
graphics::rasterImage() and ximage(). Note that as.vector(m) on the
result does not recover the original input order; use as.vector(t(m))
for a round-trip.
A matrix for single-band tiles, or a 3D array with dimensions
[height, width, bands] for multi-band tiles.
## Not run: tile <- tiff_tile("scene.tif", col = 0L, row = 0L) m <- tile_to_array(tile) dim(m) # c(256, 256) for a single-band 256x256 tile ximage::ximage(m) ## End(Not run)## Not run: tile <- tiff_tile("scene.tif", col = 0L, row = 0L) m <- tile_to_array(tile) dim(m) # c(256, 256) for a single-band 256x256 tile ximage::ximage(m) ## End(Not run)
Turn already-read data into a full matrix
tiles_to_matrix(refs)tiles_to_matrix(refs)
refs |
data frame, output of |
matrix, data shaped from raw read into 'raster order'
refs_tiles
vfile <- system.file("extdata/volcano-cog.tif", package = "rustycogs", mustWork = TRUE) refs <- refs_tiles(vfile) mat <- refs |> subset(ifd == 4) |> tiff_read_tiles() |> tiles_to_matrix()vfile <- system.file("extdata/volcano-cog.tif", package = "rustycogs", mustWork = TRUE) refs <- refs_tiles(vfile) mat <- refs |> subset(ifd == 4) |> tiff_read_tiles() |> tiles_to_matrix()