Expand description
§vaster
Raster grid logic, without any pesky data.
Raster grids are defined by dimension (ncol, nrow) and extent (xmin, xmax, ymin, ymax). Everything else — resolution, cell centres, geotransforms, cell indexing — derives from those six numbers.
This crate provides that derivation with zero dependencies.
§Conventions
- Extent is
[xmin, xmax, ymin, ymax]— same as the Rvasterpackage - Dimension is
[ncol, nrow] - Cell indices are 0-based (the R package uses 1-based)
- Geotransform follows GDAL convention:
[origin_x, pixel_width, row_rotation, origin_y, col_rotation, pixel_height] - Cell (0, 0) is the top-left pixel, traversing right then down
§GDAL geotransform
The 6-element geotransform maps pixel coordinates to geographic coordinates:
x_geo = gt[0] + pixel * gt[1] + line * gt[2]
y_geo = gt[3] + pixel * gt[4] + line * gt[5]For north-up images (no rotation): gt[2] == 0, gt[4] == 0, gt[5] < 0.
Reference: https://gdal.org/tutorials/geotransforms_tut.html
§Quick start
use vaster::*;
let extent = [0.0, 360.0, -90.0, 90.0];
let dim = [360, 180];
// Build a geotransform
let gt = extent_dim_to_gt(&extent, &dim);
assert_eq!(gt[1], 1.0); // 1 degree per pixel
// Cell centre of top-left pixel
let (x, y) = xy_from_cell(&dim, &extent, 0);
assert!((x - 0.5).abs() < 1e-10);
assert!((y - 89.5).abs() < 1e-10);
// Which cell contains a point?
let cell = cell_from_xy(&dim, &extent, 10.3, 45.7);
assert_eq!(cell, Some(10 + 44 * 360));§Relationship to the R package
This crate is the Rust equivalent of hypertidy/vaster, an R package for raster grid logic. The API follows the same conventions with one difference: cell indices are 0-based in Rust (1-based in R).
Functions§
- cell_
from_ row_ col - Cell index from 0-based (row, col).
- cell_
from_ xy - Cell index from geographic (x, y) coordinates.
- col_
from_ cell - Column index (0-based) from cell index.
- col_
from_ x - Fractional column index from geographic x-coordinate.
- col_
row_ from_ xy - Fractional (col, row) from geographic (x, y), using the full affine inverse.
- crop_
offset - Compute the column and row offset of an aligned sub-grid within its parent.
- extent_
dim_ to_ gt - Build a geotransform from extent and dimensions.
- geotransform_
to_ world - Convert a GDAL geotransform to world file parameters.
- gt_
to_ extent - Extract extent from a geotransform and dimensions.
- inv_
geotransform - Invert a geotransform.
- ncell
- Total number of cells.
- row_
col_ from_ cell - (row, col) from cell index (both 0-based).
- row_
from_ cell - Row index (0-based) from cell index.
- row_
from_ y - Fractional row index from geographic y-coordinate.
- vcrop
- Snap an extent to align with a parent grid.
- world_
to_ geotransform - Convert a world file to a GDAL geotransform.
- x_
centre - X-coordinates of cell centres for each column.
- x_
corner - X-coordinates of cell edges (corners) for each column boundary.
- x_
from_ col - Geographic x-coordinate of a pixel column centre.
- x_res
- Resolution (pixel width) in the x direction.
- xy_
from_ cell - Geographic (x, y) of a cell centre, from extent and dimension.
- xy_
from_ col_ row - Geographic (x, y) from pixel (col, row), using the full affine transform.
- y_
centre - Y-coordinates of cell centres for each row.
- y_
corner - Y-coordinates of cell edges (corners) for each row boundary.
- y_
from_ row - Geographic y-coordinate of a pixel row centre.
- y_res
- Resolution (pixel height) in the y direction.
Type Aliases§
- Dimension
- Raster dimensions:
[ncol, nrow]. - Extent
- Raster extent:
[xmin, xmax, ymin, ymax]. - GeoTransform
- A GDAL-style affine geotransform.
- World
File - World file parameters:
[x_res, y_skew, x_skew, y_res, x_centre, y_centre]