Skip to main content

oxigdal_terrain/
error.rs

1//! Error types for terrain analysis operations.
2
3use thiserror::Error;
4
5/// Result type for terrain operations.
6pub type Result<T> = core::result::Result<T, TerrainError>;
7
8/// Errors that can occur during terrain analysis.
9#[derive(Debug, Error)]
10pub enum TerrainError {
11    /// Invalid DEM dimensions
12    #[error("Invalid DEM dimensions: width={width}, height={height}")]
13    InvalidDimensions {
14        /// Width of the DEM
15        width: usize,
16        /// Height of the DEM
17        height: usize,
18    },
19
20    /// Invalid cell size
21    #[error("Invalid cell size: {size}. Cell size must be positive.")]
22    InvalidCellSize {
23        /// Cell size value
24        size: f64,
25    },
26
27    /// Invalid azimuth angle for hillshade
28    #[error("Invalid azimuth: {azimuth}. Azimuth must be between 0 and 360 degrees.")]
29    InvalidAzimuth {
30        /// Azimuth value
31        azimuth: f64,
32    },
33
34    /// Invalid altitude angle for hillshade
35    #[error("Invalid altitude: {altitude}. Altitude must be between 0 and 90 degrees.")]
36    InvalidAltitude {
37        /// Altitude value
38        altitude: f64,
39    },
40
41    /// Invalid observer position for viewshed
42    #[error("Invalid observer position: ({x}, {y}). Position must be within DEM bounds.")]
43    InvalidObserverPosition {
44        /// X coordinate
45        x: usize,
46        /// Y coordinate
47        y: usize,
48    },
49
50    /// Invalid observer height
51    #[error("Invalid observer height: {height}. Height must be non-negative.")]
52    InvalidObserverHeight {
53        /// Height value
54        height: f64,
55    },
56
57    /// Invalid target height
58    #[error("Invalid target height: {height}. Height must be non-negative.")]
59    InvalidTargetHeight {
60        /// Height value
61        height: f64,
62    },
63
64    /// Invalid radius for analysis
65    #[error("Invalid radius: {radius}. Radius must be positive.")]
66    InvalidRadius {
67        /// Radius value
68        radius: f64,
69    },
70
71    /// Invalid threshold value
72    #[error("Invalid threshold: {threshold}. {message}")]
73    InvalidThreshold {
74        /// Threshold value
75        threshold: f64,
76        /// Error message
77        message: String,
78    },
79
80    /// Missing or invalid NoData value
81    #[error("Missing or invalid NoData handling: {message}")]
82    InvalidNoData {
83        /// Error message
84        message: String,
85    },
86
87    /// Flow direction algorithm error
88    #[error("Flow direction error: {message}")]
89    FlowDirectionError {
90        /// Error message
91        message: String,
92    },
93
94    /// Watershed delineation error
95    #[error("Watershed delineation error: {message}")]
96    WatershedError {
97        /// Error message
98        message: String,
99    },
100
101    /// Viewshed computation error
102    #[error("Viewshed computation error: {message}")]
103    ViewshedError {
104        /// Error message
105        message: String,
106    },
107
108    /// Computation error with generic message
109    #[error("Computation error: {message}")]
110    ComputationError {
111        /// Error message
112        message: String,
113    },
114
115    /// Insufficient memory for operation
116    #[error("Insufficient memory for operation: {message}")]
117    InsufficientMemory {
118        /// Error message
119        message: String,
120    },
121
122    /// Core library error
123    #[error("Core error: {0}")]
124    CoreError(#[from] oxigdal_core::error::OxiGdalError),
125}