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

geo-engine / geoengine / 19065440894

04 Nov 2025 10:21AM UTC coverage: 88.783%. First build
19065440894

Pull #1083

github

web-flow
Merge 577088df6 into 3d9be4869
Pull Request #1083: feat: new gdal source workflow optimization

5714 of 6540 new or added lines in 71 files covered. (87.37%)

115349 of 129923 relevant lines covered (88.78%)

499710.35 hits per line

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

95.37
/operators/src/plot/box_plot.rs
1
use crate::engine::{
2
    CanonicOperatorName, ExecutionContext, InitializedPlotOperator, InitializedRasterOperator,
3
    InitializedVectorOperator, MultipleRasterOrSingleVectorSource, Operator, OperatorName,
4
    PlotOperator, PlotQueryProcessor, PlotResultDescriptor, QueryContext, QueryProcessor,
5
    TypedPlotQueryProcessor, TypedRasterQueryProcessor, TypedVectorQueryProcessor,
6
    WorkflowOperatorPath,
7
};
8
use crate::error::{self, Error};
9
use crate::optimization::OptimizationError;
10
use crate::util::Result;
11
use crate::util::input::MultiRasterOrVectorOperator;
12
use crate::util::statistics::PSquareQuantileEstimator;
13
use async_trait::async_trait;
14
use futures::StreamExt;
15
use geoengine_datatypes::collections::FeatureCollectionInfos;
16
use geoengine_datatypes::plots::{BoxPlotAttribute, Plot, PlotData};
17
use geoengine_datatypes::primitives::{
18
    AxisAlignedRectangle, BandSelection, BoundingBox2D, ColumnSelection, PlotQueryRectangle,
19
    RasterQueryRectangle, SpatialResolution, partitions_extent, time_interval_extent,
20
};
21
use geoengine_datatypes::raster::GridOrEmpty;
22
use num_traits::AsPrimitive;
23
use serde::{Deserialize, Serialize};
24
use snafu::ensure;
25

26
pub const BOXPLOT_OPERATOR_NAME: &str = "BoxPlot";
27
const EXACT_CALC_BOUND: usize = 10_000;
28
const BATCH_SIZE: usize = 1_000;
29
const MAX_NUMBER_OF_RASTER_INPUTS: usize = 8;
30

31
/// A box plot about vector data attribute values
32
pub type BoxPlot = Operator<BoxPlotParams, MultipleRasterOrSingleVectorSource>;
33

34
impl OperatorName for BoxPlot {
35
    const TYPE_NAME: &'static str = "BoxPlot";
36
}
37

38
/// The parameter spec for `BoxPlot`
39
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40
#[serde(rename_all = "camelCase")]
41
pub struct BoxPlotParams {
42
    /// Name of the (numeric) attributes to compute the box plots on.
43
    #[serde(default)]
44
    pub column_names: Vec<String>,
45
}
46

47
#[typetag::serde]
×
48
#[async_trait]
49
#[allow(clippy::too_many_lines)]
50
impl PlotOperator for BoxPlot {
51
    async fn _initialize(
52
        self: Box<Self>,
53
        path: WorkflowOperatorPath,
54
        context: &dyn ExecutionContext,
55
    ) -> Result<Box<dyn InitializedPlotOperator>> {
14 ✔
56
        let name = CanonicOperatorName::from(&self);
57

58
        match self.sources.source {
59
            MultiRasterOrVectorOperator::Raster(raster_sources) => {
60
                ensure!(
61
                    (1..=MAX_NUMBER_OF_RASTER_INPUTS).contains(&raster_sources.len()),
62
                    error::InvalidNumberOfRasterInputs {
63
                        expected: 1..MAX_NUMBER_OF_RASTER_INPUTS,
64
                        found: raster_sources.len()
65
                    }
66
                );
67
                ensure!( self.params.column_names.is_empty() || self.params.column_names.len() == raster_sources.len(),
68
                    error::InvalidOperatorSpec {
69
                        reason: "BoxPlot on raster data must either contain a name/alias for every input ('column_names' parameter) or no names at all."
70
                            .to_string(),
71
                });
72

73
                let raster_sources = futures::future::try_join_all(
74
                    raster_sources
75
                        .into_iter()
76
                        .enumerate()
77
                        .map(|(i, op)| op.initialize(path.clone_and_append(i as u8), context)),
9 ✔
78
                )
79
                .await?;
80

81
                // TODO: implement multi-band functionality and remove this check
82
                ensure!(
83
                    raster_sources
84
                        .iter()
85
                        .all(|s| s.result_descriptor().bands.len() == 1),
9 ✔
86
                    crate::error::OperatorDoesNotSupportMultiBandsSourcesYet {
87
                        operator: BoxPlot::TYPE_NAME
88
                    }
89
                );
90

91
                let output_names = if self.params.column_names.is_empty() {
92
                    (1..=raster_sources.len())
93
                        .map(|i| format!("Raster-{i}"))
9 ✔
94
                        .collect::<Vec<_>>()
95
                } else {
96
                    self.params.column_names.clone()
97
                };
98

99
                if raster_sources.len() > 1 {
100
                    let srs = raster_sources[0].result_descriptor().spatial_reference;
101
                    ensure!(
102
                        raster_sources
103
                            .iter()
104
                            .all(|op| op.result_descriptor().spatial_reference == srs),
3 ✔
105
                        error::AllSourcesMustHaveSameSpatialReference
106
                    );
107
                }
108

109
                let in_descriptors = raster_sources
110
                    .iter()
111
                    .map(InitializedRasterOperator::result_descriptor)
112
                    .collect::<Vec<_>>();
113

114
                let time = time_interval_extent(in_descriptors.iter().map(|d| d.time.bounds));
115
                let bbox = partitions_extent(in_descriptors.iter().map(|d| d.spatial_bounds()));
9 ✔
116

117
                Ok(InitializedBoxPlot::new(
118
                    name,
119
                    PlotResultDescriptor {
120
                        spatial_reference: in_descriptors[0].spatial_reference,
121
                        time,
122
                        // converting `SpatialPartition2D` to `BoundingBox2D` is ok here, because is makes the covered area only larger
123
                        bbox: bbox
124
                            .and_then(|p| BoundingBox2D::new(p.lower_left(), p.upper_right()).ok()),
7 ✔
125
                    },
126
                    output_names,
127
                    raster_sources,
128
                )
129
                .boxed())
130
            }
131
            MultiRasterOrVectorOperator::Vector(vector_source) => {
132
                ensure!( !self.params.column_names.is_empty(),
133
                    error::InvalidOperatorSpec {
134
                        reason: "BoxPlot on vector data requires the selection of at least one numeric column ('column_names' parameter)."
135
                            .to_string(),
136
                    }
137
                );
138

139
                let vector_source = vector_source
140
                    .initialize(path.clone_and_append(0), context)
141
                    .await?;
142

143
                for cn in &self.params.column_names {
144
                    match vector_source
145
                        .result_descriptor()
146
                        .column_data_type(cn.as_str())
147
                    {
148
                        Some(column) if !column.is_numeric() => {
149
                            return Err(Error::InvalidOperatorSpec {
150
                                reason: format!("Column '{cn}' is not numeric."),
151
                            });
152
                        }
153
                        Some(_) => {
154
                            // OK
155
                        }
156
                        None => {
157
                            return Err(Error::ColumnDoesNotExist {
158
                                column: cn.to_string(),
159
                            });
160
                        }
161
                    }
162
                }
163

164
                let in_desc = vector_source.result_descriptor();
165

166
                Ok(InitializedBoxPlot::new(
167
                    name,
168
                    PlotResultDescriptor {
169
                        spatial_reference: in_desc.spatial_reference,
170
                        time: in_desc.time,
171
                        bbox: in_desc.bbox,
172
                    },
173
                    self.params.column_names.clone(),
174
                    vector_source,
175
                )
176
                .boxed())
177
            }
178
        }
179
    }
14 ✔
180

181
    span_fn!(BoxPlot);
182
}
183

184
/// The initialization of `BoxPlot`
185
pub struct InitializedBoxPlot<Op> {
186
    name: CanonicOperatorName,
187
    result_descriptor: PlotResultDescriptor,
188
    names: Vec<String>,
189

190
    source: Op,
191
}
192

193
impl<Op> InitializedBoxPlot<Op> {
194
    pub fn new(
12 ✔
195
        name: CanonicOperatorName,
12 ✔
196
        result_descriptor: PlotResultDescriptor,
12 ✔
197
        names: Vec<String>,
12 ✔
198
        source: Op,
12 ✔
199
    ) -> Self {
12 ✔
200
        Self {
12 ✔
201
            name,
12 ✔
202
            result_descriptor,
12 ✔
203
            names,
12 ✔
204
            source,
12 ✔
205
        }
12 ✔
206
    }
12 ✔
207
}
208
impl InitializedPlotOperator for InitializedBoxPlot<Box<dyn InitializedVectorOperator>> {
209
    fn result_descriptor(&self) -> &PlotResultDescriptor {
×
210
        &self.result_descriptor
×
211
    }
×
212

213
    fn query_processor(&self) -> Result<TypedPlotQueryProcessor> {
5 ✔
214
        let processor = BoxPlotVectorQueryProcessor {
5 ✔
215
            input: self.source.query_processor()?,
5 ✔
216
            column_names: self.names.clone(),
5 ✔
217
        };
218

219
        Ok(TypedPlotQueryProcessor::JsonVega(processor.boxed()))
5 ✔
220
    }
5 ✔
221

222
    fn canonic_name(&self) -> CanonicOperatorName {
×
223
        self.name.clone()
×
224
    }
×
225

NEW
226
    fn optimize(
×
NEW
227
        &self,
×
NEW
228
        target_resolution: SpatialResolution,
×
NEW
229
    ) -> Result<Box<dyn PlotOperator>, OptimizationError> {
×
230
        Ok(BoxPlot {
NEW
231
            params: BoxPlotParams {
×
NEW
232
                column_names: self.names.clone(),
×
NEW
233
            },
×
234
            sources: MultipleRasterOrSingleVectorSource {
235
                source: MultiRasterOrVectorOperator::Vector(
NEW
236
                    self.source.optimize(target_resolution)?,
×
237
                ),
238
            },
239
        }
NEW
240
        .boxed())
×
NEW
241
    }
×
242
}
243

244
impl InitializedPlotOperator for InitializedBoxPlot<Vec<Box<dyn InitializedRasterOperator>>> {
245
    fn result_descriptor(&self) -> &PlotResultDescriptor {
×
246
        &self.result_descriptor
×
247
    }
×
248

249
    fn query_processor(&self) -> Result<TypedPlotQueryProcessor> {
7 ✔
250
        let input = self
7 ✔
251
            .source
7 ✔
252
            .iter()
7 ✔
253
            .map(InitializedRasterOperator::query_processor)
7 ✔
254
            .collect::<Result<Vec<_>>>()?;
7 ✔
255

256
        let processor = BoxPlotRasterQueryProcessor {
7 ✔
257
            input,
7 ✔
258
            names: self.names.clone(),
7 ✔
259
        };
7 ✔
260
        Ok(TypedPlotQueryProcessor::JsonVega(processor.boxed()))
7 ✔
261
    }
7 ✔
262

263
    fn canonic_name(&self) -> CanonicOperatorName {
×
264
        self.name.clone()
×
265
    }
×
266

NEW
267
    fn optimize(
×
NEW
268
        &self,
×
NEW
269
        target_resolution: SpatialResolution,
×
NEW
270
    ) -> Result<Box<dyn PlotOperator>, OptimizationError> {
×
271
        Ok(BoxPlot {
NEW
272
            params: BoxPlotParams {
×
NEW
273
                column_names: self.names.clone(),
×
NEW
274
            },
×
275
            sources: MultipleRasterOrSingleVectorSource {
276
                source: MultiRasterOrVectorOperator::Raster(
NEW
277
                    self.source
×
NEW
278
                        .iter()
×
NEW
279
                        .map(|s| s.optimize(target_resolution))
×
NEW
280
                        .collect::<Result<Vec<_>, OptimizationError>>()?,
×
281
                ),
282
            },
283
        }
NEW
284
        .boxed())
×
NEW
285
    }
×
286
}
287

288
/// A query processor that calculates the boxplots about its vector input.
289
pub struct BoxPlotVectorQueryProcessor {
290
    input: TypedVectorQueryProcessor,
291
    column_names: Vec<String>,
292
}
293

294
#[async_trait]
295
impl PlotQueryProcessor for BoxPlotVectorQueryProcessor {
296
    type OutputFormat = PlotData;
297

298
    fn plot_type(&self) -> &'static str {
×
299
        BOXPLOT_OPERATOR_NAME
×
300
    }
×
301

302
    async fn plot_query<'p>(
303
        &'p self,
304
        query: PlotQueryRectangle,
305
        ctx: &'p dyn QueryContext,
306
    ) -> Result<Self::OutputFormat> {
5 ✔
307
        let mut accums: Vec<BoxPlotAccum> = self
308
            .column_names
309
            .iter()
310
            .map(|name| BoxPlotAccum::new(name.clone()))
6 ✔
311
            .collect();
312

313
        let query = query.select_attributes(
314
            ColumnSelection::all(), // TODO: use columns names?
315
        );
316

317
        call_on_generic_vector_processor!(&self.input, processor => {
318
            let mut query = processor.query(query, ctx).await?;
319
            while let Some(collection) = query.next().await {
320
                let collection = collection?;
321

322
                for accum in &mut accums {
323
                    let feature_data = collection.data(&accum.name).expect("checked in param");
324
                    let iter = feature_data.float_options_iter().map(|o| match o {
20,032 ✔
325
                        Some(v) => v,
20,030 ✔
326
                        None => f64::NAN,
2 ✔
327
                    });
20,032 ✔
328
                    accum.update(iter)?;
329
                }
330
            }
331
        });
332

333
        let mut chart = geoengine_datatypes::plots::BoxPlot::new();
334
        for accum in &mut accums {
335
            if let Some(attrib) = accum.finish()? {
336
                chart.add_attribute(attrib);
337
            }
338
        }
339
        Ok(chart.to_vega_embeddable(false)?)
340
    }
5 ✔
341
}
342

343
/// A query processor that calculates the boxplots about its raster input.
344
pub struct BoxPlotRasterQueryProcessor {
345
    input: Vec<TypedRasterQueryProcessor>,
346
    names: Vec<String>,
347
}
348

349
impl BoxPlotRasterQueryProcessor {
350
    async fn process_raster(
9 ✔
351
        name: String,
9 ✔
352
        input: &TypedRasterQueryProcessor,
9 ✔
353
        query: PlotQueryRectangle,
9 ✔
354
        ctx: &dyn QueryContext,
9 ✔
355
    ) -> Result<Option<BoxPlotAttribute>> {
9 ✔
356
        let result_descrpitor = input.result_descriptor();
9 ✔
357

358
        let raster_query_rect = RasterQueryRectangle::from_bounds_and_geo_transform(
9 ✔
359
            &query,
9 ✔
360
            BandSelection::first(),
9 ✔
361
            result_descrpitor
9 ✔
362
                .tiling_grid_definition(ctx.tiling_specification())
9 ✔
363
                .tiling_geo_transform(),
9 ✔
364
        );
365

366
        call_on_generic_raster_processor!(input, processor => {
9 ✔
367

368
            let mut stream = processor.query(raster_query_rect, ctx).await?;
2 ✔
369
            let mut accum = BoxPlotAccum::new(name);
2 ✔
370

371
            while let Some(tile) = stream.next().await {
22,084 ✔
372
                let tile = tile?;
22,082 ✔
373

374
                match tile.grid_array {
22,082 ✔
375
                    // Ignore empty grids if no_data should not be included
376
                    GridOrEmpty::Empty(_) => {},
22,082 ✔
377
                    GridOrEmpty::Grid(grid) => {
×
378
                        accum.update(grid.masked_element_deref_iterator().filter_map(|pixel_option| pixel_option.map(|p| { let v: f64 = p.as_(); v})))?;
52 ✔
379
                    }
380
                }
381
            }
382
            accum.finish()
2 ✔
383
        })
384
    }
9 ✔
385
}
386

387
#[async_trait]
388
impl PlotQueryProcessor for BoxPlotRasterQueryProcessor {
389
    type OutputFormat = PlotData;
390

391
    fn plot_type(&self) -> &'static str {
×
392
        BOXPLOT_OPERATOR_NAME
×
393
    }
×
394

395
    async fn plot_query<'p>(
396
        &'p self,
397
        query: PlotQueryRectangle,
398
        ctx: &'p dyn QueryContext,
399
    ) -> Result<Self::OutputFormat> {
7 ✔
400
        let results: Vec<_> = self
401
            .input
402
            .iter()
403
            .zip(self.names.iter())
404
            .map(|(proc, name)| Self::process_raster(name.clone(), proc, query.clone(), ctx))
9 ✔
405
            .collect();
406

407
        let results = futures::future::join_all(results)
408
            .await
409
            .into_iter()
410
            .collect::<Result<Vec<_>>>();
411

412
        let mut chart = geoengine_datatypes::plots::BoxPlot::new();
413
        results?
414
            .into_iter()
415
            .flatten()
416
            .for_each(|a| chart.add_attribute(a));
7 ✔
417
        Ok(chart.to_vega_embeddable(false)?)
418
    }
7 ✔
419
}
420

421
//
422
// AUX Structures
423
//
424

425
enum BoxPlotAccumKind {
426
    Exact(Vec<f64>),
427
    Estimated(PSquareQuantileEstimator<f64>),
428
}
429

430
impl BoxPlotAccumKind {
431
    fn update(&mut self, values: impl Iterator<Item = f64>) -> crate::util::Result<()> {
33 ✔
432
        match self {
33 ✔
433
            Self::Exact(x) => {
24 ✔
434
                x.extend(values.filter(|x| x.is_finite()));
11,072 ✔
435

436
                if x.len() > EXACT_CALC_BOUND {
24 ✔
437
                    let est = PSquareQuantileEstimator::new(0.5, x.as_slice())?;
1 ✔
438
                    *self = Self::Estimated(est);
1 ✔
439
                }
23 ✔
440
                Ok(())
24 ✔
441
            }
442
            Self::Estimated(est) => {
9 ✔
443
                for v in values {
9,009 ✔
444
                    est.update(v);
9,000 ✔
445
                }
9,000 ✔
446
                Ok(())
9 ✔
447
            }
448
        }
449
    }
33 ✔
450

451
    fn median(values: &[f64]) -> f64 {
30 ✔
452
        if values.len().is_multiple_of(2) {
30 ✔
453
            let i = values.len() / 2;
21 ✔
454
            f64::midpoint(values[i], values[i - 1])
21 ✔
455
        } else {
456
            values[values.len() / 2]
9 ✔
457
        }
458
    }
30 ✔
459

460
    fn split(values: &[f64]) -> (&[f64], &[f64]) {
10 ✔
461
        let idx = values.len() / 2;
10 ✔
462

463
        let s = values.split_at(idx);
10 ✔
464

465
        if values.len().is_multiple_of(2) {
10 ✔
466
            s
5 ✔
467
        } else {
468
            (s.0, &s.1[1..])
5 ✔
469
        }
470
    }
10 ✔
471

472
    fn create_plot(
15 ✔
473
        &mut self,
15 ✔
474
        name: String,
15 ✔
475
    ) -> Result<Option<geoengine_datatypes::plots::BoxPlotAttribute>> {
15 ✔
476
        match self {
15 ✔
477
            Self::Estimated(est) => Ok(Some(BoxPlotAttribute::new(
1 ✔
478
                name,
1 ✔
479
                est.min(),
1 ✔
480
                est.max(),
1 ✔
481
                est.quantile_estimate(),
1 ✔
482
                est.marker2(),
1 ✔
483
                est.marker4(),
1 ✔
484
                false,
485
            )?)),
×
486
            Self::Exact(v) => {
14 ✔
487
                match v.len() {
14 ✔
488
                    0 => Ok(None),
3 ✔
489
                    1 => {
490
                        let x = v[0];
1 ✔
491
                        Ok(Some(BoxPlotAttribute::new(name, x, x, x, x, x, true)?))
1 ✔
492
                    }
493
                    l => {
10 ✔
494
                        v.sort_unstable_by(|a, b| {
68 ✔
495
                            a.partial_cmp(b).expect("Infinite values were filtered")
68 ✔
496
                        });
68 ✔
497
                        let min = v[0];
10 ✔
498
                        let max = v[l - 1];
10 ✔
499
                        // We compute the quartiles accodring to https://en.wikipedia.org/wiki/Quartile#Method_1
500
                        let median = Self::median(v);
10 ✔
501
                        let (low, high) = Self::split(v);
10 ✔
502
                        let q1 = Self::median(low);
10 ✔
503
                        let q3 = Self::median(high);
10 ✔
504
                        Ok(Some(BoxPlotAttribute::new(
10 ✔
505
                            name, min, max, median, q1, q3, true,
10 ✔
506
                        )?))
×
507
                    }
508
                }
509
            }
510
        }
511
    }
15 ✔
512
}
513

514
struct BoxPlotAccum {
515
    name: String,
516
    accum: BoxPlotAccumKind,
517
}
518

519
impl BoxPlotAccum {
520
    fn new(name: String) -> BoxPlotAccum {
15 ✔
521
        BoxPlotAccum {
15 ✔
522
            name,
15 ✔
523
            accum: BoxPlotAccumKind::Exact(Vec::new()),
15 ✔
524
        }
15 ✔
525
    }
15 ✔
526

527
    fn update(&mut self, values: impl Iterator<Item = f64>) -> crate::util::Result<()> {
15 ✔
528
        for chunk in &itertools::Itertools::chunks(values, BATCH_SIZE) {
33 ✔
529
            self.accum.update(chunk)?;
33 ✔
530
        }
531
        Ok(())
15 ✔
532
    }
15 ✔
533

534
    fn finish(&mut self) -> Result<Option<geoengine_datatypes::plots::BoxPlotAttribute>> {
15 ✔
535
        self.accum.create_plot(self.name.clone())
15 ✔
536
    }
15 ✔
537
}
538

539
#[cfg(test)]
540
mod tests {
541

542
    use geoengine_datatypes::primitives::{CacheHint, Coordinate2D, PlotSeriesSelection};
543
    use serde_json::json;
544

545
    use geoengine_datatypes::primitives::{
546
        BoundingBox2D, DateTime, FeatureData, NoGeometry, TimeInterval,
547
    };
548
    use geoengine_datatypes::raster::{
549
        BoundedGrid, EmptyGrid2D, GeoTransform, Grid2D, GridShape2D, MaskedGrid2D, RasterDataType,
550
        RasterTile2D, TileInformation, TilingSpecification,
551
    };
552
    use geoengine_datatypes::spatial_reference::SpatialReference;
553
    use geoengine_datatypes::util::test::TestDefault;
554
    use geoengine_datatypes::{collections::DataCollection, primitives::MultiPoint};
555

556
    use crate::engine::{
557
        ChunkByteSize, MockExecutionContext, RasterBandDescriptors, RasterOperator,
558
        RasterResultDescriptor, SpatialGridDescriptor, TimeDescriptor, VectorOperator,
559
    };
560
    use crate::mock::{MockFeatureCollectionSource, MockRasterSource, MockRasterSourceParams};
561

562
    use super::*;
563

564
    #[test]
565
    fn serialization() {
1 ✔
566
        let histogram = BoxPlot {
1 ✔
567
            params: BoxPlotParams {
1 ✔
568
                column_names: vec!["foobar".to_string()],
1 ✔
569
            },
1 ✔
570
            sources: MockFeatureCollectionSource::<MultiPoint>::multiple(vec![])
1 ✔
571
                .boxed()
1 ✔
572
                .into(),
1 ✔
573
        };
1 ✔
574

575
        let serialized = json!({
1 ✔
576
            "type": "BoxPlot",
1 ✔
577
            "params": {
1 ✔
578
                "columnNames": ["foobar"],
1 ✔
579
            },
580
            "sources": {
1 ✔
581
                "source": {
1 ✔
582
                    "type": "MockFeatureCollectionSourceMultiPoint",
1 ✔
583
                    "params": {
1 ✔
584
                        "collections": [],
1 ✔
585
                        "spatialReference": "EPSG:4326",
1 ✔
586
                        "measurements": {},
1 ✔
587
                    }
588
                }
589
            }
590
        })
591
        .to_string();
1 ✔
592

593
        let deserialized: BoxPlot = serde_json::from_str(&serialized).unwrap();
1 ✔
594

595
        assert_eq!(deserialized.params, histogram.params);
1 ✔
596
    }
1 ✔
597

598
    #[test]
599
    fn serialization_alt() {
1 ✔
600
        let histogram = BoxPlot {
1 ✔
601
            params: BoxPlotParams {
1 ✔
602
                column_names: vec![],
1 ✔
603
            },
1 ✔
604
            sources: MockFeatureCollectionSource::<MultiPoint>::multiple(vec![])
1 ✔
605
                .boxed()
1 ✔
606
                .into(),
1 ✔
607
        };
1 ✔
608

609
        let serialized = json!({
1 ✔
610
            "type": "BoxPlot",
1 ✔
611
            "params": {
1 ✔
612
            },
613
            "sources": {
1 ✔
614
                "source": {
1 ✔
615
                    "type": "MockFeatureCollectionSourceMultiPoint",
1 ✔
616
                    "params": {
1 ✔
617
                        "collections": [],
1 ✔
618
                        "spatialReference": "EPSG:4326",
1 ✔
619
                        "measurements": {},
1 ✔
620
                    }
621
                }
622
            }
623
        })
624
        .to_string();
1 ✔
625

626
        let deserialized: BoxPlot = serde_json::from_str(&serialized).unwrap();
1 ✔
627

628
        assert_eq!(deserialized.params, histogram.params);
1 ✔
629
    }
1 ✔
630

631
    #[tokio::test]
632
    async fn vector_data() {
1 ✔
633
        let vector_source = MockFeatureCollectionSource::multiple(vec![
1 ✔
634
            DataCollection::from_slices(
1 ✔
635
                &[] as &[NoGeometry],
1 ✔
636
                &[TimeInterval::default(); 8],
1 ✔
637
                &[
1 ✔
638
                    ("foo", FeatureData::Int(vec![1, 1, 2, 2, 3, 3, 4, 4])),
1 ✔
639
                    ("bar", FeatureData::Int(vec![1, 1, 2, 2, 3, 3, 4, 4])),
1 ✔
640
                ],
1 ✔
641
            )
642
            .unwrap(),
1 ✔
643
            DataCollection::from_slices(
1 ✔
644
                &[] as &[NoGeometry],
1 ✔
645
                &[TimeInterval::default(); 4],
1 ✔
646
                &[
1 ✔
647
                    ("foo", FeatureData::Int(vec![5, 6, 7, 8])),
1 ✔
648
                    ("bar", FeatureData::Int(vec![5, 6, 7, 8])),
1 ✔
649
                ],
1 ✔
650
            )
651
            .unwrap(),
1 ✔
652
        ])
653
        .boxed();
1 ✔
654

655
        let box_plot = BoxPlot {
1 ✔
656
            params: BoxPlotParams {
1 ✔
657
                column_names: vec!["foo".to_string(), "bar".to_string()],
1 ✔
658
            },
1 ✔
659
            sources: vector_source.into(),
1 ✔
660
        };
1 ✔
661

662
        let execution_context = MockExecutionContext::test_default();
1 ✔
663

664
        let query_processor = box_plot
1 ✔
665
            .boxed()
1 ✔
666
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
667
            .await
1 ✔
668
            .unwrap()
1 ✔
669
            .query_processor()
1 ✔
670
            .unwrap()
1 ✔
671
            .json_vega()
1 ✔
672
            .unwrap();
1 ✔
673

674
        let result = query_processor
1 ✔
675
            .plot_query(
1 ✔
676
                PlotQueryRectangle::new(
1 ✔
677
                    BoundingBox2D::new((-180., -90.).into(), (180., 90.).into()).unwrap(),
1 ✔
678
                    TimeInterval::default(),
1 ✔
679
                    PlotSeriesSelection::all(),
1 ✔
680
                ),
1 ✔
681
                &execution_context.mock_query_context(ChunkByteSize::MIN),
1 ✔
682
            )
1 ✔
683
            .await
1 ✔
684
            .unwrap();
1 ✔
685

686
        let mut expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
687
        expected.add_attribute(
1 ✔
688
            BoxPlotAttribute::new("foo".to_string(), 1.0, 8.0, 3.5, 2.0, 5.5, true).unwrap(),
1 ✔
689
        );
690
        expected.add_attribute(
1 ✔
691
            BoxPlotAttribute::new("bar".to_string(), 1.0, 8.0, 3.5, 2.0, 5.5, true).unwrap(),
1 ✔
692
        );
693

694
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
695
    }
1 ✔
696

697
    #[tokio::test]
698
    async fn vector_data_with_nulls() {
1 ✔
699
        let vector_source = MockFeatureCollectionSource::single(
1 ✔
700
            DataCollection::from_slices(
1 ✔
701
                &[] as &[NoGeometry],
1 ✔
702
                &[TimeInterval::default(); 7],
1 ✔
703
                &[(
1 ✔
704
                    "foo",
1 ✔
705
                    FeatureData::NullableFloat(vec![
1 ✔
706
                        Some(1.),
1 ✔
707
                        Some(2.),
1 ✔
708
                        None,
1 ✔
709
                        Some(4.),
1 ✔
710
                        None,
1 ✔
711
                        Some(6.),
1 ✔
712
                        Some(7.),
1 ✔
713
                    ]),
1 ✔
714
                )],
1 ✔
715
            )
716
            .unwrap(),
1 ✔
717
        )
718
        .boxed();
1 ✔
719

720
        let box_plot = BoxPlot {
1 ✔
721
            params: BoxPlotParams {
1 ✔
722
                column_names: vec!["foo".to_string()],
1 ✔
723
            },
1 ✔
724
            sources: vector_source.into(),
1 ✔
725
        };
1 ✔
726

727
        let execution_context = MockExecutionContext::test_default();
1 ✔
728

729
        let query_processor = box_plot
1 ✔
730
            .boxed()
1 ✔
731
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
732
            .await
1 ✔
733
            .unwrap()
1 ✔
734
            .query_processor()
1 ✔
735
            .unwrap()
1 ✔
736
            .json_vega()
1 ✔
737
            .unwrap();
1 ✔
738

739
        let result = query_processor
1 ✔
740
            .plot_query(
1 ✔
741
                PlotQueryRectangle::new(
1 ✔
742
                    BoundingBox2D::new((-180., -90.).into(), (180., 90.).into()).unwrap(),
1 ✔
743
                    TimeInterval::default(),
1 ✔
744
                    PlotSeriesSelection::all(),
1 ✔
745
                ),
1 ✔
746
                &execution_context.mock_query_context(ChunkByteSize::MIN),
1 ✔
747
            )
1 ✔
748
            .await
1 ✔
749
            .unwrap();
1 ✔
750

751
        let mut expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
752
        expected.add_attribute(
1 ✔
753
            BoxPlotAttribute::new("foo".to_string(), 1.0, 7.0, 4.0, 1.5, 6.5, true).unwrap(),
1 ✔
754
        );
755

756
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
757
    }
1 ✔
758

759
    #[tokio::test]
760
    async fn vector_data_text_column() {
1 ✔
761
        let vector_source = MockFeatureCollectionSource::single(
1 ✔
762
            DataCollection::from_slices(
1 ✔
763
                &[] as &[NoGeometry],
1 ✔
764
                &[TimeInterval::default(); 1],
1 ✔
765
                &[("foo", FeatureData::Text(vec!["test".to_string()]))],
1 ✔
766
            )
767
            .unwrap(),
1 ✔
768
        )
769
        .boxed();
1 ✔
770

771
        let box_plot = BoxPlot {
1 ✔
772
            params: BoxPlotParams {
1 ✔
773
                column_names: vec!["foo".to_string()],
1 ✔
774
            },
1 ✔
775
            sources: vector_source.into(),
1 ✔
776
        };
1 ✔
777

778
        let execution_context = MockExecutionContext::test_default();
1 ✔
779

780
        let init = box_plot
1 ✔
781
            .boxed()
1 ✔
782
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
783
            .await;
1 ✔
784

785
        assert!(init.is_err());
1 ✔
786
    }
1 ✔
787

788
    #[tokio::test]
789
    async fn vector_data_missing_column() {
1 ✔
790
        let vector_source = MockFeatureCollectionSource::single(
1 ✔
791
            DataCollection::from_slices(
1 ✔
792
                &[] as &[NoGeometry],
1 ✔
793
                &[TimeInterval::default(); 1],
1 ✔
794
                &[("foo", FeatureData::Text(vec!["test".to_string()]))],
1 ✔
795
            )
796
            .unwrap(),
1 ✔
797
        )
798
        .boxed();
1 ✔
799

800
        let box_plot = BoxPlot {
1 ✔
801
            params: BoxPlotParams {
1 ✔
802
                column_names: vec![],
1 ✔
803
            },
1 ✔
804
            sources: vector_source.into(),
1 ✔
805
        };
1 ✔
806

807
        let execution_context = MockExecutionContext::test_default();
1 ✔
808

809
        let init = box_plot
1 ✔
810
            .boxed()
1 ✔
811
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
812
            .await;
1 ✔
813

814
        assert!(init.is_err());
1 ✔
815
    }
1 ✔
816

817
    #[tokio::test]
818
    async fn vector_data_single_feature() {
1 ✔
819
        let vector_source = MockFeatureCollectionSource::multiple(vec![
1 ✔
820
            DataCollection::from_slices(
1 ✔
821
                &[] as &[NoGeometry],
1 ✔
822
                &[TimeInterval::default(); 1],
1 ✔
823
                &[("foo", FeatureData::Int(vec![1]))],
1 ✔
824
            )
825
            .unwrap(),
1 ✔
826
        ])
827
        .boxed();
1 ✔
828

829
        let box_plot = BoxPlot {
1 ✔
830
            params: BoxPlotParams {
1 ✔
831
                column_names: vec!["foo".to_string()],
1 ✔
832
            },
1 ✔
833
            sources: vector_source.into(),
1 ✔
834
        };
1 ✔
835

836
        let execution_context = MockExecutionContext::test_default();
1 ✔
837

838
        let query_processor = box_plot
1 ✔
839
            .boxed()
1 ✔
840
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
841
            .await
1 ✔
842
            .unwrap()
1 ✔
843
            .query_processor()
1 ✔
844
            .unwrap()
1 ✔
845
            .json_vega()
1 ✔
846
            .unwrap();
1 ✔
847

848
        let result = query_processor
1 ✔
849
            .plot_query(
1 ✔
850
                PlotQueryRectangle::new(
1 ✔
851
                    BoundingBox2D::new((-180., -90.).into(), (180., 90.).into()).unwrap(),
1 ✔
852
                    TimeInterval::default(),
1 ✔
853
                    PlotSeriesSelection::all(),
1 ✔
854
                ),
1 ✔
855
                &execution_context.mock_query_context(ChunkByteSize::MIN),
1 ✔
856
            )
1 ✔
857
            .await
1 ✔
858
            .unwrap();
1 ✔
859

860
        let mut expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
861
        expected.add_attribute(
1 ✔
862
            BoxPlotAttribute::new("foo".to_string(), 1.0, 1.0, 1.0, 1.0, 1.0, true).unwrap(),
1 ✔
863
        );
864

865
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
866
    }
1 ✔
867

868
    #[tokio::test]
869
    async fn vector_data_empty() {
1 ✔
870
        let vector_source = MockFeatureCollectionSource::multiple(vec![
1 ✔
871
            DataCollection::from_slices(
1 ✔
872
                &[] as &[NoGeometry],
1 ✔
873
                &[] as &[TimeInterval],
1 ✔
874
                &[("foo", FeatureData::Int(vec![]))],
1 ✔
875
            )
876
            .unwrap(),
1 ✔
877
        ])
878
        .boxed();
1 ✔
879

880
        let box_plot = BoxPlot {
1 ✔
881
            params: BoxPlotParams {
1 ✔
882
                column_names: vec!["foo".to_string()],
1 ✔
883
            },
1 ✔
884
            sources: vector_source.into(),
1 ✔
885
        };
1 ✔
886

887
        let execution_context = MockExecutionContext::test_default();
1 ✔
888

889
        let query_processor = box_plot
1 ✔
890
            .boxed()
1 ✔
891
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
892
            .await
1 ✔
893
            .unwrap()
1 ✔
894
            .query_processor()
1 ✔
895
            .unwrap()
1 ✔
896
            .json_vega()
1 ✔
897
            .unwrap();
1 ✔
898

899
        let result = query_processor
1 ✔
900
            .plot_query(
1 ✔
901
                PlotQueryRectangle::new(
1 ✔
902
                    BoundingBox2D::new((-180., -90.).into(), (180., 90.).into()).unwrap(),
1 ✔
903
                    TimeInterval::default(),
1 ✔
904
                    PlotSeriesSelection::all(),
1 ✔
905
                ),
1 ✔
906
                &execution_context.mock_query_context(ChunkByteSize::MIN),
1 ✔
907
            )
1 ✔
908
            .await
1 ✔
909
            .unwrap();
1 ✔
910

911
        let expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
912
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
913
    }
1 ✔
914

915
    #[tokio::test]
916
    async fn vector_data_estimator_switch() {
1 ✔
917
        let mut data = Vec::<i64>::with_capacity(2 * super::EXACT_CALC_BOUND);
1 ✔
918

919
        for i in 1..=data.capacity() as i64 {
20,000 ✔
920
            data.push(i);
20,000 ✔
921
        }
20,000 ✔
922

923
        let vector_source = MockFeatureCollectionSource::multiple(vec![
1 ✔
924
            DataCollection::from_slices(
1 ✔
925
                &[] as &[NoGeometry],
1 ✔
926
                &[TimeInterval::default(); 2 * super::EXACT_CALC_BOUND],
1 ✔
927
                &[("foo", FeatureData::Int(data))],
1 ✔
928
            )
929
            .unwrap(),
1 ✔
930
        ])
931
        .boxed();
1 ✔
932

933
        let box_plot = BoxPlot {
1 ✔
934
            params: BoxPlotParams {
1 ✔
935
                column_names: vec!["foo".to_string()],
1 ✔
936
            },
1 ✔
937
            sources: vector_source.into(),
1 ✔
938
        };
1 ✔
939

940
        let execution_context = MockExecutionContext::test_default();
1 ✔
941

942
        let query_processor = box_plot
1 ✔
943
            .boxed()
1 ✔
944
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
945
            .await
1 ✔
946
            .unwrap()
1 ✔
947
            .query_processor()
1 ✔
948
            .unwrap()
1 ✔
949
            .json_vega()
1 ✔
950
            .unwrap();
1 ✔
951

952
        let result = query_processor
1 ✔
953
            .plot_query(
1 ✔
954
                PlotQueryRectangle::new(
1 ✔
955
                    BoundingBox2D::new((-180., -90.).into(), (180., 90.).into()).unwrap(),
1 ✔
956
                    TimeInterval::default(),
1 ✔
957
                    PlotSeriesSelection::all(),
1 ✔
958
                ),
1 ✔
959
                &execution_context.mock_query_context(ChunkByteSize::MIN),
1 ✔
960
            )
1 ✔
961
            .await
1 ✔
962
            .unwrap();
1 ✔
963

964
        let mut expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
965
        expected.add_attribute(
1 ✔
966
            BoxPlotAttribute::new(
1 ✔
967
                "foo".to_string(),
1 ✔
968
                1.0,
969
                2.0 * super::EXACT_CALC_BOUND as f64,
1 ✔
970
                super::EXACT_CALC_BOUND as f64,
1 ✔
971
                0.5 * super::EXACT_CALC_BOUND as f64,
1 ✔
972
                1.5 * super::EXACT_CALC_BOUND as f64,
1 ✔
973
                false,
974
            )
975
            .unwrap(),
1 ✔
976
        );
977

978
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
979
    }
1 ✔
980

981
    #[tokio::test]
982
    async fn no_data_raster_exclude_no_data() {
1 ✔
983
        let tile_size_in_pixels = GridShape2D::new_2d(3, 2);
1 ✔
984
        let result_descriptor = RasterResultDescriptor {
1 ✔
985
            data_type: RasterDataType::U8,
1 ✔
986
            spatial_reference: SpatialReference::epsg_4326().into(),
1 ✔
987
            time: TimeDescriptor::new_irregular(Some(TimeInterval::default())),
1 ✔
988
            spatial_grid: SpatialGridDescriptor::source_from_parts(
1 ✔
989
                GeoTransform::new(Coordinate2D::new(0., 0.), 1., -1.),
1 ✔
990
                tile_size_in_pixels.bounding_box(),
1 ✔
991
            ),
1 ✔
992
            bands: RasterBandDescriptors::new_single_band(),
1 ✔
993
        };
1 ✔
994

995
        let tiling_specification =
1 ✔
996
            geoengine_datatypes::raster::TilingSpecification::new(tile_size_in_pixels);
1 ✔
997

998
        let box_plot = BoxPlot {
1 ✔
999
            params: BoxPlotParams {
1 ✔
1000
                column_names: vec![],
1 ✔
1001
            },
1 ✔
1002
            sources: MockRasterSource {
1 ✔
1003
                params: MockRasterSourceParams {
1 ✔
1004
                    data: vec![RasterTile2D::new_with_tile_info(
1 ✔
1005
                        TimeInterval::default(),
1 ✔
1006
                        TileInformation {
1 ✔
1007
                            global_geo_transform: TestDefault::test_default(),
1 ✔
1008
                            global_tile_position: [0, 0].into(),
1 ✔
1009
                            tile_size_in_pixels,
1 ✔
1010
                        },
1 ✔
1011
                        0,
1 ✔
1012
                        EmptyGrid2D::<u8>::new(tile_size_in_pixels).into(),
1 ✔
1013
                        CacheHint::default(),
1 ✔
1014
                    )],
1 ✔
1015
                    result_descriptor,
1 ✔
1016
                },
1 ✔
1017
            }
1 ✔
1018
            .boxed()
1 ✔
1019
            .into(),
1 ✔
1020
        };
1 ✔
1021

1022
        let execution_context = MockExecutionContext::new_with_tiling_spec(tiling_specification);
1 ✔
1023

1024
        let query_processor = box_plot
1 ✔
1025
            .boxed()
1 ✔
1026
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
1027
            .await
1 ✔
1028
            .unwrap()
1 ✔
1029
            .query_processor()
1 ✔
1030
            .unwrap()
1 ✔
1031
            .json_vega()
1 ✔
1032
            .unwrap();
1 ✔
1033

1034
        let result = query_processor
1 ✔
1035
            .plot_query(
1 ✔
1036
                PlotQueryRectangle::new(
1 ✔
1037
                    BoundingBox2D::new((-180., -90.).into(), (180., 90.).into()).unwrap(),
1 ✔
1038
                    TimeInterval::default(),
1 ✔
1039
                    PlotSeriesSelection::all(),
1 ✔
1040
                ),
1 ✔
1041
                &execution_context.mock_query_context(ChunkByteSize::MIN),
1 ✔
1042
            )
1 ✔
1043
            .await
1 ✔
1044
            .unwrap();
1 ✔
1045

1046
        let expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
1047

1048
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
1049
    }
1 ✔
1050

1051
    #[tokio::test]
1052
    async fn no_data_raster_include_no_data() {
1 ✔
1053
        let tile_size_in_pixels = GridShape2D::new_2d(3, 2);
1 ✔
1054
        let result_descriptor = RasterResultDescriptor {
1 ✔
1055
            data_type: RasterDataType::U8,
1 ✔
1056
            spatial_reference: SpatialReference::epsg_4326().into(),
1 ✔
1057
            time: TimeDescriptor::new_irregular(Some(TimeInterval::default())),
1 ✔
1058
            spatial_grid: SpatialGridDescriptor::source_from_parts(
1 ✔
1059
                GeoTransform::new(Coordinate2D::new(0., 0.), 1., -1.),
1 ✔
1060
                tile_size_in_pixels.bounding_box(),
1 ✔
1061
            ),
1 ✔
1062
            bands: RasterBandDescriptors::new_single_band(),
1 ✔
1063
        };
1 ✔
1064

1065
        let tiling_specification = TilingSpecification::new(tile_size_in_pixels);
1 ✔
1066
        let box_plot = BoxPlot {
1 ✔
1067
            params: BoxPlotParams {
1 ✔
1068
                column_names: vec![],
1 ✔
1069
            },
1 ✔
1070
            sources: MockRasterSource {
1 ✔
1071
                params: MockRasterSourceParams {
1 ✔
1072
                    data: vec![RasterTile2D::new_with_tile_info(
1 ✔
1073
                        TimeInterval::default(),
1 ✔
1074
                        TileInformation {
1 ✔
1075
                            global_geo_transform: TestDefault::test_default(),
1 ✔
1076
                            global_tile_position: [0, 0].into(),
1 ✔
1077
                            tile_size_in_pixels,
1 ✔
1078
                        },
1 ✔
1079
                        0,
1 ✔
1080
                        Grid2D::new(tile_size_in_pixels, vec![0, 0, 0, 0, 0, 0])
1 ✔
1081
                            .unwrap()
1 ✔
1082
                            .into(),
1 ✔
1083
                        CacheHint::default(),
1 ✔
1084
                    )],
1 ✔
1085
                    result_descriptor,
1 ✔
1086
                },
1 ✔
1087
            }
1 ✔
1088
            .boxed()
1 ✔
1089
            .into(),
1 ✔
1090
        };
1 ✔
1091

1092
        let execution_context = MockExecutionContext::new_with_tiling_spec(tiling_specification);
1 ✔
1093

1094
        let query_processor = box_plot
1 ✔
1095
            .boxed()
1 ✔
1096
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
1097
            .await
1 ✔
1098
            .unwrap()
1 ✔
1099
            .query_processor()
1 ✔
1100
            .unwrap()
1 ✔
1101
            .json_vega()
1 ✔
1102
            .unwrap();
1 ✔
1103

1104
        let result = query_processor
1 ✔
1105
            .plot_query(
1 ✔
1106
                PlotQueryRectangle::new(
1 ✔
1107
                    BoundingBox2D::new((0., -3.).into(), (2., 0.).into()).unwrap(),
1 ✔
1108
                    TimeInterval::default(),
1 ✔
1109
                    PlotSeriesSelection::all(),
1 ✔
1110
                ),
1 ✔
1111
                &execution_context.mock_query_context(ChunkByteSize::MIN),
1 ✔
1112
            )
1 ✔
1113
            .await
1 ✔
1114
            .unwrap();
1 ✔
1115

1116
        let mut expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
1117
        expected.add_attribute(
1 ✔
1118
            BoxPlotAttribute::new("Raster-1".to_owned(), 0.0, 0.0, 0.0, 0.0, 0.0, true).unwrap(),
1 ✔
1119
        );
1120

1121
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
1122
    }
1 ✔
1123

1124
    #[tokio::test]
1125
    async fn empty_tile_raster_exclude_no_data() {
1 ✔
1126
        let tile_size_in_pixels = GridShape2D::new_2d(3, 2);
1 ✔
1127
        let result_descriptor = RasterResultDescriptor {
1 ✔
1128
            data_type: RasterDataType::U8,
1 ✔
1129
            spatial_reference: SpatialReference::epsg_4326().into(),
1 ✔
1130
            time: TimeDescriptor::new_irregular(Some(TimeInterval::default())),
1 ✔
1131
            spatial_grid: SpatialGridDescriptor::source_from_parts(
1 ✔
1132
                GeoTransform::new(Coordinate2D::new(0., 0.), 1., -1.),
1 ✔
1133
                tile_size_in_pixels.bounding_box(),
1 ✔
1134
            ),
1 ✔
1135
            bands: RasterBandDescriptors::new_single_band(),
1 ✔
1136
        };
1 ✔
1137

1138
        let tiling_specification = TilingSpecification::new(tile_size_in_pixels);
1 ✔
1139
        let box_plot = BoxPlot {
1 ✔
1140
            params: BoxPlotParams {
1 ✔
1141
                column_names: vec![],
1 ✔
1142
            },
1 ✔
1143
            sources: MockRasterSource {
1 ✔
1144
                params: MockRasterSourceParams {
1 ✔
1145
                    data: vec![RasterTile2D::new_with_tile_info(
1 ✔
1146
                        TimeInterval::default(),
1 ✔
1147
                        TileInformation {
1 ✔
1148
                            global_geo_transform: TestDefault::test_default(),
1 ✔
1149
                            global_tile_position: [0, 0].into(),
1 ✔
1150
                            tile_size_in_pixels,
1 ✔
1151
                        },
1 ✔
1152
                        0,
1 ✔
1153
                        EmptyGrid2D::<u8>::new(tile_size_in_pixels).into(),
1 ✔
1154
                        CacheHint::default(),
1 ✔
1155
                    )],
1 ✔
1156
                    result_descriptor,
1 ✔
1157
                },
1 ✔
1158
            }
1 ✔
1159
            .boxed()
1 ✔
1160
            .into(),
1 ✔
1161
        };
1 ✔
1162

1163
        let execution_context = MockExecutionContext::new_with_tiling_spec(tiling_specification);
1 ✔
1164

1165
        let query_processor = box_plot
1 ✔
1166
            .boxed()
1 ✔
1167
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
1168
            .await
1 ✔
1169
            .unwrap()
1 ✔
1170
            .query_processor()
1 ✔
1171
            .unwrap()
1 ✔
1172
            .json_vega()
1 ✔
1173
            .unwrap();
1 ✔
1174

1175
        let result = query_processor
1 ✔
1176
            .plot_query(
1 ✔
1177
                PlotQueryRectangle::new(
1 ✔
1178
                    BoundingBox2D::new((-180., -90.).into(), (180., 90.).into()).unwrap(),
1 ✔
1179
                    TimeInterval::default(),
1 ✔
1180
                    PlotSeriesSelection::all(),
1 ✔
1181
                ),
1 ✔
1182
                &execution_context.mock_query_context(ChunkByteSize::MIN),
1 ✔
1183
            )
1 ✔
1184
            .await
1 ✔
1185
            .unwrap();
1 ✔
1186

1187
        let expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
1188

1189
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
1190
    }
1 ✔
1191

1192
    #[tokio::test]
1193
    async fn single_value_raster_stream() {
1 ✔
1194
        let tile_size_in_pixels = GridShape2D::new_2d(3, 2);
1 ✔
1195
        let result_descriptor = RasterResultDescriptor {
1 ✔
1196
            data_type: RasterDataType::U8,
1 ✔
1197
            spatial_reference: SpatialReference::epsg_4326().into(),
1 ✔
1198
            time: TimeDescriptor::new_irregular(Some(TimeInterval::default())),
1 ✔
1199
            spatial_grid: SpatialGridDescriptor::source_from_parts(
1 ✔
1200
                GeoTransform::new(Coordinate2D::new(0., 0.), 1., -1.),
1 ✔
1201
                tile_size_in_pixels.bounding_box(),
1 ✔
1202
            ),
1 ✔
1203
            bands: RasterBandDescriptors::new_single_band(),
1 ✔
1204
        };
1 ✔
1205

1206
        let tiling_specification = TilingSpecification::new(tile_size_in_pixels);
1 ✔
1207
        let execution_context = MockExecutionContext::new_with_tiling_spec(tiling_specification);
1 ✔
1208
        let histogram = BoxPlot {
1 ✔
1209
            params: BoxPlotParams {
1 ✔
1210
                column_names: vec![],
1 ✔
1211
            },
1 ✔
1212
            sources: MockRasterSource {
1 ✔
1213
                params: MockRasterSourceParams {
1 ✔
1214
                    data: vec![RasterTile2D::new_with_tile_info(
1 ✔
1215
                        TimeInterval::default(),
1 ✔
1216
                        TileInformation {
1 ✔
1217
                            global_geo_transform: TestDefault::test_default(),
1 ✔
1218
                            global_tile_position: [0, 0].into(),
1 ✔
1219
                            tile_size_in_pixels,
1 ✔
1220
                        },
1 ✔
1221
                        0,
1 ✔
1222
                        Grid2D::new(tile_size_in_pixels, vec![4; 6]).unwrap().into(),
1 ✔
1223
                        CacheHint::default(),
1 ✔
1224
                    )],
1 ✔
1225
                    result_descriptor,
1 ✔
1226
                },
1 ✔
1227
            }
1 ✔
1228
            .boxed()
1 ✔
1229
            .into(),
1 ✔
1230
        };
1 ✔
1231

1232
        let query_processor = histogram
1 ✔
1233
            .boxed()
1 ✔
1234
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
1235
            .await
1 ✔
1236
            .unwrap()
1 ✔
1237
            .query_processor()
1 ✔
1238
            .unwrap()
1 ✔
1239
            .json_vega()
1 ✔
1240
            .unwrap();
1 ✔
1241

1242
        let result = query_processor
1 ✔
1243
            .plot_query(
1 ✔
1244
                PlotQueryRectangle::new(
1 ✔
1245
                    BoundingBox2D::new((-180., -90.).into(), (180., 90.).into()).unwrap(),
1 ✔
1246
                    TimeInterval::new_instant(DateTime::new_utc(2013, 12, 1, 12, 0, 0)).unwrap(),
1 ✔
1247
                    PlotSeriesSelection::all(),
1 ✔
1248
                ),
1 ✔
1249
                &execution_context.mock_query_context_test_default(),
1 ✔
1250
            )
1 ✔
1251
            .await
1 ✔
1252
            .unwrap();
1 ✔
1253

1254
        let mut expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
1255
        expected.add_attribute(
1 ✔
1256
            BoxPlotAttribute::new("Raster-1".to_owned(), 4.0, 4.0, 4.0, 4.0, 4.0, true).unwrap(),
1 ✔
1257
        );
1258

1259
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
1260
    }
1 ✔
1261

1262
    #[tokio::test]
1263
    async fn raster_with_no_data_exclude_no_data() {
1 ✔
1264
        let tile_size_in_pixels = GridShape2D::new_2d(4, 2);
1 ✔
1265
        let result_descriptor = RasterResultDescriptor {
1 ✔
1266
            data_type: RasterDataType::U8,
1 ✔
1267
            spatial_reference: SpatialReference::epsg_4326().into(),
1 ✔
1268
            time: TimeDescriptor::new_irregular(Some(TimeInterval::default())),
1 ✔
1269
            spatial_grid: SpatialGridDescriptor::source_from_parts(
1 ✔
1270
                GeoTransform::new(Coordinate2D::new(0., 0.), 1., -1.),
1 ✔
1271
                tile_size_in_pixels.bounding_box(),
1 ✔
1272
            ),
1 ✔
1273
            bands: RasterBandDescriptors::new_single_band(),
1 ✔
1274
        };
1 ✔
1275

1276
        let tiling_specification = TilingSpecification::new(tile_size_in_pixels);
1 ✔
1277
        let execution_context = MockExecutionContext::new_with_tiling_spec(tiling_specification);
1 ✔
1278

1279
        let histogram = BoxPlot {
1 ✔
1280
            params: BoxPlotParams {
1 ✔
1281
                column_names: vec![],
1 ✔
1282
            },
1 ✔
1283
            sources: MockRasterSource {
1 ✔
1284
                params: MockRasterSourceParams {
1 ✔
1285
                    data: vec![RasterTile2D::new_with_tile_info(
1 ✔
1286
                        TimeInterval::default(),
1 ✔
1287
                        TileInformation {
1 ✔
1288
                            global_geo_transform: TestDefault::test_default(),
1 ✔
1289
                            global_tile_position: [0, 0].into(),
1 ✔
1290
                            tile_size_in_pixels,
1 ✔
1291
                        },
1 ✔
1292
                        0,
1 ✔
1293
                        MaskedGrid2D::new(
1 ✔
1294
                            Grid2D::new(tile_size_in_pixels, vec![1, 2, 0, 4, 0, 6, 7, 0]).unwrap(),
1 ✔
1295
                            Grid2D::new(
1 ✔
1296
                                tile_size_in_pixels,
1 ✔
1297
                                vec![true, true, false, true, false, true, true, false],
1 ✔
1298
                            )
1 ✔
1299
                            .unwrap(),
1 ✔
1300
                        )
1 ✔
1301
                        .unwrap()
1 ✔
1302
                        .into(),
1 ✔
1303
                        CacheHint::default(),
1 ✔
1304
                    )],
1 ✔
1305
                    result_descriptor,
1 ✔
1306
                },
1 ✔
1307
            }
1 ✔
1308
            .boxed()
1 ✔
1309
            .into(),
1 ✔
1310
        };
1 ✔
1311

1312
        let query_processor = histogram
1 ✔
1313
            .boxed()
1 ✔
1314
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
1315
            .await
1 ✔
1316
            .unwrap()
1 ✔
1317
            .query_processor()
1 ✔
1318
            .unwrap()
1 ✔
1319
            .json_vega()
1 ✔
1320
            .unwrap();
1 ✔
1321

1322
        let result = query_processor
1 ✔
1323
            .plot_query(
1 ✔
1324
                PlotQueryRectangle::new(
1 ✔
1325
                    BoundingBox2D::new((0., -4.).into(), (2., 0.).into()).unwrap(),
1 ✔
1326
                    TimeInterval::new_instant(DateTime::new_utc(2013, 12, 1, 12, 0, 0)).unwrap(),
1 ✔
1327
                    PlotSeriesSelection::all(),
1 ✔
1328
                ),
1 ✔
1329
                &execution_context.mock_query_context_test_default(),
1 ✔
1330
            )
1 ✔
1331
            .await
1 ✔
1332
            .unwrap();
1 ✔
1333

1334
        let mut expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
1335
        expected.add_attribute(
1 ✔
1336
            BoxPlotAttribute::new("Raster-1".to_string(), 1.0, 7.0, 4.0, 1.5, 6.5, true).unwrap(),
1 ✔
1337
        );
1338

1339
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
1340
    }
1 ✔
1341

1342
    #[tokio::test]
1343
    async fn raster_with_no_data_include_no_data() {
1 ✔
1344
        let tile_size_in_pixels = GridShape2D::new_2d(4, 2);
1 ✔
1345
        let result_descriptor = RasterResultDescriptor {
1 ✔
1346
            data_type: RasterDataType::U8,
1 ✔
1347
            spatial_reference: SpatialReference::epsg_4326().into(),
1 ✔
1348
            time: TimeDescriptor::new_irregular(Some(TimeInterval::default())),
1 ✔
1349
            spatial_grid: SpatialGridDescriptor::source_from_parts(
1 ✔
1350
                GeoTransform::new(Coordinate2D::new(0., 0.), 1., -1.),
1 ✔
1351
                tile_size_in_pixels.bounding_box(),
1 ✔
1352
            ),
1 ✔
1353
            bands: RasterBandDescriptors::new_single_band(),
1 ✔
1354
        };
1 ✔
1355

1356
        let tiling_specification = TilingSpecification::new(tile_size_in_pixels);
1 ✔
1357
        let execution_context = MockExecutionContext::new_with_tiling_spec(tiling_specification);
1 ✔
1358

1359
        let histogram = BoxPlot {
1 ✔
1360
            params: BoxPlotParams {
1 ✔
1361
                column_names: vec![],
1 ✔
1362
            },
1 ✔
1363
            sources: MockRasterSource {
1 ✔
1364
                params: MockRasterSourceParams {
1 ✔
1365
                    data: vec![RasterTile2D::new_with_tile_info(
1 ✔
1366
                        TimeInterval::default(),
1 ✔
1367
                        TileInformation {
1 ✔
1368
                            global_geo_transform: TestDefault::test_default(),
1 ✔
1369
                            global_tile_position: [0, 0].into(),
1 ✔
1370
                            tile_size_in_pixels,
1 ✔
1371
                        },
1 ✔
1372
                        0,
1 ✔
1373
                        Grid2D::new(tile_size_in_pixels, vec![1, 2, 0, 4, 0, 6, 7, 0])
1 ✔
1374
                            .unwrap()
1 ✔
1375
                            .into(),
1 ✔
1376
                        CacheHint::default(),
1 ✔
1377
                    )],
1 ✔
1378
                    result_descriptor,
1 ✔
1379
                },
1 ✔
1380
            }
1 ✔
1381
            .boxed()
1 ✔
1382
            .into(),
1 ✔
1383
        };
1 ✔
1384

1385
        let query_processor = histogram
1 ✔
1386
            .boxed()
1 ✔
1387
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
1388
            .await
1 ✔
1389
            .unwrap()
1 ✔
1390
            .query_processor()
1 ✔
1391
            .unwrap()
1 ✔
1392
            .json_vega()
1 ✔
1393
            .unwrap();
1 ✔
1394

1395
        let result = query_processor
1 ✔
1396
            .plot_query(
1 ✔
1397
                PlotQueryRectangle::new(
1 ✔
1398
                    BoundingBox2D::new((0., -4.).into(), (2., 0.).into()).unwrap(),
1 ✔
1399
                    TimeInterval::new_instant(DateTime::new_utc(2013, 12, 1, 12, 0, 0)).unwrap(),
1 ✔
1400
                    PlotSeriesSelection::all(),
1 ✔
1401
                ),
1 ✔
1402
                &execution_context.mock_query_context_test_default(),
1 ✔
1403
            )
1 ✔
1404
            .await
1 ✔
1405
            .unwrap();
1 ✔
1406

1407
        let mut expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
1408
        expected.add_attribute(
1 ✔
1409
            BoxPlotAttribute::new("Raster-1".to_string(), 0.0, 7.0, 1.5, 0.0, 5.0, true).unwrap(),
1 ✔
1410
        );
1411

1412
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
1413
    }
1 ✔
1414

1415
    #[tokio::test]
1416
    async fn multiple_rasters_with_no_data_exclude_no_data() {
1 ✔
1417
        let tile_size_in_pixels = GridShape2D::new_2d(4, 2);
1 ✔
1418
        let result_descriptor = RasterResultDescriptor {
1 ✔
1419
            data_type: RasterDataType::U8,
1 ✔
1420
            spatial_reference: SpatialReference::epsg_4326().into(),
1 ✔
1421
            time: TimeDescriptor::new_irregular(Some(TimeInterval::default())),
1 ✔
1422
            spatial_grid: SpatialGridDescriptor::source_from_parts(
1 ✔
1423
                GeoTransform::new(Coordinate2D::new(0., 0.), 1., -1.),
1 ✔
1424
                tile_size_in_pixels.bounding_box(),
1 ✔
1425
            ),
1 ✔
1426
            bands: RasterBandDescriptors::new_single_band(),
1 ✔
1427
        };
1 ✔
1428

1429
        let tiling_specification = TilingSpecification::new(tile_size_in_pixels);
1 ✔
1430
        let execution_context = MockExecutionContext::new_with_tiling_spec(tiling_specification);
1 ✔
1431

1432
        let src = MockRasterSource {
1 ✔
1433
            params: MockRasterSourceParams {
1 ✔
1434
                data: vec![RasterTile2D::new_with_tile_info(
1 ✔
1435
                    TimeInterval::default(),
1 ✔
1436
                    TileInformation {
1 ✔
1437
                        global_geo_transform: TestDefault::test_default(),
1 ✔
1438
                        global_tile_position: [0, 0].into(),
1 ✔
1439
                        tile_size_in_pixels,
1 ✔
1440
                    },
1 ✔
1441
                    0,
1 ✔
1442
                    MaskedGrid2D::new(
1 ✔
1443
                        Grid2D::new(tile_size_in_pixels, vec![1, 2, 0, 4, 0, 6, 7, 0]).unwrap(),
1 ✔
1444
                        Grid2D::new(
1 ✔
1445
                            tile_size_in_pixels,
1 ✔
1446
                            vec![true, true, false, true, false, true, true, false],
1 ✔
1447
                        )
1 ✔
1448
                        .unwrap(),
1 ✔
1449
                    )
1 ✔
1450
                    .unwrap()
1 ✔
1451
                    .into(),
1 ✔
1452
                    CacheHint::default(),
1 ✔
1453
                )],
1 ✔
1454
                result_descriptor,
1 ✔
1455
            },
1 ✔
1456
        };
1 ✔
1457

1458
        let histogram = BoxPlot {
1 ✔
1459
            params: BoxPlotParams {
1 ✔
1460
                column_names: vec![],
1 ✔
1461
            },
1 ✔
1462
            sources: vec![
1 ✔
1463
                src.clone().boxed(),
1 ✔
1464
                src.clone().boxed(),
1 ✔
1465
                src.clone().boxed(),
1 ✔
1466
            ]
1 ✔
1467
            .into(),
1 ✔
1468
        };
1 ✔
1469

1470
        let query_processor = histogram
1 ✔
1471
            .boxed()
1 ✔
1472
            .initialize(WorkflowOperatorPath::initialize_root(), &execution_context)
1 ✔
1473
            .await
1 ✔
1474
            .unwrap()
1 ✔
1475
            .query_processor()
1 ✔
1476
            .unwrap()
1 ✔
1477
            .json_vega()
1 ✔
1478
            .unwrap();
1 ✔
1479

1480
        let result = query_processor
1 ✔
1481
            .plot_query(
1 ✔
1482
                PlotQueryRectangle::new(
1 ✔
1483
                    BoundingBox2D::new((-180., -90.).into(), (180., 90.).into()).unwrap(),
1 ✔
1484
                    TimeInterval::new_instant(DateTime::new_utc(2013, 12, 1, 12, 0, 0)).unwrap(),
1 ✔
1485
                    PlotSeriesSelection::all(),
1 ✔
1486
                ),
1 ✔
1487
                &execution_context.mock_query_context_test_default(),
1 ✔
1488
            )
1 ✔
1489
            .await
1 ✔
1490
            .unwrap();
1 ✔
1491

1492
        let mut expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
1493
        expected.add_attribute(
1 ✔
1494
            BoxPlotAttribute::new("Raster-1".to_string(), 1.0, 7.0, 4.0, 1.5, 6.5, true).unwrap(),
1 ✔
1495
        );
1496
        expected.add_attribute(
1 ✔
1497
            BoxPlotAttribute::new("Raster-2".to_string(), 1.0, 7.0, 4.0, 1.5, 6.5, true).unwrap(),
1 ✔
1498
        );
1499
        expected.add_attribute(
1 ✔
1500
            BoxPlotAttribute::new("Raster-3".to_string(), 1.0, 7.0, 4.0, 1.5, 6.5, true).unwrap(),
1 ✔
1501
        );
1502

1503
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
1504
    }
1 ✔
1505
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc