eorst/rasterdataset/mod.rs
1//! RasterDataset module for handling raster data.
2
3/// Builder for constructing RasterDataset instances.
4pub mod builder;
5/// Implementation methods for RasterDataset.
6pub mod impl_methods;
7/// Processing methods (apply, reduce, mosaic).
8pub mod processing;
9/// Rasterization methods.
10pub mod rasterization;
11/// Sampling and extraction methods.
12pub mod sampling;
13/// ML methods (feature-gated).
14#[cfg(feature = "use_lgbm")]
15pub mod ml;
16/// Zonal statistics methods (feature-gated).
17#[cfg(feature = "use_polars")]
18pub mod zonal_stats;
19/// I/O methods (read_block, write_window3).
20pub mod io;
21/// Composition methods (stack, extend).
22pub mod composition;
23
24use crate::core_types::RasterType;
25use crate::metadata::RasterMetadata;
26use crate::blocks::RasterBlock;
27use std::path::PathBuf;
28
29// Re-export RasterDatasetBuilder from builder module
30pub use builder::RasterDatasetBuilder;
31
32/// Main data structure of eorst. Stores the raster dataset [metadata](crate::RasterMetadata) and [blocks](crate::RasterBlock).
33///
34/// The easiest way to create a RasterDataset is by using [`RasterDatasetBuilder`]:
35///
36/// ```rust,ignore
37/// use std::path::PathBuf;
38/// use eorst::{types::BlockSize, RasterDatasetBuilder, DataSourceBuilder, RasterDataset};
39///
40/// let data_source = DataSourceBuilder::from_file(&PathBuf::from("scene.tif")).build();
41/// let rds: RasterDataset<u16> = RasterDatasetBuilder::from_source(&data_source)
42/// .block_size(BlockSize { cols: 2048, rows: 2048 })
43/// .build();
44/// ```
45///
46/// ## Processing with [`apply`](RasterDataset::apply)
47///
48/// [`apply`](RasterDataset::apply) is the main entry point. Pass a worker function
49/// that receives a [`RasterDataBlock`] — the block data, metadata, and no-data value.
50/// The worker returns an `Array4` which is written directly to the output GeoTIFF:
51///
52/// ```rust,ignore
53/// use eorst::{RasterDataBlock, RasterDataset};
54/// use anyhow::Result;
55/// use ndarray::Array4;
56///
57/// fn worker(block: &RasterDataBlock<u16>) -> Result<Array4<i16>> {
58/// let red = block.select_layers(&["red"])?;
59/// let nir = block.select_layers(&["nir"])?;
60/// let ndvi = ((&nir.data - &red.data) / (&nir.data + &red.data + 1e-10)) * 10000i16;
61/// Ok(ndvi.cast::<i16>()?)
62/// }
63///
64/// rds.apply::<i16>(worker, 8, &PathBuf::from("output.tif"))?;
65/// ```
66///
67/// The [`Select`](crate::selection::Select) trait on `RasterDataBlock` lets you select
68/// layers and time slices by name without tracking indices manually.
69///
70/// ## Alternative: Manual Block Iteration
71///
72/// You can also iterate over blocks manually:
73///
74/// ```rust,ignore
75/// for iter in rds.iter() {
76/// let block_id = iter.iter_index;
77/// let block_data = rds.read_block::<i32>(block_id);
78/// // ... process block_data directly
79/// }
80/// ```
81
82#[derive(Debug, Clone, PartialEq)]
83pub struct RasterDataset<T>
84where
85 T: RasterType,
86{
87 /// Metadata of a RasterDataset
88 pub metadata: RasterMetadata<T>,
89 /// Blocks of a RasterDataset
90 pub blocks: Vec<RasterBlock<T>>,
91 /// Temporaty layers, removed when the RasterDataset is Dropped.
92 pub(crate) tmp_layers: Vec<PathBuf>,
93}
94
95