Examples¶
Real-world examples of using the CNG Datasets toolkit.
Vector Processing Examples¶
Protected Areas (WDPA)¶
Large-scale protected areas processing:
from cng_datasets.vector import H3VectorProcessor
processor = H3VectorProcessor(
input_url="s3://public-wdpa/wdpa.parquet",
output_url="s3://public-wdpa/hex/",
h3_resolution=10,
parent_resolutions=[9, 8, 0],
chunk_size=500,
)
output_files = processor.process_all_chunks()
See: catalog/wdpa/
Redlining Data¶
Historical redlining polygon processing:
from cng_datasets.vector import H3VectorProcessor
processor = H3VectorProcessor(
input_url="s3://public-redlining/redlining.parquet",
output_url="s3://public-redlining/hex/",
h3_resolution=10,
parent_resolutions=[9, 8, 7, 0],
chunk_size=100,
)
output_files = processor.process_all_chunks()
See: catalog/mappinginequality/
PAD-US¶
Protected Areas Database of the United States:
from cng_datasets.vector import H3VectorProcessor
processor = H3VectorProcessor(
input_url="s3://public-padus/padus.parquet",
output_url="s3://public-padus/hex/",
h3_resolution=10,
parent_resolutions=[9, 8, 0],
)
output_files = processor.process_all_chunks()
See: catalog/pad-us/
Raster Processing Examples¶
Global Wetlands (GLWD)¶
Global wetlands raster to H3:
from cng_datasets.raster import RasterProcessor
# Create COG
processor = RasterProcessor(
input_path="/vsis3/public-wetlands/glwd.tif",
output_cog_path="s3://public-wetlands/glwd-cog.tif",
compression="zstd",
)
processor.create_cog()
# Convert to H3 by h0 regions
for h0_index in range(122):
processor = RasterProcessor(
input_path="/vsis3/public-wetlands/glwd.tif",
output_parquet_path="s3://public-wetlands/hex/",
h0_index=h0_index,
h3_resolution=8,
parent_resolutions=[0],
value_column="wetland_class",
nodata_value=255,
)
processor.process_h0_region()
See: wetlands/glwd/ directory
IUCN Range Maps¶
Species range maps processing:
from cng_datasets.raster import RasterProcessor
import glob
from pathlib import Path
# Process each species raster
for raster_file in glob.glob("species/*.tif"):
species = Path(raster_file).stem
processor = RasterProcessor(
input_path=raster_file,
output_cog_path=f"s3://public-iucn/{species}-cog.tif",
output_parquet_path=f"s3://public-iucn/{species}/hex/",
h3_resolution=9,
parent_resolutions=[8, 0],
value_column="presence",
)
processor.create_cog()
processor.process_all_h0_regions()
See: catalog/iucn/
Kubernetes Examples¶
Vector Dataset Workflow¶
# Generate workflow
cng-datasets workflow \
--dataset wdpa \
--source-url https://d1gam3xoknrgr2.cloudfront.net/current/WDPA_WDOECM_Nov2024_Public_all_gdb.zip \
--bucket public-wdpa \
--h3-resolution 10 \
--parent-resolutions "9,8,0" \
--output-dir wdpa/k8s/
# Run workflow
kubectl apply -f wdpa/k8s/workflow-rbac.yaml
kubectl apply -f wdpa/k8s/configmap.yaml -f wdpa/k8s/workflow.yaml
Raster Dataset Workflow¶
cng-datasets raster-workflow \
--dataset glwd \
--source-url https://example.com/glwd.tif \
--bucket public-wetlands \
--h3-resolution 8 \
--parent-resolutions "0" \
--hex-resampling mode \
--output-dir wetlands/k8s/
kubectl apply -f wetlands/k8s/configmap.yaml -f wetlands/k8s/workflow.yaml
Annual Raster Series¶
A {year} placeholder in the source URL and --years build one collection,
partitioned as hex/year=<year>/h0=<cell>/data_0.parquet. --h0-cells keeps a
regional source to the h0 cells it covers (here CONUS):
cng-datasets raster-workflow \
--dataset nlcd/annual \
--source-url "https://example.com/Annual_NLCD_LndCov_{year}_CU_C1V1.tif" \
--years 1985,1990,2015-2024 \
--bucket public-nlcd \
--h3-resolution 10 --parent-resolutions "9,8,0" \
--hex-resampling mode \
--h0-cells 9,19,20,21,34,36 \
--output-dir nlcd/k8s/
Climate Cube Workflow¶
cng-datasets mdim-workflow \
--dataset climate/loca2-tasmax \
--input 'ZARR:"/vsicurl/https://cadcat.s3.us-west-2.amazonaws.com/loca2/ucsd/gfdl-esm4/ssp370/r1i1p1f1/day/tasmax/d03"' \
--variable tasmax --bucket public-climate \
--h3-resolution 6 --time-agg year \
--h0-cells 9,19,20,21,34,36 \
--output-dir climate/k8s/
See Multidimensional processing for the options.
Multi-Provider Sync¶
Sync datasets across cloud providers:
from cng_datasets.storage import RcloneSync
syncer = RcloneSync()
# Sync from AWS to Cloudflare R2
syncer.sync(
source="aws:public-wdpa/",
destination="cloudflare:public-wdpa/",
)
# Sync from AWS to Google Cloud Storage
syncer.sync(
source="aws:public-wdpa/",
destination="gcs:public-wdpa/",
)
See: Individual dataset directories for complete examples and job scripts.