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
//! Process rasters in memory-efficient chunks.
//!
//! It is often inefficient to load a large rasters
//! completely into memory while processing it. This module
//! provides iterators to load data in smaller chunks.
//!
//! # Raster Memory Layout
//!
//! Large rasters are typically sub-divided internally into
//! rectangular blocks of a specific size. For instance,
//! each band of a GDAL raster may be configured with a
//! _block size_ and the total dimension is split into
//! consecutive blocks of the specified size.
//!
//! The individual blocks support _random access_ while data
//! within a block may require reading the entire block (eg.
//! if the blocks are compressed). While the GDAL API
//! supports reading an arbitary window of data, the
//! underlying driver implements this by reading all the
//! necessary blocks and copying the necessary data into the
//! buffer. Thus, it is more efficient to read along block
//! boundaries.
//!
//! # Memory Efficient Iteration
//!
//! In order to process with a small memory footprint, the
//! algorithm must satisfy a **locality constraint**: to
//! process data at pixel `(x, y)`, it is sufficient to
//! access a small window (say `5x5`) centered around the
//! pixel. In particular, the chunks supported by this
//! module have the following properties:
//!
//! - **Full Width.** Each chunk spans the full width of the
//! raster. This simplifies the iteration logic, and is
//! currently the only supported mode.
//!
//! - **Fixed Padding.** Each chunk may additionally use a
//! fixed number of rows above and below it.
/// Builder to configure chunking. Supports configuring the
/// following paramaters.
///
/// - `width`, `height` - the dimensions of the all the
/// raster bands to be processed (typically from the same
/// [`Dataset`]).
///
/// - `block_size` - the block size of the bands. For
/// multi-band data, this is the least common multiple of
/// the individual block sizes (see [`add_block_size`]).
///
/// - `data_height` - the minimum number of rows required in
/// each chunk of data. Does not include the padding. This
/// value is always maintained as an integer multiple of
/// `block_size` for efficiency.
///
/// - `padding` - the number of additional rows required on
/// either size of the data.
///
/// - `start`,`end` - the semi-open range (i.e. `start..end`
/// in the usual notation) to process (not including
/// padding). The `start` is always at least the `padding`
/// value.
///
/// [`add_block_size`]: ChunkConfig::add_block_size
/// [`Dataset`]: gdal::Dataset
/// The type of item produced by the iterations. Consists
/// of:
///
/// 1. reference to the underlying `ChunkConfig`
/// 1. the start index of this chunk
/// 1. the number of rows (incl. padding) for this chunk
pub type ChunkWindow<'a> = ;