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

geo-engine / geoengine / 19537157963

20 Nov 2025 12:39PM UTC coverage: 88.458%. First build
19537157963

Pull #1083

github

web-flow
Merge 49b049e99 into ba34db99d
Pull Request #1083: feat: new gdal source workflow optimization

6339 of 7660 new or added lines in 79 files covered. (82.75%)

116533 of 131738 relevant lines covered (88.46%)

492817.7 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 { column: cn.clone() });
158
                        }
159
                    }
160
                }
161

162
                let in_desc = vector_source.result_descriptor();
163

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

179
    span_fn!(BoxPlot);
180
}
181

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

188
    source: Op,
189
}
190

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

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

217
        Ok(TypedPlotQueryProcessor::JsonVega(processor.boxed()))
5 ✔
218
    }
5 ✔
219

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

364
        call_on_generic_raster_processor!(input, processor => {
9 ✔
365

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

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

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

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

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

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

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

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

419
//
420
// AUX Structures
421
//
422

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

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

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

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

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

461
        let s = values.split_at(idx);
10 ✔
462

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

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

512
struct BoxPlotAccum {
513
    name: String,
514
    accum: BoxPlotAccumKind,
515
}
516

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

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

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

537
#[cfg(test)]
538
mod tests {
539

540
    use geoengine_datatypes::primitives::{CacheHint, Coordinate2D, PlotSeriesSelection};
541
    use serde_json::json;
542

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

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

560
    use super::*;
561

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

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

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

593
        assert_eq!(deserialized.params, histogram.params);
1 ✔
594
    }
1 ✔
595

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

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

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

626
        assert_eq!(deserialized.params, histogram.params);
1 ✔
627
    }
1 ✔
628

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

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

660
        let execution_context = MockExecutionContext::test_default();
1 ✔
661

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

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

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

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

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

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

725
        let execution_context = MockExecutionContext::test_default();
1 ✔
726

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

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

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

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

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

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

776
        let execution_context = MockExecutionContext::test_default();
1 ✔
777

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

783
        assert!(init.is_err());
1 ✔
784
    }
1 ✔
785

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

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

805
        let execution_context = MockExecutionContext::test_default();
1 ✔
806

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

812
        assert!(init.is_err());
1 ✔
813
    }
1 ✔
814

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

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

834
        let execution_context = MockExecutionContext::test_default();
1 ✔
835

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

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

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

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

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

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

885
        let execution_context = MockExecutionContext::test_default();
1 ✔
886

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

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

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

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

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

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

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

938
        let execution_context = MockExecutionContext::test_default();
1 ✔
939

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

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

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

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

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

993
        let tiling_specification =
1 ✔
994
            geoengine_datatypes::raster::TilingSpecification::new(tile_size_in_pixels);
1 ✔
995

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

1020
        let execution_context = MockExecutionContext::new_with_tiling_spec(tiling_specification);
1 ✔
1021

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

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

1044
        let expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
1045

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

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

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

1090
        let execution_context = MockExecutionContext::new_with_tiling_spec(tiling_specification);
1 ✔
1091

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

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

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

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

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

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

1161
        let execution_context = MockExecutionContext::new_with_tiling_spec(tiling_specification);
1 ✔
1162

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

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

1185
        let expected = geoengine_datatypes::plots::BoxPlot::new();
1 ✔
1186

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1501
        assert_eq!(expected.to_vega_embeddable(false).unwrap(), result);
1 ✔
1502
    }
1 ✔
1503
}
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