GDAL
gdal_rasterband.h
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
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
41
42/* ******************************************************************** */
43/* GDALRasterBand */
44/* ******************************************************************** */
45
46class GDALAbstractBandBlockCache;
47class GDALColorTable;
48class GDALDataset;
49class GDALDoublePointsCache;
51class GDALRasterBlock;
52class GDALMDArray;
54
56typedef enum
57{
58 GMVR_UNKNOWN,
60 GMVR_0_AND_1_ONLY,
61 GMVR_0_AND_255_ONLY,
62} GDALMaskValueRange;
63
65typedef int GDALSuggestedBlockAccessPattern;
66
68constexpr GDALSuggestedBlockAccessPattern GSBAP_UNKNOWN = 0;
69
71constexpr GDALSuggestedBlockAccessPattern GSBAP_RANDOM = 1;
72
74constexpr GDALSuggestedBlockAccessPattern GSBAP_TOP_TO_BOTTOM = 2;
75
77constexpr GDALSuggestedBlockAccessPattern GSBAP_BOTTOM_TO_TOP = 3;
78
81constexpr GDALSuggestedBlockAccessPattern GSBAP_LARGEST_CHUNK_POSSIBLE = 0x100;
82
84
87{
88 public:
90 int nXOff;
91
93 int nYOff;
94
96 int nXSize;
97
99 int nYSize;
100};
101
103
104class 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,
124
125 protected:
127 explicit GDALRasterBand(int bForceCachedIO);
128
130 GDALRasterBand(GDALRasterBand &&) = default;
132
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 GDALRasterBandOwnedOrNot() = default;
159
160 GDALRasterBandOwnedOrNot(GDALRasterBandOwnedOrNot &&) = default;
161
162 void reset()
163 {
164 m_poBandOwned.reset();
165 m_poBandRef = nullptr;
166 }
167
168 void resetNotOwned(GDALRasterBand *poBand)
169 {
170 m_poBandOwned.reset();
171 m_poBandRef = poBand;
172 }
173
174 void reset(std::unique_ptr<GDALRasterBand> poBand)
175 {
176 m_poBandOwned = std::move(poBand);
177 m_poBandRef = nullptr;
178 }
179
180 const GDALRasterBand *get() const
181 {
182 return static_cast<const GDALRasterBand *>(*this);
183 }
184
185 GDALRasterBand *get()
186 {
187 return static_cast<GDALRasterBand *>(*this);
188 }
189
190 bool IsOwned() const
191 {
192 return m_poBandOwned != nullptr;
193 }
194
195 operator const GDALRasterBand *() const
196 {
197 return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
198 }
199
200 operator GDALRasterBand *()
201 {
202 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,
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
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,
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
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,
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)
274
275 int InitBlockInfo();
276
277 void AddBlockToFreeList(GDALRasterBlock *);
278
279 bool HasBlockCache() const
280 {
281 return poBandBlockCache != nullptr;
282 }
283
284 bool HasDirtyBlocks() const;
285
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,
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,
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,
334 GDALProgressFunc pfnProgress = nullptr,
335 void *pProgressData = nullptr) const;
336
337#if __cplusplus >= 202002L
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,
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
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);
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
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
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
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 uint64_t count() const;
616
617 WindowIterator begin() const;
618
619 WindowIterator end() const;
620
621 private:
622 const int m_nRasterXSize;
623 const int m_nRasterYSize;
624 int m_nBlockXSize;
625 int m_nBlockYSize;
626 };
627
629
630 WindowIteratorWrapper IterateWindows(size_t maxSize = 0) const;
631
632#ifndef DOXYGEN_XML
633 void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,
634 ...) const CPL_PRINT_FUNC_FORMAT(4, 5);
635#endif
636
638 static void ThrowIfNotSameDimensions(const GDALRasterBand &first,
639 const GDALRasterBand &second);
640
642
646 {
647 return static_cast<GDALRasterBandH>(poBand);
648 }
649
653 {
654 return static_cast<GDALRasterBand *>(hBand);
655 }
656
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
667
668 private:
670};
671
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
680GDAL_EXTERN_TEMPLATE_READ_RASTER(uint8_t)
681GDAL_EXTERN_TEMPLATE_READ_RASTER(int8_t)
682GDAL_EXTERN_TEMPLATE_READ_RASTER(uint16_t)
683GDAL_EXTERN_TEMPLATE_READ_RASTER(int16_t)
684GDAL_EXTERN_TEMPLATE_READ_RASTER(uint32_t)
685GDAL_EXTERN_TEMPLATE_READ_RASTER(int32_t)
686GDAL_EXTERN_TEMPLATE_READ_RASTER(uint64_t)
687GDAL_EXTERN_TEMPLATE_READ_RASTER(int64_t)
688#ifdef CPL_FLOAT_H_INCLUDED
689GDAL_EXTERN_TEMPLATE_READ_RASTER(GFloat16)
690#endif
691GDAL_EXTERN_TEMPLATE_READ_RASTER(float)
692GDAL_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>)
696GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<float>)
697GDAL_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
706GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint8_t)
707GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int8_t)
708GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint16_t)
709GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int16_t)
710GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint32_t)
711GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int32_t)
712GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint64_t)
713GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int64_t)
714#ifdef CPL_FLOAT_H_INCLUDED
715GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(GFloat16)
716#endif
717GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(float)
718GDAL_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>)
722GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<float>)
723GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<double>)
724
725
726
727#include "gdal_computedrasterband.h"
728
729#endif
A color table / palette.
Definition gdal_colortable.h:32
Class represented the result of an operation on one or two input bands.
Definition gdal_computedrasterband.h:39
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
Class modeling a multi-dimensional array.
Definition gdal_multidim.h:852
GDALMajorObject(const GDALMajorObject &)=default
Copy constructor.
virtual const char * GetMetadataItem(const char *pszName, const char *pszDomain="")
Fetch single metadata item.
Definition gdalmajorobject.cpp:322
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition gdal_rat.h:48
A single raster band (or channel).
Definition gdal_rasterband.h:105
virtual CPLErr CreateMaskBand(int nFlagsIn)
Adds a mask band to the current band.
Definition gdalrasterband.cpp:9465
virtual GDALRasterAttributeTable * GetDefaultRAT()
Fetch default Raster Attribute Table.
Definition gdalrasterband.cpp:8915
virtual CPLErr SetDefaultRAT(const GDALRasterAttributeTable *poRAT)
Set default Raster Attribute Table.
Definition gdalrasterband.cpp:8964
virtual GDALRasterBand * GetOverview(int i)
Fetch overview raster band object.
Definition gdalrasterband.cpp:3372
virtual int HasArbitraryOverviews()
Check for arbitrary overviews.
Definition gdalrasterband.cpp:3292
virtual CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax, int *pnBuckets, GUIntBig **ppanHistogram, int bForce, GDALProgressFunc, void *pProgressData)
Fetch default raster histogram.
Definition gdalrasterband.cpp:4898
void static GDALRasterBandH ToHandle(GDALRasterBand *poBand)
Convert a GDALRasterBand* to a GDALRasterBandH.
Definition gdal_rasterband.h:645
virtual int GetMaskFlags()
Return the status flags of the mask band associated with the band.
Definition gdalrasterband.cpp:9387
virtual bool IsMaskBand() const
Returns whether a band is a mask band.
Definition gdalrasterband.cpp:9525
virtual int GetOverviewCount()
Return the number of overview layers available.
Definition gdalrasterband.cpp:3329
virtual GDALRasterBand * GetMaskBand()
Return the mask band associated with the band.
Definition gdalrasterband.cpp:9051
virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData)=0
Default internal implementation ... to be overridden by subclasses that support reading.
virtual CPLErr InterpolateAtPoint(double dfPixel, double dfLine, GDALRIOResampleAlg eInterpolation, double *pdfRealValue, double *pdfImagValue=nullptr) const
Interpolates the value between pixels using a resampling algorithm, taking pixel/line coordinates as ...
Definition gdalrasterband.cpp:10898
virtual bool EmitErrorMessageIfWriteNotSupported(const char *pszCaller) const
Emit an error message if a write operation to this band is not supported.
Definition gdalrasterband.cpp:1302
virtual CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets, GUIntBig *panHistogram)
Set default histogram.
Definition gdalrasterband.cpp:8818
GDALComputedRasterBand operator!=(const GDALRasterBand &other) const
Return a band whose value is 1 if the pixel value of the left operand is different from the pixel val...
Definition gdalrasterband.cpp:12018
virtual int IGetDataCoverageStatus(int nXOff, int nYOff, int nXSize, int nYSize, int nMaskFlagStop, double *pdfDataPct)
Get the coverage status of a sub-window of the raster.
Definition gdalrasterband.cpp:10223
GDALComputedRasterBand operator*(const GDALRasterBand &other) const
Multiply this band with another one.
Definition gdalrasterband.cpp:11539
virtual CPLVirtualMem * GetVirtualMemAuto(GDALRWFlag eRWFlag, int *pnPixelSpace, GIntBig *pnLineSpace, char **papszOptions)
Create a CPLVirtualMem object from a GDAL raster band object.
Definition gdalrasterband.cpp:9900
virtual CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets, GUIntBig *panHistogram, int bIncludeOutOfRange, int bApproxOK, GDALProgressFunc, void *pProgressData)
Compute raster histogram.
Definition gdalrasterband.cpp:4189
virtual CPLErr BuildOverviews(const char *pszResampling, int nOverviews, const int *panOverviewList, GDALProgressFunc pfnProgress, void *pProgressData, CSLConstList papszOptions)
If the operation is unsupported for the indicated dataset, then CE_Failure is returned,...
Definition gdalrasterband.cpp:3530
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 GDALRasterBand * GetRasterSampleOverview(GUIntBig)
Fetch best sampling overview.
Definition gdalrasterband.cpp:3424
int GetDataCoverageStatus(int nXOff, int nYOff, int nXSize, int nYSize, int nMaskFlagStop=0, double *pdfDataPct=nullptr)
Get the coverage status of a sub-window of the raster.
Definition gdalrasterband.cpp:10201
std::shared_ptr< GDALMDArray > AsMDArray() const
Return a view of this raster band as a 2D multidimensional GDALMDArray.
Definition gdalrasterband.cpp:10865
virtual GDALMaskValueRange GetMaskValueRange() const
Returns the range of values that a mask band can take.
Definition gdalrasterband.cpp:9576
CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override
Set metadata.
GDALComputedRasterBand operator==(const GDALRasterBand &other) const
Return a band whose value is 1 if the pixel value of the left operand is equal to the pixel value of ...
Definition gdalrasterband.cpp:11946
virtual CPLErr IWriteBlock(int nBlockXOff, int nBlockYOff, void *pData)
Write a block of data.
Definition gdalrasterband.cpp:1169
CPLErr SetMetadataItem(const char *pszName, const char *pszValue, const char *pszDomain) override
Set single metadata item.
CPLErr InterpolateAtGeolocation(double dfGeolocX, double dfGeolocY, const OGRSpatialReference *poSRS, GDALRIOResampleAlg eInterpolation, double *pdfRealValue, double *pdfImagValue=nullptr, CSLConstList papszTransformerOptions=nullptr) const
Interpolates the value between pixels using a resampling algorithm, taking georeferenced coordinates ...
Definition gdalrasterband.cpp:10995
GDALRasterBand()
Definition gdalrasterband.cpp:59
virtual CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize, int nBufXSize, int nBufYSize, GDALDataType eBufType, char **papszOptions)
Advise driver of upcoming read requests.
Definition gdalrasterband.cpp:5128
static GDALRasterBand * FromHandle(GDALRasterBandH hBand)
Convert a GDALRasterBandH to a GDALRasterBand*.
Definition gdal_rasterband.h:652
A single raster block in the block cache.
Definition gdal_rasterblock.h:33
A rectangular subset of pixels within a raster.
Definition gdal_rasterband.h:87
int nXSize
window width
Definition gdal_rasterband.h:96
int nYOff
top offset of the window
Definition gdal_rasterband.h:93
int nXOff
left offset of the window
Definition gdal_rasterband.h:90
int nYSize
window height
Definition gdal_rasterband.h:99
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:152
CPLErr
Error category.
Definition cpl_error.h:37
int CPLErrorNum
Error number.
Definition cpl_error.h:80
Core portability definitions for CPL.
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:208
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:844
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1087
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:870
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:205
Public (C callable) GDAL entry points.
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:386
GDALAccess
Definition gdal.h:118
@ GA_ReadOnly
Definition gdal.h:119
GDALDataType
Definition gdal.h:48
@ GDT_Byte
Definition gdal.h:50
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:135
@ GRIORA_NearestNeighbour
Definition gdal.h:136
GDALColorInterp
Types of color interpretation for raster bands.
Definition gdal.h:270
GDALRWFlag
Definition gdal.h:125
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal_fwd.h:45
OGRLayer::FeatureIterator begin(OGRLayer *poLayer)
Return begin of feature iterator.
Definition ogrsf_frmts.h:470
OGRLayer::FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition ogrsf_frmts.h:478
Structure to pass extra arguments to RasterIO() method, must be initialized with INIT_RASTERIO_EXTRA_...
Definition gdal.h:168