OxiGDAL Terrain
Advanced terrain analysis and DEM (Digital Elevation Model) processing library for OxiGDAL. Provides comprehensive geospatial analysis capabilities for terrain derivatives, hydrological modeling, visibility analysis, and geomorphometric classification—all in 100% Pure Rust.
Features
- Terrain Derivatives: Slope (Horn, Zevenbergen-Thorne), aspect, curvature (profile, plan, total), hillshade (traditional, multidirectional, combined), TPI, TRI, roughness
- Hydrological Analysis: Flow direction (D8, D-Infinity), flow accumulation, sink filling, watershed delineation, stream network extraction with Strahler ordering
- Visibility Analysis: Viewshed computation (binary and cumulative), line-of-sight analysis
- Geomorphometry: Landform classification (Weiss, Iwahashi-Pike), convergence index, positive/negative openness
- Parallel Processing: Optional parallel computation with Rayon for large datasets
- Pure Rust: No C/Fortran dependencies—100% safe, idiomatic Rust implementation
- SciRS2 Integration: Seamless integration with SciRS2-Core for scientific computing
- Comprehensive Error Handling: Rich error types with no unwrap panic policy
- Feature-Gated: Modular design with optional feature flags for selective compilation
Installation
Add to your Cargo.toml:
[]
= "0.1.3"
# With all features enabled
= { = "0.1.3", = ["all_features", "parallel"] }
Feature Flags
default: Enablesstd,derivatives,hydrologystd: Standard library support (enabled by default)derivatives: Terrain derivatives (slope, aspect, curvature, etc.)hydrology: Hydrological analysis (flow, watershed, streams)visibility: Visibility analysis (viewshed, line-of-sight)geomorphometry: Geomorphometric features (landforms, convergence, openness)parallel: Parallel processing support with Rayonall_features: Enables all analysis features (excludesparallel)
Quick Start
Basic Slope Calculation
use ;
use *;
Hydrological Analysis
use *;
use *;
Visibility Analysis
use *;
use *;
Geomorphometric Classification
use *;
use *;
API Overview
| Module | Description | Key Functions |
|---|---|---|
derivatives |
Terrain surface characteristics | slope, aspect, curvature, hillshade, tpi, tri, roughness |
hydrology |
Hydrological flow and watersheds | flow_direction, flow_accumulation, fill_sinks, watershed_from_point, extract_streams |
visibility |
Viewshed and line-of-sight | viewshed_binary, viewshed_cumulative, line_of_sight |
geomorphometry |
Landform and surface properties | classify_weiss, classify_iwahashi_pike, convergence_index, openness |
Derivatives Module
slope()- Calculate slope (auto-select algorithm)slope_horn()- Horn's method for slope calculationslope_zevenbergen_thorne()- Zevenbergen-Thorne methodaspect()- Calculate aspect direction with flat handling optionscurvature()- Calculate total curvatureprofile_curvature()- Slope of slope along steepest descentplan_curvature()- Slope of aspect perpendicular to steepest descenttangential_curvature()- Surface curvature perpendicular to slope directionhillshade()- Shaded relief for visualization (auto-select algorithm)hillshade_traditional()- Traditional hillshade renderinghillshade_multidirectional()- 16-directional hillshadehillshade_combined()- Combined hillshade with slope adjustmenttpi()- Topographic Position Index (elevation relative to neighbors)tpi_parallel()- Parallel TPI computationtri()- Terrain Ruggedness Indextri_parallel()- Parallel TRI computationtri_riley()- Riley's TRI variantroughness()- Surface roughness (auto-select method)roughness_range()- Range of elevations in neighborhoodroughness_stddev()- Standard deviation of elevationsvector_ruggedness_measure()- VRM for roughness quantification
Hydrology Module
flow_direction()- Flow direction calculation (D8 or D-Infinity)flow_direction_d8()- D8 (8-directional) flow algorithmflow_direction_dinf()- D-Infinity continuous flow algorithmflow_accumulation()- Cumulative flow contributionfill_sinks()- Hydrologically correct DEM preprocessingextract_streams()- Extract stream network from flow accumulationstrahler_order()- Assign Strahler stream orderwatershed_from_point()- Delineate watershed from pour point
Visibility Module
viewshed_binary()- Boolean visibility mapviewshed_cumulative()- Weighted visibility accumulationline_of_sight()- Line-of-sight visibility between two points
Geomorphometry Module
classify_weiss()- Landform classification using Weiss (2001) methodclassify_iwahashi_pike()- Iwahashi & Pike (2007) classificationconvergence_index()- Surface convergence/divergence indexpositive_openness()- Exposed terrain opennessnegative_openness()- Enclosed terrain openness
Algorithms
Slope Calculation
- Horn (1981): 3x3 neighborhood with smooth gradient estimation
- Zevenbergen & Thorne (1987): Improved edge handling for irregular DEMs
Flow Direction
- D8 (O'Callaghan & Mark, 1984): 8-directional steepest descent
- D-Infinity (Tarboton, 1997): Continuous flow direction on triangulated surface
Landform Classification
- Weiss (2001): Profile/plan curvature-based classification
- Iwahashi & Pike (2007): Slope/curvature-based landform types
Performance
Benchmarks on Apple Silicon (M3 Max) with synthetic DEM:
| Operation | 100x100 | 500x500 | 1000x1000 |
|---|---|---|---|
| Slope (Horn) | 0.15ms | 3.2ms | 13ms |
| Aspect (Horn) | 0.18ms | 3.5ms | 14ms |
| Curvature (Profile) | 0.16ms | 3.1ms | 12ms |
| Hillshade (Traditional) | 0.22ms | 4.2ms | 17ms |
| TPI (radius=1) | 0.14ms | 2.8ms | 11ms |
| TRI (Standard) | 0.13ms | 2.6ms | 10ms |
Note: Performance scales approximately O(n) with grid size. Parallel variants (with parallel feature) show 3-4x speedup on large datasets (1000x1000+).
No Unwrap Policy
This library strictly follows the "no unwrap" policy. All fallible operations return Result<T, TerrainError> with descriptive error variants:
InvalidDimensions- DEM dimensions out of boundsInvalidCellSize- Non-positive cell sizeInvalidObserverPosition- Position outside DEM boundsInvalidAzimuth/InvalidAltitude- Invalid angle parametersFlowDirectionError- Flow computation issuesWatershedError- Watershed delineation problemsViewshedError- Visibility computation errorsComputationError- Generic computation failuresInsufficientMemory- Memory allocation issues
Example error handling:
use ;
use *;
Pure Rust
This library is 100% Pure Rust with no C/Fortran dependencies. All numerical operations use:
- SciRS2-Core: Scientific computing primitives and linear algebra
- Standard Rust: Safe, idiomatic Rust without external C bindings
Examples
The examples directory contains complete, runnable examples:
terrain_derivatives.rs- Calculate all terrain derivativeshydrological_analysis.rs- Watershed delineation workflowvisibility_analysis.rs- Viewshed computationlandform_classification.rs- Geomorphometric classification
Run examples with:
Documentation
- API Documentation: Full rustdoc with examples
- OxiGDAL: Parent geospatial library
- SciRS2: Scientific computing foundation
Integration with OxiGDAL
oxigdal-terrain is a specialized module within the OxiGDAL ecosystem:
use Band;
use slope_horn;
// Load raster from GDAL source
let band = from_file?;
let dem = band.?;
// Apply terrain analysis
let slope = slope_horn?;
Contributing
Contributions welcome! Please ensure:
- No
unwrap()calls in production code - Comprehensive error handling with
TerrainError - Benchmark critical operations with Criterion
- Write doc tests for public APIs
- Follow COOLJAPAN coding standards
Testing
Run the full test suite:
Run benchmarks:
Code Statistics
- 2,933 lines of Rust code
- 25 source files organized by feature
- ~130 lines of documentation
- 100% Pure Rust implementation
License
This project is licensed under Apache-2.0. See LICENSE for details.
Related COOLJAPAN Projects
- OxiGDAL - Core geospatial library
- OxiBLAS - Pure Rust BLAS
- OxiFFT - Pure Rust FFT
- SciRS2 - Scientific computing ecosystem
- NumRS2 - Numerical computing (NumPy-like)
- Oxicode - Serialization framework
Part of the COOLJAPAN Pure Rust Ecosystem