Skip to main content

ras2cng logo

ras2cng — RAS to Cloud Native GIS

PyPI version Python 3.10+ License: MIT Documentation

Full-project archival and cloud-native export tool for HEC-RAS. Extracts geometry, results, and terrain from any HEC-RAS project into hierarchical GeoParquet archives with a manifest.json catalog and spatial index metadata — ready for DuckDB analytics, PMTiles tile delivery, and PostGIS sync. Archives are spatially post-processed by default for predicate pushdown and stable viewer-side joins.

Built on ras-commander by CLB Engineering Corporation.

Installation

# Core (geometry + results + project archive)
pip install ras2cng

# All optional extras (DuckDB analytics, PostGIS sync, PMTiles rasterio)
pip install "ras2cng[all]"

# Individual extras
pip install "ras2cng[duckdb]"    # DuckDB SQL analytics
pip install "ras2cng[postgis]"   # PostGIS sync
pip install "ras2cng[pmtiles]"   # rasterio (PMTiles also needs tippecanoe + pmtiles CLIs)

Quick Start

Full Project Archive (recommended)

# Inspect project structure (no export)
ras2cng inspect path/to/MyProject/

# Archive all geometry from all geometry files (default — safe, no results duplication)
ras2cng archive path/to/MyProject/ ./archive/

# Also export plan results summary variables
ras2cng archive path/to/MyProject/ ./archive/ --results

# Also convert terrain TIFFs to Cloud Optimized GeoTIFF
ras2cng archive path/to/MyProject/ ./archive/ --results --terrain

# Constrained-worker workflow: extract now, index later on a larger worker
ras2cng archive path/to/MyProject/ ./archive/ --results \
  --results-layout variable --results-geometry none --no-sort
ras2cng spatial-index ./archive/

Output structure (consolidated parquet per source file):

archive/
├── manifest.json              # Project catalog (schema v2.5, index and terrain metadata)
├── MyProject.parquet          # Project metadata (RasPrj dataframes, _table column)
├── MyProject.g01.parquet      # All geometry from g01 (HDF + text), layer column
├── MyProject.g06.parquet      # All geometry from g06
├── MyProject.p01.parquet      # All results from p01, layer column (--results)
└── terrain/                   # (--terrain flag)
    └── Terrain50_cog.tif

Query layers within consolidated files:

SELECT * FROM 'MyProject.g01.parquet' WHERE layer = 'mesh_cells'
SELECT * FROM 'MyProject.p01.parquet' WHERE layer = 'maximum_depth'
SELECT * FROM 'MyProject.parquet' WHERE _table = 'plan_df'

Archive GeoParquet files keep bbox covering metadata and, unless --no-sort was used, include a persisted hilbert_index sorted by layer,hilbert_index. Geometryless result tables get join_index; when matching mesh_cells or mesh_faces geometry is present, they also inherit hilbert_index for spatially local joins.

Single-File Export

# Export mesh cell geometry from HDF
ras2cng geometry model.g01.hdf mesh_cells.parquet --layer mesh_cells

# Export max depth results joined to polygon geometry
ras2cng results model.p01.hdf max_depth.parquet \
  --geometry mesh_cells.parquet --var "Maximum Depth"

# Export gridded precipitation and cumulative precipitation GeoTIFFs
ras2cng precip model.p01.hdf ./precipitation/

# Query with DuckDB (use _ as table name)
ras2cng query max_depth.parquet \
  "SELECT mesh_name, AVG(maximum_depth) FROM _ GROUP BY mesh_name"

# Generate PMTiles (requires tippecanoe + pmtiles on PATH)
ras2cng pmtiles max_depth.parquet flood_depth.pmtiles --layer flood --min-zoom 8 --max-zoom 14

# Sync to PostGIS
ras2cng sync max_depth.parquet "postgresql://user:pass@host/db" max_depth --schema hydraulics

Python API

from ras2cng import (
    archive_project,
    inspect_project,
    export_geometry_layers,
    export_results_layer,
    export_all_variables,
    export_precipitation_rasters,
    list_precipitation_timestamps,
    DuckSession,
    query_parquet,
    generate_pmtiles_from_input,
    sync_to_postgres,
)
from pathlib import Path

# Full project archive
manifest = archive_project(
    Path("path/to/MyProject/"),
    Path("./archive/"),
    include_results=True,
    include_terrain=True,
)
print(f"Exported {len(manifest.geometry)} geometry configurations")

# Inspect project without extracting
info = inspect_project(Path("path/to/MyProject/"))
print(f"{info.name}: {len(info.geom_files)} geometry files, {len(info.plan_files)} plans")

# Single file export
export_geometry_layers(Path("model.g01.hdf"), Path("mesh_cells.parquet"), layer="mesh_cells")

# Gridded precipitation rasters
export_precipitation_rasters(Path("model.p01.hdf"), Path("./precipitation"))

# DuckDB query (table alias is always _)
df = query_parquet(Path("max_depth.parquet"), "SELECT * FROM _ WHERE maximum_depth > 3.0")

Extractable Data

Geometry Layers (from .g##.hdf)

Layer Geometry Source
mesh_cells Polygon (Point fallback) HdfMesh
mesh_faces LineString HdfMesh native faces, keyed by face_id
mesh_areas Polygon HdfMesh
bc_lines LineString HdfBndry
breaklines LineString HdfBndry
refinement_regions Polygon HdfBndry
reference_lines LineString HdfBndry
reference_points Point HdfBndry
structures LineString HdfStruc
cross_sections LineString HdfXsec
centerlines LineString HdfXsec
storage_areas Polygon Text geometry

Results Variables (from .p##.hdf, opt-in)

Exported from plan HDF files. Common 2D mesh summary variables:

  • Maximum Depthmaximum_depth
  • Maximum Water Surfacemaximum_water_surface
  • Maximum Face Velocitymaximum_face_velocity

Column names are snake_case (ras-commander normalization). Use --all flag to export every available variable.

Why results are opt-in: Plan HDF files contain a copy of the geometry. Exporting geometry first (archive default), then adding --results avoids redundant extraction.

Gridded Precipitation Rasters (from .p##.hdf or .u##.hdf)

Exported from Event Conditions/Meteorology/Precipitation as GeoTIFF rasters:

  • Per-timestep precipitation amount rasters
  • Cumulative-through-timestep precipitation rasters
  • CRS, transform, timestamps, and units preserved from HDF attributes

Use ras2cng precip model.p01.hdf ./precipitation/ for the CLI workflow.

Output Formats

Format Command Requirements
GeoParquet geometry, results, archive Built-in
GeoTIFF precipitation rasters precip pip install "ras2cng[all]" or rasterio
Cloud Optimized GeoTIFF archive --terrain gdal_translate CLI
DuckDB SQL query pip install "ras2cng[duckdb]"
Vector PMTiles pmtiles tippecanoe + pmtiles CLIs
Raster PMTiles pmtiles gdal_translate + pmtiles CLIs
PostGIS sync pip install "ras2cng[postgis]"

External CLIs for PMTiles / COG

# via conda-forge
conda install -c conda-forge tippecanoe pmtiles gdal

Or download from felt/tippecanoe and protomaps/go-pmtiles.

Documentation

Full documentation: https://ras2cng.readthedocs.io/en/latest/

GitHub Pages mirror: https://gpt-cmdr.github.io/ras2cng/

About CLB Engineering

ras2cng is an open-source project of CLB Engineering Corporation, the creators of ras-commander and hms-commander.

CLB pioneered the LLM Forward approach to civil engineering — a framework where licensed professional engineers leverage Large Language Models to accelerate H&H modeling workflows while maintaining full professional responsibility.

Contact: info@clbengineering.com | Website: clbengineering.com

License

MIT License — see LICENSE for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ras2cng-0.7.0.tar.gz (920.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ras2cng-0.7.0-py3-none-any.whl (149.2 kB view details)

Uploaded Python 3

File details

Details for the file ras2cng-0.7.0.tar.gz.

File metadata

  • Download URL: ras2cng-0.7.0.tar.gz
  • Upload date:
  • Size: 920.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ras2cng-0.7.0.tar.gz
Algorithm Hash digest
SHA256 d31e6d8ac393a28ee3b418eca2808225f8487125b7deefe0408bd9f313df58e4
MD5 bd4c5d60b7c8e4539603c4c7ca9b0a58
BLAKE2b-256 cb8724647f4b8c451145d2282cbb5bd6f7627fd9002a503b465932562f13a294

See more details on using hashes here.

File details

Details for the file ras2cng-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: ras2cng-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 149.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ras2cng-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c73c53d1e731278aee474f90e7379d45dd1b86950b19fac2e19a96237c288f38
MD5 84334a08874946fb874047cdacfdebfd
BLAKE2b-256 1992ff56e9cdc9973e219296abbbe25d5f81f805eb782bf4f6887aa74c6a7bcd

See more details on using hashes here.

Release history Release notifications | RSS feed

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

This release

0.7.0 This release

2 files

0.6.1

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.1.0

2 files

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