Skip to content

[Feature]: Put rasters on one grid: project and align them (coordinate system, cell size, origin, extent, resampling), and rasterize polygons onto it #821

Closed

Description

@elpidioassinaturas

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.function resample, 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.georeference with transform, 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_mask fills polygons into a grid's cells by scanline, but only to clip a raster to polygons (raster.process clip).

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 same grid lines 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 -tap does. Two runs at the same crs and cellSize then 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.project builds on warp.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 by crs, cellSize, origin and extent, 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, as cube.reduce's mode.

    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.

  • nearest is 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 take nearest or mode, continuous values bilinear or cubic, and average when going coarser. A palette raster is always nearest, as warp already 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_mask does, holes cut out. Polygons narrower than a cell can be missed, as the docs will say.
    • Values:
      • a numeric field gives its values (Int32 for whole numbers, Float32 otherwise);
      • a text field gives 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.
    • 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.
  • 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 with path a 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:

  1. raster.project: the grid parameters, average and mode, the docs (analysis.md), and tests:
    • a raster projected to EPSG:5880 and back within half a cell;
    • two runs with the same crs and cellSize sharing cell corners;
    • grid matching a template exactly;
    • average and mode checked by hand on a small grid;
    • the cap refused before allocating;
    • hostile parameters.
  2. 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

  1. elpidioassinaturas commented on Oct 24, 2026

    @elpidioassinaturas
    ContributorAuthor

    A note on GeoLibre, since its suite already has related tools: reproject_raster, resample, vector_polygons_to_raster and aggregate_raster. I'd still put this in RustGIS itself, for three reasons:

    • GeoLibre is optional. It is a separate download on the desktop (about 20 MB) and a 25 MB load in the browser. A plugin can't install it, so a plugin that brings data to the user's area and wants it on one grid couldn't count on it. Scripts and the assistant couldn't either.
    • Its average and mode don't aggregate. In wbraster (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.
    • The pieces are already in RustGIS. warp.rs has the approximate transformer and the nearest, bilinear and cubic samplers, and polygon_mask fills polygons by scanline. What wbraster does have and its GeoLibre tool doesn't expose (an output extent, a resolution and a snap origin) matches the crs, cellSize, origin and extent proposed above.

    So the plan stays as written: raster.project on warp.rs, then raster.rasterize, as RustGIS's own code with no new dependency. If that suits you, I'll start with the first.

  2. added
    enhancement
    on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions