Line data Source code
1 : /******************************************************************************
2 : *
3 : * Name: gdal_rasterband.h
4 : * Project: GDAL Core
5 : * Purpose: Declaration of GDALRasterBand class
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 1998, Frank Warmerdam
10 : * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
11 : *
12 : * SPDX-License-Identifier: MIT
13 : ****************************************************************************/
14 :
15 : #ifndef GDALRASTERBAND_H_INCLUDED
16 : #define GDALRASTERBAND_H_INCLUDED
17 :
18 : #include "cpl_port.h"
19 : #include "gdal.h"
20 : #include "gdal_majorobject.h"
21 :
22 : #include <cstddef>
23 : #include <cstdint>
24 : #include <complex>
25 : #include <iterator>
26 : #include <memory>
27 : #if __cplusplus >= 202002L
28 : #include <span>
29 : #endif
30 : #include <vector>
31 :
32 : //! @cond Doxygen_Suppress
33 : #if !defined(OPTIONAL_OUTSIDE_GDAL)
34 : #if defined(GDAL_COMPILATION)
35 : #define OPTIONAL_OUTSIDE_GDAL(val)
36 : #else
37 : #define OPTIONAL_OUTSIDE_GDAL(val) = val
38 : #endif
39 : #endif
40 : //! @endcond
41 :
42 : /* ******************************************************************** */
43 : /* GDALRasterBand */
44 : /* ******************************************************************** */
45 :
46 : class GDALAbstractBandBlockCache;
47 : class GDALColorTable;
48 : class GDALDataset;
49 : class GDALDoublePointsCache;
50 : class GDALRasterAttributeTable;
51 : class GDALRasterBlock;
52 : class GDALMDArray;
53 : class OGRSpatialReference;
54 :
55 : /** Range of values found in a mask band */
56 : typedef enum
57 : {
58 : GMVR_UNKNOWN, /*! Unknown (can also be used for any values between 0 and 255
59 : for a Byte band) */
60 : GMVR_0_AND_1_ONLY, /*! Only 0 and 1 */
61 : GMVR_0_AND_255_ONLY, /*! Only 0 and 255 */
62 : } GDALMaskValueRange;
63 :
64 : /** Suggested/most efficient access pattern to blocks. */
65 : typedef int GDALSuggestedBlockAccessPattern;
66 :
67 : /** Unknown, or no particular read order is suggested. */
68 : constexpr GDALSuggestedBlockAccessPattern GSBAP_UNKNOWN = 0;
69 :
70 : /** Random access to blocks is efficient. */
71 : constexpr GDALSuggestedBlockAccessPattern GSBAP_RANDOM = 1;
72 :
73 : /** Reading by strips from top to bottom is the most efficient. */
74 : constexpr GDALSuggestedBlockAccessPattern GSBAP_TOP_TO_BOTTOM = 2;
75 :
76 : /** Reading by strips from bottom to top is the most efficient. */
77 : constexpr GDALSuggestedBlockAccessPattern GSBAP_BOTTOM_TO_TOP = 3;
78 :
79 : /** Reading the largest chunk from the raster is the most efficient (can be
80 : * combined with above values). */
81 : constexpr GDALSuggestedBlockAccessPattern GSBAP_LARGEST_CHUNK_POSSIBLE = 0x100;
82 :
83 : class GDALComputedRasterBand;
84 :
85 : /** A rectangular subset of pixels within a raster */
86 : class GDALRasterWindow
87 : {
88 : public:
89 : /** left offset of the window */
90 : int nXOff;
91 :
92 : /** top offset of the window */
93 : int nYOff;
94 :
95 : /** window width */
96 : int nXSize;
97 :
98 : /** window height */
99 : int nYSize;
100 : };
101 :
102 : /** A single raster band (or channel). */
103 :
104 : class CPL_DLL GDALRasterBand : public GDALMajorObject
105 : {
106 : private:
107 : friend class GDALArrayBandBlockCache;
108 : friend class GDALHashSetBandBlockCache;
109 : friend class GDALRasterBlock;
110 : friend class GDALDataset;
111 :
112 : CPLErr eFlushBlockErr = CE_None;
113 : GDALAbstractBandBlockCache *poBandBlockCache = nullptr;
114 :
115 : CPL_INTERNAL void SetFlushBlockErr(CPLErr eErr);
116 : CPL_INTERNAL CPLErr UnreferenceBlock(GDALRasterBlock *poBlock);
117 : CPL_INTERNAL void IncDirtyBlocks(int nInc);
118 :
119 : CPL_INTERNAL CPLErr RasterIOInternal(
120 : GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize,
121 : void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType,
122 : GSpacing nPixelSpace, GSpacing nLineSpace,
123 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
124 :
125 : protected:
126 : GDALRasterBand();
127 : explicit GDALRasterBand(int bForceCachedIO);
128 :
129 : //! @cond Doxygen_Suppress
130 : GDALRasterBand(GDALRasterBand &&) = default;
131 : //! @endcond
132 :
133 : //! @cond Doxygen_Suppress
134 : GDALDataset *poDS = nullptr;
135 : int nBand = 0; /* 1 based */
136 :
137 : int nRasterXSize = 0;
138 : int nRasterYSize = 0;
139 :
140 : GDALDataType eDataType = GDT_Byte;
141 : GDALAccess eAccess = GA_ReadOnly;
142 :
143 : /* stuff related to blocking, and raster cache */
144 : int nBlockXSize = -1;
145 : int nBlockYSize = -1;
146 : int nBlocksPerRow = 0;
147 : int nBlocksPerColumn = 0;
148 :
149 : int nBlockReads = 0;
150 : int bForceCachedIO = 0;
151 :
152 : friend class GDALComputedRasterBand;
153 : friend class GDALComputedDataset;
154 :
155 : class GDALRasterBandOwnedOrNot
156 : {
157 : public:
158 1847710 : GDALRasterBandOwnedOrNot() = default;
159 :
160 : GDALRasterBandOwnedOrNot(GDALRasterBandOwnedOrNot &&) = default;
161 :
162 1847940 : void reset()
163 : {
164 1847940 : m_poBandOwned.reset();
165 1847940 : m_poBandRef = nullptr;
166 1847940 : }
167 :
168 1795 : void resetNotOwned(GDALRasterBand *poBand)
169 : {
170 1795 : m_poBandOwned.reset();
171 1795 : m_poBandRef = poBand;
172 1795 : }
173 :
174 163592 : void reset(std::unique_ptr<GDALRasterBand> poBand)
175 : {
176 163592 : m_poBandOwned = std::move(poBand);
177 163592 : m_poBandRef = nullptr;
178 163592 : }
179 :
180 2 : const GDALRasterBand *get() const
181 : {
182 2 : return static_cast<const GDALRasterBand *>(*this);
183 : }
184 :
185 1524920 : GDALRasterBand *get()
186 : {
187 1524920 : return static_cast<GDALRasterBand *>(*this);
188 : }
189 :
190 688838 : bool IsOwned() const
191 : {
192 688838 : return m_poBandOwned != nullptr;
193 : }
194 :
195 2 : operator const GDALRasterBand *() const
196 : {
197 2 : return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
198 : }
199 :
200 3287820 : operator GDALRasterBand *()
201 : {
202 3287820 : return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
203 : }
204 :
205 : private:
206 : CPL_DISALLOW_COPY_ASSIGN(GDALRasterBandOwnedOrNot)
207 : std::unique_ptr<GDALRasterBand> m_poBandOwned{};
208 : GDALRasterBand *m_poBandRef = nullptr;
209 : };
210 :
211 : GDALRasterBandOwnedOrNot poMask{};
212 : bool m_bEnablePixelTypeSignedByteWarning =
213 : true; // Remove me in GDAL 4.0. See GetMetadataItem() implementation
214 : int nMaskFlags = 0;
215 :
216 : void InvalidateMaskBand();
217 :
218 : friend class GDALProxyRasterBand;
219 : friend class GDALDefaultOverviews;
220 :
221 : CPLErr
222 : RasterIOResampled(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
223 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
224 : GDALDataType eBufType, GSpacing nPixelSpace,
225 : GSpacing nLineSpace,
226 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
227 :
228 : int EnterReadWrite(GDALRWFlag eRWFlag);
229 : void LeaveReadWrite();
230 : void InitRWLock();
231 : void SetValidPercent(GUIntBig nSampleCount, GUIntBig nValidCount);
232 :
233 : mutable GDALDoublePointsCache *m_poPointsCache = nullptr;
234 :
235 : //! @endcond
236 :
237 : protected:
238 : virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData) = 0;
239 : virtual CPLErr IWriteBlock(int nBlockXOff, int nBlockYOff, void *pData);
240 :
241 : virtual CPLErr
242 : IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize,
243 : void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType,
244 : GSpacing nPixelSpace, GSpacing nLineSpace,
245 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
246 :
247 : virtual int IGetDataCoverageStatus(int nXOff, int nYOff, int nXSize,
248 : int nYSize, int nMaskFlagStop,
249 : double *pdfDataPct);
250 :
251 : virtual bool
252 : EmitErrorMessageIfWriteNotSupported(const char *pszCaller) const;
253 :
254 : //! @cond Doxygen_Suppress
255 : CPLErr
256 : OverviewRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
257 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
258 : GDALDataType eBufType, GSpacing nPixelSpace,
259 : GSpacing nLineSpace,
260 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
261 :
262 : CPLErr TryOverviewRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,
263 : int nXSize, int nYSize, void *pData,
264 : int nBufXSize, int nBufYSize,
265 : GDALDataType eBufType, GSpacing nPixelSpace,
266 : GSpacing nLineSpace,
267 : GDALRasterIOExtraArg *psExtraArg, int *pbTried);
268 :
269 : CPLErr SplitRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
270 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
271 : GDALDataType eBufType, GSpacing nPixelSpace,
272 : GSpacing nLineSpace, GDALRasterIOExtraArg *psExtraArg)
273 : CPL_WARN_UNUSED_RESULT;
274 :
275 : int InitBlockInfo();
276 :
277 : void AddBlockToFreeList(GDALRasterBlock *);
278 :
279 2297150 : bool HasBlockCache() const
280 : {
281 2297150 : return poBandBlockCache != nullptr;
282 : }
283 :
284 : bool HasDirtyBlocks() const;
285 :
286 : //! @endcond
287 :
288 : public:
289 : ~GDALRasterBand() override;
290 :
291 : int GetXSize() const;
292 : int GetYSize() const;
293 : int GetBand() const;
294 : GDALDataset *GetDataset() const;
295 :
296 : GDALDataType GetRasterDataType(void) const;
297 : void GetBlockSize(int *pnXSize, int *pnYSize) const;
298 : CPLErr GetActualBlockSize(int nXBlockOff, int nYBlockOff, int *pnXValid,
299 : int *pnYValid) const;
300 :
301 : virtual GDALSuggestedBlockAccessPattern
302 : GetSuggestedBlockAccessPattern() const;
303 :
304 : GDALAccess GetAccess();
305 :
306 : #ifndef DOXYGEN_SKIP
307 : CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
308 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
309 : GDALDataType eBufType, GSpacing nPixelSpace,
310 : GSpacing nLineSpace,
311 : GDALRasterIOExtraArg *psExtraArg
312 : OPTIONAL_OUTSIDE_GDAL(nullptr)) CPL_WARN_UNUSED_RESULT;
313 : #else
314 : CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
315 : int nYSize, void *pData, int nBufXSize, int nBufYSize,
316 : GDALDataType eBufType, GSpacing nPixelSpace,
317 : GSpacing nLineSpace,
318 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
319 : #endif
320 :
321 : template <class T>
322 : CPLErr ReadRaster(T *pData, size_t nArrayEltCount = 0, double dfXOff = 0,
323 : double dfYOff = 0, double dfXSize = 0, double dfYSize = 0,
324 : size_t nBufXSize = 0, size_t nBufYSize = 0,
325 : GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour,
326 : GDALProgressFunc pfnProgress = nullptr,
327 : void *pProgressData = nullptr) const;
328 :
329 : template <class T>
330 : CPLErr ReadRaster(std::vector<T> &vData, double dfXOff = 0,
331 : double dfYOff = 0, double dfXSize = 0, double dfYSize = 0,
332 : size_t nBufXSize = 0, size_t nBufYSize = 0,
333 : GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour,
334 : GDALProgressFunc pfnProgress = nullptr,
335 : void *pProgressData = nullptr) const;
336 :
337 : #if __cplusplus >= 202002L
338 : //! @cond Doxygen_Suppress
339 : template <class T>
340 : inline CPLErr
341 : ReadRaster(std::span<T> pData, double dfXOff = 0, double dfYOff = 0,
342 : double dfXSize = 0, double dfYSize = 0, size_t nBufXSize = 0,
343 : size_t nBufYSize = 0,
344 : GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour,
345 : GDALProgressFunc pfnProgress = nullptr,
346 : void *pProgressData = nullptr) const
347 : {
348 : return ReadRaster(pData.data(), pData.size(), dfXOff, dfYOff, dfXSize,
349 : dfYSize, nBufXSize, nBufYSize, eResampleAlg,
350 : pfnProgress, pProgressData);
351 : }
352 :
353 : //! @endcond
354 : #endif
355 :
356 : GDALComputedRasterBand
357 : operator+(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
358 : GDALComputedRasterBand operator+(double cst) const CPL_WARN_UNUSED_RESULT;
359 : friend GDALComputedRasterBand CPL_DLL
360 : operator+(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
361 :
362 : GDALComputedRasterBand
363 : operator-(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
364 : GDALComputedRasterBand operator-(double cst) const CPL_WARN_UNUSED_RESULT;
365 : friend GDALComputedRasterBand CPL_DLL
366 : operator-(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
367 :
368 : GDALComputedRasterBand
369 : operator*(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
370 : GDALComputedRasterBand operator*(double cst) const CPL_WARN_UNUSED_RESULT;
371 : friend GDALComputedRasterBand CPL_DLL
372 : operator*(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
373 :
374 : GDALComputedRasterBand
375 : operator/(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
376 : GDALComputedRasterBand operator/(double cst) const CPL_WARN_UNUSED_RESULT;
377 : friend GDALComputedRasterBand CPL_DLL
378 : operator/(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
379 :
380 : GDALComputedRasterBand
381 : operator>(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
382 : GDALComputedRasterBand operator>(double cst) const CPL_WARN_UNUSED_RESULT;
383 : friend GDALComputedRasterBand CPL_DLL
384 : operator>(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
385 :
386 : GDALComputedRasterBand
387 : operator>=(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
388 : GDALComputedRasterBand operator>=(double cst) const CPL_WARN_UNUSED_RESULT;
389 : friend GDALComputedRasterBand CPL_DLL
390 : operator>=(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
391 :
392 : GDALComputedRasterBand
393 : operator<(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
394 : GDALComputedRasterBand operator<(double cst) const CPL_WARN_UNUSED_RESULT;
395 : friend GDALComputedRasterBand CPL_DLL
396 : operator<(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
397 :
398 : GDALComputedRasterBand
399 : operator<=(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
400 : GDALComputedRasterBand operator<=(double cst) const CPL_WARN_UNUSED_RESULT;
401 : friend GDALComputedRasterBand CPL_DLL
402 : operator<=(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
403 :
404 : GDALComputedRasterBand
405 : operator==(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
406 : GDALComputedRasterBand operator==(double cst) const CPL_WARN_UNUSED_RESULT;
407 : friend GDALComputedRasterBand CPL_DLL
408 : operator==(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
409 :
410 : GDALComputedRasterBand
411 : operator!=(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
412 : GDALComputedRasterBand operator!=(double cst) const CPL_WARN_UNUSED_RESULT;
413 : friend GDALComputedRasterBand CPL_DLL
414 : operator!=(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
415 :
416 : #if defined(__GNUC__)
417 : #pragma GCC diagnostic push
418 : #pragma GCC diagnostic ignored "-Weffc++"
419 : #endif
420 :
421 : GDALComputedRasterBand
422 : operator&&(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
423 : GDALComputedRasterBand operator&&(bool cst) const CPL_WARN_UNUSED_RESULT;
424 : friend GDALComputedRasterBand CPL_DLL
425 : operator&&(bool cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
426 :
427 : GDALComputedRasterBand
428 : operator||(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
429 : GDALComputedRasterBand operator||(bool cst) const CPL_WARN_UNUSED_RESULT;
430 : friend GDALComputedRasterBand CPL_DLL
431 : operator||(bool cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
432 :
433 : #if defined(__GNUC__)
434 : #pragma GCC diagnostic pop
435 : #endif
436 :
437 : GDALComputedRasterBand operator!() const CPL_WARN_UNUSED_RESULT;
438 :
439 : GDALComputedRasterBand operator-() const CPL_WARN_UNUSED_RESULT;
440 :
441 : GDALComputedRasterBand AsType(GDALDataType) const CPL_WARN_UNUSED_RESULT;
442 :
443 : CPLErr ReadBlock(int nXBlockOff, int nYBlockOff,
444 : void *pImage) CPL_WARN_UNUSED_RESULT;
445 :
446 : CPLErr WriteBlock(int nXBlockOff, int nYBlockOff,
447 : void *pImage) CPL_WARN_UNUSED_RESULT;
448 :
449 : // This method should only be overloaded by GDALProxyRasterBand
450 : virtual GDALRasterBlock *
451 : GetLockedBlockRef(int nXBlockOff, int nYBlockOff,
452 : int bJustInitialize = FALSE) CPL_WARN_UNUSED_RESULT;
453 :
454 : // This method should only be overloaded by GDALProxyRasterBand
455 : virtual GDALRasterBlock *
456 : TryGetLockedBlockRef(int nXBlockOff,
457 : int nYBlockYOff) CPL_WARN_UNUSED_RESULT;
458 :
459 : // This method should only be overloaded by GDALProxyRasterBand
460 : virtual CPLErr FlushBlock(int nXBlockOff, int nYBlockOff,
461 : int bWriteDirtyBlock = TRUE);
462 :
463 : unsigned char *
464 : GetIndexColorTranslationTo(/* const */ GDALRasterBand *poReferenceBand,
465 : unsigned char *pTranslationTable = nullptr,
466 : int *pApproximateMatching = nullptr);
467 :
468 : // New OpengIS CV_SampleDimension stuff.
469 :
470 : virtual CPLErr FlushCache(bool bAtClosing = false);
471 : virtual CPLErr DropCache();
472 : virtual char **GetCategoryNames();
473 : virtual double GetNoDataValue(int *pbSuccess = nullptr);
474 : virtual int64_t GetNoDataValueAsInt64(int *pbSuccess = nullptr);
475 : virtual uint64_t GetNoDataValueAsUInt64(int *pbSuccess = nullptr);
476 : virtual double GetMinimum(int *pbSuccess = nullptr);
477 : virtual double GetMaximum(int *pbSuccess = nullptr);
478 : virtual double GetOffset(int *pbSuccess = nullptr);
479 : virtual double GetScale(int *pbSuccess = nullptr);
480 : virtual const char *GetUnitType();
481 : virtual GDALColorInterp GetColorInterpretation();
482 : virtual GDALColorTable *GetColorTable();
483 : virtual CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0);
484 :
485 : virtual CPLErr SetCategoryNames(char **papszNames);
486 : virtual CPLErr SetNoDataValue(double dfNoData);
487 : virtual CPLErr SetNoDataValueAsInt64(int64_t nNoData);
488 : virtual CPLErr SetNoDataValueAsUInt64(uint64_t nNoData);
489 : CPLErr SetNoDataValueAsString(const char *pszNoData,
490 : bool *pbCannotBeExactlyRepresented = nullptr);
491 : virtual CPLErr DeleteNoDataValue();
492 : virtual CPLErr SetColorTable(GDALColorTable *poCT);
493 : virtual CPLErr SetColorInterpretation(GDALColorInterp eColorInterp);
494 : virtual CPLErr SetOffset(double dfNewOffset);
495 : virtual CPLErr SetScale(double dfNewScale);
496 : virtual CPLErr SetUnitType(const char *pszNewValue);
497 :
498 : virtual CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
499 : double *pdfMax, double *pdfMean,
500 : double *padfStdDev);
501 : virtual CPLErr ComputeStatistics(int bApproxOK, double *pdfMin,
502 : double *pdfMax, double *pdfMean,
503 : double *pdfStdDev, GDALProgressFunc,
504 : void *pProgressData);
505 : virtual CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
506 : double dfStdDev);
507 : virtual CPLErr ComputeRasterMinMax(int bApproxOK, double *adfMinMax);
508 : virtual CPLErr ComputeRasterMinMaxLocation(double *pdfMin, double *pdfMax,
509 : int *pnMinX, int *pnMinY,
510 : int *pnMaxX, int *pnMaxY);
511 :
512 : // Only defined when Doxygen enabled
513 : #ifdef DOXYGEN_SKIP
514 : CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override;
515 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
516 : const char *pszDomain) override;
517 : #endif
518 : virtual const char *GetMetadataItem(const char *pszName,
519 : const char *pszDomain = "") override;
520 :
521 : virtual int HasArbitraryOverviews();
522 : virtual int GetOverviewCount();
523 : virtual GDALRasterBand *GetOverview(int i);
524 : virtual GDALRasterBand *GetRasterSampleOverview(GUIntBig);
525 : virtual CPLErr BuildOverviews(const char *pszResampling, int nOverviews,
526 : const int *panOverviewList,
527 : GDALProgressFunc pfnProgress,
528 : void *pProgressData,
529 : CSLConstList papszOptions);
530 :
531 : virtual CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
532 : int nBufXSize, int nBufYSize,
533 : GDALDataType eBufType, char **papszOptions);
534 :
535 : virtual CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets,
536 : GUIntBig *panHistogram, int bIncludeOutOfRange,
537 : int bApproxOK, GDALProgressFunc,
538 : void *pProgressData);
539 :
540 : virtual CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax,
541 : int *pnBuckets, GUIntBig **ppanHistogram,
542 : int bForce, GDALProgressFunc,
543 : void *pProgressData);
544 : virtual CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets,
545 : GUIntBig *panHistogram);
546 :
547 : virtual GDALRasterAttributeTable *GetDefaultRAT();
548 : virtual CPLErr SetDefaultRAT(const GDALRasterAttributeTable *poRAT);
549 :
550 : virtual GDALRasterBand *GetMaskBand();
551 : virtual int GetMaskFlags();
552 : virtual CPLErr CreateMaskBand(int nFlagsIn);
553 : virtual bool IsMaskBand() const;
554 : virtual GDALMaskValueRange GetMaskValueRange() const;
555 :
556 : virtual CPLVirtualMem *
557 : GetVirtualMemAuto(GDALRWFlag eRWFlag, int *pnPixelSpace,
558 : GIntBig *pnLineSpace,
559 : char **papszOptions) CPL_WARN_UNUSED_RESULT;
560 :
561 : int GetDataCoverageStatus(int nXOff, int nYOff, int nXSize, int nYSize,
562 : int nMaskFlagStop = 0,
563 : double *pdfDataPct = nullptr);
564 :
565 : std::shared_ptr<GDALMDArray> AsMDArray() const;
566 :
567 : CPLErr InterpolateAtGeolocation(
568 : double dfGeolocX, double dfGeolocY, const OGRSpatialReference *poSRS,
569 : GDALRIOResampleAlg eInterpolation, double *pdfRealValue,
570 : double *pdfImagValue = nullptr,
571 : CSLConstList papszTransformerOptions = nullptr) const;
572 :
573 : virtual CPLErr InterpolateAtPoint(double dfPixel, double dfLine,
574 : GDALRIOResampleAlg eInterpolation,
575 : double *pdfRealValue,
576 : double *pdfImagValue = nullptr) const;
577 :
578 : //! @cond Doxygen_Suppress
579 : class CPL_DLL WindowIterator
580 : {
581 : public:
582 : using iterator_category = std::input_iterator_tag;
583 : using difference_type = std::ptrdiff_t;
584 :
585 : using value_type = GDALRasterWindow;
586 : using pointer = value_type *;
587 : using reference = value_type &;
588 :
589 : WindowIterator(int nRasterXSize, int nRasterYSize, int nBlockXSize,
590 : int nBlockYSize, int nRow, int nCol);
591 :
592 : bool operator==(const WindowIterator &other) const;
593 :
594 : bool operator!=(const WindowIterator &other) const;
595 :
596 : value_type operator*() const;
597 :
598 : WindowIterator &operator++();
599 :
600 : private:
601 : int m_nRasterXSize;
602 : int m_nRasterYSize;
603 : int m_nBlockXSize;
604 : int m_nBlockYSize;
605 : int m_row;
606 : int m_col;
607 : };
608 :
609 : class CPL_DLL WindowIteratorWrapper
610 : {
611 : public:
612 : explicit WindowIteratorWrapper(const GDALRasterBand &band,
613 : size_t maxSize);
614 :
615 : WindowIterator begin() const;
616 :
617 : WindowIterator end() const;
618 :
619 : private:
620 : const int m_nRasterXSize;
621 : const int m_nRasterYSize;
622 : int m_nBlockXSize;
623 : int m_nBlockYSize;
624 : };
625 :
626 : //! @endcond
627 :
628 : WindowIteratorWrapper IterateWindows(size_t maxSize = 0) const;
629 :
630 : #ifndef DOXYGEN_XML
631 : void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,
632 : ...) const CPL_PRINT_FUNC_FORMAT(4, 5);
633 : #endif
634 :
635 : //! @cond Doxygen_Suppress
636 : static void ThrowIfNotSameDimensions(const GDALRasterBand &first,
637 : const GDALRasterBand &second);
638 :
639 : //! @endcond
640 :
641 : /** Convert a GDALRasterBand* to a GDALRasterBandH.
642 : * @since GDAL 2.3
643 : */
644 426689 : static inline GDALRasterBandH ToHandle(GDALRasterBand *poBand)
645 : {
646 426689 : return static_cast<GDALRasterBandH>(poBand);
647 : }
648 :
649 : /** Convert a GDALRasterBandH to a GDALRasterBand*.
650 : * @since GDAL 2.3
651 : */
652 5262809 : static inline GDALRasterBand *FromHandle(GDALRasterBandH hBand)
653 : {
654 5262809 : return static_cast<GDALRasterBand *>(hBand);
655 : }
656 :
657 : //! @cond Doxygen_Suppress
658 : // Remove me in GDAL 4.0. See GetMetadataItem() implementation
659 : // Internal use in GDAL only !
660 : virtual void EnablePixelTypeSignedByteWarning(bool b)
661 : #ifndef GDAL_COMPILATION
662 : CPL_WARN_DEPRECATED("Do not use that method outside of GDAL!")
663 : #endif
664 : ;
665 :
666 : //! @endcond
667 :
668 : private:
669 : CPL_DISALLOW_COPY_ASSIGN(GDALRasterBand)
670 : };
671 :
672 : //! @cond Doxygen_Suppress
673 : #define GDAL_EXTERN_TEMPLATE_READ_RASTER(T) \
674 : extern template CPLErr GDALRasterBand::ReadRaster<T>( \
675 : T * pData, size_t nArrayEltCount, double dfXOff, double dfYOff, \
676 : double dfXSize, double dfYSize, size_t nBufXSize, size_t nBufYSize, \
677 : GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
678 : void *pProgressData) const;
679 :
680 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint8_t)
681 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int8_t)
682 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint16_t)
683 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int16_t)
684 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint32_t)
685 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int32_t)
686 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint64_t)
687 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int64_t)
688 : #ifdef CPL_FLOAT_H_INCLUDED
689 : GDAL_EXTERN_TEMPLATE_READ_RASTER(GFloat16)
690 : #endif
691 : GDAL_EXTERN_TEMPLATE_READ_RASTER(float)
692 : GDAL_EXTERN_TEMPLATE_READ_RASTER(double)
693 : // Not allowed by C++ standard
694 : // GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<int16_t>)
695 : // GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<int32_t>)
696 : GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<float>)
697 : GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<double>)
698 :
699 : #define GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(T) \
700 : extern template CPLErr GDALRasterBand::ReadRaster<T>( \
701 : std::vector<T> & vData, double dfXOff, double dfYOff, double dfXSize, \
702 : double dfYSize, size_t nBufXSize, size_t nBufYSize, \
703 : GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
704 : void *pProgressData) const;
705 :
706 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint8_t)
707 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int8_t)
708 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint16_t)
709 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int16_t)
710 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint32_t)
711 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int32_t)
712 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint64_t)
713 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int64_t)
714 : #ifdef CPL_FLOAT_H_INCLUDED
715 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(GFloat16)
716 : #endif
717 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(float)
718 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(double)
719 : // Not allowed by C++ standard
720 : // GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<int16_t>)
721 : // GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<int32_t>)
722 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<float>)
723 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<double>)
724 :
725 : //! @endcond
726 :
727 : #include "gdal_computedrasterband.h"
728 :
729 : #endif
|