@@ -46,6 +46,9 @@ class TemporalAggregationOperator: public GenericOperator {
4646private:
4747 double duration;
4848 AggregationType aggregationType;
49+
50+ std::unique_ptr<GenericRaster>
51+ sampleAggregation (std::unique_ptr<GenericRaster> unique_ptr, const QueryRectangle &rectangle, const QueryTools &tools);
4952};
5053
5154TemporalAggregationOperator::TemporalAggregationOperator (int sourcecounts[],
@@ -180,6 +183,12 @@ std::unique_ptr<GenericRaster> TemporalAggregationOperator::getRaster(
180183 // TODO: allow LOOSE computations
181184
182185 auto input = getRasterFromSource (0 , rect, tools, RasterQM::EXACT);
186+
187+ if (input->stref .t2 == input->stref .t1 + input->stref .epsilon ()) {
188+ // TODO: refactor when raster time series are introduced
189+ return sampleAggregation (std::move (input), rect, tools);
190+ }
191+
183192 auto accumulator = createAccumulator (*input);
184193
185194 size_t n = 1 ;
@@ -201,9 +210,32 @@ std::unique_ptr<GenericRaster> TemporalAggregationOperator::getRaster(
201210 n += 1 ;
202211 }
203212
204- auto output = callUnaryOperatorFunc<Output>(input.get (), accumulator.get (), aggregationType, n);
213+ return callUnaryOperatorFunc<Output>(input.get (), accumulator.get (), aggregationType, n);
214+ }
215+
216+ std::unique_ptr<GenericRaster>
217+ TemporalAggregationOperator::sampleAggregation (std::unique_ptr<GenericRaster> input, const QueryRectangle &rect, const QueryTools &tools) {
218+ const size_t n = 3 ; // TODO: introduce (optional) parameter
219+ double timeDelta = (rect.t2 - rect.t1 ) / n;
220+
221+ auto accumulator = createAccumulator (*input);
222+
223+ QueryRectangle nextRect = rect;
224+ nextRect.t1 = input->stref .t1 + timeDelta;
225+ nextRect.t2 = nextRect.t1 + nextRect.epsilon ();
226+
227+ for (size_t i = 0 ; i < n; ++i) {
228+ std::unique_ptr<GenericRaster> rasterFromSource = getRasterFromSource (0 , nextRect, tools,
229+ RasterQM::EXACT);
230+
231+ // accumulate
232+ callUnaryOperatorFunc<Accumulate>(rasterFromSource.get (), accumulator.get (), aggregationType);
233+
234+ nextRect.t1 = rasterFromSource->stref .t1 + timeDelta;
235+ nextRect.t2 = nextRect.t1 + nextRect.epsilon ();
236+ }
205237
206- return output ;
238+ return callUnaryOperatorFunc<Output>(input. get (), accumulator. get (), aggregationType, n) ;
207239}
208240
209241#endif
0 commit comments