1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
//! Digital Elevation Model (DEM) processing routines.
//!
//! This module provides bindings to the algorithms in the
//! [`gdaldem` tool](https://gdal.org/programs/gdaldem.html#gdaldem).
//!
//! The routines assume an open dataset containing customary digital elevation model data.
//! This includes assumptions that `x` (east-west), `y` (north-south), and `z` (elevation) units are identical.
//! If `x` and `y` units are identical, but `z` (elevation) units are different,
//! `hillshade` and `slope` support a scale setting to set the ratio of vertical units to horizontal.
//! See [`SlopeOptions::with_scale`] for details.
//!
//! # Examples
//!
//! Examples may be found associated with the following functions:
//!
//! * [`aspect()`]
//! * [`color_relief()`]
//! * [`hillshade()`]
//! * [`roughness()`]
//! * [`slope()`]
//! * [`terrain_ruggedness_index()`]
//! * [`topographic_position_index()`]
//!
use ;
use crateCslStringList;
use crateResult;
use crate;
use crateDataset;
pub use *;
pub use *;
use ;
pub use *;
pub use ;
pub use *;
pub use *;
pub use *;
pub use *;
/// Slope aspect-angle routine for DEM datasets.
///
/// This method outputs a 32-bit float raster with values between 0° and 360°
/// representing the azimuth that slopes are facing. The definition of the azimuth is such that:
///
/// * 0° means that the slope is facing the North,
/// * 90° it's facing the East,
/// * 180° it's facing the South and;
/// * 270° it's facing the West (provided that the top of your input raster is north oriented).
///
/// By default, the aspect value `-9999` is used as the no-data value to indicate undefined aspect in flat
/// areas with slope=0. See [`AspectOptions::with_zero_for_flat`] for alternative.
///
/// Note: Results are nonsensical if the underlying [`Dataset`] does not contain digital elevation data.
///
/// # Example
///
/// ```rust, no_run
/// use gdal::Dataset;
/// # fn main() -> gdal::errors::Result<()> {
/// use std::path::Path;
/// use gdal::raster::processing::dem::*;
/// let ds = Dataset::open("fixtures/dem-hills.tiff")?;
/// let mut opts = AspectOptions::new();
/// opts
/// .with_algorithm(DemSlopeAlg::Horn)
/// .with_zero_for_flat(true);
/// let aspect_ds = aspect(&ds, Path::new("target/dem-hills-aspect.tiff"), &opts)?;
/// let stats = aspect_ds.rasterband(1)?.get_statistics(true, false)?.unwrap();
/// println!("{stats:#?}");
/// # Ok(())
/// # }
/// ```
/// The resulting output is:
///
/// ```text
/// StatisticsAll {
/// min: 0.0,
/// max: 359.9951171875,
/// mean: 165.72752499997543,
/// std_dev: 98.5901999514453,
/// }
/// ```
///
/// See: [`gdaldem aspect`](https://gdal.org/programs/gdaldem.html#aspect) for details,
/// Generate a color-relief rendering of DEM data.
///
/// This routine outputs a 3-band (RGB) or 4-band (RGBA) raster with values computed from
/// the elevation and a text-based color configuration file.
///
/// The color configuration file contains associations between various elevation values
/// and the corresponding desired color. See [`ColorReliefOptions::new`] for details.
///
/// By default, the colors between the given elevation
/// values are blended smoothly and the result is a nice colorized DEM.
/// The [`ColorMatchingMode::ExactColorEntry`] or [`ColorMatchingMode::NearestColorEntry`] options
/// can be used to avoid that linear interpolation for values that don't match an index of
/// the color configuration file. See [`ColorMatchingMode`] for details.
///
/// Note: Results are nonsensical if the underlying [`Dataset`] does not contain digital elevation data.
///
/// # Example
///
/// ```rust, no_run
/// use gdal::Dataset;
/// # fn main() -> gdal::errors::Result<()> {
/// use std::path::Path;
/// use gdal::raster::processing::dem::*;
/// let ds = Dataset::open("fixtures/dem-hills.tiff")?;
/// let mut opts = ColorReliefOptions::new("fixtures/color-relief.clr");
/// opts.with_alpha(true);
/// let hs_ds = color_relief(&ds, Path::new("target/dem-hills-relief.tiff"), &opts)?;
/// // Note: Output will actually be a 4-band raster.
/// let stats = hs_ds.rasterband(1)?.get_statistics(true, false)?.unwrap();
/// println!("{stats:#?}");
/// # Ok(())
/// # }
/// ```
/// The resulting output is:
///
/// ```text
/// StatisticsAll {
/// min: 50.0,
/// max: 255.0,
/// mean: 206.85964128690114,
/// std_dev: 52.73836661993173,
/// }
/// ```
/// See: [`gdaldem color-relief`](https://gdal.org/programs/gdaldem.html#color-relief) for details,
///
/// Performs hill-shade rendering of DEM data.
///
/// This routine outputs an 8-bit raster with a nice shaded relief effect.
/// It’s very useful for visualizing the terrain.
/// You can optionally specify the azimuth and altitude of the light source,
/// a vertical exaggeration factor and a scaling factor to account for
/// differences between vertical and horizontal units.
///
/// The value `0` is used as the output no-data value.
///
/// Note: Results are nonsensical if the underlying [`Dataset`] does not contain digital elevation data.
///
/// # Example
///
/// ```rust, no_run
/// use gdal::Dataset;
/// use gdal::raster::processing::dem::*;
/// # fn main() -> gdal::errors::Result<()> {
/// use std::path::Path;
/// let ds = Dataset::open("fixtures/dem-hills.tiff")?;
/// let mut opts = HillshadeOptions::new();
/// opts
/// .with_algorithm(DemSlopeAlg::Horn)
/// .with_z_factor(4.0)
/// .with_scale(98473.0)
/// .with_shading_mode(ShadingMode::Combined);
/// let hs_ds = hillshade(&ds, Path::new("target/dem-hills-shade.tiff"), &opts)?;
/// let stats = hs_ds.rasterband(1)?.get_statistics(true, false)?.unwrap();
/// println!("{stats:#?}");
/// # Ok(())
/// # }
/// ```
/// The resulting output is:
///
/// ```text
/// StatisticsAll {
/// min: 31.0,
/// max: 255.0,
/// mean: 234.71988886841396,
/// std_dev: 30.556285572761446,
/// }
/// ```
/// See: [`gdaldem hillshade`](https://gdal.org/programs/gdaldem.html#hillshade) for details,
///
/// Roughness routine for DEM datasets.
///
/// This processor outputs a single-band raster with values computed from the elevation.
/// Roughness is the largest inter-cell difference of a central pixel and its surrounding cell,
/// as defined in Wilson et al (2007, Marine Geodesy 30:3-35).
///
/// The value `-9999` is used as the output no-data value.
///
/// Note: Results are nonsensical if the underlying [`Dataset`] does not contain digital elevation data.
///
/// # Example
///
/// ```rust, no_run
/// # fn main() -> gdal::errors::Result<()> {
/// use gdal::Dataset;
/// use std::path::Path;
/// use gdal::raster::processing::dem::*;
/// let ds = Dataset::open("fixtures/dem-hills.tiff")?;
/// let roughness_ds = roughness(&ds, Path::new("target/dem-hills-roughness.tiff"), &RoughnessOptions::default())?;
/// let stats = roughness_ds.rasterband(1)?.get_statistics(true, false)?.unwrap();
/// println!("{stats:#?}");
/// # Ok(())
/// # }
/// ```
/// The resulting output is:
///
/// ```text
/// StatisticsAll {
/// min: 0.0,
/// max: 14.361007690429688,
/// mean: 1.5128357817365072,
/// std_dev: 2.0120679959607686,
/// }
/// ```
///
/// See: [`gdaldem roughness`](https://gdal.org/programs/gdaldem.html#roughness) for details.
/// Slope computation routine for DEM datasets.
///
/// This method will take a DEM raster Dataset and output a 32-bit float raster with slope values.
///
/// You have the option of specifying the type of slope value you want:
/// [degrees or percent slope](SlopeOptions::with_percentage_results).
///
/// In cases where the horizontal units differ from the vertical units, you can also supply
/// a [scaling factor](SlopeOptions::with_scale).
///
/// The value `-9999` is used as the output no-data value.
///
/// Note: Results are nonsensical if the underlying [`Dataset`] does not contain digital elevation data.
///
/// # Example
///
/// ```rust, no_run
/// # fn main() -> gdal::errors::Result<()> {
/// use std::path::Path;
/// use gdal::Dataset;
/// use gdal::raster::processing::dem::*;
/// let ds = Dataset::open("fixtures/dem-hills.tiff")?;
/// let mut opts = SlopeOptions::new();
/// opts
/// .with_algorithm(DemSlopeAlg::Horn)
/// .with_percentage_results(true)
/// .with_scale(98473.0);
/// let slope_ds = slope(&ds, Path::new("target/dem-hills-slope.tiff"), &opts)?;
/// let stats = slope_ds.rasterband(1)?.get_statistics(true, false)?.unwrap();
/// println!("{stats:#?}");
/// # Ok(())
/// # }
/// ```
/// The resulting output is:
///
/// ```text
/// StatisticsAll {
/// min: 0.0,
/// max: 65.44061279296875,
/// mean: 6.171115265248098,
/// std_dev: 8.735612161193623,
/// }
/// ```
///
/// See: [`gdaldem slope`](https://gdal.org/programs/gdaldem.html#slope) for details,
/// Topographic Position Index (TPI) routine for DEM datasets
///
/// This method outputs a single-band raster with values computed from the elevation.
/// A Topographic Position Index is defined as the difference between a central pixel and the
/// mean of its surrounding cells (see Wilson et al 2007, Marine Geodesy 30:3-35).
///
/// The value `-9999` is used as the output no-data value.
///
/// Note: Results are nonsensical if the underlying [`Dataset`] does not contain digital elevation data.
///
/// # Example
///
/// ```rust, no_run
/// # fn main() -> gdal::errors::Result<()> {
/// use std::path::Path;
/// use gdal::Dataset;
/// use gdal::raster::processing::dem::*;
/// let ds = Dataset::open("fixtures/dem-hills.tiff")?;
/// let tpi_ds = topographic_position_index(&ds, Path::new("target/dem-hills-tpi.tiff"), &TpiOptions::default())?;
/// let stats = tpi_ds.rasterband(1)?.get_statistics(true, false)?.unwrap();
/// println!("{stats:#?}");
/// # Ok(())
/// # }
/// ```
/// The resulting output is:
///
/// ```text
/// StatisticsAll {
/// min: -4.7376708984375,
/// max: 4.7724151611328125,
/// mean: 0.00012131847966825689,
/// std_dev: 0.48943078832474257,
/// }
/// ```
///
/// See: [`gdaldem tpi`](https://gdal.org/programs/gdaldem.html#tpi) for details.
/// Terrain Ruggedness Index (TRI) routine for DEM datasets
///
/// This method outputs a single-band raster with values computed from the elevation.
/// TRI stands for Terrain Ruggedness Index, which measures the difference between a
/// central pixel and its surrounding cells.
///
/// The value `-9999` is used as the output no-data value.
///
/// # Example
///
/// ```rust, no_run
/// # fn main() -> gdal::errors::Result<()> {
/// use std::path::Path;
/// use gdal::Dataset;
/// use gdal::raster::processing::dem::*;
/// let ds = Dataset::open("fixtures/dem-hills.tiff")?;
/// let mut opts = TriOptions::new();
/// opts.with_algorithm(DemTriAlg::Wilson);
/// let tri_ds = terrain_ruggedness_index(&ds, Path::new("target/dem-hills-tri.tiff"), &opts)?;
/// let stats = tri_ds.rasterband(1)?.get_statistics(true, false)?.unwrap();
/// println!("{stats:#?}");
/// # Ok(())
/// # }
/// ```
/// The resulting output is:
///
/// ```text
/// StatisticsAll {
/// min: 0.0,
/// max: 4.983623504638672,
/// mean: 0.49063101456532326,
/// std_dev: 0.6719356336694824,
/// }
/// ```
///
/// See: [`gdaldem tri`](https://gdal.org/programs/gdaldem.html#tri) for details.
/// Execute the processor on the given [`Dataset`].