14#ifndef GDALCOMPUTEDRASTERBAND_H_INCLUDED
15#define GDALCOMPUTEDRASTERBAND_H_INCLUDED
18#include "gdal_dataset.h"
19#include "gdal_rasterband.h"
38class CPL_DLL GDALComputedRasterBand final :
public GDALRasterBand
42 ~GDALComputedRasterBand()
override;
71 GDALComputedRasterBand(
72 Operation op,
const std::vector<const GDALRasterBand *> &bands,
73 double constant = std::numeric_limits<double>::quiet_NaN());
74 GDALComputedRasterBand(Operation op,
const GDALRasterBand &band);
75 GDALComputedRasterBand(Operation op,
double constant,
76 const GDALRasterBand &band);
77 GDALComputedRasterBand(Operation op,
const GDALRasterBand &band,
79 GDALComputedRasterBand(Operation op,
const GDALRasterBand &band,
83 GDALComputedRasterBand(Operation op,
const GDALRasterBand &firstBand,
84 const GDALRasterBand &secondBand);
86 GDALComputedRasterBand(GDALComputedRasterBand &&) =
default;
105 return static_cast<GDALComputedRasterBand *
>(hBand);
114 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
120 friend class GDALComputedDataset;
121 std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser> m_poOwningDS{};
122 bool m_bHasNoData{
false};
123 double m_dfNoDataValue{0};
125 GDALComputedRasterBand(
const GDALComputedRasterBand &,
bool);
126 GDALComputedRasterBand(
const GDALComputedRasterBand &) =
delete;
127 GDALComputedRasterBand &
operator=(
const GDALComputedRasterBand &) =
delete;
128 GDALComputedRasterBand &
operator=(GDALComputedRasterBand &&) =
delete;
134GDALComputedRasterBand CPL_DLL abs(
const GDALRasterBand &band);
137GDALComputedRasterBand CPL_DLL fabs(
const GDALRasterBand &band);
140GDALComputedRasterBand CPL_DLL sqrt(
const GDALRasterBand &band);
143GDALComputedRasterBand CPL_DLL log(
const GDALRasterBand &band);
146GDALComputedRasterBand CPL_DLL log10(
const GDALRasterBand &band);
149GDALComputedRasterBand CPL_DLL pow(
const GDALRasterBand &band,
double constant);
151GDALComputedRasterBand CPL_DLL pow(
double constant,
const GDALRasterBand &band);
152GDALComputedRasterBand CPL_DLL pow(
const GDALRasterBand &band1,
153 const GDALRasterBand &band2);
156GDALComputedRasterBand CPL_DLL IfThenElse(
const GDALRasterBand &condBand,
157 const GDALRasterBand &thenBand,
158 const GDALRasterBand &elseBand);
162GDALComputedRasterBand CPL_DLL IfThenElse(
const GDALRasterBand &condBand,
164 const GDALRasterBand &elseBand);
166GDALComputedRasterBand CPL_DLL IfThenElse(
const GDALRasterBand &condBand,
167 const GDALRasterBand &thenBand,
170GDALComputedRasterBand CPL_DLL IfThenElse(
const GDALRasterBand &condBand,
171 double thenValue,
double elseValue);
178GDALComputedRasterBand CPL_DLL min(
const GDALRasterBand &first,
179 const GDALRasterBand &second);
186template <
typename U,
typename Enable>
struct minDealFirstArg;
189struct minDealFirstArg<
190 U, typename std::enable_if<std::is_arithmetic<U>::value>::type>
192 inline static void process(std::vector<const GDALRasterBand *> &,
193 double &constant,
const U &first)
195 if (std::isnan(constant) ||
static_cast<double>(first) < constant)
196 constant =
static_cast<double>(first);
201struct minDealFirstArg<
202 U, typename std::enable_if<!std::is_arithmetic<U>::value>::type>
204 inline static void process(std::vector<const GDALRasterBand *> &bands,
205 double &,
const U &first)
208 GDALRasterBand::ThrowIfNotSameDimensions(first, *(bands.front()));
209 bands.push_back(&first);
213inline static GDALComputedRasterBand
214minInternal(std::vector<const GDALRasterBand *> &bands,
double constant)
216 return GDALComputedRasterBand(GDALComputedRasterBand::Operation::OP_MIN,
220template <
typename U,
typename... V>
221GDALComputedRasterBand minInternal(std::vector<const GDALRasterBand *> &bands,
222 double constant,
const U &first, V &&...rest)
224 minDealFirstArg<U, void>::process(bands, constant, first);
225 return minInternal(bands, constant, std::forward<V>(rest)...);
230template <
typename U,
typename... V>
231inline GDALComputedRasterBand min(
const U &first, V &&...rest)
233 std::vector<const GDALRasterBand *> bands;
234 return detail::minInternal(bands, std::numeric_limits<double>::quiet_NaN(),
235 first, std::forward<V>(rest)...);
240GDALComputedRasterBand CPL_DLL max(
const GDALRasterBand &first,
241 const GDALRasterBand &second);
248template <
typename U,
typename Enable>
struct maxDealFirstArg;
251struct maxDealFirstArg<
252 U, typename std::enable_if<std::is_arithmetic<U>::value>::type>
254 inline static void process(std::vector<const GDALRasterBand *> &,
255 double &constant,
const U &first)
257 if (std::isnan(constant) ||
static_cast<double>(first) > constant)
258 constant =
static_cast<double>(first);
263struct maxDealFirstArg<
264 U, typename std::enable_if<!std::is_arithmetic<U>::value>::type>
266 inline static void process(std::vector<const GDALRasterBand *> &bands,
267 double &,
const U &first)
270 GDALRasterBand::ThrowIfNotSameDimensions(first, *(bands.front()));
271 bands.push_back(&first);
275inline static GDALComputedRasterBand
276maxInternal(std::vector<const GDALRasterBand *> &bands,
double constant)
278 return GDALComputedRasterBand(GDALComputedRasterBand::Operation::OP_MAX,
282template <
typename U,
typename... V>
283GDALComputedRasterBand maxInternal(std::vector<const GDALRasterBand *> &bands,
284 double constant,
const U &first, V &&...rest)
286 maxDealFirstArg<U, void>::process(bands, constant, first);
287 return maxInternal(bands, constant, std::forward<V>(rest)...);
292template <
typename U,
typename... V>
293inline GDALComputedRasterBand max(
const U &first, V &&...rest)
295 std::vector<const GDALRasterBand *> bands;
296 return detail::maxInternal(bands, std::numeric_limits<double>::quiet_NaN(),
297 first, std::forward<V>(rest)...);
302GDALComputedRasterBand CPL_DLL mean(
const GDALRasterBand &first,
303 const GDALRasterBand &second);
306inline GDALComputedRasterBand
307meanInternal(std::vector<const GDALRasterBand *> &bands)
309 return GDALComputedRasterBand(GDALComputedRasterBand::Operation::OP_MEAN,
313template <
typename U,
typename... V>
314inline GDALComputedRasterBand
315meanInternal(std::vector<const GDALRasterBand *> &bands,
const U &first,
319 GDALRasterBand::ThrowIfNotSameDimensions(first, *(bands.front()));
320 bands.push_back(&first);
321 return meanInternal(bands, std::forward<V>(rest)...);
324template <
typename... Args>
inline GDALComputedRasterBand mean(Args &&...args)
326 std::vector<const GDALRasterBand *> bands;
327 return meanInternal(bands, std::forward<Args>(args)...);
Class represented the result of an operation on one or two input bands.
Definition gdal_computedrasterband.h:39
static GDALComputedRasterBand * FromHandle(GDALComputedRasterBandH hBand)
Convert a GDALComputedRasterBandH to a GDALComputedRasterBand*.
Definition gdal_computedrasterband.h:103
static GDALComputedRasterBandH ToHandle(GDALComputedRasterBand *poBand)
Convert a GDALComputedRasterBand* to a GDALComputedRasterBandH.
Definition gdal_computedrasterband.h:95
GDALMajorObject & operator=(const GDALMajorObject &)=default
Copy assignment operator.
A single raster band (or channel).
Definition gdal_rasterband.h:105
virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData)=0
Default internal implementation ... to be overridden by subclasses that support reading.
virtual CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize, void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType, GSpacing nPixelSpace, GSpacing nLineSpace, GDALRasterIOExtraArg *psExtraArg)
Read/write a region of image data for this band.
Definition rasterio.cpp:223
virtual double GetNoDataValue(int *pbSuccess=nullptr)
Fetch the no data value for this band.
Definition gdalrasterband.cpp:2347
CPLErr
Error category.
Definition cpl_error.h:37
Core portability definitions for CPL.
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:386
GDALDataType
Definition gdal.h:48
GDALRWFlag
Definition gdal.h:125
void * GDALComputedRasterBandH
Opaque type used for the C bindings of the C++ GDALComputedRasterBand class.
Definition gdal_fwd.h:48