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
//! GDAL Raster Data API
//!
//! ## Example
//!
//! This example shows opening a raster [`Dataset`](crate::Dataset) and using a few of the data access methods.
//! The GDAL [Raster Data Model](https://gdal.org/user/raster_data_model.html) document provides
//! details on the various constructs involved, as this example only touches the surface.
//!
//! ```rust, no_run
//! // `Dataset` is required for opening files. `Metadata` is required to enable reading of some
//! // general information properties, such as `description`.
//! use gdal::{Dataset, Metadata};
//! # fn main() -> gdal::errors::Result<()> {
//! // The `Dataset::open` function is used to open all datasets, regardless of type.
//! // There's a `Dataset:open_ex` variant which provides some additional options.
//! let dataset = Dataset::open("fixtures/tinymarble.tif")?;
//! // The `description` property for a `Dataset` is often (but not necessarily) the file name
//! println!("Dataset description: {}", dataset.description()?);
//! let band_count = dataset.raster_count();
//! println!("Number of bands: {band_count}");
//! // Beware! In GDAL, band indexes are 1-based!
//! for i in 1..=band_count {
//! println!(" Band {i}");
//! let band = dataset.rasterband(i)?;
//! // Depending on the file, the description field may be the empty string :(
//! println!(" Description: '{}'", band.description()?);
//! // In GDAL, all no-data values are coerced to floating point types, regardless of the
//! // underlying pixel type.
//! println!(" No-data value: {:?}", band.no_data_value());
//! println!(" Pixel data type: {}", band.band_type());
//! // Scale and offset are often used with integral pixel types to convert between pixel value
//! // to some physical unit (e.g. watts per square meter per steradian)
//! println!(" Scale: {:?}", band.scale());
//! println!(" Offset: {:?}", band.offset());
//! // In GDAL you can read arbitrary regions of the raster, and have them up- or down-sampled
//! // when the output buffer size is different from the read size. The terminology GDAL
//! // uses takes getting used to. All parameters here are in pixel coordinates.
//! // Also note, tuples are in `(x, y)`/`(cols, rows)` order.
//! // `window` is the (x, y) coordinate of the upper left corner of the region to read.
//! let window = (20, 30);
//! // `window_size` is the amount to read `(cols, rows)`
//! let window_size = (2, 3);
//! // `size` is the output buffer size. If this is different from `window_size`, then
//! // the `resample_alg` parameter below becomes relevant.
//! let size = (2, 3);
//! // Options here include `NearestNeighbor` (default), `Bilinear`, `Cubic`, etc.
//! let resample_alg = None;
//! // Note the `u8` type parameter. GDAL will convert the native pixel type to whatever is
//! // specified here... which may or may not be right for your use case!
//! let rv = band.read_as::<u8>(window, window_size, size, resample_alg)?;
//! // `Rasterband::read_as` returns a `Buffer` struct, which contains the shape of the output
//! // `(cols, rows)` and a `Vec<_>` containing the pixel values.
//! println!(" Data size: {:?}", rv.shape());
//! println!(" Data values: {:?}", rv.data());
//! }
//! # Ok(())
//! # }
//! ```
//!
//! The resulting output is:
//!
//! ```text
//! Dataset description: fixtures/tinymarble.tif
//! Number of bands: 3
//! Band 1
//! Description: ''
//! No-data value: None
//! Pixel data type: 1
//! Scale: None
//! Offset: None
//! Data size: (2, 3)
//! Data values: [47, 74, 77, 118, 98, 122]
//! Band 2
//! ...
//! ```
pub use ;
pub use RasterCreationOptions;
pub use ;
pub use ;
pub use ;
pub use ;
pub use reproject;