scaffold¶
Barebones HEC-RAS project synthesis from a computed plan HDF — powers the
map-hdf command.
Overview¶
RASMapper's stored-map engine only consumes a .rasmap file and a plan HDF,
and the plan HDF carries everything a project scaffold needs: projection WKT
(root Projection attribute), unit system, plan/project titles, Plan ShortID,
and a full geometry copy. The scaffold module exploits this to generate maps
from minimal inputs — a plan HDF plus a terrain raster — with no original
HEC-RAS project on disk.
build_scaffold() synthesizes:
{Project}.prj/{Project}.pNN— minimal text stubs (~11 lines total){Project}.uNN/{Project}.gNN— 1-line stubs (silence missing-file log noise){Project}.rasmap— projection + terrain layer + empty Results elementTerrain\Projection.prj— ESRI WKT extracted from the plan HDF (kept insideTerrain\so it never collides with the HEC-RAS project.prj)Terrain\*.hdf/.vrt/.tif— built headlessly from raw GeoTIFFs viaRasProcess.exe CreateTerrain(RasTerrain.create_terrain_from_rasters), or imported from a pre-built terrain HDF sidecar set
The plan HDF itself is hardlinked (same volume) or copied under its canonical
{Project}.pNN.hdf name — the input file may have any name; project name and
plan number are recovered from Plan Data/Plan Information attributes.
Scaffolds carry a .ras2cng-scaffold marker and are reused across runs when
the source HDF is unchanged, so the expensive terrain build happens once.
Usage¶
from ras2cng import build_scaffold, read_plan_hdf_metadata
from ras2cng.mapping import generate_result_maps
meta = read_plan_hdf_metadata("results_renamed.hdf")
print(meta.project_name, meta.plan_number, meta.plan_short_id)
info = build_scaffold(
"results_renamed.hdf",
"workdir/",
terrain_tifs=["dem.tif"], # or terrain_hdf="Terrain50.hdf"
ras_version="6.6",
)
generate_result_maps(info.prj_file, "maps/", plans=[f"p{info.meta.plan_number}"])
Requirements¶
- Windows HEC-RAS install (RasMapperLib + bundled GDAL) — the one dependency that cannot be synthesized
- The plan HDF must be computed (
Resultsgroup present) and carry aProjectionattribute, or passprojection_file=explicitly - Pre-built terrain sidecar sets must be complete: the
.hdf, its sibling.vrt, and every tile TIFF referenced by the HDF's/Terraingroup
API Reference¶
ras2cng.scaffold.PlanHdfMetadata
dataclass
¶
Metadata extracted from a computed plan HDF, sufficient to scaffold a project.
Source code in ras2cng/scaffold.py
ras2cng.scaffold.ScaffoldInfo
dataclass
¶
ras2cng.scaffold.read_plan_hdf_metadata(plan_hdf)
¶
Extract scaffold metadata from a computed plan HDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan_hdf
|
Path
|
Path to a HEC-RAS results HDF (*.pNN.hdf) |
required |
Returns:
| Type | Description |
|---|---|
PlanHdfMetadata
|
PlanHdfMetadata |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file is not a computed plan results HDF or required attributes are missing/unparseable. |
Source code in ras2cng/scaffold.py
ras2cng.scaffold.build_scaffold(plan_hdf, workdir, *, terrain_tifs=None, terrain_hdf=None, projection_file=None, render_mode='sloping', ras_version='6.6')
¶
Synthesize a barebones HEC-RAS project around a plan HDF.
Exactly one of terrain_tifs / terrain_hdf must be provided. Raw TIFFs are converted to a HEC-RAS terrain via RasProcess.exe CreateTerrain; a pre-built terrain HDF is copied in along with its .vrt and tile TIFF sidecars.
A previously built scaffold (identified by its marker file) is reused when the source plan HDF is unchanged, skipping the expensive terrain build.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan_hdf
|
Path
|
Computed plan results HDF (any filename) |
required |
workdir
|
Path
|
Scaffold directory (created; must be empty or a prior scaffold) |
required |
terrain_tifs
|
Optional[list[Path]]
|
Raw terrain GeoTIFF(s) to build into a HEC-RAS terrain |
None
|
terrain_hdf
|
Optional[Path]
|
Pre-built HEC-RAS terrain HDF (sidecars must sit beside it) |
None
|
projection_file
|
Optional[Path]
|
ESRI .prj overriding the plan HDF projection WKT |
None
|
render_mode
|
str
|
Initial rasmap render mode (horizontal/sloping/slopingPretty) |
'sloping'
|
ras_version
|
str
|
HEC-RAS version for CreateTerrain (default "6.6") |
'6.6'
|
Returns:
| Type | Description |
|---|---|
ScaffoldInfo
|
ScaffoldInfo with project_dir, prj_file, canonical plan_hdf, terrain_hdf |
Source code in ras2cng/scaffold.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
ras2cng.scaffold.terrain_sidecar_files(terrain_hdf)
¶
List the full sidecar file set a HEC-RAS terrain HDF depends on.
The terrain HDF's /Terrain children each carry a File attribute naming
their tile TIFF (bare filename, same directory); a sibling .vrt mosaics them.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
Listing every missing member, if any. |