Skip to content

Zarr v3 writing, sharding and bit shuffle; netCDF writing; RST; shapefiles from memory - #14

Merged
giswqs merged 1 commit into
mainfrom
driver-gaps-raster
Oct 14, 2026
Merged

giswqs merged 1 commit into
mainfrom
driver-gaps-raster

Conversation

@giswqs

@giswqs giswqs commented Oct 14, 2026

Copy link
Copy Markdown
Member

Closes the raster gaps listed in #11 (Zarr, netCDF writing, RST) and reads Shapefile and MapInfo MIF/MID from memory (#12's open item), checked against GDAL 3.12.

Results against GDAL 3.12

scripts/raster_roundtrip.py (read = GDAL writes, terrio reads; write = terrio writes, GDAL reads back; pixels, type, geotransform, CRS, nodata compared):

Format Read vs GDAL Write → GDAL read-back Before
Zarr 65/65 65/65 13/13, 13/13
netCDF 26/26 26/26 13/13, not written
RST 4/4 4/4 3/4, 4/4
every other format unchanged, all pass unchanged, all pass

Zarr read variants added to the script: GDAL's Zarr v3, v3 with CHUNK_MEMORY_LAYOUT=F (a transpose codec), v2 Fortran order, Blosc with BLOSC_SHUFFLE=BIT. Write variants: v2 none/zlib, v3 none/zstd/gzip. netCDF: GDAL's classic (FORMAT=NC) files are now read too; terrio writes CDF-1 and CDF-2.

Sharding: GDAL 3.12 cannot read sharded arrays ("Unsupported codec: sharding_indexed"), so terrio's reader was checked against zarr-python 3.2 instead: 28 arrays (sharded with and without zstd, odd inner chunks, index at the start with big-endian gzip inner chunks, sharded and transposed, transposed, Blosc lz4/zstd bit shuffle; float32/int16/uint8/float64) all read identical to NumPy. zarr-python and xarray read terrio's v3 stores (zstd included); xarray and rioxarray read terrio's netCDF files with the same CRS and transform as GDAL's own files.

compare_with_gdal.py --pixels over the test data: 60 files identical; the only difference is the one listed in #13 (kml_samples.kml, an empty layer's extent).

What changed

  • Zarr (drivers/zarr.rs): v3 writing as GDAL writes it (--co FORMAT=ZARR_V3: group and array zarr.json, dimension_names, / chunk keys, X/Y coordinate arrays, _CRS); zstd for v2 and v3 and gzip for v3 (pure-Rust ruzstd encoder, so it works in WebAssembly). Reading: v3 sharding_indexed (nested, index at either end, CRC32C index), transpose and v2 order: "F", Blosc bit shuffle. Arrays without georeferencing are no longer flipped upside down.
  • netCDF writer (drivers/netcdf_write.rs, new): classic CDF-1 (default), CDF-2 (FORMAT=NC2, or automatically above 2 GiB), CDF-5 (FORMAT=NC5). Laid out as GDAL lays it out: Band1(lat, lon) or (y, x) (several bands: band_data(band, y, x) so GDAL reads one multi-band dataset), rows south to north, pixel-centre coordinate variables with CF standard names and units, a grid mapping variable named as GDAL names it with CF parameters (latitude_longitude, transverse_mercator incl. UTM, mercator incl. Web Mercator, LCC 1SP/2SP, Albers, LAEA, polar stereographic, sinusoidal), crs_wkt, spatial_ref, GeoTransform, _FillValue, _Unsigned/valid_range for bytes, Conventions = "CF-1.5". UInt16 is a short with _Unsigned = "true" (GDAL reads it as UInt16); UInt32 and 64-bit integers are stored as doubles, as GDAL stores them, because this GDAL build reads neither unsigned ints nor CDF-5.
  • netCDF reader: signed types flagged _Unsigned failed with a type mismatch (GDAL's classic Byte files); their fill values keep their bits (-1s → 65535).
  • RST: a projected CRS GDAL writes with an empty reference system is read as GDAL reads it, a local CRS in metres; the GeoTIFF writer writes local CRSs as GDAL does (citation and linear unit only).
  • Memory: Shapefiles (.shp + .dbf/.prj/.cpg) and MapInfo MIF/MID are read from zip archives in memory, in WebAssembly too (shapefile::parse, vector::read_parts). The JS test that expected an error now reads ne_countries.zip (177 features, as GDAL).
  • API/CLI: RasterWriteOptions::creation_options (GDAL-style KEY/VALUE), terrio convert --co KEY=VALUE and the same on the raster processing commands; netCDF is now writable in the driver list.

Known differences

  • Zarr v3 needs a fill value; without nodata terrio writes 0 (integers) or NaN (floats), which GDAL reports as nodata. GDAL writes fill_value: null, which is invalid in v3 (GDAL warns, zarr-python refuses to open it).
  • netCDF without nodata: GDAL reports the type's default fill value as nodata, for terrio's files as for its own.

Still missing

  • netCDF-4 writing, groups below the root, record (unlimited) dimensions.
  • Zarr: v2 filters (delta), writing sharded or Blosc-compressed arrays.
  • RST reading of .ref projections other than geographic (GDAL reads Mercator etc.).

Shared files touched

  • crates/terrio/src/dataset.rs: RasterWriteOptions::creation_options; options passed to the driver writers.
  • crates/terrio/src/formats.rs: netCDF writable.
  • crates/terrio/src/memory.rs: Shapefile/MapInfo from zip archives in the in-memory codecs; test.
  • crates/terrio/src/drivers/mod.rs: writer signature takes the write options; netCDF writer.
  • crates/terrio/src/drivers/vector/mod.rs, shapefile.rs: byte-based shapefile parsing, read_parts.
  • crates/terrio/src/drivers/gtiff_write.rs: local CRS GeoKeys.
  • CLI convert.rs, rasterout.rs, python/src/raster.rs: option struct literals, --co.
  • scripts/raster_roundtrip.py, js/README.md, js/tests/node.test.mjs, ROADMAP.md.

Checks

cargo fmt, cargo clippy --workspace --all-targets -D warnings, cargo test --workspace (with and without TERRIO_TEST_DATA), cargo build -p terrio --target wasm32-unknown-unknown, the npm package's node tests on a wasm-pack build (16/16 with test data), the Python tests (83 passed), and pre-commit run --all-files all pass.

Zarr: write v3 stores as GDAL does (FORMAT=ZARR_V3 creation
option), with gzip or zstd (pure-Rust ruzstd encoder; zstd for v2
too). Read v3 sharding (nested, index at either end, CRC32C),
transposition and v2 Fortran order, and Blosc bit shuffling. Arrays
without georeferencing are no longer flipped.

netCDF: a classic writer (CDF-1, CDF-2 with FORMAT=NC2 or when
large, CDF-5 with FORMAT=NC5) laid out as GDAL writes rasters: CF
lon/lat or x/y coordinates, a grid mapping with CF parameters for
the common projections plus crs_wkt, spatial_ref and GeoTransform,
nodata as _FillValue, unsigned types with _Unsigned. The reader now
reads signed types flagged _Unsigned and their fill values.

RST: an empty reference system in metres is read as GDAL's local
CRS, and the GeoTIFF writer writes local CRSs as GDAL does.

Shapefile and MapInfo MIF/MID are read from memory (zip archives of
their files), WebAssembly included.

RasterWriteOptions gains creation_options (CLI --co KEY=VALUE).
@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Free
  • Run ID: 2d32a5ca-3b6c-4023-8cb6-242ac8b21139
📥 Commits

Reviewing files that changed from the base of the PR and between f3199a7 and 216e93c.

📒 Files selected for processing: 19
  • ROADMAP.md
  • crates/terrio-cli/src/cmd/convert.rs
  • crates/terrio-cli/src/cmd/rasterout.rs
  • crates/terrio/src/dataset.rs
  • crates/terrio/src/drivers/gtiff_write.rs
  • crates/terrio/src/drivers/mod.rs
  • crates/terrio/src/drivers/netcdf.rs
  • crates/terrio/src/drivers/netcdf_write.rs
  • crates/terrio/src/drivers/rst.rs
  • crates/terrio/src/drivers/vector/mod.rs
  • crates/terrio/src/drivers/vector/shapefile.rs
  • crates/terrio/src/drivers/zarr.rs
  • crates/terrio/src/formats.rs
  • crates/terrio/src/memory.rs
  • crates/terrio/tests/real_data.rs
  • js/README.md
  • js/tests/node.test.mjs
  • python/src/raster.rs
  • scripts/raster_roundtrip.py

opengeos is on CodeRabbit Free, which includes PR summaries. Ask your admin to upgrade for code reviews.

  • Ask an admin to upgrade

Open in CodeRabbit

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@giswqs
giswqs merged commit 95c4a28 into main Oct 14, 2026
9 checks passed
@giswqs
giswqs deleted the driver-gaps-raster branch October 14, 2026 16:35
giswqs added a commit that referenced this pull request Oct 14, 2026
Use the creation options #14 added: RASTER_TABLE names the tile table
and TILE_FORMAT picks PNG or JPEG tiles, as in GDAL. The docs list
netCDF writing and the formats read from bytes in WebAssembly.
giswqs added a commit that referenced this pull request Oct 14, 2026
Use the creation options #14 added: RASTER_TABLE names the tile table
and TILE_FORMAT picks PNG or JPEG tiles, as in GDAL. The docs list
netCDF writing and the formats read from bytes in WebAssembly.
giswqs added a commit that referenced this pull request Oct 14, 2026
Use the creation options #14 added: RASTER_TABLE names the tile table
and TILE_FORMAT picks PNG or JPEG tiles, as in GDAL. The docs list
netCDF writing and the formats read from bytes in WebAssembly.
giswqs added a commit that referenced this pull request Oct 14, 2026
…eader (#19)

* GeoPackage: R-tree indexes, raster tiles, own reader

Write GeoPackages the way GDAL does, and read them with terrio's own
SQLite reader instead of wbvector's:

- An R-tree spatial index for every geometry column: the rtree virtual
  table, its node/rowid/parent shadow tables packed in one go
  (sort-tile-recursive, float bounds rounded outwards as SQLite does)
  and GDAL's triggers, plus gpkg_ogr_contents and gpkg_extensions.
  GDAL reports HasSpatialIndex, spatial filters match, and SQLite's
  integrity_check and rtreecheck pass.
- Raster writing: Byte rasters as PNG (or JPEG) tile pyramids, one-band
  Int16, UInt16 and Float32 rasters as 2D gridded coverages (16-bit PNG
  or float TIFF tiles), GDAL's CUSTOM tiling, overview zoom levels,
  nodata and band count metadata. GDAL reads them back identically and
  validate_gpkg.py accepts them.
- A reader of feature and attribute tables with GDAL's field types,
  feature ids and CRSs; files with both layers and rasters open as
  their layers and list the rasters as GPKG:file:table subdatasets.
- GeoPackages read from and written to bytes, WebAssembly included.

The SQLite writer now builds index b-trees of any size and writes
triggers and virtual tables. Layers without a CRS use GDAL's undefined
SRS (99999); layers without geometries are attribute tables.

CRS identification no longer takes a datum's or prime meridian's EPSG
code for the CRS's (a WKT GDAL wrote was identified as EPSG:8901).

* Docs: GeoPackage rasters, bytes and benchmarks

Formats, JavaScript and architecture pages list GeoPackage raster
writing and reading from bytes; the GeoPackage benchmark rows are
re-measured with terrio's own reader.

* GeoPackage: RASTER_TABLE and TILE_FORMAT creation options

Use the creation options #14 added: RASTER_TABLE names the tile table
and TILE_FORMAT picks PNG or JPEG tiles, as in GDAL. The docs list
netCDF writing and the formats read from bytes in WebAssembly.

* CRS: identify WKT whose only codes are a datum's

After #20, a WKT GDAL wrote into a GeoPackage, with EPSG codes on its
datum and prime meridian only, got no code at all (the registry took
8901, the prime meridian's, which the new check rightly rejects). Match
it again without its authorities, as GDAL does: EPSG:4326.

* Docs: netCDF writing, GeoPackage in WebAssembly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant