Repository navigation
Description
Before you start
- I searched the existing issues and the roadmap and did not find a duplicate request.
What problem does this solve?
In #629, @giswqs asked to keep Terrio out of the native COG writer PR and to experiment with it separately once Terrio supported narrower Cargo features. opengeos/terrio#154 added those features, so I evaluated Terrio's GeoTIFF/COG path without changing RustGIS's production writer or I/O.
Evidence of experiment branch: deniial00/RustGIS@terrio-cog-evaluation, pinned to commit ee149b8 on that branch:
- README with method, results and reproduction
- Desktop correctness and performance
- Build and size measurements
- Wasm export verification
- Dependency graphs
The experiment is a standalone Cargo workspace with its own lockfile. It is not a RustGIS workspace member, so normal RustGIS builds do not resolve or compile Terrio. Terrio is pinned to ce3c4463f19864284d743720123c4d022784c497 with default-features = false, features = ["geotiff"].
Findings
Recommendation: keep the native writer for now. Terrio's minimal build works on native and wasm32-unknown-unknown, and its files pass GDAL's COG validator. But it does not produce equivalent overview pixels for several RustGIS export cases.
Both writers received identical inputs and settings: EPSG:32617, a north-up 30 m grid, 512×512 tiles, pixel interleaving, DEFLATE level 6, predictor 1 and automatic overviews.
| Case | Native | Terrio | Finding |
|---|---|---|---|
| RGB | Pass | Pass | Exact pixels and overviews |
| Odd dimensions | Pass | Pass | Edge dimensions and pixels match |
| BigTIFF | Pass | Pass | 64-bit TIFF header and COG layout |
| Float32 + no-data | Pass | Fail | 2,501 wrong second-level overview pixels |
| UInt16 + no-data | Pass | Fail | 2,585 wrong second-level overview pixels: 2,501 no-data weighting errors (up to 2,977) plus 84 off-by-one rounding differences |
| Palette | Pass | Fail | Overviews invent class indexes |
| Classes | Pass | Fail | Overviews invent classes (9 where class 19 was expected) |
| Grey + alpha | Pass | Fail | Transparent pixels darken colour overviews |
| RGBA | Pass | Fail | Expected (200,100,50), got (100,50,25) |
All 18 desktop outputs pass GDAL's full COG validator with no warnings or errors. Full-resolution pixels are identical between the two writers in every case, and georeferencing, EPSG, no-data values, palettes, UInt16 storage, alpha bands, odd dimensions and BigTIFF are all preserved. The failures are only in the overviews, which a viewer uses when zoomed out. The actual wasm exports show the same six failures.
The quickest way to see it is the classes case, whose first overview should only contain 1, 7 and 19 (run from a checkout of the branch above):
cargo run --release --manifest-path experiments/terrio-cog/Cargo.toml --features terrio -- export terrio classes 1025 769 terrio-classes.tif
gdal_translate -ovr 0 terrio-classes.tif terrio-classes-ov0.tif
gdalinfo -hist terrio-classes-ov0.tif # also contains 4, 9, 10, 12, 13, ...Main causes in the pinned Terrio revision:
- COG export ignores
overview_resampling, so a request for nearest overviews on classes still averages. - Colour overviews are not weighted by alpha.
- Recursive overview averaging loses the original valid-pixel weights.
Cost measurements
These are small export programs, not the full RustGIS app or web bundle. Tests ran on an Apple M1 Pro with rustc 1.98.1 and GDAL 3.13.3.
| Measurement | Native | With Terrio |
|---|---|---|
| Desktop clean build | 136.8 s | 239.3 s |
| Stripped desktop executable | 1.58 MiB | 8.13 MiB |
| Wasm clean build | 104.1 s | 194.8 s |
| Wasm, gzip -9 | 0.301 MiB | 1.365 MiB |
| Wasm, Brotli 11 | 0.221 MiB | 1.092 MiB |
Desktop export, 4096×4096, median of 3 fresh processes; the times include writing and syncing the file:
| Input | Writer | Export ms | Peak memory MiB | Output MiB |
|---|---|---|---|---|
| RGB | Native | 1254.8 | 202.3 | 21.88 |
| RGB | Terrio | 326.5 | 323.1 | 20.64 |
| Float32 + no-data | Native | 411.8 | 74.4 | 1.55 |
| Float32 + no-data | Terrio | 84.8 | 194.8 | 3.01 |
Terrio is faster for these inputs but uses more peak memory. Its large Float32 output also fails the overview checks, so that speed is not for an equivalent file.
Proposed solution
Do not replace or add Terrio in the production writer yet. Keep the experiment as reproducible evidence and file the upstream Terrio issue(s) later. Re-evaluate after Terrio provides:
- COG overview resampling that honours nearest selection for categorical rasters.
- Alpha-weighted averaging for colour overviews.
- Valid-pixel-aware overviews, either by preserving weights recursively or by building from the full-resolution image.
- A public COG writer with bounded memory, for borrowed samples and a
Writedestination, on native and wasm. - Optional JPEG XL/WebP and other unrelated codecs in the
wbraster/wbgeotiffdependency chain.
After those fixes, rerun the same comparison before considering a production integration.
Estimated scope
Medium: a broader feature that is feasible in a reasonable timeframe
Alternatives considered
- Keep RustGIS's native writer: no new dependency, and it passes this comparison.
- Adopt Terrio now: rejected, because it gives different overview results for classes, alpha, and no-data rasters.
- Patch Terrio's behaviour in an adapter: rejected, because precomputed overviews or local fixes would hide upstream gaps and duplicate writer logic.
Activity
giswqs commentedon Oct 21, 2026
@deniial00 Thank you very much for the thorough testing. This is very helpful. Let's keep experimenting and fixing things in terrio and revisit this later when terrio is more mature.
deniial00 commentedon Oct 22, 2026
Update: the Terrio fixes are merged; parity now holds, and the application sizes are measured
The overview problems reported in opengeos/terrio#158 were fixed upstream and merged: the overview fix as opengeos/terrio#165 and a row-averaging speed-up as opengeos/terrio#168. I re-ran the same comparison against the merged code and measured the real applications. Everything is on the fork branch, pinned to
f53f0b4: parity and speed report, application sizes, integration patch.The tested commit was squash-merged, so it is not an ancestor of Terrio
main, butdrivers/gtiff_write.rsonmainis byte-identical to the tested one and nothing has touched it since.mainalso has unrelated commits, so I did not measure its exact sizes.Parity with the native writer
Same nine inputs and settings as before (EPSG:32617, 512 px tiles, Deflate 6, automatic overviews). Every sample of every overview is compared with an independent oracle, and each file is checked with GDAL's COG validator.
ce3c4463)All six earlier failures are fixed, and the 4096×4096 benchmark outputs pass too. One difference remains, in a supplemental 1027×771 test: the class and palette overviews differ from the native writer in 449 edge pixels. Both pick a real class, not an invented one. They differ in which pixel they choose in a partly filled edge block: the native writer takes the centre of the clipped block, Terrio the centre of the full-size block clamped to the image edge. That is a convention choice.
Correction
Earlier I wrote (in opengeos/terrio#158, now edited, and in my link comment here) that GDAL's
NEARESTtakes the centre pixel of a block. That was wrong. I checked GDAL 3.13.3 directly, and it starts from the top-left pixel(0,0). So "centre pixel" is RustGIS's own convention, not GDAL's, and the edge difference above should not be read as non-compliance.Speed and memory (4096×4096, median of 3 fresh processes, Apple M1 Pro)
Terrio is about 4.5× and 4.3× faster here, but uses 1.6× and 2.6× the peak memory, and its Float32 file is about 2× larger. In the same run, the merged speed-up made Terrio 3.1× (RGB) and 2.7× (Float32) faster than the earlier fix. This is synthetic data, not a representative corpus.
Actual application size
Terrio's COG writer, with
default-features = false, features = ["geotiff"], was wired into the realshare.exportRasterCOG path in a snapshot of this repo, then the apps were built with the release settings (the macOS app and DMG throughpackaging/package.sh, the web app through Trunk). One clean build per variant, macOS arm64.rustgisbinary.dmgdownloadrustgis-cliKeeping the native writer alongside Terrio adds only about 34 KB more, so the cost comes from Terrio's dependencies, not the writer. The shipped web app contains no Terrio today, so the web figures are a prospective integration: the web UI does not currently request a COG, so this code would not be reachable there unless a COG option is added. All 32 real exports through each variant's CLI passed the same checks, and both the desktop and web apps started and ran.
Open points
For whoever picks this up, the facts that remain:
I'll leave it to the maintainers to decide how, or whether, to continue. I'm happy to help with whichever direction you prefer, and to re-run the comparison on request.