Repository navigation
Description
The need
Many analyses need their inputs on one grid: map algebra, the Suitability Modeler, cube.trend and cube.reduce over layers, and the covariate stacks of digital soil mapping or land-cover models. The data rarely come that way. For one study area in Brazil, for example:
- an elevation model at 1 arc-second in EPSG:4326 (Copernicus GLO-30);
- land-cover classes at 30 m in EPSG:4326 (MapBiomas);
- NDVI at 231 m in the MODIS sinusoidal projection (MOD13Q1, from the Brazil Data Cube);
- soil, geology and vegetation units as polygons (IBGE's BDiA, 1:250,000).
To model with them, all four have to be on, say, SIRGAS 2000 / Brazil Polyconic (EPSG:5880) at 100 m, cell for cell.
RustGIS can't do that today:
- Raster Functions › Resample (
raster.functionresample,rasterops::resample_to) puts a raster on another raster's grid, by nearest neighbour only. A grid can't be described by a coordinate system and cell size, and nothing averages when going coarser. - Process › Resample (
raster.process) merges n × n pixels into one, in the raster's own system. - Georeference (
raster.georeferencewithtransform,crates/analysis/src/warp.rs) does reproject, with nearest, bilinear or cubic, but only through a control-point fit. Its grid covers the image's footprint, with no origin or extent to line it up with anything else. - Mosaic Rasters refuses tiles whose cells don't line up and points to Resample.
- Nothing turns polygons into a raster.
rasterops::polygon_maskfills polygons into a grid's cells by scanline, but only to clip a raster to polygons (raster.processclip).
Proposal
Two commands that share one way of describing a grid.
Project Raster (raster.project, Analyze › Alignment beside Georeference):
{"layer": "ndvi_2024", "crs": "EPSG:5880", "cellSize": 100, "extent": "Piauí", "resampling": "average", "name": "ndvi_100m", "path": "ndvi_100m.tif"}Polygons to Raster (raster.rasterize, Analyze › Alignment and the Tools pane):
{"layer": "pedo_area", "field": "legenda", "grid": "ndvi_100m", "name": "solos_100m"}The grid, in both:
grid: a raster layer whose coordinate system, cell size, origin and extent are taken exactly. Every output made with the samegridlines up with it.- Or, given one by one:
-
crs, the output's coordinate system; -
cellSize, in its units; -
origin:[x, y], a point that a cell corner falls on. Default[0, 0], so cell corners fall on multiples of the cell size, as GDAL's-tapdoes. Two runs at the samecrsandcellSizethen line up with no template. -
extent:- a polygon layer (its selected or all features' bounds);
[west, south, east, north]in degrees;"view";- by default, the input's footprint.
The extent is widened to whole cells on that origin.
-
Choices in this proposal
-
raster.projectbuilds onwarp.rs. It already maps each output cell back to the image, with the approximate transformer (exact every 8 cells, within 1/8 pixel) and the nearest, bilinear and cubic samplers. A raster's own geotransform is an affine fit, so projecting is warping through it onto a grid given bycrs,cellSize,originandextent, rather than onto the footprint. Georeference keeps its behaviour. -
Two more resampling methods for going coarser:
average, the mean of the source pixels whose centres fall in each output cell, no-data skipped;mode, the most frequent value among them, the least of those tied, ascube.reduce'smode.
These are needed to aggregate a continuous variable or a classes map to a coarser cell without just picking one pixel from each block. A cell that no source pixel's centre falls in (the output finer than the source) takes the nearest.
-
nearestis the default, as in Resample and in GDAL: it never invents values, which is right for classes. Bilinear, cubic and average are asked for. The docs say which suits what: classes takenearestormode, continuous valuesbilinearorcubic, andaveragewhen going coarser. A palette raster is always nearest, aswarpalready does. -
Datum shifts are applied as everywhere in RustGIS: through each system's transformer, with its
+towgs84. So SAD69 or Córrego Alegre data are shifted by their Helmert step, a few metres from the IBGE's grid (NTv2). Grid-based shifts are out of scope. -
raster.rasterize:- Rule and geometry: a cell takes a polygon's value when its centre falls inside, as
polygon_maskdoes, holes cut out. Polygons narrower than a cell can be missed, as the docs will say. - Values:
- a numeric
fieldgives its values (Int32 for whole numbers, Float32 otherwise); - a text
fieldgives codes 1 to n, in sorted order of its values, listed in the result and in a table added beside the raster (<name> classes); - with no field,
value(default 1) gives a presence mask.
- a numeric
- Overlaps: a later feature wins over an earlier one, as GDAL burns.
- Selection and no-data: only selected features are burned when there is a selection, as other tools honour it. Cells under no polygon are no-data.
- Not in this command: lines, points and an "all touched" rule.
- Rule and geometry: a cell takes a polygon's value when its centre falls inside, as
-
Bounded: the output is capped at
MAX_SAMPLES, cells × bands: 120 million on the desktop, 32 million in the web app. A grid past it is refused, naming the cell size that fits, before anything is computed. A raster opened from an overview is projected at that reduced resolution, and the result says so, as Georeference does. -
Output as the other raster tools: a new layer named
name, and withpatha cloud-optimised GeoTIFF that becomes the layer's file. -
One raster per run. A script or the plugin that brought the data loops over its layers, giving each the first output as
grid. The Workflows pane gets the two forms. A multi-input "Align Rasters" form can follow if it is wanted.
Out of scope
- Grid-based datum shifts (the IBGE's SAD69 → SIRGAS 2000 NTv2 grid): a separate step in the coordinate systems.
- Rasterizing lines and points.
- Zonal statistics by class (
raster.zonal), which I have as a separate branch.
Plan
Two PRs:
raster.project: the grid parameters,averageandmode, the docs (analysis.md), and tests:- a raster projected to EPSG:5880 and back within half a cell;
- two runs with the same
crsandcellSizesharing cell corners; gridmatching a template exactly;averageandmodechecked by hand on a small grid;- the cap refused before allocating;
- hostile parameters.
raster.rasterize: on the same grid parameters, with tests for:- holes and overlaps;
- a text field's codes and their table;
- the selection;
- a template grid shared with
raster.project.
I can do both if this is welcome.
Activity
elpidioassinaturas commentedon Oct 24, 2026
A note on GeoLibre, since its suite already has related tools:
reproject_raster,resample,vector_polygons_to_rasterandaggregate_raster. I'd still put this in RustGIS itself, for three reasons:averageandmodedon't aggregate. Inwbraster(Raster::sample_window_stat_pixel), each output cell takes the statistic of the 3 × 3 source pixels around the nearest one. Going from 30 m to 1 km, a cell's "average" is then 9 of the ~1,100 pixels it covers. The proposal here takes every source pixel whose centre falls in the cell, which is what a coarser cell of a land-cover or elevation grid should hold.warp.rshas the approximate transformer and the nearest, bilinear and cubic samplers, andpolygon_maskfills polygons by scanline. Whatwbrasterdoes have and its GeoLibre tool doesn't expose (an output extent, a resolution and a snap origin) matches thecrs,cellSize,originandextentproposed above.So the plan stays as written:
raster.projectonwarp.rs, thenraster.rasterize, as RustGIS's own code with no new dependency. If that suits you, I'll start with the first.Analysis: raster.project's review fixes (opengeos#821)
Analysis: raster.project refuses an extent or grid of the wrong kind;…
Analysis: raster.project's fourth review round (opengeos#821)
Analysis: mode takes a colour image's alpha among the pixels that show (
Analysis: raster.project reports the name its layer got; mode takes n…
Analysis: average sums a cell as its pixels come, keeping no copy of …
Analysis: project a raster onto a chosen grid (raster.project, #821 p…
fix(engine): raster.rasterize's codes table leaves a table of its nam…
feat(analysis): burn polygons onto a chosen grid (raster.rasterize, #821