• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geo-engine / geoengine / 7276350647

20 Dec 2023 01:21PM UTC coverage: 89.798% (-0.03%) from 89.823%
7276350647

push

github

web-flow
Merge pull request #906 from geo-engine/raster_result_describer

result descriptors for query processors

1080 of 1240 new or added lines in 43 files covered. (87.1%)

11 existing lines in 3 files now uncovered.

115920 of 129090 relevant lines covered (89.8%)

58689.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.3
/operators/src/processing/raster_vector_join/mod.rs
1
mod aggregated;
2
mod aggregator;
3
mod non_aggregated;
4
mod util;
5

6
use crate::engine::{
7
    CanonicOperatorName, ExecutionContext, InitializedRasterOperator, InitializedVectorOperator,
8
    Operator, OperatorName, SingleVectorMultipleRasterSources, TypedVectorQueryProcessor,
9
    VectorColumnInfo, VectorOperator, VectorQueryProcessor, VectorResultDescriptor,
10
    WorkflowOperatorPath,
11
};
12
use crate::error::{self, Error};
13
use crate::processing::raster_vector_join::non_aggregated::RasterVectorJoinProcessor;
14
use crate::util::Result;
15

16
use crate::processing::raster_vector_join::aggregated::RasterVectorAggregateJoinProcessor;
17
use async_trait::async_trait;
18
use geoengine_datatypes::collections::VectorDataType;
19
use geoengine_datatypes::primitives::FeatureDataType;
20
use geoengine_datatypes::raster::{Pixel, RasterDataType};
21
use serde::{Deserialize, Serialize};
22
use snafu::ensure;
23

24
use self::aggregator::{
25
    Aggregator, FirstValueFloatAggregator, FirstValueIntAggregator, MeanValueAggregator,
26
    TypedAggregator,
27
};
28

29
/// An operator that attaches raster values to vector data
30
pub type RasterVectorJoin = Operator<RasterVectorJoinParams, SingleVectorMultipleRasterSources>;
31

32
impl OperatorName for RasterVectorJoin {
33
    const TYPE_NAME: &'static str = "RasterVectorJoin";
34
}
35

36
const MAX_NUMBER_OF_RASTER_INPUTS: usize = 8;
37

38
/// The parameter spec for `RasterVectorJoin`
39
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
25✔
40
#[serde(rename_all = "camelCase")]
41
pub struct RasterVectorJoinParams {
42
    /// Each name reflects the output column of the join result.
43
    /// For each raster input, one name must be defined.
44
    pub names: Vec<String>,
45

46
    /// Specifies which method is used for aggregating values for a feature
47
    pub feature_aggregation: FeatureAggregationMethod,
48

49
    /// Whether NO DATA values should be ignored in aggregating the joined feature data
50
    /// `false` by default
51
    #[serde(default)]
52
    pub feature_aggregation_ignore_no_data: bool,
53

54
    /// Specifies which method is used for aggregating values over time
55
    pub temporal_aggregation: TemporalAggregationMethod,
56

57
    /// Whether NO DATA values should be ignored in aggregating the joined temporal data
58
    /// `false` by default
59
    #[serde(default)]
60
    pub temporal_aggregation_ignore_no_data: bool,
61
}
62

63
/// How to aggregate the values for the geometries inside a feature e.g.
64
/// the mean of all the raster values corresponding to the individual
65
/// points inside a `MultiPoint` feature.
66
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy)]
8✔
67
#[serde(rename_all = "camelCase")]
68
pub enum FeatureAggregationMethod {
69
    First,
70
    Mean,
71
}
72

73
/// How to aggregate the values over time
74
/// If there are multiple rasters valid during the validity of a feature
75
/// the featuer is either split into multiple (None-aggregation) or the
76
/// values are aggreagated
77
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy)]
8✔
78
#[serde(rename_all = "camelCase")]
79
pub enum TemporalAggregationMethod {
80
    None,
81
    First,
82
    Mean,
83
}
84

85
#[allow(clippy::too_many_lines)]
86
#[typetag::serde]
2✔
87
#[async_trait]
88
impl VectorOperator for RasterVectorJoin {
89
    async fn _initialize(
6✔
90
        mut self: Box<Self>,
6✔
91
        path: WorkflowOperatorPath,
6✔
92
        context: &dyn ExecutionContext,
6✔
93
    ) -> Result<Box<dyn InitializedVectorOperator>> {
6✔
94
        ensure!(
6✔
95
            (1..=MAX_NUMBER_OF_RASTER_INPUTS).contains(&self.sources.rasters.len()),
6✔
96
            error::InvalidNumberOfRasterInputs {
×
97
                expected: 1..MAX_NUMBER_OF_RASTER_INPUTS,
×
98
                found: self.sources.rasters.len()
×
99
            }
×
100
        );
101
        ensure!(
6✔
102
            self.sources.rasters.len() == self.params.names.len(),
6✔
103
            error::InvalidOperatorSpec {
×
104
                reason: "`rasters` must be of equal length as `names`"
×
105
            }
×
106
        );
107

108
        let name = CanonicOperatorName::from(&self);
6✔
109

110
        let vector_source = self
6✔
111
            .sources
6✔
112
            .vector
6✔
113
            .initialize(path.clone_and_append(0), context)
6✔
114
            .await?;
5✔
115

116
        let vector_rd = vector_source.result_descriptor();
6✔
117

6✔
118
        ensure!(
6✔
119
            vector_rd.data_type != VectorDataType::Data,
6✔
120
            error::InvalidType {
×
121
                expected: format!(
×
122
                    "{}, {} or {}",
×
123
                    VectorDataType::MultiPoint,
×
124
                    VectorDataType::MultiLineString,
×
125
                    VectorDataType::MultiPolygon
×
126
                ),
×
127
                found: VectorDataType::Data.to_string()
×
128
            },
×
129
        );
130

131
        let raster_sources = futures::future::try_join_all(
6✔
132
            self.sources
6✔
133
                .rasters
6✔
134
                .into_iter()
6✔
135
                .enumerate()
6✔
136
                .map(|(i, op)| op.initialize(path.clone_and_append(i as u8 + 1), context)),
7✔
137
        )
6✔
138
        .await?;
5✔
139

140
        let source_descriptors = raster_sources
6✔
141
            .iter()
6✔
142
            .map(InitializedRasterOperator::result_descriptor)
6✔
143
            .collect::<Vec<_>>();
6✔
144

145
        // TODO: implement multi-band functionality for aggregated join and remove this check
146
        ensure!(
6✔
147
            matches!(
5✔
148
                self.params.temporal_aggregation,
6✔
149
                TemporalAggregationMethod::None
150
            ) || source_descriptors.iter().all(|rd| rd.bands.len() == 1),
5✔
151
            crate::error::OperatorDoesNotSupportMultiBandsSourcesYet {
×
152
                operator: "RasterVectorAggregateJoin"
×
153
            }
×
154
        );
155

156
        let spatial_reference = vector_rd.spatial_reference;
6✔
157

158
        for other_spatial_reference in source_descriptors
7✔
159
            .iter()
6✔
160
            .map(|source_descriptor| source_descriptor.spatial_reference)
7✔
161
        {
162
            ensure!(
7✔
163
                spatial_reference == other_spatial_reference,
7✔
164
                crate::error::InvalidSpatialReference {
1✔
165
                    expected: spatial_reference,
1✔
166
                    found: other_spatial_reference,
1✔
167
                }
1✔
168
            );
169
        }
170

171
        let raster_sources_bands = source_descriptors
5✔
172
            .iter()
5✔
173
            .map(|rd| rd.bands.count())
6✔
174
            .collect::<Vec<_>>();
5✔
175

5✔
176
        let params = self.params;
5✔
177

5✔
178
        let result_descriptor = vector_rd.map_columns(|columns| {
5✔
179
            let mut columns = columns.clone();
5✔
180
            for ((i, new_column_name), source_descriptor) in
6✔
181
                params.names.iter().enumerate().zip(&source_descriptors)
5✔
182
            {
183
                let feature_data_type = match params.temporal_aggregation {
6✔
184
                    TemporalAggregationMethod::First | TemporalAggregationMethod::None => {
185
                        match raster_sources[i].result_descriptor().data_type {
4✔
186
                            RasterDataType::U8
187
                            | RasterDataType::U16
188
                            | RasterDataType::U32
189
                            | RasterDataType::U64
190
                            | RasterDataType::I8
191
                            | RasterDataType::I16
192
                            | RasterDataType::I32
193
                            | RasterDataType::I64 => FeatureDataType::Int,
4✔
194
                            RasterDataType::F32 | RasterDataType::F64 => FeatureDataType::Float,
×
195
                        }
196
                    }
197
                    TemporalAggregationMethod::Mean => FeatureDataType::Float,
2✔
198
                };
199

200
                for (i, band) in source_descriptor.bands.iter().enumerate() {
9✔
201
                    let column_name = if i == 0 {
9✔
202
                        new_column_name.clone()
6✔
203
                    } else {
204
                        format!("{new_column_name}_{i}")
3✔
205
                    };
206

207
                    columns.insert(
9✔
208
                        column_name,
9✔
209
                        VectorColumnInfo {
9✔
210
                            data_type: feature_data_type,
9✔
211
                            measurement: band.measurement.clone(),
9✔
212
                        },
9✔
213
                    );
9✔
214
                }
215
            }
216
            columns
5✔
217
        });
5✔
218

5✔
219
        Ok(InitializedRasterVectorJoin {
5✔
220
            name,
5✔
221
            result_descriptor,
5✔
222
            vector_source,
5✔
223
            raster_sources,
5✔
224
            raster_sources_bands,
5✔
225
            state: params,
5✔
226
        }
5✔
227
        .boxed())
5✔
228
    }
12✔
229

230
    span_fn!(RasterVectorJoin);
×
231
}
232

233
pub struct InitializedRasterVectorJoin {
234
    name: CanonicOperatorName,
235
    result_descriptor: VectorResultDescriptor,
236
    vector_source: Box<dyn InitializedVectorOperator>,
237
    raster_sources: Vec<Box<dyn InitializedRasterOperator>>,
238
    raster_sources_bands: Vec<u32>,
239
    state: RasterVectorJoinParams,
240
}
241

242
impl InitializedVectorOperator for InitializedRasterVectorJoin {
243
    fn result_descriptor(&self) -> &VectorResultDescriptor {
2✔
244
        &self.result_descriptor
2✔
245
    }
2✔
246

247
    fn query_processor(&self) -> Result<TypedVectorQueryProcessor> {
4✔
248
        let typed_raster_processors = self
4✔
249
            .raster_sources
4✔
250
            .iter()
4✔
251
            .map(InitializedRasterOperator::query_processor)
4✔
252
            .collect::<Result<Vec<_>>>()?;
4✔
253

254
        Ok(match self.vector_source.query_processor()? {
4✔
255
            TypedVectorQueryProcessor::Data(_) => unreachable!(),
×
256
            TypedVectorQueryProcessor::MultiPoint(points) => {
4✔
257
                TypedVectorQueryProcessor::MultiPoint(match self.state.temporal_aggregation {
4✔
258
                    TemporalAggregationMethod::None => RasterVectorJoinProcessor::new(
×
259
                        points,
×
NEW
260
                        self.result_descriptor.clone(),
×
261
                        typed_raster_processors,
×
262
                        self.raster_sources_bands.clone(),
×
263
                        self.state.names.clone(),
×
264
                        self.state.feature_aggregation,
×
265
                        self.state.feature_aggregation_ignore_no_data,
×
266
                    )
×
267
                    .boxed(),
×
268
                    TemporalAggregationMethod::First | TemporalAggregationMethod::Mean => {
269
                        RasterVectorAggregateJoinProcessor::new(
4✔
270
                            points,
4✔
271
                            self.result_descriptor.clone(),
4✔
272
                            typed_raster_processors,
4✔
273
                            self.state.names.clone(),
4✔
274
                            self.state.feature_aggregation,
4✔
275
                            self.state.feature_aggregation_ignore_no_data,
4✔
276
                            self.state.temporal_aggregation,
4✔
277
                            self.state.temporal_aggregation_ignore_no_data,
4✔
278
                        )
4✔
279
                        .boxed()
4✔
280
                    }
281
                })
282
            }
283
            TypedVectorQueryProcessor::MultiPolygon(polygons) => {
×
284
                TypedVectorQueryProcessor::MultiPolygon(match self.state.temporal_aggregation {
×
285
                    TemporalAggregationMethod::None => RasterVectorJoinProcessor::new(
×
286
                        polygons,
×
NEW
287
                        self.result_descriptor.clone(),
×
288
                        typed_raster_processors,
×
289
                        self.raster_sources_bands.clone(),
×
290
                        self.state.names.clone(),
×
291
                        self.state.feature_aggregation,
×
292
                        self.state.feature_aggregation_ignore_no_data,
×
293
                    )
×
294
                    .boxed(),
×
295
                    TemporalAggregationMethod::First | TemporalAggregationMethod::Mean => {
296
                        RasterVectorAggregateJoinProcessor::new(
×
297
                            polygons,
×
NEW
298
                            self.result_descriptor.clone(),
×
299
                            typed_raster_processors,
×
300
                            self.state.names.clone(),
×
301
                            self.state.feature_aggregation,
×
302
                            self.state.feature_aggregation_ignore_no_data,
×
303
                            self.state.temporal_aggregation,
×
304
                            self.state.temporal_aggregation_ignore_no_data,
×
305
                        )
×
306
                        .boxed()
×
307
                    }
308
                })
309
            }
310
            TypedVectorQueryProcessor::MultiLineString(_) => return Err(Error::NotYetImplemented),
×
311
        })
312
    }
4✔
313

314
    fn canonic_name(&self) -> CanonicOperatorName {
×
315
        self.name.clone()
×
316
    }
×
317
}
318

319
pub fn create_feature_aggregator<P: Pixel>(
28✔
320
    number_of_features: usize,
28✔
321
    aggregation: FeatureAggregationMethod,
28✔
322
    ignore_no_data: bool,
28✔
323
) -> TypedAggregator {
28✔
324
    match aggregation {
28✔
325
        FeatureAggregationMethod::First => match P::TYPE {
16✔
326
            RasterDataType::U8
327
            | RasterDataType::U16
328
            | RasterDataType::U32
329
            | RasterDataType::U64
330
            | RasterDataType::I8
331
            | RasterDataType::I16
332
            | RasterDataType::I32
333
            | RasterDataType::I64 => {
334
                FirstValueIntAggregator::new(number_of_features, ignore_no_data).into_typed()
16✔
335
            }
336
            RasterDataType::F32 | RasterDataType::F64 => {
337
                FirstValueFloatAggregator::new(number_of_features, ignore_no_data).into_typed()
×
338
            }
339
        },
340
        FeatureAggregationMethod::Mean => {
341
            MeanValueAggregator::new(number_of_features, ignore_no_data).into_typed()
12✔
342
        }
343
    }
344
}
28✔
345

346
#[cfg(test)]
347
mod tests {
348
    use super::*;
349
    use std::str::FromStr;
350

351
    use crate::engine::{
352
        ChunkByteSize, MockExecutionContext, MockQueryContext, QueryProcessor,
353
        RasterBandDescriptor, RasterBandDescriptors, RasterOperator, RasterResultDescriptor,
354
    };
355
    use crate::mock::{MockFeatureCollectionSource, MockRasterSource, MockRasterSourceParams};
356
    use crate::source::{GdalSource, GdalSourceParameters};
357
    use crate::util::gdal::add_ndvi_dataset;
358
    use futures::StreamExt;
359
    use geoengine_datatypes::collections::{FeatureCollectionInfos, MultiPointCollection};
360
    use geoengine_datatypes::dataset::NamedData;
361
    use geoengine_datatypes::primitives::{
362
        BoundingBox2D, ColumnSelection, DataRef, DateTime, FeatureDataRef, MultiPoint,
363
        SpatialResolution, TimeInterval, VectorQueryRectangle,
364
    };
365
    use geoengine_datatypes::primitives::{CacheHint, Measurement};
366
    use geoengine_datatypes::raster::RasterTile2D;
367
    use geoengine_datatypes::spatial_reference::SpatialReference;
368
    use geoengine_datatypes::util::{gdal::hide_gdal_errors, test::TestDefault};
369
    use serde_json::json;
370

371
    #[test]
1✔
372
    fn serialization() {
1✔
373
        let raster_vector_join = RasterVectorJoin {
1✔
374
            params: RasterVectorJoinParams {
1✔
375
                names: ["foo", "bar"].iter().copied().map(str::to_string).collect(),
1✔
376
                feature_aggregation: FeatureAggregationMethod::First,
1✔
377
                feature_aggregation_ignore_no_data: false,
1✔
378
                temporal_aggregation: TemporalAggregationMethod::Mean,
1✔
379
                temporal_aggregation_ignore_no_data: false,
1✔
380
            },
1✔
381
            sources: SingleVectorMultipleRasterSources {
1✔
382
                vector: MockFeatureCollectionSource::<MultiPoint>::multiple(vec![]).boxed(),
1✔
383
                rasters: vec![],
1✔
384
            },
1✔
385
        };
1✔
386

1✔
387
        let serialized = json!({
1✔
388
            "type": "RasterVectorJoin",
1✔
389
            "params": {
1✔
390
                "names": ["foo", "bar"],
1✔
391
                "featureAggregation": "first",
1✔
392
                "temporalAggregation": "mean",
1✔
393
            },
1✔
394
            "sources": {
1✔
395
                "vector": {
1✔
396
                    "type": "MockFeatureCollectionSourceMultiPoint",
1✔
397
                    "params": {
1✔
398
                        "collections": [],
1✔
399
                        "spatialReference": "EPSG:4326",
1✔
400
                        "measurements": {},
1✔
401
                    }
1✔
402
                },
1✔
403
                "rasters": [],
1✔
404
            },
1✔
405
        })
1✔
406
        .to_string();
1✔
407

1✔
408
        let deserialized: RasterVectorJoin = serde_json::from_str(&serialized).unwrap();
1✔
409

1✔
410
        assert_eq!(deserialized.params, raster_vector_join.params);
1✔
411
    }
1✔
412

413
    fn ndvi_source(name: NamedData) -> Box<dyn RasterOperator> {
4✔
414
        let gdal_source = GdalSource {
4✔
415
            params: GdalSourceParameters { data: name },
4✔
416
        };
4✔
417

4✔
418
        gdal_source.boxed()
4✔
419
    }
4✔
420

421
    #[tokio::test]
1✔
422
    async fn ndvi_time_point() {
1✔
423
        let point_source = MockFeatureCollectionSource::single(
1✔
424
            MultiPointCollection::from_data(
1✔
425
                MultiPoint::many(vec![
1✔
426
                    (-13.95, 20.05),
1✔
427
                    (-14.05, 20.05),
1✔
428
                    (-13.95, 19.95),
1✔
429
                    (-14.05, 19.95),
1✔
430
                ])
1✔
431
                .unwrap(),
1✔
432
                vec![
1✔
433
                    TimeInterval::new(
1✔
434
                        DateTime::new_utc(2014, 1, 1, 0, 0, 0),
1✔
435
                        DateTime::new_utc(2014, 1, 1, 0, 0, 0),
1✔
436
                    )
1✔
437
                    .unwrap();
1✔
438
                    4
1✔
439
                ],
1✔
440
                Default::default(),
1✔
441
                CacheHint::default(),
1✔
442
            )
1✔
443
            .unwrap(),
1✔
444
        )
1✔
445
        .boxed();
1✔
446

1✔
447
        let mut exe_ctc = MockExecutionContext::test_default();
1✔
448
        let ndvi_id = add_ndvi_dataset(&mut exe_ctc);
1✔
449

1✔
450
        let operator = RasterVectorJoin {
1✔
451
            params: RasterVectorJoinParams {
1✔
452
                names: vec!["ndvi".to_string()],
1✔
453
                feature_aggregation: FeatureAggregationMethod::First,
1✔
454
                feature_aggregation_ignore_no_data: false,
1✔
455
                temporal_aggregation: TemporalAggregationMethod::First,
1✔
456
                temporal_aggregation_ignore_no_data: false,
1✔
457
            },
1✔
458
            sources: SingleVectorMultipleRasterSources {
1✔
459
                vector: point_source,
1✔
460
                rasters: vec![ndvi_source(ndvi_id.clone())],
1✔
461
            },
1✔
462
        };
1✔
463

464
        let operator = operator
1✔
465
            .boxed()
1✔
466
            .initialize(WorkflowOperatorPath::initialize_root(), &exe_ctc)
1✔
467
            .await
×
468
            .unwrap();
1✔
469

1✔
470
        let query_processor = operator.query_processor().unwrap().multi_point().unwrap();
1✔
471

472
        let result = query_processor
1✔
473
            .query(
1✔
474
                VectorQueryRectangle {
1✔
475
                    spatial_bounds: BoundingBox2D::new((-180., -90.).into(), (180., 90.).into())
1✔
476
                        .unwrap(),
1✔
477
                    time_interval: TimeInterval::default(),
1✔
478
                    spatial_resolution: SpatialResolution::new(0.1, 0.1).unwrap(),
1✔
479
                    attributes: ColumnSelection::all(),
1✔
480
                },
1✔
481
                &MockQueryContext::new(ChunkByteSize::MIN),
1✔
482
            )
1✔
483
            .await
×
484
            .unwrap()
1✔
485
            .map(Result::unwrap)
1✔
486
            .collect::<Vec<MultiPointCollection>>()
1✔
487
            .await;
31✔
488

489
        assert_eq!(result.len(), 1);
1✔
490

491
        let FeatureDataRef::Int(data) = result[0].data("ndvi").unwrap() else {
1✔
492
            unreachable!();
×
493
        };
494

495
        // these values are taken from loading the tiff in QGIS
496
        assert_eq!(data.as_ref(), &[54, 55, 51, 55]);
1✔
497
    }
498

499
    #[tokio::test]
1✔
500
    #[allow(clippy::float_cmp)]
501
    async fn ndvi_time_range() {
1✔
502
        let point_source = MockFeatureCollectionSource::single(
1✔
503
            MultiPointCollection::from_data(
1✔
504
                MultiPoint::many(vec![
1✔
505
                    (-13.95, 20.05),
1✔
506
                    (-14.05, 20.05),
1✔
507
                    (-13.95, 19.95),
1✔
508
                    (-14.05, 19.95),
1✔
509
                ])
1✔
510
                .unwrap(),
1✔
511
                vec![
1✔
512
                    TimeInterval::new(
1✔
513
                        DateTime::new_utc(2014, 1, 1, 0, 0, 0),
1✔
514
                        DateTime::new_utc(2014, 3, 1, 0, 0, 0),
1✔
515
                    )
1✔
516
                    .unwrap();
1✔
517
                    4
1✔
518
                ],
1✔
519
                Default::default(),
1✔
520
                CacheHint::default(),
1✔
521
            )
1✔
522
            .unwrap(),
1✔
523
        )
1✔
524
        .boxed();
1✔
525

1✔
526
        let mut exe_ctc = MockExecutionContext::test_default();
1✔
527
        let ndvi_id = add_ndvi_dataset(&mut exe_ctc);
1✔
528

1✔
529
        let operator = RasterVectorJoin {
1✔
530
            params: RasterVectorJoinParams {
1✔
531
                names: vec!["ndvi".to_string()],
1✔
532
                feature_aggregation: FeatureAggregationMethod::First,
1✔
533
                feature_aggregation_ignore_no_data: false,
1✔
534
                temporal_aggregation: TemporalAggregationMethod::Mean,
1✔
535
                temporal_aggregation_ignore_no_data: false,
1✔
536
            },
1✔
537
            sources: SingleVectorMultipleRasterSources {
1✔
538
                vector: point_source,
1✔
539
                rasters: vec![ndvi_source(ndvi_id.clone())],
1✔
540
            },
1✔
541
        };
1✔
542

543
        let operator = operator
1✔
544
            .boxed()
1✔
545
            .initialize(WorkflowOperatorPath::initialize_root(), &exe_ctc)
1✔
546
            .await
×
547
            .unwrap();
1✔
548

1✔
549
        let query_processor = operator.query_processor().unwrap().multi_point().unwrap();
1✔
550

551
        let result = query_processor
1✔
552
            .query(
1✔
553
                VectorQueryRectangle {
1✔
554
                    spatial_bounds: BoundingBox2D::new((-180., -90.).into(), (180., 90.).into())
1✔
555
                        .unwrap(),
1✔
556
                    time_interval: TimeInterval::default(),
1✔
557
                    spatial_resolution: SpatialResolution::new(0.1, 0.1).unwrap(),
1✔
558
                    attributes: ColumnSelection::all(),
1✔
559
                },
1✔
560
                &MockQueryContext::new(ChunkByteSize::MIN),
1✔
561
            )
1✔
562
            .await
×
563
            .unwrap()
1✔
564
            .map(Result::unwrap)
1✔
565
            .collect::<Vec<MultiPointCollection>>()
1✔
566
            .await;
62✔
567

568
        assert_eq!(result.len(), 1);
1✔
569

570
        let FeatureDataRef::Float(data) = result[0].data("ndvi").unwrap() else {
1✔
571
            unreachable!();
×
572
        };
573

574
        // these values are taken from loading the tiff in QGIS
575
        assert_eq!(
1✔
576
            data.as_ref(),
1✔
577
            &[
1✔
578
                (54. + 52.) / 2.,
1✔
579
                (55. + 55.) / 2.,
1✔
580
                (51. + 50.) / 2.,
1✔
581
                (55. + 53.) / 2.,
1✔
582
            ]
1✔
583
        );
1✔
584
    }
585

586
    #[tokio::test]
1✔
587
    #[allow(clippy::float_cmp)]
588
    async fn ndvi_with_default_time() {
1✔
589
        hide_gdal_errors();
1✔
590

1✔
591
        let point_source = MockFeatureCollectionSource::single(
1✔
592
            MultiPointCollection::from_data(
1✔
593
                MultiPoint::many(vec![
1✔
594
                    (-13.95, 20.05),
1✔
595
                    (-14.05, 20.05),
1✔
596
                    (-13.95, 19.95),
1✔
597
                    (-14.05, 19.95),
1✔
598
                ])
1✔
599
                .unwrap(),
1✔
600
                vec![TimeInterval::default(); 4],
1✔
601
                Default::default(),
1✔
602
                CacheHint::default(),
1✔
603
            )
1✔
604
            .unwrap(),
1✔
605
        )
1✔
606
        .boxed();
1✔
607

1✔
608
        let mut exe_ctc = MockExecutionContext::test_default();
1✔
609
        let ndvi_id = add_ndvi_dataset(&mut exe_ctc);
1✔
610

1✔
611
        let operator = RasterVectorJoin {
1✔
612
            params: RasterVectorJoinParams {
1✔
613
                names: vec!["ndvi".to_string()],
1✔
614
                feature_aggregation: FeatureAggregationMethod::First,
1✔
615
                feature_aggregation_ignore_no_data: false,
1✔
616
                temporal_aggregation: TemporalAggregationMethod::Mean,
1✔
617
                temporal_aggregation_ignore_no_data: false,
1✔
618
            },
1✔
619
            sources: SingleVectorMultipleRasterSources {
1✔
620
                vector: point_source,
1✔
621
                rasters: vec![ndvi_source(ndvi_id.clone())],
1✔
622
            },
1✔
623
        };
1✔
624

625
        let operator = operator
1✔
626
            .boxed()
1✔
627
            .initialize(WorkflowOperatorPath::initialize_root(), &exe_ctc)
1✔
628
            .await
×
629
            .unwrap();
1✔
630

1✔
631
        let query_processor = operator.query_processor().unwrap().multi_point().unwrap();
1✔
632

633
        let result = query_processor
1✔
634
            .query(
1✔
635
                VectorQueryRectangle {
1✔
636
                    spatial_bounds: BoundingBox2D::new((-180., -90.).into(), (180., 90.).into())
1✔
637
                        .unwrap(),
1✔
638
                    time_interval: TimeInterval::default(),
1✔
639
                    spatial_resolution: SpatialResolution::new(0.1, 0.1).unwrap(),
1✔
640
                    attributes: ColumnSelection::all(),
1✔
641
                },
1✔
642
                &MockQueryContext::new(ChunkByteSize::MIN),
1✔
643
            )
1✔
644
            .await
×
645
            .unwrap()
1✔
646
            .map(Result::unwrap)
1✔
647
            .collect::<Vec<MultiPointCollection>>()
1✔
648
            .await;
3✔
649

650
        assert_eq!(result.len(), 1);
1✔
651

652
        let FeatureDataRef::Float(data) = result[0].data("ndvi").unwrap() else {
1✔
653
            unreachable!();
×
654
        };
655

656
        assert_eq!(data.as_ref(), &[0., 0., 0., 0.]);
1✔
657

658
        assert_eq!(data.nulls(), vec![true, true, true, true]);
1✔
659
    }
660

661
    #[tokio::test]
1✔
662
    async fn it_checks_sref() {
1✔
663
        let point_source = MockFeatureCollectionSource::with_collections_and_sref(
1✔
664
            vec![MultiPointCollection::from_data(
1✔
665
                MultiPoint::many(vec![
1✔
666
                    (-13.95, 20.05),
1✔
667
                    (-14.05, 20.05),
1✔
668
                    (-13.95, 19.95),
1✔
669
                    (-14.05, 19.95),
1✔
670
                ])
1✔
671
                .unwrap(),
1✔
672
                vec![TimeInterval::default(); 4],
1✔
673
                Default::default(),
1✔
674
                CacheHint::default(),
1✔
675
            )
1✔
676
            .unwrap()],
1✔
677
            SpatialReference::from_str("EPSG:3857").unwrap(),
1✔
678
        )
1✔
679
        .boxed();
1✔
680

1✔
681
        let mut exe_ctc = MockExecutionContext::test_default();
1✔
682
        let ndvi_id = add_ndvi_dataset(&mut exe_ctc);
1✔
683

684
        let operator = RasterVectorJoin {
1✔
685
            params: RasterVectorJoinParams {
1✔
686
                names: vec!["ndvi".to_string()],
1✔
687
                feature_aggregation: FeatureAggregationMethod::First,
1✔
688
                feature_aggregation_ignore_no_data: false,
1✔
689
                temporal_aggregation: TemporalAggregationMethod::Mean,
1✔
690
                temporal_aggregation_ignore_no_data: false,
1✔
691
            },
1✔
692
            sources: SingleVectorMultipleRasterSources {
1✔
693
                vector: point_source,
1✔
694
                rasters: vec![ndvi_source(ndvi_id.clone())],
1✔
695
            },
1✔
696
        }
1✔
697
        .boxed()
1✔
698
        .initialize(WorkflowOperatorPath::initialize_root(), &exe_ctc)
1✔
699
        .await;
×
700

701
        assert!(matches!(
1✔
702
            operator,
1✔
703
            Err(Error::InvalidSpatialReference {
704
                expected: _,
705
                found: _,
706
            })
707
        ));
708
    }
709

710
    #[tokio::test]
1✔
711
    #[allow(clippy::too_many_lines)]
712
    async fn it_includes_bands_in_result_descriptor() {
1✔
713
        let point_source = MockFeatureCollectionSource::with_collections_and_sref(
1✔
714
            vec![MultiPointCollection::from_data(
1✔
715
                MultiPoint::many(vec![
1✔
716
                    (-13.95, 20.05),
1✔
717
                    (-14.05, 20.05),
1✔
718
                    (-13.95, 19.95),
1✔
719
                    (-14.05, 19.95),
1✔
720
                ])
1✔
721
                .unwrap(),
1✔
722
                vec![TimeInterval::default(); 4],
1✔
723
                Default::default(),
1✔
724
                CacheHint::default(),
1✔
725
            )
1✔
726
            .unwrap()],
1✔
727
            SpatialReference::from_str("EPSG:4326").unwrap(),
1✔
728
        )
1✔
729
        .boxed();
1✔
730

1✔
731
        let raster_source = MockRasterSource {
1✔
732
            params: MockRasterSourceParams {
1✔
733
                data: Vec::<RasterTile2D<u8>>::new(),
1✔
734
                result_descriptor: RasterResultDescriptor {
1✔
735
                    data_type: RasterDataType::U8,
1✔
736
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
737
                    time: None,
1✔
738
                    bbox: None,
1✔
739
                    resolution: None,
1✔
740
                    bands: RasterBandDescriptors::new(vec![
1✔
741
                        RasterBandDescriptor::new_unitless("band_0".into()),
1✔
742
                        RasterBandDescriptor::new_unitless("band_1".into()),
1✔
743
                    ])
1✔
744
                    .unwrap(),
1✔
745
                },
1✔
746
            },
1✔
747
        }
1✔
748
        .boxed();
1✔
749

1✔
750
        let raster_source2 = MockRasterSource {
1✔
751
            params: MockRasterSourceParams {
1✔
752
                data: Vec::<RasterTile2D<u8>>::new(),
1✔
753
                result_descriptor: RasterResultDescriptor {
1✔
754
                    data_type: RasterDataType::U8,
1✔
755
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
756
                    time: None,
1✔
757
                    bbox: None,
1✔
758
                    resolution: None,
1✔
759
                    bands: RasterBandDescriptors::new(vec![
1✔
760
                        RasterBandDescriptor::new_unitless("band_0".into()),
1✔
761
                        RasterBandDescriptor::new_unitless("band_1".into()),
1✔
762
                        RasterBandDescriptor::new_unitless("band_2".into()),
1✔
763
                    ])
1✔
764
                    .unwrap(),
1✔
765
                },
1✔
766
            },
1✔
767
        }
1✔
768
        .boxed();
1✔
769

1✔
770
        let exe_ctc = MockExecutionContext::test_default();
1✔
771

772
        let join = RasterVectorJoin {
1✔
773
            params: RasterVectorJoinParams {
1✔
774
                names: vec!["s0".to_string(), "s1".to_string()],
1✔
775
                feature_aggregation: FeatureAggregationMethod::First,
1✔
776
                feature_aggregation_ignore_no_data: false,
1✔
777
                temporal_aggregation: TemporalAggregationMethod::None,
1✔
778
                temporal_aggregation_ignore_no_data: false,
1✔
779
            },
1✔
780
            sources: SingleVectorMultipleRasterSources {
1✔
781
                vector: point_source,
1✔
782
                rasters: vec![raster_source, raster_source2],
1✔
783
            },
1✔
784
        }
1✔
785
        .boxed()
1✔
786
        .initialize(WorkflowOperatorPath::initialize_root(), &exe_ctc)
1✔
787
        .await
×
788
        .unwrap();
1✔
789

1✔
790
        assert_eq!(
1✔
791
            join.result_descriptor(),
1✔
792
            &VectorResultDescriptor {
1✔
793
                data_type: VectorDataType::MultiPoint,
1✔
794
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
795
                columns: [
1✔
796
                    (
1✔
797
                        "s0".to_string(),
1✔
798
                        VectorColumnInfo {
1✔
799
                            data_type: FeatureDataType::Int,
1✔
800
                            measurement: Measurement::Unitless
1✔
801
                        }
1✔
802
                    ),
1✔
803
                    (
1✔
804
                        "s0_1".to_string(),
1✔
805
                        VectorColumnInfo {
1✔
806
                            data_type: FeatureDataType::Int,
1✔
807
                            measurement: Measurement::Unitless
1✔
808
                        }
1✔
809
                    ),
1✔
810
                    (
1✔
811
                        "s1".to_string(),
1✔
812
                        VectorColumnInfo {
1✔
813
                            data_type: FeatureDataType::Int,
1✔
814
                            measurement: Measurement::Unitless
1✔
815
                        }
1✔
816
                    ),
1✔
817
                    (
1✔
818
                        "s1_1".to_string(),
1✔
819
                        VectorColumnInfo {
1✔
820
                            data_type: FeatureDataType::Int,
1✔
821
                            measurement: Measurement::Unitless
1✔
822
                        }
1✔
823
                    ),
1✔
824
                    (
1✔
825
                        "s1_2".to_string(),
1✔
826
                        VectorColumnInfo {
1✔
827
                            data_type: FeatureDataType::Int,
1✔
828
                            measurement: Measurement::Unitless
1✔
829
                        }
1✔
830
                    )
1✔
831
                ]
1✔
832
                .into_iter()
1✔
833
                .collect(),
1✔
834
                time: None,
1✔
835
                bbox: None
1✔
836
            }
1✔
837
        );
1✔
838
    }
839
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc