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

geo-engine / geoengine / 44096749148

17 Nov 2026 12:05PM UTC coverage: 88.446% (-0.02%) from 88.461%
44096749148

push

github

web-flow
fix(backend): cut OGC API tiles from the grid of their tile matrix (#1465)

* fix(backend): cut OGC API tiles from the grid of their tile matrix

A tile's grid and pixels came from the operator chain the tile was computed
with: for WebMercatorQuad a slice of the layer's whole grid, at a power-of-two
multiple of the source resolution, split by the number of tiles of the zoom
level (e.g. 421×419 px at z5 for the NDVI) and scaled to 256 px by the PNG
encoder; for CustomWebMercator at coarser tile matrices the grid of the
optimized Reprojection, which is not aligned to the tile matrix.

Now a tile is cut from the grid its tile matrix defines: its spatial reference,
origin and cell size (the zoom level's cell size for WebMercatorQuad, 256 px
per tile), and its pixels follow from the origin and tile size alone, one
`tile_grid_bbox` for all tile matrix sets. The layer is warped onto that grid
as in the previous commit, but without initializing the old chain.
CustomWebMercator still derives its tile matrices from the layer reprojected
with DataBounds; `layer_descriptor` computes that grid without operators, for
the tiles and the tile matrix set definition alike (a test checks it equals
the Reprojection's). Tile matrix set definitions, URLs and tile sizes do not
change. Removed: `reproject_if_necessary`, `processing_graph_with_reprojection`,
`processing_graph_with_resampling`, `required_origin_and_resolution` (with its
projector per tile), `find_next_best_resolution`.

Fixtures changed (regression fixture: 34 of 86 tiles, no status changed;
`ndvi_webmercator_0_0_0.png`, `natural_earth_rgb_1_0_1.png`):
- Custom tiles: unchanged.
- WebMercatorQuad, all sources: the tiles are the WebMercatorQuad tiles now.
  Against gdalwarp of the source onto the tile's extent (256 px, nearest
  neighbour), the data/no-data masks of the EPSG:4326 and EPSG:3857 tiles match
  exactly (before: up to 42% of the pixels off at the edge of the EPSG:3857
  data), and at z5 and z8 the ti... (continued)

290 of 294 new or added lines in 5 files covered. (98.64%)

33 existing lines in 8 files now uncovered.

142979 of 161656 relevant lines covered (88.45%)

551678.7 hits per line

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

90.2
/geoengine/operators/src/processing/downsample/mod.rs
1
use crate::adapters::{
2
    FoldTileAccu, FoldTileAccuMut, RasterSubQueryAdapter, SubQueryTileAggregator,
3
};
4
use crate::engine::{
5
    CanonicOperatorName, ExecutionContext, InitializedRasterOperator, InitializedSources, Operator,
6
    OperatorName, ProcessingGraphOperatorPath, QueryContext, QueryProcessor, RasterOperator,
7
    RasterQueryProcessor, RasterResultDescriptor, SingleRasterSource, TypedRasterOperator,
8
    TypedRasterQueryProcessor,
9
};
10
use crate::optimization::{OptimizableOperator, OptimizationError};
11
use crate::util::Result;
12
use async_trait::async_trait;
13
use futures::future::BoxFuture;
14
use futures::stream::BoxStream;
15
use futures::{Future, FutureExt, TryFuture, TryFutureExt};
16
use geoengine_datatypes::primitives::{
17
    BandSelection, CacheHint, Coordinate2D, find_next_best_overview_level_resolution,
18
};
19
use geoengine_datatypes::primitives::{RasterQueryRectangle, SpatialResolution, TimeInterval};
20
use geoengine_datatypes::raster::{
21
    ChangeGridBounds, GeoTransform, GridBoundingBox2D, GridContains, GridIdx2D, GridIndexAccess,
22
    GridOrEmpty, Pixel, RasterTile2D, TileInformation, TilingSpecification,
23
    UpdateIndexedElementsParallel,
24
};
25
use rayon::ThreadPool;
26
use serde::{Deserialize, Serialize};
27
use snafu::{Snafu, ensure};
28
use std::marker::PhantomData;
29
use std::sync::Arc;
30

31
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
32
#[serde(rename_all = "camelCase")]
33
pub struct DownsamplingParams {
34
    pub sampling_method: DownsamplingMethod,
35
    pub output_resolution: DownsamplingResolution,
36
    pub output_origin_reference: Option<Coordinate2D>,
37
}
38

39
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
40
#[serde(rename_all = "camelCase")]
41
pub struct Fraction {
42
    pub x: f64,
43
    pub y: f64,
44
}
45

46
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
47
#[serde(rename_all = "camelCase", tag = "type")]
48
pub enum DownsamplingResolution {
49
    Resolution(SpatialResolution),
50
    Fraction(Fraction),
51
}
52

53
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
54
#[serde(rename_all = "camelCase")]
55
pub enum DownsamplingMethod {
56
    NearestNeighbor,
57
    // Mean,
58
}
59

60
#[derive(Debug, Snafu)]
61
#[snafu(visibility(pub(crate)), context(suffix(false)), module(error))]
62
pub enum DownsamplingError {
63
    #[snafu(display("The fraction used to downsample must be >= 1, was {f}."))]
64
    FractionMustBeOneOrLarger { f: f64 },
65
    #[snafu(display("The output resolution must be higher than the input resolution."))]
66
    OutputMustBeLowerResolutionThanInput {
67
        input: SpatialResolution,
68
        output: SpatialResolution,
69
    },
70
}
71

72
pub type Downsampling = Operator<DownsamplingParams, SingleRasterSource>;
73

74
impl OperatorName for Downsampling {
75
    const TYPE_NAME: &'static str = "Downsampling";
76
}
77

78
#[async_trait]
79
impl RasterOperator for Downsampling {
80
    async fn _initialize(
81
        self: Box<Self>,
82
        path: ProcessingGraphOperatorPath,
83
        context: &dyn ExecutionContext,
84
    ) -> Result<Box<dyn InitializedRasterOperator>> {
8 ✔
85
        let name = CanonicOperatorName::from(&self);
86
        let initialized_source = self
87
            .sources
88
            .initialize_sources(path.clone(), context)
89
            .await?;
90
        InitializedDownsampling::new_with_source_and_params(
91
            name,
92
            path,
93
            initialized_source.raster,
94
            self.params,
95
            context.tiling_specification(),
96
        )
97
        .map(InitializedRasterOperator::boxed)
98
    }
8 ✔
99

100
    span_fn!(Downsampling);
101
}
102

103
pub struct InitializedDownsampling<O: InitializedRasterOperator> {
104
    name: CanonicOperatorName,
105
    path: ProcessingGraphOperatorPath,
106
    output_result_descriptor: RasterResultDescriptor,
107
    raster_source: O,
108
    sampling_method: DownsamplingMethod,
109
    tiling_specification: TilingSpecification,
110
}
111

112
impl<O: InitializedRasterOperator> InitializedDownsampling<O> {
113
    pub fn new_with_source_and_params(
8 ✔
114
        name: CanonicOperatorName,
8 ✔
115
        path: ProcessingGraphOperatorPath,
8 ✔
116
        raster_source: O,
8 ✔
117
        params: DownsamplingParams,
8 ✔
118
        tiling_specification: TilingSpecification,
8 ✔
119
    ) -> Result<Self> {
8 ✔
120
        let in_descriptor = raster_source.result_descriptor();
8 ✔
121

122
        let in_spatial_grid = in_descriptor.spatial_grid_descriptor();
8 ✔
123

124
        let output_resolution = match params.output_resolution {
8 ✔
125
            DownsamplingResolution::Resolution(res) => {
8 ✔
126
                ensure!(
8 ✔
127
                    res.x().abs() >= in_spatial_grid.spatial_resolution().x().abs(),
8 ✔
128
                    error::OutputMustBeLowerResolutionThanInput {
×
129
                        input: in_spatial_grid.spatial_resolution(),
×
130
                        output: res
×
131
                    }
×
132
                );
133
                ensure!(
8 ✔
134
                    res.y().abs() >= in_spatial_grid.spatial_resolution().y().abs(), // TODO: allow neg y size in SpatialResolution
8 ✔
135
                    error::OutputMustBeLowerResolutionThanInput {
×
136
                        input: in_spatial_grid.spatial_resolution(),
×
137
                        output: res
×
138
                    }
×
139
                );
140
                res
8 ✔
141
            }
142

143
            DownsamplingResolution::Fraction(fraction) => {
×
144
                ensure!(
×
145
                    fraction.x >= 1.0,
×
146
                    error::FractionMustBeOneOrLarger { f: fraction.x }
×
147
                );
148
                ensure!(
×
149
                    fraction.y >= 1.0,
×
150
                    error::FractionMustBeOneOrLarger { f: fraction.y }
×
151
                );
152

153
                SpatialResolution::new_unchecked(
×
154
                    in_spatial_grid.spatial_resolution().x().get() * fraction.x,
×
155
                    in_spatial_grid.spatial_resolution().y().get() * fraction.y, // TODO: allow negative size
×
156
                )
157
            }
158
        };
159

160
        let output_gspatial_grid = if let Some(oc) = params.output_origin_reference {
8 ✔
UNCOV
161
            in_spatial_grid
×
UNCOV
162
                .with_moved_origin_to_nearest_grid_edge(oc)
×
UNCOV
163
                .replace_origin(oc)
×
UNCOV
164
                .with_changed_resolution(output_resolution)
×
165
        } else {
166
            in_spatial_grid.with_changed_resolution(output_resolution)
8 ✔
167
        };
168

169
        let out_descriptor = RasterResultDescriptor {
8 ✔
170
            spatial_reference: in_descriptor.spatial_reference,
8 ✔
171
            data_type: in_descriptor.data_type, // TODO: datatype depends on resample method!
8 ✔
172
            time: in_descriptor.time,
8 ✔
173
            spatial_grid: output_gspatial_grid,
8 ✔
174
            bands: in_descriptor.bands.clone(),
8 ✔
175
        };
8 ✔
176

177
        Ok(InitializedDownsampling {
8 ✔
178
            name,
8 ✔
179
            path,
8 ✔
180
            output_result_descriptor: out_descriptor,
8 ✔
181
            raster_source,
8 ✔
182
            sampling_method: params.sampling_method,
8 ✔
183
            tiling_specification,
8 ✔
184
        })
8 ✔
185
    }
8 ✔
186
}
187

188
impl<O: InitializedRasterOperator> InitializedRasterOperator for InitializedDownsampling<O> {
189
    fn query_processor(&self) -> Result<TypedRasterQueryProcessor> {
3 ✔
190
        let source_processor = self.raster_source.query_processor()?;
3 ✔
191

192
        let res = call_on_generic_raster_processor!(
3 ✔
193
            source_processor, p => match self.sampling_method  {
3 ✔
194
                DownsamplingMethod::NearestNeighbor => DownsampleProcessor::<_,_>::new(
3 ✔
195
                        p,
3 ✔
196
                        self.output_result_descriptor.clone(),
3 ✔
197
                        self.tiling_specification,
3 ✔
198
                    ).boxed()
3 ✔
199
                    .into(),
3 ✔
200
            }
201
        );
202

203
        Ok(res)
3 ✔
204
    }
3 ✔
205

206
    fn result_descriptor(&self) -> &RasterResultDescriptor {
11 ✔
207
        &self.output_result_descriptor
11 ✔
208
    }
11 ✔
209

210
    fn canonic_name(&self) -> CanonicOperatorName {
×
211
        self.name.clone()
×
212
    }
×
213

UNCOV
214
    fn name(&self) -> &'static str {
×
UNCOV
215
        Downsampling::TYPE_NAME
×
UNCOV
216
    }
×
217

UNCOV
218
    fn path(&self) -> ProcessingGraphOperatorPath {
×
UNCOV
219
        self.path.clone()
×
UNCOV
220
    }
×
221

222
    fn optimize(
2 ✔
223
        &self,
2 ✔
224
        target_resolution: SpatialResolution,
2 ✔
225
    ) -> Result<TypedRasterOperator, OptimizationError> {
2 ✔
226
        self.ensure_resolution_is_compatible_for_optimization(target_resolution)?;
2 ✔
227

228
        let out_descriptor = self.result_descriptor();
2 ✔
229
        let in_descriptor = self.raster_source.result_descriptor();
2 ✔
230

231
        let input_resolution = in_descriptor.spatial_grid.spatial_resolution();
2 ✔
232

233
        let new_origin = if in_descriptor.spatial_grid.geo_transform().origin_coordinate
2 ✔
234
            == out_descriptor
2 ✔
235
                .spatial_grid
2 ✔
236
                .geo_transform()
2 ✔
237
                .origin_coordinate
2 ✔
238
        {
239
            None
2 ✔
240
        } else {
241
            Some(
×
242
                out_descriptor
×
243
                    .spatial_grid
×
244
                    .geo_transform()
×
245
                    .origin_coordinate,
×
246
            )
×
247
        };
248

249
        if input_resolution == target_resolution {
2 ✔
250
            // special case where downsampling becomes redundant, unless it also regrids
251

252
            // TODO: source does not need to be optimized, but we need it as an `RasterOperator` and not `InitializedRasterOperator`
253
            let optimzed_source = self.raster_source.optimize(target_resolution)?;
×
254

255
            if new_origin.is_some() {
×
256
                return Ok(Downsampling {
×
257
                    params: DownsamplingParams {
×
258
                        sampling_method: self.sampling_method,
×
259
                        output_resolution: DownsamplingResolution::Resolution(target_resolution),
×
260
                        output_origin_reference: new_origin,
×
261
                    },
×
262
                    sources: SingleRasterSource {
×
263
                        raster: optimzed_source,
×
264
                    },
×
265
                }
×
266
                .typed());
×
267
            }
×
268
            return Ok(optimzed_source);
×
269
        }
2 ✔
270

271
        // target resolution must be coarser than input
272
        debug_assert!(input_resolution < target_resolution);
2 ✔
273

274
        let snapped_input_resolution =
2 ✔
275
            find_next_best_overview_level_resolution(input_resolution, target_resolution);
2 ✔
276

277
        let optimzed_source = self.raster_source.optimize(snapped_input_resolution)?;
2 ✔
278

279
        Ok(Downsampling {
2 ✔
280
            params: DownsamplingParams {
2 ✔
281
                sampling_method: self.sampling_method,
2 ✔
282
                output_resolution: DownsamplingResolution::Resolution(target_resolution),
2 ✔
283
                output_origin_reference: new_origin,
2 ✔
284
            },
2 ✔
285
            sources: SingleRasterSource {
2 ✔
286
                raster: optimzed_source,
2 ✔
287
            },
2 ✔
288
        }
2 ✔
289
        .typed())
2 ✔
290
    }
2 ✔
291
}
292

293
pub struct DownsampleProcessor<Q, P>
294
where
295
    Q: RasterQueryProcessor<RasterType = P>,
296
    P: Copy,
297
{
298
    source: Q,
299
    out_result_descriptor: RasterResultDescriptor,
300
    tiling_specification: TilingSpecification,
301
}
302

303
impl<Q, P> DownsampleProcessor<Q, P>
304
where
305
    Q: RasterQueryProcessor<RasterType = P>,
306
    P: Copy,
307
{
308
    pub fn new(
13 ✔
309
        source: Q,
13 ✔
310
        out_result_descriptor: RasterResultDescriptor,
13 ✔
311
        tiling_specification: TilingSpecification,
13 ✔
312
    ) -> Self {
13 ✔
313
        Self {
13 ✔
314
            source,
13 ✔
315
            out_result_descriptor,
13 ✔
316
            tiling_specification,
13 ✔
317
        }
13 ✔
318
    }
13 ✔
319
}
320

321
#[async_trait]
322
impl<Q, P> RasterQueryProcessor for DownsampleProcessor<Q, P>
323
where
324
    Q: RasterQueryProcessor<RasterType = P>,
325
    P: Pixel,
326
{
327
    type RasterType = P;
328

329
    async fn _time_query<'a>(
330
        &'a self,
331
        query: geoengine_datatypes::primitives::TimeInterval,
332
        ctx: &'a dyn QueryContext,
333
    ) -> Result<BoxStream<'a, Result<geoengine_datatypes::primitives::TimeInterval>>> {
2 ✔
334
        self.source.time_query(query, ctx).await
335
    }
2 ✔
336
}
337

338
#[async_trait]
339
impl<Q, P> QueryProcessor for DownsampleProcessor<Q, P>
340
where
341
    Q: RasterQueryProcessor<RasterType = P>,
342
    P: Pixel,
343
{
344
    type Output = RasterTile2D<P>;
345
    type SpatialBounds = GridBoundingBox2D;
346
    type Selection = BandSelection;
347
    type ResultDescription = RasterResultDescriptor;
348

349
    async fn _query<'a>(
350
        &'a self,
351
        query: RasterQueryRectangle,
352
        ctx: &'a dyn QueryContext,
353
    ) -> Result<BoxStream<'a, Result<Self::Output>>> {
13 ✔
354
        // do not interpolate if the source resolution is already fine enough
355

356
        let in_spatial_grid = self.source.result_descriptor().spatial_grid_descriptor();
357
        let out_spatial_grid = self.result_descriptor().spatial_grid_descriptor();
358

359
        // if the output resolution is the same as the input resolution, we can just forward the query // TODO: except the origin changes?
360
        if in_spatial_grid == out_spatial_grid {
361
            return self.source.query(query, ctx).await;
362
        }
363

364
        let tiling_grid_definition =
365
            out_spatial_grid.tiling_grid_definition(ctx.tiling_specification());
366
        // This is the tiling strategy we want to fill
367
        let tiling_strategy: geoengine_datatypes::raster::TilingStrategy =
368
            tiling_grid_definition.generate_data_tiling_strategy();
369

370
        let sub_query = DownsampleSubQuery::<_, P> {
371
            input_geo_transform: in_spatial_grid
372
                .tiling_grid_definition(ctx.tiling_specification())
373
                .tiling_geo_transform(),
374
            output_geo_transform: tiling_grid_definition.tiling_geo_transform(),
375
            fold_fn: fold_future,
376
            tiling_specification: self.tiling_specification,
377
            _phantom_pixel_type: PhantomData,
378
        };
379

380
        let time_stream = self.time_query(query.time_interval(), ctx).await?;
381

382
        Ok(Box::pin(RasterSubQueryAdapter::<'a, P, _, _, _>::new(
383
            &self.source,
384
            query,
385
            tiling_strategy,
386
            ctx,
387
            sub_query,
388
            time_stream,
389
        )))
390
    }
13 ✔
391

392
    fn result_descriptor(&self) -> &RasterResultDescriptor {
68 ✔
393
        &self.out_result_descriptor
68 ✔
394
    }
68 ✔
395
}
396

397
#[derive(Debug, Clone)]
398
pub struct DownsampleSubQuery<F, T> {
399
    input_geo_transform: GeoTransform,
400
    output_geo_transform: GeoTransform,
401
    fold_fn: F,
402
    tiling_specification: TilingSpecification,
403
    _phantom_pixel_type: PhantomData<T>,
404
}
405

406
impl<'a, T, FoldM, FoldF> SubQueryTileAggregator<'a, T> for DownsampleSubQuery<FoldM, T>
407
where
408
    T: Pixel,
409
    FoldM: Send + Sync + 'a + Clone + Fn(DownsampleAccu<T>, RasterTile2D<T>) -> FoldF,
410
    FoldF: Send + TryFuture<Ok = DownsampleAccu<T>, Error = crate::error::Error>,
411
{
412
    type FoldFuture = FoldF;
413

414
    type FoldMethod = FoldM;
415

416
    type TileAccu = DownsampleAccu<T>;
417
    type TileAccuFuture = BoxFuture<'a, Result<Self::TileAccu>>;
418

419
    fn new_fold_accu(
36 ✔
420
        &self,
36 ✔
421
        tile_info: TileInformation,
36 ✔
422
        query_rect: RasterQueryRectangle,
36 ✔
423
        pool: &Arc<ThreadPool>,
36 ✔
424
    ) -> Self::TileAccuFuture {
36 ✔
425
        create_accu(
36 ✔
426
            self.input_geo_transform,
36 ✔
427
            self.output_geo_transform,
36 ✔
428
            tile_info,
36 ✔
429
            &query_rect,
36 ✔
430
            pool.clone(),
36 ✔
431
            self.tiling_specification,
36 ✔
432
        )
36 ✔
433
        .boxed()
36 ✔
434
    }
36 ✔
435

436
    fn tile_query_rectangle(
36 ✔
437
        &self,
36 ✔
438
        tile_info: TileInformation,
36 ✔
439
        _query_rect: RasterQueryRectangle,
36 ✔
440
        time: TimeInterval,
36 ✔
441
        band_idx: u32,
36 ✔
442
    ) -> Result<Option<RasterQueryRectangle>> {
36 ✔
443
        let out_tile_pixel_bounds = tile_info.global_pixel_bounds();
36 ✔
444
        //.intersection(&query_rect.spatial_query.grid_bounds());
445
        //let out_tile_pixel_bounds = out_tile_pixel_bounds;
446
        let out_tile_spatial_bounds = self
36 ✔
447
            .output_geo_transform
36 ✔
448
            .grid_to_spatial_bounds(&out_tile_pixel_bounds);
36 ✔
449
        let input_pixel_bounds = self
36 ✔
450
            .input_geo_transform
36 ✔
451
            .spatial_to_grid_bounds(&out_tile_spatial_bounds);
36 ✔
452

453
        Ok(Some(RasterQueryRectangle::new(
36 ✔
454
            input_pixel_bounds,
36 ✔
455
            time,
36 ✔
456
            BandSelection::new_single(band_idx),
36 ✔
457
        )))
36 ✔
458
    }
36 ✔
459

460
    fn fold_method(&self) -> Self::FoldMethod {
36 ✔
461
        self.fold_fn.clone()
36 ✔
462
    }
36 ✔
463
}
464

465
#[derive(Clone, Debug)]
466
pub struct DownsampleAccu<T: Pixel> {
467
    pub output_tile_info: TileInformation,
468
    pub output_grid: GridOrEmpty<GridBoundingBox2D, T>,
469
    pub input_global_geo_transform: GeoTransform,
470

471
    pub time: Option<TimeInterval>,
472
    pub cache_hint: CacheHint,
473
    pub pool: Arc<ThreadPool>,
474
}
475

476
impl<T: Pixel> DownsampleAccu<T> {
477
    pub fn new(
36 ✔
478
        output_tile_info: TileInformation,
36 ✔
479
        input_global_geo_transform: GeoTransform,
36 ✔
480
        time: Option<TimeInterval>,
36 ✔
481
        cache_hint: CacheHint,
36 ✔
482
        pool: Arc<ThreadPool>,
36 ✔
483
    ) -> Self {
36 ✔
484
        DownsampleAccu {
36 ✔
485
            output_tile_info,
36 ✔
486
            output_grid: GridOrEmpty::new_empty_shape(output_tile_info.global_pixel_bounds()),
36 ✔
487
            input_global_geo_transform,
36 ✔
488
            time,
36 ✔
489
            cache_hint,
36 ✔
490
            pool,
36 ✔
491
        }
36 ✔
492
    }
36 ✔
493
}
494

495
#[async_trait]
496
impl<T: Pixel> FoldTileAccu for DownsampleAccu<T> {
497
    type RasterType = T;
498

499
    async fn into_tile(self) -> Result<RasterTile2D<Self::RasterType>> {
36 ✔
500
        // TODO: later do conversation of accu into tile here
501

502
        let output_tile = RasterTile2D::new_with_tile_info(
503
            self.time.expect("there is at least one input"),
504
            self.output_tile_info,
505
            0, // TODO: need band?
506
            self.output_grid.unbounded(),
507
            self.cache_hint,
508
        );
509

510
        Ok(output_tile)
511
    }
36 ✔
512

513
    fn thread_pool(&self) -> &Arc<ThreadPool> {
×
514
        &self.pool
×
515
    }
×
516
}
517

518
impl<T: Pixel> FoldTileAccuMut for DownsampleAccu<T> {
519
    fn set_time(&mut self, time: TimeInterval) {
182 ✔
520
        self.time = Some(time);
182 ✔
521
    }
182 ✔
522

523
    fn set_cache_hint(&mut self, cache_hint: CacheHint) {
×
524
        self.cache_hint = cache_hint;
×
525
    }
×
526
}
527

528
pub fn create_accu<T: Pixel>(
36 ✔
529
    input_geo_transform: GeoTransform,
36 ✔
530
    _output_geo_transform: GeoTransform,
36 ✔
531
    tile_info: TileInformation,
36 ✔
532
    _query_rect: &RasterQueryRectangle,
36 ✔
533
    pool: Arc<ThreadPool>,
36 ✔
534
    _tiling_specification: TilingSpecification,
36 ✔
535
) -> impl Future<Output = Result<DownsampleAccu<T>>> + use<T> {
36 ✔
536
    crate::util::spawn_blocking(move || {
36 ✔
537
        DownsampleAccu::new(
36 ✔
538
            tile_info,
36 ✔
539
            input_geo_transform,
36 ✔
540
            None,
36 ✔
541
            CacheHint::max_duration(),
36 ✔
542
            pool.clone(),
36 ✔
543
        )
544
    })
36 ✔
545
    .map_err(From::from)
36 ✔
546
}
36 ✔
547

548
pub fn fold_future<T>(
182 ✔
549
    accu: DownsampleAccu<T>,
182 ✔
550
    tile: RasterTile2D<T>,
182 ✔
551
) -> impl Future<Output = Result<DownsampleAccu<T>>>
182 ✔
552
where
182 ✔
553
    T: Pixel,
182 ✔
554
{
555
    crate::util::spawn_blocking_with_thread_pool(accu.pool.clone(), || fold_impl(accu, tile)).then(
182 ✔
556
        |x| async move {
182 ✔
557
            match x {
182 ✔
558
                Ok(r) => Ok(r),
182 ✔
559
                Err(e) => Err(e.into()),
×
560
            }
561
        },
364 ✔
562
    )
563
}
182 ✔
564

565
pub fn fold_impl<T>(mut accu: DownsampleAccu<T>, tile: RasterTile2D<T>) -> DownsampleAccu<T>
182 ✔
566
where
182 ✔
567
    T: Pixel,
182 ✔
568
{
569
    let _span = tracing::debug_span!("downsample_fold").entered();
182 ✔
570

571
    // get the time now because it is not known when the accu was created
572
    accu.set_time(tile.time);
182 ✔
573
    accu.cache_hint.merge_with(&tile.cache_hint);
182 ✔
574

575
    // TODO: add a skip if both tiles are empty?
576
    if tile.is_empty() {
182 ✔
577
        // TODO: and ignore no-data.
578
        return accu;
94 ✔
579
    }
88 ✔
580

581
    // copy all input tiles into the accu to have all data for interpolation
582
    let mut accu_tile = accu.output_grid.into_materialized_masked_grid();
88 ✔
583
    let in_tile_grid = tile.into_inner_positioned_grid();
88 ✔
584
    let accu_geo_transform = accu.output_tile_info.global_geo_transform;
88 ✔
585
    let in_geo_transform = accu.input_global_geo_transform;
88 ✔
586

587
    let map_fn = |grid_idx: GridIdx2D, current_value: Option<T>| -> Option<T> {
17,032,481 ✔
588
        let accu_pixel_coord = accu_geo_transform.grid_idx_to_pixel_center_coordinate_2d(grid_idx); // use center coordinate similar to ArcGIS
17,032,481 ✔
589
        let source_pixel_idx = in_geo_transform.coordinate_to_grid_idx_2d(accu_pixel_coord);
17,032,481 ✔
590

591
        if in_tile_grid.contains(&source_pixel_idx) {
17,032,481 ✔
592
            in_tile_grid.get_at_grid_index_unchecked(source_pixel_idx)
4,734,024 ✔
593
        } else {
594
            current_value
12,298,457 ✔
595
        }
596
    };
17,032,481 ✔
597

598
    accu_tile.update_indexed_elements_parallel(map_fn);
88 ✔
599

600
    accu.output_grid = accu_tile.into();
88 ✔
601

602
    accu
88 ✔
603
}
182 ✔
604

605
#[cfg(test)]
606
mod tests {
607
    use super::*;
608
    use crate::engine::{
609
        ChunkByteSize, MockExecutionContext, RasterBandDescriptors, SpatialGridDescriptor,
610
        TimeDescriptor,
611
    };
612
    use crate::mock::{MockRasterSource, MockRasterSourceParams};
613
    use futures::StreamExt;
614
    use geoengine_datatypes::primitives::TimeStep;
615
    use geoengine_datatypes::raster::{Grid, GridShape2D, RasterDataType};
616
    use geoengine_datatypes::spatial_reference::SpatialReference;
617
    use geoengine_datatypes::util::test::TestDefault;
618

619
    #[allow(clippy::too_many_lines)]
620
    #[tokio::test]
621
    async fn nearest_neighbor_4() {
1 ✔
622
        // In this test, 2x2 tiles with 4x4 pixels are downsampled using nearest neighbor to one tile with 4x4 pixels. The resolution is now 1/2 of the original resolution.
623
        // The test uses the following input:
624
        //
625
        // _1, _2, _3, _4 | 21, 22, 23, 24
626
        // _5, _6, _7, _8 | 25, 26, 27, 28
627
        // _9, 10, 11, 12 | 29, 30, 31, 32
628
        // 13, 14, 15, 16 | 33, 34, 35, 36
629
        // ---------------+---------------
630
        // 41, 42, 43, 44 | 61, 62, 63, 64
631
        // 45, 46, 47, 48 | 65, 66, 67, 68
632
        // 49, 50, 51, 52 | 69, 70, 71, 72
633
        // 53, 54, 55, 56 | 73, 74, 75, 76
634
        //
635
        // The input is downsampled to:
636
        //
637
        // _6. _8, 26, 28
638
        // 14, 16, 33, 36
639
        // 46, 48, 66, 68
640
        // 54, 56, 74, 76
641
        //
642
        // The center of each pixel is mapped to a coordinate. Then, for this coordinate the nearest pixel center is selected.
643
        // In this case, we have the special case that the pixel center of the target pixel hits the edge between two original pixels.
644
        // The pixel which "owns" the edge is selected because pixels are defiend from the upper left edge.
645
        // E.g. _6 is selected for the first pixel since it owns the edge between _1, _2, _5_ and _6.
646

647
        let in_geo_transform = GeoTransform::new_unchecked(Coordinate2D::new(0.0, 0.0), 1.0, -1.0);
1 ✔
648
        let out_geo_transform = GeoTransform::new_unchecked(Coordinate2D::new(0.0, 0.0), 2.0, -2.0);
1 ✔
649
        let tile_size_in_pixels = GridShape2D {
1 ✔
650
            shape_array: [4, 4],
1 ✔
651
        };
1 ✔
652

653
        let exe_ctx = MockExecutionContext::new_with_tiling_spec_and_thread_count(
1 ✔
654
            TilingSpecification::new(tile_size_in_pixels),
1 ✔
655
            8,
656
        );
657

658
        let data: Vec<RasterTile2D<u8>> = vec![
1 ✔
659
            RasterTile2D {
1 ✔
660
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
661
                tile_position: [0, 0].into(),
1 ✔
662
                band: 0,
1 ✔
663
                global_geo_transform: in_geo_transform,
1 ✔
664
                grid_array: Grid::new(
1 ✔
665
                    tile_size_in_pixels,
1 ✔
666
                    vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
1 ✔
667
                )
1 ✔
668
                .unwrap()
1 ✔
669
                .into(),
1 ✔
670
                properties: Default::default(),
1 ✔
671
                cache_hint: CacheHint::no_cache(),
1 ✔
672
            },
1 ✔
673
            RasterTile2D {
1 ✔
674
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
675
                tile_position: [0, 1].into(),
1 ✔
676
                band: 0,
1 ✔
677
                global_geo_transform: in_geo_transform,
1 ✔
678
                grid_array: Grid::new(
1 ✔
679
                    tile_size_in_pixels,
1 ✔
680
                    vec![
1 ✔
681
                        21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
1 ✔
682
                    ],
1 ✔
683
                )
1 ✔
684
                .unwrap()
1 ✔
685
                .into(),
1 ✔
686
                properties: Default::default(),
1 ✔
687
                cache_hint: CacheHint::no_cache(),
1 ✔
688
            },
1 ✔
689
            RasterTile2D {
1 ✔
690
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
691
                tile_position: [1, 0].into(),
1 ✔
692
                band: 0,
1 ✔
693
                global_geo_transform: in_geo_transform,
1 ✔
694
                grid_array: Grid::new(
1 ✔
695
                    tile_size_in_pixels,
1 ✔
696
                    vec![
1 ✔
697
                        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
1 ✔
698
                    ],
1 ✔
699
                )
1 ✔
700
                .unwrap()
1 ✔
701
                .into(),
1 ✔
702
                properties: Default::default(),
1 ✔
703
                cache_hint: CacheHint::no_cache(),
1 ✔
704
            },
1 ✔
705
            RasterTile2D {
1 ✔
706
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
707
                tile_position: [1, 1].into(),
1 ✔
708
                band: 0,
1 ✔
709
                global_geo_transform: in_geo_transform,
1 ✔
710
                grid_array: Grid::new(
1 ✔
711
                    tile_size_in_pixels,
1 ✔
712
                    vec![
1 ✔
713
                        61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
1 ✔
714
                    ],
1 ✔
715
                )
1 ✔
716
                .unwrap()
1 ✔
717
                .into(),
1 ✔
718
                properties: Default::default(),
1 ✔
719
                cache_hint: CacheHint::no_cache(),
1 ✔
720
            },
1 ✔
721
        ];
722

723
        let result_descriptor = RasterResultDescriptor {
1 ✔
724
            data_type: RasterDataType::U8,
1 ✔
725
            spatial_reference: SpatialReference::epsg_4326().into(),
1 ✔
726
            time: TimeDescriptor::new_regular_with_epoch(
1 ✔
727
                Some(
1 ✔
728
                    TimeInterval::new(
1 ✔
729
                        data.first().unwrap().time.start(),
1 ✔
730
                        data.last().unwrap().time.end(),
1 ✔
731
                    )
1 ✔
732
                    .unwrap(),
1 ✔
733
                ),
1 ✔
734
                TimeStep::millis(5).unwrap(),
1 ✔
735
            ),
1 ✔
736
            spatial_grid: SpatialGridDescriptor::source_from_parts(
1 ✔
737
                in_geo_transform,
1 ✔
738
                GridBoundingBox2D::new_min_max(0, 7, 0, 7).unwrap(),
1 ✔
739
            ),
1 ✔
740
            bands: RasterBandDescriptors::new_single_band(),
1 ✔
741
        };
1 ✔
742

743
        let mrs1 = MockRasterSource {
1 ✔
744
            params: MockRasterSourceParams {
1 ✔
745
                data: data.clone(),
1 ✔
746
                result_descriptor: result_descriptor.clone(),
1 ✔
747
            },
1 ✔
748
        }
1 ✔
749
        .typed();
1 ✔
750

751
        let downsampler = Downsampling {
1 ✔
752
            params: DownsamplingParams {
1 ✔
753
                sampling_method: DownsamplingMethod::NearestNeighbor,
1 ✔
754
                output_origin_reference: None,
1 ✔
755
                output_resolution: DownsamplingResolution::Resolution(
1 ✔
756
                    SpatialResolution::new_unchecked(
1 ✔
757
                        out_geo_transform.x_pixel_size().get(),
1 ✔
758
                        out_geo_transform.y_pixel_size().get().abs(),
1 ✔
759
                    ),
1 ✔
760
                ),
1 ✔
761
            },
1 ✔
762
            sources: SingleRasterSource { raster: mrs1 },
1 ✔
763
        }
1 ✔
764
        .typed();
1 ✔
765

766
        let query_rect = RasterQueryRectangle::new(
1 ✔
767
            GridBoundingBox2D::new_min_max(0, 3, 0, 3).unwrap(),
1 ✔
768
            TimeInterval::new_unchecked(0, 5),
1 ✔
769
            [0].try_into().unwrap(),
1 ✔
770
        );
771

772
        let query_ctx = exe_ctx.mock_query_context(ChunkByteSize::test_default());
1 ✔
773

774
        let op = downsampler
1 ✔
775
            .initialize(ProcessingGraphOperatorPath::initialize_root(), &exe_ctx)
1 ✔
776
            .await
1 ✔
777
            .unwrap();
1 ✔
778

779
        let qp = op.query_processor().unwrap().get_u8().unwrap();
1 ✔
780

781
        let result = qp
1 ✔
782
            .raster_query(query_rect, &query_ctx)
1 ✔
783
            .await
1 ✔
784
            .unwrap()
1 ✔
785
            .collect::<Vec<_>>()
1 ✔
786
            .await;
1 ✔
787

788
        assert_eq!(result.len(), 1);
1 ✔
789

790
        let tile = result[0].as_ref().unwrap();
1 ✔
791
        let grid = tile.grid_array.clone().into_materialized_masked_grid();
1 ✔
792
        // _6. _8, 26, 28
793
        // 14, 16, 33, 36
794
        // 46, 48, 66, 68
795
        // 54, 56, 74, 76
796
        assert_eq!(
1 ✔
797
            grid.inner_grid.data,
1 ✔
798
            &[6, 8, 26, 28, 14, 16, 34, 36, 46, 48, 66, 68, 54, 56, 74, 76]
1 ✔
799
        );
1 ✔
800
    }
1 ✔
801

802
    #[allow(clippy::too_many_lines)]
803
    #[tokio::test]
804
    async fn nearest_neighbor_3() {
1 ✔
805
        // In this test, 3x3 tiles with 3x3 pixels are downsampled using nearest neighbor to one tile with 3x3 pixels. The resolution is now 1/3 of the original resolution.
806
        // The test uses the following input:
807
        //
808
        // _0, _1, _2 | 10, 11, 12 | 20, 21, 22
809
        // _3, _4, _5 | 13, 14, 15 | 23, 24, 25
810
        // _6, _7, _8 | 16, 17, 18 | 26, 27, 28
811
        // -----------+------------+-----------
812
        // 30, 31, 32 | 40, 41, 42 | 50, 51, 52
813
        // 33, 34, 35 | 43, 44, 45 | 53, 54, 55
814
        // 36, 37, 38 | 46, 47, 48 | 56, 57, 58
815
        // -----------+------------+-----------
816
        // 60, 61, 62 | 70, 71, 72 | 80, 81, 82
817
        // 63, 64, 65 | 73, 74, 75 | 83, 84, 85
818
        // 66, 67, 68 | 76, 77, 78 | 86, 87, 88
819
        //
820
        // The input is downsampled to:
821
        //
822
        // _4. 14, 24
823
        // 34, 44, 54
824
        // 64, 74, 84
825
        //
826
        // The center of each pixel is mapped to a coordinate. Then, for this coordinate the nearest pixel center is selected.
827
        // In this case, each pixel corresponds to the center of the corresponding tile.
828
        // E.g. _4 is selected for the first pixel since it is in the center of the tile.
829

830
        let in_geo_transform = GeoTransform::new_unchecked(Coordinate2D::new(0.0, 0.0), 1.0, -1.0);
1 ✔
831
        let out_geo_transform = GeoTransform::new_unchecked(Coordinate2D::new(0.0, 0.0), 3.0, -3.0);
1 ✔
832
        let tile_size_in_pixels = GridShape2D {
1 ✔
833
            shape_array: [3, 3],
1 ✔
834
        };
1 ✔
835

836
        let exe_ctx = MockExecutionContext::new_with_tiling_spec_and_thread_count(
1 ✔
837
            TilingSpecification::new(tile_size_in_pixels),
1 ✔
838
            8,
839
        );
840

841
        let data: Vec<RasterTile2D<u8>> = vec![
1 ✔
842
            RasterTile2D {
1 ✔
843
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
844
                tile_position: [0, 0].into(),
1 ✔
845
                band: 0,
1 ✔
846
                global_geo_transform: in_geo_transform,
1 ✔
847
                grid_array: Grid::new(tile_size_in_pixels, vec![0, 1, 2, 3, 4, 5, 6, 7, 8])
1 ✔
848
                    .unwrap()
1 ✔
849
                    .into(),
1 ✔
850
                properties: Default::default(),
1 ✔
851
                cache_hint: CacheHint::no_cache(),
1 ✔
852
            },
1 ✔
853
            RasterTile2D {
1 ✔
854
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
855
                tile_position: [0, 1].into(),
1 ✔
856
                band: 0,
1 ✔
857
                global_geo_transform: in_geo_transform,
1 ✔
858
                grid_array: Grid::new(
1 ✔
859
                    tile_size_in_pixels,
1 ✔
860
                    vec![10, 11, 12, 13, 14, 15, 16, 17, 18],
1 ✔
861
                )
1 ✔
862
                .unwrap()
1 ✔
863
                .into(),
1 ✔
864
                properties: Default::default(),
1 ✔
865
                cache_hint: CacheHint::no_cache(),
1 ✔
866
            },
1 ✔
867
            RasterTile2D {
1 ✔
868
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
869
                tile_position: [0, 2].into(),
1 ✔
870
                band: 0,
1 ✔
871
                global_geo_transform: in_geo_transform,
1 ✔
872
                grid_array: Grid::new(
1 ✔
873
                    tile_size_in_pixels,
1 ✔
874
                    vec![20, 21, 22, 23, 24, 25, 26, 27, 28],
1 ✔
875
                )
1 ✔
876
                .unwrap()
1 ✔
877
                .into(),
1 ✔
878
                properties: Default::default(),
1 ✔
879
                cache_hint: CacheHint::no_cache(),
1 ✔
880
            },
1 ✔
881
            RasterTile2D {
1 ✔
882
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
883
                tile_position: [1, 0].into(),
1 ✔
884
                band: 0,
1 ✔
885
                global_geo_transform: in_geo_transform,
1 ✔
886
                grid_array: Grid::new(
1 ✔
887
                    tile_size_in_pixels,
1 ✔
888
                    vec![30, 31, 32, 33, 34, 35, 36, 37, 38],
1 ✔
889
                )
1 ✔
890
                .unwrap()
1 ✔
891
                .into(),
1 ✔
892
                properties: Default::default(),
1 ✔
893
                cache_hint: CacheHint::no_cache(),
1 ✔
894
            },
1 ✔
895
            RasterTile2D {
1 ✔
896
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
897
                tile_position: [1, 1].into(),
1 ✔
898
                band: 0,
1 ✔
899
                global_geo_transform: in_geo_transform,
1 ✔
900
                grid_array: Grid::new(
1 ✔
901
                    tile_size_in_pixels,
1 ✔
902
                    vec![40, 41, 42, 43, 44, 45, 46, 47, 48],
1 ✔
903
                )
1 ✔
904
                .unwrap()
1 ✔
905
                .into(),
1 ✔
906
                properties: Default::default(),
1 ✔
907
                cache_hint: CacheHint::no_cache(),
1 ✔
908
            },
1 ✔
909
            RasterTile2D {
1 ✔
910
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
911
                tile_position: [1, 2].into(),
1 ✔
912
                band: 0,
1 ✔
913
                global_geo_transform: in_geo_transform,
1 ✔
914
                grid_array: Grid::new(
1 ✔
915
                    tile_size_in_pixels,
1 ✔
916
                    vec![50, 51, 52, 53, 54, 55, 56, 57, 58],
1 ✔
917
                )
1 ✔
918
                .unwrap()
1 ✔
919
                .into(),
1 ✔
920
                properties: Default::default(),
1 ✔
921
                cache_hint: CacheHint::no_cache(),
1 ✔
922
            },
1 ✔
923
            RasterTile2D {
1 ✔
924
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
925
                tile_position: [2, 0].into(),
1 ✔
926
                band: 0,
1 ✔
927
                global_geo_transform: in_geo_transform,
1 ✔
928
                grid_array: Grid::new(
1 ✔
929
                    tile_size_in_pixels,
1 ✔
930
                    vec![60, 61, 62, 63, 64, 65, 66, 67, 68],
1 ✔
931
                )
1 ✔
932
                .unwrap()
1 ✔
933
                .into(),
1 ✔
934
                properties: Default::default(),
1 ✔
935
                cache_hint: CacheHint::no_cache(),
1 ✔
936
            },
1 ✔
937
            RasterTile2D {
1 ✔
938
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
939
                tile_position: [2, 1].into(),
1 ✔
940
                band: 0,
1 ✔
941
                global_geo_transform: in_geo_transform,
1 ✔
942
                grid_array: Grid::new(
1 ✔
943
                    tile_size_in_pixels,
1 ✔
944
                    vec![70, 71, 72, 73, 74, 75, 76, 77, 78],
1 ✔
945
                )
1 ✔
946
                .unwrap()
1 ✔
947
                .into(),
1 ✔
948
                properties: Default::default(),
1 ✔
949
                cache_hint: CacheHint::no_cache(),
1 ✔
950
            },
1 ✔
951
            RasterTile2D {
1 ✔
952
                time: TimeInterval::new_unchecked(0, 5),
1 ✔
953
                tile_position: [2, 2].into(),
1 ✔
954
                band: 0,
1 ✔
955
                global_geo_transform: in_geo_transform,
1 ✔
956
                grid_array: Grid::new(
1 ✔
957
                    tile_size_in_pixels,
1 ✔
958
                    vec![80, 81, 82, 83, 84, 85, 86, 87, 88],
1 ✔
959
                )
1 ✔
960
                .unwrap()
1 ✔
961
                .into(),
1 ✔
962
                properties: Default::default(),
1 ✔
963
                cache_hint: CacheHint::no_cache(),
1 ✔
964
            },
1 ✔
965
        ];
966

967
        let result_descriptor = RasterResultDescriptor {
1 ✔
968
            data_type: RasterDataType::U8,
1 ✔
969
            spatial_reference: SpatialReference::epsg_4326().into(),
1 ✔
970
            time: TimeDescriptor::new_regular_with_epoch(
1 ✔
971
                Some(
1 ✔
972
                    TimeInterval::new(
1 ✔
973
                        data.first().unwrap().time.start(),
1 ✔
974
                        data.last().unwrap().time.end(),
1 ✔
975
                    )
1 ✔
976
                    .unwrap(),
1 ✔
977
                ),
1 ✔
978
                TimeStep::millis(5).unwrap(),
1 ✔
979
            ),
1 ✔
980
            spatial_grid: SpatialGridDescriptor::source_from_parts(
1 ✔
981
                in_geo_transform,
1 ✔
982
                GridBoundingBox2D::new_min_max(0, 8, 0, 8).unwrap(),
1 ✔
983
            ),
1 ✔
984
            bands: RasterBandDescriptors::new_single_band(),
1 ✔
985
        };
1 ✔
986

987
        let mrs1 = MockRasterSource {
1 ✔
988
            params: MockRasterSourceParams {
1 ✔
989
                data: data.clone(),
1 ✔
990
                result_descriptor: result_descriptor.clone(),
1 ✔
991
            },
1 ✔
992
        }
1 ✔
993
        .typed();
1 ✔
994

995
        let downsampler = Downsampling {
1 ✔
996
            params: DownsamplingParams {
1 ✔
997
                sampling_method: DownsamplingMethod::NearestNeighbor,
1 ✔
998
                output_origin_reference: None,
1 ✔
999
                output_resolution: DownsamplingResolution::Resolution(
1 ✔
1000
                    SpatialResolution::new_unchecked(
1 ✔
1001
                        out_geo_transform.x_pixel_size().get(),
1 ✔
1002
                        out_geo_transform.y_pixel_size().get().abs(),
1 ✔
1003
                    ),
1 ✔
1004
                ),
1 ✔
1005
            },
1 ✔
1006
            sources: SingleRasterSource { raster: mrs1 },
1 ✔
1007
        }
1 ✔
1008
        .typed();
1 ✔
1009

1010
        let query_rect = RasterQueryRectangle::new(
1 ✔
1011
            GridBoundingBox2D::new_min_max(0, 2, 0, 2).unwrap(),
1 ✔
1012
            TimeInterval::new_unchecked(0, 5),
1 ✔
1013
            [0].try_into().unwrap(),
1 ✔
1014
        );
1015

1016
        let query_ctx = exe_ctx.mock_query_context(ChunkByteSize::test_default());
1 ✔
1017

1018
        let op = downsampler
1 ✔
1019
            .initialize(ProcessingGraphOperatorPath::initialize_root(), &exe_ctx)
1 ✔
1020
            .await
1 ✔
1021
            .unwrap();
1 ✔
1022

1023
        let qp = op.query_processor().unwrap().get_u8().unwrap();
1 ✔
1024

1025
        let result = qp
1 ✔
1026
            .raster_query(query_rect, &query_ctx)
1 ✔
1027
            .await
1 ✔
1028
            .unwrap()
1 ✔
1029
            .collect::<Vec<_>>()
1 ✔
1030
            .await;
1 ✔
1031

1032
        assert_eq!(result.len(), 1);
1 ✔
1033

1034
        let tile = result[0].as_ref().unwrap();
1 ✔
1035
        let grid = tile.grid_array.clone().into_materialized_masked_grid();
1 ✔
1036
        // _4. 14, 24
1037
        // 34, 44, 54
1038
        // 64, 74, 84
1039

1040
        assert_eq!(grid.inner_grid.data, &[4, 14, 24, 34, 44, 54, 64, 74, 84]);
1 ✔
1041
    }
1 ✔
1042
}
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