Raster Processing

Create Cloud-Optimized GeoTIFFs (COGs) and H3-indexed parquet from raster datasets.

Overview

The raster processing module provides tools to:

  • Create Cloud-Optimized GeoTIFFs optimized for cloud rendering (titiler)

  • Convert rasters to H3-indexed parquet files

  • Auto-detect optimal H3 resolution from pixel size

  • Process global rasters by h0 regions for memory efficiency

Basic Usage

Python API

from cng_datasets.raster import RasterProcessor

# Process raster to COG and H3-indexed parquet
processor = RasterProcessor(
    input_path="wetlands.tif",
    output_cog_path="s3://bucket/wetlands-cog.tif",
    output_parquet_path="s3://bucket/wetlands/hex/",
    h3_resolution=None,  # Auto-detect
    parent_resolutions=[8, 0],
    value_column="wetland_class",
    nodata_value=255,
)

# Create COG
processor.create_cog()

# Convert to H3-indexed parquet
processor.process_all_h0_regions()

Command-Line Interface

# Create COG only
cng-datasets raster \
    --input wetlands.tif \
    --output-cog s3://bucket/wetlands-cog.tif \
    --compression deflate

# Raster to H3 parquet (auto-detect resolution)
cng-datasets raster \
    --input wetlands.tif \
    --output-parquet s3://bucket/wetlands/hex/ \
    --parent-resolutions "8,0" \
    --value-column wetland_class \
    --nodata 255

# COG + H3 in one command
cng-datasets raster \
    --input data.tif \
    --output-cog s3://bucket/data-cog.tif \
    --output-parquet s3://bucket/data/hex/ \
    --resolution 10 \
    --parent-resolutions "9,8,0"

Auto-Detection of H3 Resolution

The processor can automatically detect the optimal H3 resolution based on the raster’s pixel resolution:

from cng_datasets.raster import detect_optimal_h3_resolution

# Get recommended H3 resolution
h3_res = detect_optimal_h3_resolution("high-res-raster.tif")
print(f"Recommended H3 resolution: {h3_res}")

Resolution Mapping

Detection targets an H3 edge length of ~3x the source pixel width (about 9 source pixels per cell):

Pixel Size

Detected H3

Use Case

0.5-2m

h13-h14

High-res imagery

7-25m

h10-h11

Sentinel/aerial

30-300m

h7-h10

Landsat/regional

1-12km

h4-h6

Climate/global

The processor provides helpful feedback when you choose a resolution different from the detected one:

  • Finer resolution: “Using h12 instead of detected h10 - will create more cells”

  • Coarser resolution: “Using h8 instead of detected h10 - will aggregate more pixels”

h8 is the catalog join key

The 3x edge target agrees with the catalog convention (roughly one cell per pixel) at fine pixels and diverges as pixels coarsen — a ~1 km global raster detects h6, two levels below h8. A dataset whose finest resolution is coarser than h8 carries no h8 column at all, so it cannot be joined against the rest of the catalog on the universal join key.

A finer target only carries h8 if h8 is among the parent resolutions, and the raster default is --parent-resolutions 0 — so an h10 build emits h10 and h0, and nothing to join on either.

raster warns in both cases, naming the consequence and the flag that fixes it. Pass --resolution 8 for a coarse global product, or add 8 to --parent-resolutions for a finer one, whenever a joinable output matters (issue #182):

cng-datasets raster --input chelsa-bio1.tif ... \
    --resolution 8 --parent-resolutions "7,6,0"

cng-datasets raster --input nlcd-2021.tif ... \
    --resolution 10 --parent-resolutions "9,8,0"

Parameters

RasterProcessor

  • input_path (str): Path to input raster file (supports /vsis3/ URLs)

  • output_cog_path (str, optional): Path to output COG

  • output_parquet_path (str, optional): Path to output parquet directory

  • h3_resolution (int, optional): H3 resolution (None for auto-detect)

  • parent_resolutions (list[int]): Parent resolutions for aggregation (default: [0])

  • h0_index (int, optional): Process specific h0 region (0-121)

  • value_column (str): Name for raster value column (default: “value”)

  • nodata_value (float or comma-separated string, optional): NoData value(s) to exclude. A categorical product often carries several fill codes in one band (LANDFIRE: -9999 Fill-NoData, -1111 Fill-Not-Mapped, 32767 internal), and a GDAL band can declare only one — see Several fill codes in one band.

  • compression (str): COG compression method (default: “deflate”)

  • blocksize (int): COG tile size (default: 512)

  • resampling (str): Resampling method for COG (default: “nearest”)

  • method (str): Raster→H3 algorithm (default: "exact-extract"). One of exact-extract or warp-centroid — see Aggregation methods.

  • hex_resampling (str): Reducer for aggregating source pixels into each H3 cell (default: “mean”). Valid values depend on method: with exact-extract, one of mean, sum, mode, fractions (the share of each class in a cell, one row per class), max or min; with warp-centroid, any GDAL resampleAlg (average, sum, mode, near, bilinear, cubic, …).

Several fill codes in one band

exactextract honours a single declared band NoData, so extra fill codes have to be mapped onto the primary one before aggregation. For an integer source this costs nothing: the mapping is expressed as a VRT lookup table and applied on read, so no pixels are written.

Collapsing fill codes [-9999.0, -1111.0, 32767.0] → -9999.0 for hex aggregation...
✓ Collapsed as a VRT lookup table, no raster written: /tmp/cng_collapsed_798466992877.vrt

This used to stage an uncompressed copy of the whole source instead. That copy is grid pixels x bytes per pixel — independent of the source’s compression, and independent of the chunk the pod is working, so every pod wrote the same full-grid file. For the LANDFIRE CONUS grid that is 34 GB per pod against the ephemeral-storage: 40Gi the generator emits, which evicted every pod on the largest layers of a tranche (issue #209). An ephemeral eviction surfaces as exit 137, byte-identical to an OOM kill in kubectl get pods, so it is easy to misdiagnose as memory.

A float source cannot use a lookup table — a table interpolates between its entries rather than substituting values — so it falls back to a materialised copy, which is now compressed with the predictor matching the band type. Sources that cannot be expressed exactly are refused rather than approximated.

In a generated raster-workflow the preprocess-cog step collapses the codes once, and the hex pods are handed only the primary. That step is skipped when the source is already a single-band COG needing no clip — which is precisely when the hex pods receive the full list and do the work themselves, so the path above is the normal one for a well-formed source.

Cloud-Optimized GeoTIFF (COG)

COGs are optimized for cloud rendering with titiler:

processor = RasterProcessor(
    input_path="data.tif",
    output_cog_path="s3://bucket/data-cog.tif",
    compression="deflate",  # or "zstd", "lzw"
    blocksize=512,  # Tile size
    resampling="bilinear"  # or "nearest", "cubic"
)

cog_path = processor.create_cog()

COGs include:

  • Internal tiling (configurable blocksize)

  • Overview pyramids for zoom levels

  • Optimized compression

  • EPSG:4326 reprojection if needed

  • Multi-threaded processing

The COG step of raster-workflow (preprocess-cog) writes sparse COGs with GDAL’s SPARSE_OK=TRUE. A tile that is entirely nodata, or entirely 0 when the band has no nodata value, is left out of the file, in the full-resolution image and in every overview. Pixel values are unchanged, since an unwritten tile reads back as nodata. GDAL, rasterio, terra, TiTiler, tifffile and geotiff.js 3.0 or later read these files exactly like dense ones. geotiff.js 1.x and 2.x fail on them with buffer error, which covers OpenLayers before 10.9.0 and georaster-layer-for-leaflet.

When the hex reducer is categorical (mode or fractions), the warp to EPSG:4326 uses nearest resampling, so no class code is invented along a class boundary. Continuous sources warp with bilinear.

Densities: total, not sum

The reducer follows the source’s units, not the quantity you want in the end.

Source values

Reducer

Each cell holds

An amount per pixel (persons, tonnes)

sum

The amount in the cell

A per-area density (Mg/ha, persons/km²)

total --value-units "Mg/ha"

The amount in the cell (Mg)

A per-area density

mean

The average density in the cell (Mg/ha)

An intensity (NDVI, temperature)

mean

The average

sum adds the pixel values themselves. For a density that is a sum of densities, which undercounts by the pixel area: the 300 m carbon rasters came out 6–7 times below their published totals (#105). total multiplies each pixel by its true area on the sphere before adding, so cells at different latitudes integrate correctly, and SUM() over the table is the grand total.

  • total needs --value-units with a per-area denominator, which sets the scale: /ha, ha-1, ha⁻¹ or per hectare multiply by 100 (km² to ha); /km2 or km-2 by 1; /m2 or m-2 by 10⁶.

  • sum with a per-area --value-units is refused. sum without --value-units prints a warning at generation, and the hex pod warns when the band’s own units are per-area. Most density rasters declare no units, so --value-units is the declaration the guard trusts.

  • --value-units is recorded as value_units in each partition’s key-value metadata. For total it is the units without the area (Mg).

  • total is an exact-extract reducer; --method warp-centroid refuses it.

Clipping to a polygon

--cutline clips the COG step to the polygons of a vector layer, such as a country boundary, and --cutline-where picks features from it:

cng-datasets raster-workflow --dataset worldcover-2021/peru \
  --source-url s3://<bucket>/worldcover-2021.tif \
  --cutline s3://<bucket>/country-boundaries.parquet --cutline-where "iso3 = 'PER'" \
  --nodata 0 --hex-resampling mode ...
  • Any vector GDAL reads works: GeoParquet, GeoPackage, GeoJSON, a zipped shapefile, local or by URL. A cutline in another CRS is reprojected.

  • A pixel whose centre falls outside the polygons becomes nodata, so the step needs a nodata value: --nodata, or the source’s own. Without one it stops rather than writing 0.

  • A source already in EPSG:4326 keeps its grid. The extent is the polygons’ bounds snapped outward to the source pixels and cut to the source, and the warp is nearest, so every pixel inside keeps its value. A source in another CRS is warped as usual, with the clip.

  • It adds the preprocess-cog step even for one source that is already a COG, as --target-extent and --target-resolution now do. --cutline and --target-extent exclude each other.

Mode and fractions builds of one layer

A categorical layer is usually built twice from the same COG: --hex-resampling mode for the dominant class in each cell, and --hex-resampling fractions for the share of every class. The two tables have different schemas, so a fractions build writes beside the other rather than over it:

mode (and every other reducer)

fractions

Hex table

<dataset>/hex/

<dataset>/hex-fractions/

Sub-h0 staging

<dataset>/hex-chunks/

<dataset>/hex-fractions-chunks/

Job names

<name>-hex, <name>-workflow, …

<name>-fractions-hex, <name>-fractions-workflow, …

Sizes and checksums

<dataset>.checksums.json

<dataset>-fractions.checksums.json

Measured hex pod use

<dataset>.usage.json

<dataset>-fractions.usage.json

Both builds read and write the same <dataset>-cog.tif and <dataset>.render.json, since both warp with nearest and so produce the same COG. Generate them into separate --output-dirs, because workflow.yaml and configmap.yaml keep fixed file names.

Default render and thumbnail

Every COG carries its band statistics inside the file (STATISTICS_MINIMUM, _MAXIMUM, _MEAN, _STDDEV, _VALID_PERCENT), with no .aux.xml sidecar, as Portolan requires.

When raster-workflow writes the COG, a render step after the hex step draws each one and writes s3://<bucket>/<dataset>.render.json, plus <cog stem>.thumbnail.png beside each COG:

{"bucket": "public-lc", "generator": "cng-datasets x.y.z", "created": "...",
 "renders": {"lc/nlcd-2001-cog.tif": {"colormap_name": "viridis", "rescale": [[0.4, 95.0]],
                                      "nodata": 255, "thumbnail": "lc/nlcd-2001-cog.thumbnail.png"}}}

Each entry holds STAC render-extension fields. The STAC author adds title and assets and puts it under the collection’s renders. The thumbnail key names the PNG for the collection’s thumbnail asset.

  • A band with a color table is drawn with it: each entry is a colormap class, resampled nearest.

  • Any other band gets viridis stretched over its 2nd to 98th percentile, read from an overview. The stretch is in real units when the band has a scale or offset, because a map app unscales before applying rescale. Min to max would leave skewed data such as population or carbon at the bottom of the ramp.

  • A band with one value throughout gets no render.

The automatic render is a default, not the answer. Diverging data needs a symmetric range and a diverging map, a categorical raster without a color table needs a class map, and log-scaled data needs a transform. Rerun the command with overrides:

cng-datasets cog-render s3://<bucket>/<dataset>-cog.tif --output s3://<bucket>/<dataset>.render.json \
  --colormap rdbu_r --rescale -5,5          # or --colormap-json '{"1": "#1b9e77", "2": "#d95f02"}'

The thumbnail is drawn with GDAL from the COG’s overviews, with nodata transparent, so it needs no browser or tile server. It can draw a color table, --colormap-json, and viridis or rdbu (and their _r reverses). For any other --colormap it writes the render without a thumbnail and says so.

H3 Processing by h0 Regions

For global rasters, process by h0 regions (0-121) for memory efficiency:

# Process all h0 regions
processor = RasterProcessor(
    input_path="s3://bucket/global.tif",
    output_parquet_path="s3://bucket/global/hex/",
    h3_resolution=8,
    parent_resolutions=[0],
)
output_files = processor.process_all_h0_regions()

# Or process specific h0 region (useful for K8s jobs)
processor = RasterProcessor(
    input_path="s3://bucket/global.tif",
    output_parquet_path="s3://bucket/global/hex/",
    h0_index=42,  # Process only h0 region 42
    h3_resolution=8,
)
processor.process_h0_region()

This enables:

  • Memory-efficient processing of large rasters

  • Parallel processing via Kubernetes

  • Independent failure handling per region

Where the results are accumulated

Each worker writes its own chunk straight to a parquet part and returns the path; the final partition is one DuckDB statement over those parts. The parent therefore holds nothing proportional to the cell count.

It used to collect every worker’s rows as a pandas frame, hold them all in a list, and pd.concat them — which allocates the result while the inputs are still referenced, so the process peaked at roughly twice the accumulated size at exactly its largest moment.

Nor does a frame have to be built in the first place. exactextract is C++ and can serialise through GDAL, so where OGR can write Parquet the worker has it write the file directly and DuckDB normalises that into the part. The runtime image ships that driver; most distribution GDALs do not, so the pandas writer remains the fallback and which one runs is feature-detected. CNG_HEX_GDAL_WRITER=0 forces the fallback, and the two are asserted to produce identical rows.

Cost follows the raster, not the cell

Within a chunk, only the cells the source can actually reach are enumerated. The chunk’s hierarchy is descended a level at a time: a subtree whose footprint misses the source — widened by a margin, because an H3 child can protrude past its parent — is dropped whole, and a subtree that lies entirely inside the source is taken whole without descending. Work is therefore proportional to the source’s perimeter rather than its area.

This matters most for small rasters, which previously cost exactly what a continental one did. A 196 x 169 pixel raster in California enumerated all 5,764,801 res-8 descendants of its h0 — a ~196x overshoot that made a fan-out over many small rasters impractical (issue #215). Each chunk now reports what it kept:

✓ 29,465 of 5,764,801 cells reach the source (0.5% of the chunk)

That figure is also the one that explains the pod’s peak memory and runtime, and it is printed before the aggregation rather than inferred afterwards.

The restriction never removes a cell the raster touches: the margin is checked against exhaustive enumeration of every child in the test suite, including the cells that wrap the antimeridian, whose true footprint is two longitude intervals rather than one. Set CNG_HEX_PRUNE_CELLS=0 to enumerate every descendant instead, which is useful only for comparing a suspect run like for like.

Sparse sources. The prune above tests each subtree against the source’s bounding box, which does not help a source whose data is scattered across a large extent (coastlines, wetlands) or a global one. For a sparse GeoTIFF the descent also reads the file’s tile index, without reading any pixels, and drops every subtree that lies over unwritten tiles. On Global Mangrove Watch at res 10, one h0 went from 282,475,249 cells to 81,955,734. It applies only to a geographic source whose unwritten tiles read as a value already treated as nodata, so dropping them cannot change the output, and the log says why when it is off. CNG_HEX_PRUNE_COVERAGE=0 turns it off.

The antimeridian. A cell that straddles ±180° is read as one polygon, shifted by a multiple of 360° into the longitude frame of the raster it reads, rather than split into a MultiPolygon whose bounding box spans the globe. A source whose columns cover the full 360° is read through a VRT padded on both sides with its own columns, so a cell or a window across the edge is one contiguous read.

Regional rasters: restrict the fan-out with --h0-subset / --h0-cells

A generated hex job runs one completion per h0 cell, 122 in all. A regional source overlaps only a few of them, and every other pod localizes the whole COG, finds no overlap and exits — CONUS occupies 6 of the 122 cells, so 116 pods (95%) start only to do nothing, each first pulling a multi-GB COG.

Pass the cells the source covers:

cng-datasets raster-workflow \
  --dataset landfire-2024-cbd \
  --source-url s3://public-landfire/landfire-2024-cbd/landfire-2024-cbd-cog.tif \
  --bucket public-landfire --namespace geo-workflows \
  --h3-resolution 10 --parent-resolutions "9,8,0" --value-column cbd \
  --h0-subset "12,14,20,50,71,78"        # CONUS

The hex job then carries completions: 6, and the completion index selects from the list:

completions: 6
...
H0S=(12 14 20 50 71 78)
H0=${H0S[$JOB_COMPLETION_INDEX]}
cng-datasets raster ... --h0-index ${H0} ...

The list is sorted and de-duplicated, so a completion index maps to the same cell across regenerations. Values outside 0-121 are rejected, and a subset naming all 122 is the default fan-out. Omit the flag for a global source.

The restriction also applies to a serial run — cng-datasets raster with neither --h0-index nor --chunk-index, which processes the regions in one process. It used to apply only to the chunked fan-out, so on the serial path the flag was parsed, validated, echoed and then ignored, and the run worked through the whole grid anyway (issue #215).

Positions are not H3 base cell numbers

--h0-index and --h0-subset take positions — values of the i column in the h0 grid (s3://public-grids/hex/h0-valid.parquet). That column is an arbitrary permutation of the 122 H3 base cells, so position 12 is base cell 9, and exactly one of the 122 positions coincides with its own base cell. The CONUS set above is these six:

--h0-subset position

cell id

H3 base cell

12

576812596024311807

9

14

577692205326532607

34

20

577164439745200127

19

50

577199624117288959

20

71

577762574070710271

36

78

577234808489377791

21

Note that 20 appears in both columns meaning different cells. Both numberings run 0-121, so a base-cell list passed to --h0-subset is always in range, never errors, and silently builds a different part of the world — the job succeeds and writes the expected number of partitions (issue #213).

If your list came from the H3 library — which is the obvious way to compute which cells a raster covers — pass it to --h0-cells instead and it is converted for you:

cng-datasets raster-workflow ... --h0-cells "9,19,20,21,34,36"
# ✓ H3 base cells [9, 19, 20, 21, 34, 36] → h0 grid positions [12, 14, 20, 50, 71, 78]

The two flags are the same restriction in two numberings, so passing both is refused. Either way, each pod logs what its position resolved to in its first lines:

Processing h0 grid position 50...
  h0 cell: 577199624117288959 (h3 8029fffffffffff, H3 base cell 20)

To derive the mapping yourself, read the grid’s i column — not its row order, which sorts by cell id and therefore by base cell, giving position == base cell for every row and a wrong answer for all but one:

SELECT i AS position, h0, h3_get_base_cell_number(h0::ubigint) AS base_cell
FROM read_parquet('https://s3-west.nrp-nautilus.io/public-grids/hex/h0-valid.parquet')
ORDER BY i;

To find the cells for a bounding box, intersect it with the same grid. Inferring the set from the source footprint at generation time is issue #191’s option 2 and is not implemented — the subset is explicit.

Workers, and why the default is small

The hex step aggregates in parallel worker processes. Peak memory is roughly workers x bytes-per-cell x cells-per-chunk, so the worker count is a memory setting as much as a CPU one — measured on one LANDFIRE res-10 layer, unchanged in every other respect:

CNG_HEX_WORKERS

peak RSS

outcome

48–64

190.5 GiB

no slice completed in 3 h 40 m

8

~37 GiB

all six slices complete, no failures

The default is the pod’s CPU quota, read from cgroup v2 cpu.max or the v1 equivalent. When that cannot be read the default is 8, not the host’s core count: a container whose /sys/fs/cgroup is the host root reports max even though the pod is CPU limited, and taking the node’s cores there meant 256 workers against a cpu: 8 limit — a 32x oversubscription of a shared node, and a peak the manifest never asked for. It is also not stable, since two pods of the same job can land on nodes with different core counts.

The two failure modes are not symmetric: too few workers is slower, too many is an OOM kill after hours of un-checkpointed work. Set CNG_HEX_WORKERS to pin it; generated manifests already do.

raster-workflow sets these from flags and writes them into the manifest whether or not you pass them, so a tuned pod survives regeneration:

Flag

Default

Effect

--hex-cpu

4

CPU request and limit per hex pod

--hex-workers

one per --hex-cpu

Emitted as CNG_HEX_WORKERS. Lower this first when a pod runs out of memory

--hex-chunk-size

100000

Cells per exactextract call, emitted as CNG_HEX_CHUNK_SIZE

--hex-memory

32Gi

Memory request and limit. Past ~128Gi a pod waits for scarce large-RAM nodes

Everything in the pod is sized from the pod

Three separate things in a hex pod default to a share of the host, which inside a container is neither the pod’s limit nor anything the manifest asked for:

default

now

worker processes

os.cpu_count() — the node’s cores

the cgroup CPU quota, else 8

DuckDB’s buffer manager

80% of host RAM

DUCKDB_MEMORY_LIMIT, 85% of the pod

GDAL’s block cache, per worker process

5% of host RAM (12.6 GiB on a 251 GiB node)

GDAL_CACHEMAX=512 MB each

The last is the one that scales with the fan-out, because the block cache is per process and a hex pod runs many. Generated manifests set all three, so a pod’s memory profile follows from the manifest rather than from whichever node it landed on.

Bounding DuckDB also changes its behaviour under pressure from fail to spill: with a limit it writes to temp_directory instead of growing until the cgroup kills it.

What built this dataset

Every published parquet — the hex partitions, the merged data_0.parquet, the vector repartition output and the GeoParquet — records the version that produced it, in the file’s own key-value metadata rather than a sidecar, so it survives copies and syncs:

SELECT key, value
FROM parquet_kv_metadata('s3://bucket/dataset/hex/h0=*/data_0.parquet');
-- cng_datasets_version  0.12.0
-- built_at              2026-09-21T23:06:45Z
-- gdal_version          3.13.0
-- duckdb_version        2.0.0
-- image                 ghcr.io/boettiger-lab/datasets:0.12.0

image appears when the environment sets CNG_IMAGE; its absence means a local run.

This exists because generated manifests pin ghcr.io/boettiger-lab/datasets:latest, which is rebuilt on every push to main — so the code that ran was not necessarily a released version, and nothing recorded which. When a build turns out to have been wrong, as with the multi-band mislabel in #214, the question “which datasets are affected?” otherwise has no answer but correlating S3 timestamps against git history.

A dataset with no stamp predates 0.8.0 and should be checked against the correctness fixes in 0.7.0 — the multi-band read (#214) and the h0 position/base-cell confusion (#213, #218).

The library versions are recorded because two of this project’s sharper problems were environment-dependent rather than code-dependent: a GDAL without WarpOptions(cutlineWKT=) (#197), and one without OGR’s Parquet driver.

Kubernetes Processing

cng-datasets raster-workflow generates the whole pipeline: setup-bucket, the COG step, the hex fan-out, repartition, and a merge step when chunks are smaller than an h0 cell.

cng-datasets raster-workflow \
  --dataset wetlands \
  --source-url https://example.com/wetlands.tif \
  --bucket public-wetlands \
  --h3-resolution 8 \
  --parent-resolutions "0" \
  --hex-resampling mode \
  --output-dir wetlands/k8s

kubectl apply -f wetlands/k8s/workflow-rbac.yaml   # once per namespace
kubectl apply -f wetlands/k8s/configmap.yaml -f wetlands/k8s/workflow.yaml

Repeat --source-url to mosaic several tiles into one COG. --target-extent clips a mosaic to a bounding box, and --band picks one band of a multi-band source.

Splitting an h0 cell: --chunk-resolution

By default one hex pod handles one h0 base cell, about 282 million cells at res 10. A pod’s memory follows the largest chunk’s cell count, so a fine global build can need more memory than any node offers. --chunk-resolution N makes the unit of work each h0’s res-N descendants instead, cutting the cells per pod about 7x per level. --max-hex-memory 8Gi picks the coarsest chunk resolution that fits that budget. Coarsest, because each extra level also multiplies the pod count by about 7.

A sub-h0 build adds a merge-chunks step that restores the published h0=<cell>/data_0.parquet layout, so readers see no difference. Past ~200 chunks one indexed Job exceeds the namespace pod guideline; --backend auto routes the build to Armada at that point.

Each pod reads only its own window of the source COG rather than copying the whole file (--window-reads auto, the default for a remote source), so total transfer follows the data rather than the number of pods. --window-reads never restores whole-file copies.

Merging, and checking a fan-out is complete

Every chunk writes a completion marker, whether or not it found data. merge-chunks is given the number of chunks the fan-out was sized for (--expect-chunks, which the workflow fills in) and refuses to merge unless every one has a marker, naming the missing indices. A partly failed build therefore cannot be published as a complete dataset. A fan-out that ran completely and found no data merges to an empty result and exits 0.

Before merging, merge-chunks reports what the pods used, from figures each marker records: memory limit and peak, peak anonymous memory, CPU request and mean use, worker count and elapsed time. It then suggests --hex-memory, --hex-cpu and --hex-workers for the next build of the same shape, and warns when a request was more than twice what was needed. Read it with kubectl logs job/<name>-merge.

The log goes with the Job, and a successful merge deletes the markers, so the merge also writes the same figures to <dataset>.usage.json beside the dataset (#369), with the build’s shape: source, --h3-resolution, --chunk-resolution, reducer, parent resolutions, h0 subset, workers and chunk size. A suggestion is only valid for a build of the same shape. With --years each year is its own fan-out and gets <dataset>.year=<year>.usage.json.

On Armada, a preempted job is not rescheduled and converted jobs carry no retry budget. cng-datasets gapfill reads the markers on S3 and writes an Armada job set that re-runs exactly the missing chunks. It exits 0 when nothing is missing and 1 when it wrote a job set:

cng-datasets gapfill \
  --chunks-dir s3://public-wetlands/wetlands/hex-chunks \
  --expect-chunks 5978 \
  --hex-manifest wetlands/k8s/wetlands-hex.yaml \
  --output wetlands/k8s/armada-wetlands-gapfill.yaml
armadactl submit wetlands/k8s/armada-wetlands-gapfill.yaml

Annual series: --years

A product released once a year, such as Annual NLCD, MTBS burn severity or Hansen tree-cover loss, is built as one collection rather than one dataset per year (issue #172). Give the years and put a {year} placeholder in the source URL:

cng-datasets raster-workflow \
  --dataset land-cover/nlcd --bucket public-land-cover \
  --source-url 's3://public-land-cover/raw/Annual_NLCD_LndCov_{year}_CU_C1V2.tif' \
  --years 1985,1990,1994,1996,1998,2000,2005,2010,2015-2025 \
  --h0-cells 9,19,20,21,34,36 \
  --value-column nlcd --hex-resampling mode \
  --h3-resolution 10 --parent-resolutions 9,8,7,6,5,0

The generated steps run the per-year work for every year:

  • preprocess-cog, when the source needs it, is an indexed Job with one pod per year, writing land-cover/nlcd-<year>-cog.tif.

  • hex fans out over years × h0 cells (or years × sub-h0 chunks with --chunk-resolution), writing land-cover/nlcd/hex/year=<year>/h0=<cell>/data_0.parquet. Completions run year by year.

  • merge, with --chunk-resolution, merges each year’s chunks in turn and checks each against the full chunk count.

year is a hive partition, so it is a column to any reader that reads hive partitioning:

SELECT year, h8, nlcd FROM read_parquet('s3://public-land-cover/land-cover/nlcd/hex/**', hive_partitioning = true)
WHERE year = 2020;

A change between two years is a self-join on the cell.

The hex Job’s completions are the per-year fan-out times the number of years. For a global source that quickly passes the ~200-pod guideline for one indexed Job, so pass --h0-cells for a regional source, or --backend auto to route a large series to Armada. Build a whole series from one release of the product: mixing releases makes cross-year differences reflect the release, not the land.

Output Format

Output is partitioned by h0 (continent-scale) H3 cells:

s3://bucket/dataset/
├── dataset-cog.tif          # Cloud-Optimized GeoTIFF
└── hex/                     # H3-indexed parquet
    ├── h0=<cell>/data_0.parquet
    └── ...

An annual series built with raster-workflow --years adds a level above the cell: hex/year=<year>/h0=<cell>/data_0.parquet.

Each parquet file contains one row per native H3 cell:

  • h{res}: H3 cell ID at the target resolution, e.g. h8

  • value: Aggregated raster value using area-weighted aggregation (customizable column name)

  • Parent H3 cells if parent_resolutions specified

  • Excludes nodata values if specified

Aggregation uses exact-area weighting (via exactextract) to account for partially-covered H3 cells, ensuring mass-conserving aggregation across the raster boundary.

Aggregation methods

Two raster→H3 algorithms are available via the method argument (CLI: --method).

exact-extract (default)

warp-centroid

How

Polyfill each h0 cell to its H3 children, then exactextract the area-weighted overlap of source pixels per cell.

gdal.Warp the source to a grid at the H3 edge pitch, then assign each warped pixel to a cell by its centroid.

Schema

One row per H3 cell.

One row per warped pixel — consumers must GROUP BY h<res>.

Mass-conserving

Always (by construction).

Only when the hex pitch is finer than the source pixel pitch (see #84).

hex_resampling vocabulary

mean, sum, mode, fractions, max, min.

Any GDAL resampleAlg (average/mean, sum, mode, near/nearest, bilinear, cubic, …).

Cost

Higher memory and wall time at fine resolutions (exact per-cell coverage).

Fast and low-memory.

Antimeridian

Handled.

Not antimeridian-correct by design (planar cutline).

Requires

Any supported GDAL.

A GDAL whose Python bindings accept WarpOptions(cutlineWKT=...) — each h0 is warped clipped to its own boundary. Absent from GDAL 3.8.4 (what Ubuntu noble ships); present in the project image.

warp-centroid checks for that GDAL capability when the processor is constructed, before any raster is opened or localized, and raises naming the requirement. It does not fall back to exact-extract: the two produce different output (one row per cell versus one row per warped pixel), so the substitution is a decision for the caller, not a silent downgrade.

Use exact-extract (the default) for stock/quantity rasters (population, carbon) where mass conservation matters. When the two methods are both valid (hex pitch ≤ source pitch) they agree closely, and exact-extract is never worse — so reach for warp-centroid only when its speed/memory advantage is needed at scale.

# Opt into the fast, low-memory path (note: emits one row per warped pixel)
processor = RasterProcessor(
    input_path="s3://bucket/global.tif",
    output_parquet_path="s3://bucket/global/hex/",
    h3_resolution=10,
    method="warp-centroid",
    hex_resampling="average",  # "mean" is accepted as an alias
)

Examples

See the following directories for complete examples:

  • catalog/wetlands/ - Raster to H3 conversion with global h0 processing

  • catalog/iucn/ - Species range maps raster processing

  • ncp/ - Nature contributions to people raster data