Skip to main content

cng-datasets

DOI

Tools for converting large geospatial datasets into cloud-native formats indexed on the H3 hexagonal grid.

What it produces: Takes source geospatial data (Shapefiles, GeoPackages, FileGDB, CSV points, GeoTIFFs, NetCDF and Zarr cubes) and produces:

  • GeoParquet — columnar format for analytical queries (DuckDB, Polars)
  • PMTiles — vector tiles for web map visualization
  • H3 Hex Parquet — hexagonal grid indexed at configurable H3 resolution, hive-partitioned for fast spatial joins
  • Cloud-Optimized GeoTIFF — for raster data, optimized for HTTP range requests

Two ways in:

  1. The Python API converts vector, raster and multidimensional data to H3 hex Parquet directly. It suits a small import, or a large single machine, with no orchestration at all.
  2. The CLI generates Kubernetes jobs that run the same Python code at scale on a cluster. You run one command locally, it writes the job YAML, and the cluster does the processing.

Full documentation, including the API reference, is at https://boettiger-lab.github.io/datasets/.

Installation

pip install cng-datasets

Or from source:

pip install -e "."

Python API

Vector to H3

from cng_datasets.vector import H3VectorProcessor, repartition_by_h0
from cng_datasets.vector.convert_to_parquet import convert_to_parquet

# Source (any GDAL-readable vector) to GeoParquet in EPSG:4326, with a _cng_fid id column
convert_to_parquet("https://example.com/parks.gpkg", "parks.parquet")

# Polyfill each feature at res 10, with parents 9, 8 and the h0 partition key
H3VectorProcessor(
    input_url="parks.parquet",
    output_url="parks/chunks",
    h3_resolution=10,
    parent_resolutions=[9, 8, 0],
).process_all_chunks()

# Consolidate into parks/hex/h0=<cell>/data_0.parquet, joining the attributes back
repartition_by_h0("parks/chunks", "parks/hex", source_parquet="parks.parquet")

Raster to H3

from cng_datasets.raster import RasterProcessor

processor = RasterProcessor(
    input_path="https://example.com/wetlands.tif",
    output_cog_path="wetlands-cog.tif",
    output_parquet_path="wetlands/hex",
    h3_resolution=8,
    parent_resolutions=[0],
    hex_resampling="mean",   # area-weighted; also sum, mode, fractions, max, min
)
processor.create_cog()
processor.process_all_h0_regions()   # writes wetlands/hex/h0=<cell>/data_0.parquet

Inputs and outputs may be local paths or s3:// URLs. See the API reference for every option, and cng_datasets.mdim for NetCDF and Zarr cubes.

Kubernetes Usage

Generate a vector processing pipeline

cng-datasets workflow \
  --dataset cpad-2024 \
  --source-url https://example.com/cpad.gdb \
  --bucket public-cpad \
  --layer CPAD_SuperUnits \
  --h3-resolution 10 \
  --parent-resolutions "9,8,0" \
  --hex-memory 32Gi \
  --max-completions 200 \
  --max-parallelism 50

This generates YAML files for a 6-step pipeline:

  1. setup-bucket — creates the S3 bucket with public-read policy
  2. convert — reads source data, reprojects to EPSG:4326, writes GeoParquet in spatial (Hilbert) order
  3. plan — cuts the GeoParquet into hex chunks by estimated H3 cells (--cells-per-chunk)
  4. pmtiles — converts GeoParquet to PMTiles (parallel with step 5)
  5. hex — computes H3 cell assignments in parallel pods, sized to the plan
  6. repartition — consolidates hex chunks into hive-partitioned layout

Jobs run in the geo-workflows namespace unless --namespace or --profile says otherwise.

Multiple sources: Add --source-url multiple times to merge datasets:

cng-datasets workflow \
  --dataset merged-regions \
  --source-url https://example.com/region1.shp \
  --source-url https://example.com/region2.shp \
  --source-url https://example.com/region3.shp \
  --bucket my-bucket

Apply them:

kubectl apply -f <output-dir>/workflow-rbac.yaml   # once per namespace
kubectl apply -f <output-dir>/configmap.yaml -f <output-dir>/workflow.yaml

The workflow orchestrator runs steps sequentially, launching pmtiles and hex in parallel.

Generate a raster processing pipeline

cng-datasets raster-workflow \
  --dataset wetlands-cog \
  --source-url https://example.com/wetlands.tif \
  --bucket public-wetlands

Multi-layer sources

For GeoDatabase or GeoPackage files with multiple layers, run one workflow per layer. Use --layer to select each layer and --dataset with / for hierarchical S3 paths:

# Inspect layers
ogrinfo /vsicurl/https://example.com/data.gdb

# Process each layer separately
cng-datasets workflow --dataset mydata/layer-a --layer LayerA ...
cng-datasets workflow --dataset mydata/layer-b --layer LayerB ...

The / in --dataset creates nested S3 paths (e.g., mydata/layer-a.parquet) while using hyphens for k8s resource names.

CLI Reference

Command Purpose
cng-datasets workflow Generate vector processing k8s pipeline
cng-datasets raster-workflow Generate raster processing k8s pipeline (--years for an annual series)
cng-datasets mdim-workflow Generate a NetCDF/Zarr cube processing k8s pipeline
cng-datasets sync-job Generate a job that syncs a bucket to another provider with rclone
cng-datasets storage setup-bucket Create and configure an S3 bucket
cng-convert-to-parquet Convert vector data to GeoParquet
cng-datasets vector-plan Plan hex chunks by estimated H3 cells (used inside k8s pods)
cng-datasets vector Run H3 hex tiling (used inside k8s pods)
cng-datasets mdim Run cube H3 tiling (used inside k8s pods)
cng-datasets raster Run raster H3 tiling (used inside k8s pods)
cng-datasets repartition Consolidate hex chunks (used inside k8s pods)
cng-datasets merge-chunks Consolidate sub-h0 raster hex chunks (used inside k8s pods)
cng-datasets gapfill Re-run the sub-h0 chunks that never completed (Armada backend)

Commands marked "used inside k8s pods" are called by the generated jobs — you don't run them directly.

cng-datasets workflow options

--dataset NAME             Dataset name for S3 paths. Use / for hierarchy (e.g., "padus/fee").
--source-url URL           Public URL to source data.
--bucket BUCKET            Target S3 bucket name.
--layer LAYER              Layer name for multi-layer sources (GDB, GPKG).
--h3-resolution N          H3 resolution for hex tiling (default: 10, or 8 for lines).
--resolution-by-area SPEC  Variable resolution by polygon area, e.g. '12:8,600:6,5'.
--parent-resolutions STR   Comma-separated parent resolutions (default: "9,8,0").
--hex-memory SIZE          Memory per hex pod (default: 8Gi).
--cells-per-chunk N        Estimated H3 cells per hex chunk (default: 5,000,000).
--chunk-size N             Fixed features per chunk instead of a plan (default 1000).
--max-completions N        Maximum hex chunks, max 200 (default: 200).
--max-parallelism N        Max concurrent pods (default: 50).
--id-column COL            ID column name (auto-detected if omitted).
--output-dir DIR           Directory for generated YAML files.
--intermediate-chunk-size  Rows per unnest batch (decrease if OOM).
--row-group-size N         Rows per parquet row group (default: 100000).
--convert-memory SIZE      Memory for the convert pod (default: --hex-memory).
--simplify-tolerance T     Simplify geometry during convert (degrees for EPSG:4326).
--trim-strings             Strip whitespace from string columns during convert.
--lat-column/--lon-column  Coordinate columns for a CSV of points (auto-detected).
--expect-features N        Fail the convert step unless it writes exactly N features.
--namespace NS             Kubernetes namespace (default: geo-workflows).
--profile NAME             Cluster profile name or YAML path (default: NRP settings).
--backend BACKEND          k8s (default) | armada.

cng-datasets raster-workflow options

--dataset NAME             Dataset name for S3 paths. Use / for hierarchy.
--source-url URL           Public URL to a source raster. Repeat to mosaic tiles.
--years LIST               Annual series, e.g. '1985,2015-2025'; the URL holds {year}.
--bucket BUCKET            Target S3 bucket name.
--h3-resolution N          H3 resolution for hex tiling (default: 8).
--parent-resolutions STR   Comma-separated parent resolutions (default: "0").
--hex-resampling R         mean | sum | mode | fractions | max | min (default: mean).
--nodata VALS              NoData value(s) to exclude, comma-separated.
--hex-memory SIZE          Memory per hex pod (default: 32Gi).
--hex-cpu N                CPU request/limit per hex pod (default: 4).
--hex-workers N            Worker processes per hex pod (default: one per --hex-cpu).
--hex-chunk-size N         Cells per exact_extract call (default: 100000).
--h0-subset POSITIONS      h0 grid positions the source overlaps (default: all 122).
--h0-cells BASECELLS       The same, as H3 base cell numbers (see the note below).
--chunk-resolution N       H3 resolution of one hex pod's unit of work (default: 0, one h0).
--max-hex-memory SIZE      Pick --chunk-resolution automatically to fit this budget.
--backend BACKEND          k8s (default) | armada | auto (armada past ~200 chunks).
--max-parallelism N        Max concurrent hex pods (default: 61).
--namespace NS             Kubernetes namespace (default: geo-workflows).
--output-dir DIR           Directory for generated YAML files.

S3 Output Layout

bucket/
├── dataset.parquet              # GeoParquet
├── dataset.pmtiles              # PMTiles
├── dataset/
│   └── hex/
│       └── h0={cell}/data_0.parquet   # H3-indexed, hive-partitioned
├── README.md
└── stac-collection.json

Docker

The CLI and all dependencies are packaged in a Docker image used by the k8s jobs:

docker pull ghcr.io/boettiger-lab/datasets:latest

Troubleshooting

OOM on hex jobs (vector): Lower --cells-per-chunk so each chunk holds fewer cells, increase --hex-memory (e.g., 32Gi → 64Gi), or decrease --intermediate-chunk-size. kubectl logs job/<name>-plan shows the chunk count and the largest chunk.

Raster hex pod too big even at one worker: the pod's memory tracks the largest chunk's H3-cell count, and the default chunk is a whole h0 base cell (~282M cells at res 10). Pass --chunk-resolution 1 or 2 to raster-workflow to make the unit a descendant of an h0 instead — roughly 7x fewer cells per level — or --max-hex-memory 8Gi to have it chosen for you. The generated workflow gains a merge step that restores the usual h0={cell}/data_0.parquet layout, so the published layout is unchanged. Past ~200 chunks a single indexed Job exceeds the namespace pod guideline; --backend auto routes to Armada at that point. Sub-chunked pods read only their own window of the source COG rather than localizing the whole file (--window-reads), so total transfer stays proportional to the data instead of to the number of chunks.

OOM on hex jobs (raster): Lower --hex-workers before raising --hex-memory. Peak RSS is roughly --hex-workers × --hex-chunk-size × bytes per cell, and a memory request large enough to matter (past ~128Gi) makes the pod contend for scarce large-RAM nodes, turning a retryable OOM into an unschedulable one. Both knobs are always written into the manifest as CNG_HEX_WORKERS / CNG_HEX_CHUNK_SIZE, so a tuned pod survives regeneration.

Convert fails on curved geometries (MULTISURFACE): Handled automatically — the converter linearizes curved geometry types via ogr2ogr before processing.

Monitoring:

kubectl get jobs              # Pipeline status
kubectl logs job/<name>       # Job logs
kubectl get pods | grep OOM   # Check for memory issues

Development

The tests expect the GDAL, PROJ and DuckDB stack in the project's Docker image, so run them there:

docker run --rm -v "$PWD":/app -w /app ghcr.io/boettiger-lab/datasets:latest \
  bash -c 'pip install -q -e ".[dev]" && python -m pytest tests/ -q'

See CHANGELOG.md for what changed in each release.

License

Apache 2.0

Citation

If you use cng-datasets in your work, please cite it via its Zenodo archive. The DOI badge at the top of this README resolves to the latest release; each release also has its own version-specific DOI. Citation metadata (authors, title, funding) lives in .zenodo.json and is minted automatically by Zenodo on each GitHub release.

Boettiger, C., & Buhler, C. K. cng-datasets: A cloud-native toolkit for processing large geospatial datasets on Kubernetes. Zenodo. https://zenodo.org/badge/latestdoi/921944685

Once the first release is archived on Zenodo, replace the redirect above with the concrete versioned DOI it mints.

Metadata

Release files for cng-datasets 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cng-datasets 0.14.0
File Size Uploaded Provenance Actions
cng_datasets-0.14.0.tar.gz 391.0 kB With provenance Details for cng_datasets-0.14.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cng-datasets 0.14.0
File Interpreter ABI Platform Actions
cng_datasets-0.14.0-py3-none-any.whl Python 3 none any Details for cng_datasets-0.14.0-py3-none-any.whl

Total release size: 633.9 kB

Release files / cng_datasets-0.14.0.tar.gz

Download URL cng_datasets-0.14.0.tar.gz
Size 391.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8eacb845201c4348c8a146ab8a028cf2dcc823f0f451089693be11c974b95a67
BLAKE2b-256 checksum
How to use checksums
145facdd78c0121ef1ad3b22667f60bdd99e6f23c416a91e86ef001516d91beb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / cng_datasets-0.14.0-py3-none-any.whl

Download URL cng_datasets-0.14.0-py3-none-any.whl
Size 242.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46e4f3e6c1e17672503d12470168dd92cd0983397e16d1a7c8ed823a90ac20e8
BLAKE2b-256 checksum
How to use checksums
da55b28b173be2eab406baadfcb61a04031873f44c297f5cd20af81eb9d40e60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for cng-datasets 0.14.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cng_datasets-0.14.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.14.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page