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
//! Reader for the [COPC Temporal Index Extension](https://github.com/360-geo/copc/blob/master/copc-temporal/docs/temporal-index-spec.md).
//!
//! When a COPC file contains data from multiple survey passes over the same area,
//! a spatial query alone returns points from *every* pass that touched that region.
//! The temporal index extension adds per-node GPS time metadata so that clients can
//! filter by time **before** decompressing any point data.
//!
//! This crate reads the temporal index incrementally via [`ByteSource`], matching
//! the streaming design of [`copc_streaming`].
//!
//! # Quick start
//!
//! ```rust,ignore
//! use copc_streaming::{Aabb, CopcStreamingReader, FileSource};
//! use copc_temporal::{GpsTime, TemporalCache};
//!
//! let mut reader = CopcStreamingReader::open(
//! FileSource::open("survey.copc.laz")?,
//! ).await?;
//!
//! let mut temporal = match TemporalCache::from_reader(&reader).await? {
//! Some(t) => t,
//! None => return Ok(()), // no temporal index in this file
//! };
//!
//! let start = GpsTime(1_000_000.0);
//! let end = GpsTime(1_000_010.0);
//!
//! // One call: loads hierarchy + temporal pages, fetches chunks,
//! // filters by both bounds and time.
//! let points = temporal.query_points(
//! &mut reader, &my_query_box, start, end,
//! ).await?;
//! ```
//!
//! # Fast path: select only the fields you need
//!
//! [`TemporalCache::query_points`] decodes every field and materializes
//! `las::Point` values. For hot paths,
//! [`TemporalCache::query_chunks`] returns `(Chunk, candidate_range)`
//! pairs with a caller-chosen [`Fields`](copc_streaming::Fields) mask and
//! lets you walk columns directly. `candidate_range` is the sub-range of
//! point indices within each chunk whose GPS times could possibly match
//! `[start, end]` based on the temporal index stride samples — use it to
//! skip points that are guaranteed not to match.
//!
//! ```rust,ignore
//! use copc_streaming::Fields;
//! use copc_temporal::indices_in_time_range;
//!
//! let chunks = temporal
//! .query_chunks(
//! &mut reader,
//! &my_query_box,
//! start,
//! end,
//! Fields::Z | Fields::GPS_TIME,
//! )
//! .await?;
//!
//! for (chunk, range) in &chunks {
//! // Narrow to the candidate range first, then filter exactly.
//! let precise: Vec<u32> = indices_in_time_range(chunk, start, end)
//! .unwrap()
//! .into_iter()
//! .filter(|&i| (range.start..range.end).contains(&i))
//! .collect();
//! // ... walk chunk.positions() / chunk.gps_time() at these indices
//! }
//! ```
//!
//! # Low-level access
//!
//! For full control over page loading, use the building blocks directly:
//!
//! ```rust,ignore
//! // Load only temporal pages that overlap the time range.
//! temporal.load_pages_for_time_range(reader.source(), start, end).await?;
//!
//! // Find matching nodes, estimate point ranges, fetch chunks yourself.
//! for entry in temporal.nodes_in_range(start, end) {
//! let range = entry.estimate_point_range(
//! start, end, temporal.stride(), hier.point_count,
//! );
//! // ...
//! }
//! ```
//!
//! # How it works
//!
//! [`TemporalCache::from_reader`] loads the header and root page.
//! [`TemporalCache::query_chunks`] / [`TemporalCache::query_points`] then
//! load the relevant hierarchy and temporal pages, fetch matching chunks,
//! and return them (with candidate ranges) or the points inside both the
//! bounding box and time window.
//!
//! For time-only queries (no spatial filter), use
//! [`TemporalCache::query_chunks_by_time`] /
//! [`TemporalCache::query_points_by_time`].
//!
//! For advanced use cases you can call [`TemporalCache::load_pages_for_time_range`]
//! and [`TemporalCache::nodes_in_range`] separately, or
//! [`TemporalCache::load_all_pages`] to fetch the entire index at once.
pub use TemporalError;
pub use GpsTime;
pub use ;
pub use NodeTemporalEntry;
// Re-export copc-streaming types that temporal consumers will need.
pub use ;
/// Indices of points whose GPS time falls within `[start, end]`.
///
/// Returns `None` if the chunk was not decoded with
/// [`copc_streaming::Fields::GPS_TIME`] or the underlying format does not
/// include GPS time. Pair the returned indices with any other column
/// iterator on the chunk to build a filtered view without materializing
/// `las::Point` values.
///
/// ```rust,ignore
/// use copc_streaming::Fields;
///
/// let chunk = reader.fetch_chunk(&key, Fields::Z | Fields::GPS_TIME).await?;
/// let indices = copc_temporal::indices_in_time_range(&chunk, start, end)
/// .expect("we asked for GPS_TIME");
/// for &i in &indices {
/// let p = chunk.point(i as usize);
/// // ...
/// }
/// ```
/// Filter points to only those whose GPS time falls within `[start, end]`.
///
/// Points without a GPS time are excluded. Convenience for the simple
/// `Vec<las::Point>` API; prefer [`indices_in_time_range`] on a
/// [`copc_streaming::Chunk`] when you're already on the column-oriented path.