Skip to main content

CLI for exporting HEC-RAS geometry/results to cloud-native GIS formats (GeoParquet, PMTiles, DuckDB, PostGIS)

Project description

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 — ready for DuckDB analytics, PMTiles tile delivery, and PostGIS sync.

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

Output structure (consolidated parquet per source file):

archive/
├── manifest.json              # Project catalog (schema v2.0)
├── 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'

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"

# 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,
    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")

# 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_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.

Output Formats

Format Command Requirements
GeoParquet geometry, results, archive Built-in
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.

Project 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.5.0.tar.gz (689.1 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.5.0-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ras2cng-0.5.0.tar.gz
Algorithm Hash digest
SHA256 23044ebde40a2ba7dc4c13c731ae25c6b45eee5ed90e4eb77cbe75f08446f4c8
MD5 b454ba4613143e9145760dbe0a94d414
BLAKE2b-256 3a0917c5c6a107f8224b6fadc6b4f3e73c7a9964d3b67f5749b5bb45b6aeea7b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ras2cng-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22bf5427b1f422883a4d41292ce54b2e5d113264b15468cf1bdc4a509ebcfb04
MD5 ca093c769d03beb69233999cac251f86
BLAKE2b-256 3ad63e83a94dfedbb030c1ad70b24a4e48fa75663a1e00b108c832fe7fd607f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page