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 >= 201703L
28#include <optional>
29#endif
30#if __cplusplus >= 202002L
31#include <span>
32#endif
33#include <vector>
34
36#if !defined(OPTIONAL_OUTSIDE_GDAL)
37#if defined(GDAL_COMPILATION)
38#define OPTIONAL_OUTSIDE_GDAL(val)
39#else
40#define OPTIONAL_OUTSIDE_GDAL(val) = val
41#endif
42#endif
44
45/* ******************************************************************** */
46/* GDALRasterBand */
47/* ******************************************************************** */
48
49class GDALAbstractBandBlockCache;
50class GDALColorTable;
51class GDALDataset;
52class GDALDoublePointsCache;
54class GDALRasterBlock;
55class GDALMDArray;
57
59typedef enum
60{
61 GMVR_UNKNOWN,
63 GMVR_0_AND_1_ONLY,
64 GMVR_0_AND_255_ONLY,
65} GDALMaskValueRange;
66
68typedef int GDALSuggestedBlockAccessPattern;
69
71constexpr GDALSuggestedBlockAccessPattern GSBAP_UNKNOWN = 0;
72
74constexpr GDALSuggestedBlockAccessPattern GSBAP_RANDOM = 1;
75
77constexpr GDALSuggestedBlockAccessPattern GSBAP_TOP_TO_BOTTOM = 2;
78
80constexpr GDALSuggestedBlockAccessPattern GSBAP_BOTTOM_TO_TOP = 3;
81
84constexpr GDALSuggestedBlockAccessPattern GSBAP_LARGEST_CHUNK_POSSIBLE = 0x100;
85
87
90{
91 public:
93 int nXOff;
94
96 int nYOff;
97
99 int nXSize;
100
103};
104
107class CPL_DLL GDALRasterBand : public GDALMajorObject
108{
109 private:
110 friend class GDALArrayBandBlockCache;
111 friend class GDALHashSetBandBlockCache;
112 friend class GDALRasterBlock;
113 friend class GDALDataset;
114
115 CPLErr eFlushBlockErr = CE_None;
116 GDALAbstractBandBlockCache *poBandBlockCache = nullptr;
117
118 CPL_INTERNAL void SetFlushBlockErr(CPLErr eErr);
119 CPL_INTERNAL CPLErr UnreferenceBlock(GDALRasterBlock *poBlock);
120 CPL_INTERNAL void IncDirtyBlocks(int nInc);
121
122 CPL_INTERNAL CPLErr RasterIOInternal(
123 GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize,
124 void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType,
125 GSpacing nPixelSpace, GSpacing nLineSpace,
127
128 CPL_INTERNAL bool HasNoData() const;
129
130 protected:
132 explicit GDALRasterBand(int bForceCachedIO);
133
135 GDALRasterBand(GDALRasterBand &&) = default;
137
139 GDALDataset *poDS = nullptr;
140 int nBand = 0; /* 1 based */
141
142 int nRasterXSize = 0;
143 int nRasterYSize = 0;
144
145 GDALDataType eDataType = GDT_UInt8;
146 GDALAccess eAccess = GA_ReadOnly;
147
148 /* stuff related to blocking, and raster cache */
149 int nBlockXSize = -1;
150 int nBlockYSize = -1;
151 int nBlocksPerRow = 0;
152 int nBlocksPerColumn = 0;
153
154 int nBlockReads = 0;
155 int bForceCachedIO = 0;
156
157 friend class GDALComputedRasterBand;
158 friend class GDALComputedDataset;
159
160 class GDALRasterBandOwnedOrNot
161 {
162 public:
163 GDALRasterBandOwnedOrNot() = default;
164
165 GDALRasterBandOwnedOrNot(GDALRasterBandOwnedOrNot &&) = default;
166
167 void reset()
168 {
169 m_poBandOwned.reset();
170 m_poBandRef = nullptr;
171 }
172
173 void resetNotOwned(GDALRasterBand *poBand)
174 {
175 m_poBandOwned.reset();
176 m_poBandRef = poBand;
177 }
178
179 void reset(std::unique_ptr<GDALRasterBand> poBand)
180 {
181 m_poBandOwned = std::move(poBand);
182 m_poBandRef = nullptr;
183 }
184
185 const GDALRasterBand *get() const
186 {
187 return static_cast<const GDALRasterBand *>(*this);
188 }
189
190 GDALRasterBand *get()
191 {
192 return static_cast<GDALRasterBand *>(*this);
193 }
194
195 bool IsOwned() const
196 {
197 return m_poBandOwned != nullptr;
198 }
199
200 operator const GDALRasterBand *() const
201 {
202 return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
203 }
204
205 operator GDALRasterBand *()
206 {
207 return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
208 }
209
210 private:
211 CPL_DISALLOW_COPY_ASSIGN(GDALRasterBandOwnedOrNot)
212 std::unique_ptr<GDALRasterBand> m_poBandOwned{};
213 GDALRasterBand *m_poBandRef = nullptr;
214 };
215
216 GDALRasterBandOwnedOrNot poMask{};
217 bool m_bEnablePixelTypeSignedByteWarning =
218 true; // Remove me in GDAL 4.0. See GetMetadataItem() implementation
219 int nMaskFlags = 0;
220
221 void InvalidateMaskBand();
222
223 friend class GDALProxyRasterBand;
224 friend class GDALDefaultOverviews;
225
226 CPLErr
227 RasterIOResampled(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
228 int nYSize, void *pData, int nBufXSize, int nBufYSize,
229 GDALDataType eBufType, GSpacing nPixelSpace,
230 GSpacing nLineSpace,
232
233 int EnterReadWrite(GDALRWFlag eRWFlag);
234 void LeaveReadWrite();
235 void InitRWLock();
236 void SetValidPercent(GUIntBig nSampleCount, GUIntBig nValidCount);
237
238 mutable GDALDoublePointsCache *m_poPointsCache = nullptr;
239
241
242 protected:
243 virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData) = 0;
244 virtual CPLErr IWriteBlock(int nBlockXOff, int nBlockYOff, void *pData);
245
246 virtual CPLErr
247 IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize,
248 void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType,
249 GSpacing nPixelSpace, GSpacing nLineSpace,
251
252 virtual int IGetDataCoverageStatus(int nXOff, int nYOff, int nXSize,
253 int nYSize, int nMaskFlagStop,
254 double *pdfDataPct);
255
256 virtual bool
257 EmitErrorMessageIfWriteNotSupported(const char *pszCaller) const;
258
260 CPLErr
261 OverviewRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
262 int nYSize, void *pData, int nBufXSize, int nBufYSize,
263 GDALDataType eBufType, GSpacing nPixelSpace,
264 GSpacing nLineSpace,
266
267 CPLErr TryOverviewRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,
268 int nXSize, int nYSize, void *pData,
269 int nBufXSize, int nBufYSize,
270 GDALDataType eBufType, GSpacing nPixelSpace,
271 GSpacing nLineSpace,
272 GDALRasterIOExtraArg *psExtraArg, int *pbTried);
273
274 CPLErr SplitRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
275 int nYSize, void *pData, int nBufXSize, int nBufYSize,
276 GDALDataType eBufType, GSpacing nPixelSpace,
277 GSpacing nLineSpace, GDALRasterIOExtraArg *psExtraArg)
279
280 int InitBlockInfo();
281
282 void AddBlockToFreeList(GDALRasterBlock *);
283
284 bool HasBlockCache() const
285 {
286 return poBandBlockCache != nullptr;
287 }
288
289 bool HasDirtyBlocks() const;
290
292
293 public:
294 ~GDALRasterBand() override;
295
296 int GetXSize() const;
297 int GetYSize() const;
298 int GetBand() const;
299 GDALDataset *GetDataset() const;
300
301 GDALDataType GetRasterDataType(void) const;
302 void GetBlockSize(int *pnXSize, int *pnYSize) const;
303 CPLErr GetActualBlockSize(int nXBlockOff, int nYBlockOff, int *pnXValid,
304 int *pnYValid) const;
305
306 virtual GDALSuggestedBlockAccessPattern
307 GetSuggestedBlockAccessPattern() const;
308
309 GDALAccess GetAccess();
310
311#ifndef DOXYGEN_SKIP
312 CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
313 int nYSize, void *pData, int nBufXSize, int nBufYSize,
314 GDALDataType eBufType, GSpacing nPixelSpace,
315 GSpacing nLineSpace,
316 GDALRasterIOExtraArg *psExtraArg
317 OPTIONAL_OUTSIDE_GDAL(nullptr)) CPL_WARN_UNUSED_RESULT;
318#else
319 CPLErr RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
320 int nYSize, void *pData, int nBufXSize, int nBufYSize,
321 GDALDataType eBufType, GSpacing nPixelSpace,
322 GSpacing nLineSpace,
324#endif
325
326 template <class T>
327 CPLErr ReadRaster(T *pData, size_t nArrayEltCount = 0, double dfXOff = 0,
328 double dfYOff = 0, double dfXSize = 0, double dfYSize = 0,
329 size_t nBufXSize = 0, size_t nBufYSize = 0,
331 GDALProgressFunc pfnProgress = nullptr,
332 void *pProgressData = nullptr) const;
333
334 template <class T>
335 CPLErr ReadRaster(std::vector<T> &vData, double dfXOff = 0,
336 double dfYOff = 0, double dfXSize = 0, double dfYSize = 0,
337 size_t nBufXSize = 0, size_t nBufYSize = 0,
339 GDALProgressFunc pfnProgress = nullptr,
340 void *pProgressData = nullptr) const;
341
342#if __cplusplus >= 202002L
344 template <class T>
345 inline CPLErr
346 ReadRaster(std::span<T> pData, double dfXOff = 0, double dfYOff = 0,
347 double dfXSize = 0, double dfYSize = 0, size_t nBufXSize = 0,
348 size_t nBufYSize = 0,
350 GDALProgressFunc pfnProgress = nullptr,
351 void *pProgressData = nullptr) const
352 {
353 return ReadRaster(pData.data(), pData.size(), dfXOff, dfYOff, dfXSize,
354 dfYSize, nBufXSize, nBufYSize, eResampleAlg,
355 pfnProgress, pProgressData);
356 }
357
359#endif
360
362 operator+(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
363 GDALComputedRasterBand operator+(double cst) const CPL_WARN_UNUSED_RESULT;
364 friend GDALComputedRasterBand CPL_DLL
365 operator+(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
366
368 operator-(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
369 GDALComputedRasterBand operator-(double cst) const CPL_WARN_UNUSED_RESULT;
370 friend GDALComputedRasterBand CPL_DLL
371 operator-(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
372
374 operator*(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
375 GDALComputedRasterBand operator*(double cst) const CPL_WARN_UNUSED_RESULT;
376 friend GDALComputedRasterBand CPL_DLL
377 operator*(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
378
380 operator/(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
381 GDALComputedRasterBand operator/(double cst) const CPL_WARN_UNUSED_RESULT;
382 friend GDALComputedRasterBand CPL_DLL
383 operator/(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
384
386 operator>(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
387 GDALComputedRasterBand operator>(double cst) const CPL_WARN_UNUSED_RESULT;
388 friend GDALComputedRasterBand CPL_DLL
389 operator>(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
390
392 operator>=(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
393 GDALComputedRasterBand operator>=(double cst) const CPL_WARN_UNUSED_RESULT;
394 friend GDALComputedRasterBand CPL_DLL
395 operator>=(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
396
398 operator<(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
399 GDALComputedRasterBand operator<(double cst) const CPL_WARN_UNUSED_RESULT;
400 friend GDALComputedRasterBand CPL_DLL
401 operator<(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
402
404 operator<=(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
405 GDALComputedRasterBand operator<=(double cst) const CPL_WARN_UNUSED_RESULT;
406 friend GDALComputedRasterBand CPL_DLL
407 operator<=(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
408
410 operator==(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
411 GDALComputedRasterBand operator==(double cst) const CPL_WARN_UNUSED_RESULT;
412 friend GDALComputedRasterBand CPL_DLL
413 operator==(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
414
416 operator!=(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
417 GDALComputedRasterBand operator!=(double cst) const CPL_WARN_UNUSED_RESULT;
418 friend GDALComputedRasterBand CPL_DLL
419 operator!=(double cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
420
421#if defined(__GNUC__)
422#pragma GCC diagnostic push
423#pragma GCC diagnostic ignored "-Weffc++"
424#endif
425
427 operator&&(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
428 GDALComputedRasterBand operator&&(bool cst) const CPL_WARN_UNUSED_RESULT;
429 friend GDALComputedRasterBand CPL_DLL
430 operator&&(bool cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
431
433 operator||(const GDALRasterBand &other) const CPL_WARN_UNUSED_RESULT;
434 GDALComputedRasterBand operator||(bool cst) const CPL_WARN_UNUSED_RESULT;
435 friend GDALComputedRasterBand CPL_DLL
436 operator||(bool cst, const GDALRasterBand &other) CPL_WARN_UNUSED_RESULT;
437
438#if defined(__GNUC__)
439#pragma GCC diagnostic pop
440#endif
441
443
445
447
448 CPLErr ReadBlock(int nXBlockOff, int nYBlockOff,
449 void *pImage) CPL_WARN_UNUSED_RESULT;
450
451 CPLErr WriteBlock(int nXBlockOff, int nYBlockOff,
452 void *pImage) CPL_WARN_UNUSED_RESULT;
453
454 // This method should only be overloaded by GDALProxyRasterBand
455 virtual GDALRasterBlock *
456 GetLockedBlockRef(int nXBlockOff, int nYBlockOff,
457 int bJustInitialize = FALSE) CPL_WARN_UNUSED_RESULT;
458
459 // This method should only be overloaded by GDALProxyRasterBand
460 virtual GDALRasterBlock *
461 TryGetLockedBlockRef(int nXBlockOff,
462 int nYBlockYOff) CPL_WARN_UNUSED_RESULT;
463
464 // This method should only be overloaded by GDALProxyRasterBand
465 virtual CPLErr FlushBlock(int nXBlockOff, int nYBlockOff,
466 int bWriteDirtyBlock = TRUE);
467
468 unsigned char *
469 GetIndexColorTranslationTo(/* const */ GDALRasterBand *poReferenceBand,
470 unsigned char *pTranslationTable = nullptr,
471 int *pApproximateMatching = nullptr);
472
473 // New OpengIS CV_SampleDimension stuff.
474
475 virtual CPLErr FlushCache(bool bAtClosing = false);
476 virtual CPLErr DropCache();
477 virtual char **GetCategoryNames();
478 virtual double GetNoDataValue(int *pbSuccess = nullptr);
479 virtual int64_t GetNoDataValueAsInt64(int *pbSuccess = nullptr);
480 virtual uint64_t GetNoDataValueAsUInt64(int *pbSuccess = nullptr);
481
482#if __cplusplus >= 201703L
483 template <class T> inline std::optional<T> GetNoDataValue() const
484 {
485 int bSuccess = false;
486 if constexpr (std::is_same_v<T, int64_t>)
487 {
488 const int64_t v =
489 const_cast<GDALRasterBand *>(this)->GetNoDataValueAsInt64(
490 &bSuccess);
491 if (!bSuccess)
492 return {};
493 return v;
494 }
495 else if constexpr (std::is_same_v<T, uint64_t>)
496 {
497 const uint64_t v =
498 const_cast<GDALRasterBand *>(this)->GetNoDataValueAsUInt64(
499 &bSuccess);
500 if (!bSuccess)
501 return {};
502 return v;
503 }
504 else
505 {
506 const double v =
507 const_cast<GDALRasterBand *>(this)->GetNoDataValue(&bSuccess);
508 if (!bSuccess)
509 return {};
510 return v;
511 }
512 }
513#endif
514
515 virtual double GetMinimum(int *pbSuccess = nullptr);
516 virtual double GetMaximum(int *pbSuccess = nullptr);
517 virtual double GetOffset(int *pbSuccess = nullptr);
518 virtual double GetScale(int *pbSuccess = nullptr);
519 virtual const char *GetUnitType();
520 virtual GDALColorInterp GetColorInterpretation();
521 virtual GDALColorTable *GetColorTable();
522 virtual CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0);
523
524 virtual CPLErr SetCategoryNames(char **papszNames);
525 virtual CPLErr SetNoDataValue(double dfNoData);
526 virtual CPLErr SetNoDataValueAsInt64(int64_t nNoData);
527 virtual CPLErr SetNoDataValueAsUInt64(uint64_t nNoData);
528 CPLErr SetNoDataValueAsString(const char *pszNoData,
529 bool *pbCannotBeExactlyRepresented = nullptr);
530 virtual CPLErr DeleteNoDataValue();
531 virtual CPLErr SetColorTable(GDALColorTable *poCT);
532 virtual CPLErr SetColorInterpretation(GDALColorInterp eColorInterp);
533 virtual CPLErr SetOffset(double dfNewOffset);
534 virtual CPLErr SetScale(double dfNewScale);
535 virtual CPLErr SetUnitType(const char *pszNewValue);
536
537 virtual CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
538 double *pdfMax, double *pdfMean,
539 double *padfStdDev);
540 virtual CPLErr ComputeStatistics(int bApproxOK, double *pdfMin,
541 double *pdfMax, double *pdfMean,
542 double *pdfStdDev, GDALProgressFunc,
543 void *pProgressData);
544 virtual CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
545 double dfStdDev);
546 virtual CPLErr ComputeRasterMinMax(int bApproxOK, double *adfMinMax);
547 virtual CPLErr ComputeRasterMinMaxLocation(double *pdfMin, double *pdfMax,
548 int *pnMinX, int *pnMinY,
549 int *pnMaxX, int *pnMaxY);
550
551// Only defined when Doxygen enabled
552#ifdef DOXYGEN_SKIP
553 CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override;
554 CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
555 const char *pszDomain) override;
556#endif
557 virtual const char *GetMetadataItem(const char *pszName,
558 const char *pszDomain = "") override;
559
560 virtual int HasArbitraryOverviews();
561 virtual int GetOverviewCount();
562 virtual GDALRasterBand *GetOverview(int i);
563 virtual GDALRasterBand *GetRasterSampleOverview(GUIntBig);
564 virtual CPLErr BuildOverviews(const char *pszResampling, int nOverviews,
565 const int *panOverviewList,
566 GDALProgressFunc pfnProgress,
567 void *pProgressData,
568 CSLConstList papszOptions);
569
570 virtual CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
571 int nBufXSize, int nBufYSize,
572 GDALDataType eBufType, CSLConstList papszOptions);
573
574 virtual CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets,
575 GUIntBig *panHistogram, int bIncludeOutOfRange,
576 int bApproxOK, GDALProgressFunc,
577 void *pProgressData);
578
579 virtual CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax,
580 int *pnBuckets, GUIntBig **ppanHistogram,
581 int bForce, GDALProgressFunc,
582 void *pProgressData);
583 virtual CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets,
584 GUIntBig *panHistogram);
585
586 virtual GDALRasterAttributeTable *GetDefaultRAT();
587 virtual CPLErr SetDefaultRAT(const GDALRasterAttributeTable *poRAT);
588
589 virtual GDALRasterBand *GetMaskBand();
590 virtual int GetMaskFlags();
591 virtual CPLErr CreateMaskBand(int nFlagsIn);
592 virtual bool IsMaskBand() const;
593 virtual GDALMaskValueRange GetMaskValueRange() const;
594 bool HasConflictingMaskSources(std::string *posDetailMessage = nullptr,
595 bool bMentionPrioritarySource = true) const;
596
597 virtual CPLVirtualMem *
598 GetVirtualMemAuto(GDALRWFlag eRWFlag, int *pnPixelSpace,
599 GIntBig *pnLineSpace,
601
602 int GetDataCoverageStatus(int nXOff, int nYOff, int nXSize, int nYSize,
603 int nMaskFlagStop = 0,
604 double *pdfDataPct = nullptr);
605
606 std::shared_ptr<GDALMDArray> AsMDArray() const;
607
608 CPLErr InterpolateAtGeolocation(
609 double dfGeolocX, double dfGeolocY, const OGRSpatialReference *poSRS,
610 GDALRIOResampleAlg eInterpolation, double *pdfRealValue,
611 double *pdfImagValue = nullptr,
612 CSLConstList papszTransformerOptions = nullptr) const;
613
614 virtual CPLErr InterpolateAtPoint(double dfPixel, double dfLine,
615 GDALRIOResampleAlg eInterpolation,
616 double *pdfRealValue,
617 double *pdfImagValue = nullptr) const;
618
620 class CPL_DLL WindowIterator
621 {
622 public:
623 using iterator_category = std::input_iterator_tag;
624 using difference_type = std::ptrdiff_t;
625
626 using value_type = GDALRasterWindow;
627 using pointer = value_type *;
628 using reference = value_type &;
629
630 WindowIterator(int nRasterXSize, int nRasterYSize, int nBlockXSize,
631 int nBlockYSize, int nRow, int nCol);
632
633 bool operator==(const WindowIterator &other) const;
634
635 bool operator!=(const WindowIterator &other) const;
636
637 value_type operator*() const;
638
639 WindowIterator &operator++();
640
641 private:
642 int m_nRasterXSize;
643 int m_nRasterYSize;
644 int m_nBlockXSize;
645 int m_nBlockYSize;
646 int m_row;
647 int m_col;
648 };
649
650 class CPL_DLL WindowIteratorWrapper
651 {
652 public:
653 explicit WindowIteratorWrapper(const GDALRasterBand &band,
654 size_t maxSize = 0);
655
656 explicit WindowIteratorWrapper(const GDALRasterBand &band1,
657 const GDALRasterBand &band2,
658 size_t maxSize = 0);
659
660 uint64_t count() const;
661
662 WindowIterator begin() const;
663
664 WindowIterator end() const;
665
666 private:
667 const int m_nRasterXSize;
668 const int m_nRasterYSize;
669 int m_nBlockXSize;
670 int m_nBlockYSize;
671
672 WindowIteratorWrapper(int nRasterXSize, int nRasterYSize,
673 int nBlockXSize, int nBlockYSize, size_t maxSize);
674 };
675
677
678 WindowIteratorWrapper IterateWindows(size_t maxSize = 0) const;
679
680 virtual bool MayMultiBlockReadingBeMultiThreaded() const;
681
682#ifndef DOXYGEN_XML
683 void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,
684 ...) const CPL_PRINT_FUNC_FORMAT(4, 5);
685#endif
686
688 static void ThrowIfNotSameDimensions(const GDALRasterBand &first,
689 const GDALRasterBand &second);
690
692
696 {
697 return static_cast<GDALRasterBandH>(poBand);
698 }
699
703 {
704 return static_cast<GDALRasterBand *>(hBand);
705 }
706
708 // Remove me in GDAL 4.0. See GetMetadataItem() implementation
709 // Internal use in GDAL only !
710 virtual void EnablePixelTypeSignedByteWarning(bool b)
711#ifndef GDAL_COMPILATION
712 CPL_WARN_DEPRECATED("Do not use that method outside of GDAL!")
713#endif
714 ;
715
717
718 private:
720};
721
723#define GDAL_EXTERN_TEMPLATE_READ_RASTER(T) \
724 extern template CPLErr GDALRasterBand::ReadRaster<T>( \
725 T * pData, size_t nArrayEltCount, double dfXOff, double dfYOff, \
726 double dfXSize, double dfYSize, size_t nBufXSize, size_t nBufYSize, \
727 GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
728 void *pProgressData) const;
729
730GDAL_EXTERN_TEMPLATE_READ_RASTER(uint8_t)
731GDAL_EXTERN_TEMPLATE_READ_RASTER(int8_t)
732GDAL_EXTERN_TEMPLATE_READ_RASTER(uint16_t)
733GDAL_EXTERN_TEMPLATE_READ_RASTER(int16_t)
734GDAL_EXTERN_TEMPLATE_READ_RASTER(uint32_t)
735GDAL_EXTERN_TEMPLATE_READ_RASTER(int32_t)
736GDAL_EXTERN_TEMPLATE_READ_RASTER(uint64_t)
737GDAL_EXTERN_TEMPLATE_READ_RASTER(int64_t)
738#ifdef CPL_FLOAT_H_INCLUDED
739GDAL_EXTERN_TEMPLATE_READ_RASTER(GFloat16)
740#endif
741GDAL_EXTERN_TEMPLATE_READ_RASTER(float)
742GDAL_EXTERN_TEMPLATE_READ_RASTER(double)
743// Not allowed by C++ standard
744// GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<int16_t>)
745// GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<int32_t>)
746GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<float>)
747GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<double>)
748
749#define GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(T) \
750 extern template CPLErr GDALRasterBand::ReadRaster<T>( \
751 std::vector<T> & vData, double dfXOff, double dfYOff, double dfXSize, \
752 double dfYSize, size_t nBufXSize, size_t nBufYSize, \
753 GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
754 void *pProgressData) const;
755
756GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint8_t)
757GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int8_t)
758GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint16_t)
759GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int16_t)
760GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint32_t)
761GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int32_t)
762GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint64_t)
763GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int64_t)
764#ifdef CPL_FLOAT_H_INCLUDED
765GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(GFloat16)
766#endif
767GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(float)
768GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(double)
769// Not allowed by C++ standard
770// GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<int16_t>)
771// GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<int32_t>)
772GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<float>)
773GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<double>)
774
775
776
777#include "gdal_computedrasterband.h"
778
779#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:77
Class modeling a multi-dimensional array.
Definition gdal_multidim.h:852
Object with metadata.
Definition gdal_majorobject.h:43
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:108
void static GDALRasterBandH ToHandle(GDALRasterBand *poBand)
Convert a GDALRasterBand* to a GDALRasterBandH.
Definition gdal_rasterband.h:695
CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override
Set metadata.
virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData)=0
Default internal implementation ... to be overridden by subclasses that support reading.
CPLErr SetMetadataItem(const char *pszName, const char *pszValue, const char *pszDomain) override
Set single metadata item.
static GDALRasterBand * FromHandle(GDALRasterBandH hBand)
Convert a GDALRasterBandH to a GDALRasterBand*.
Definition gdal_rasterband.h:702
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:90
int nXSize
window width
Definition gdal_rasterband.h:99
int nYOff
top offset of the window
Definition gdal_rasterband.h:96
int nXOff
left offset of the window
Definition gdal_rasterband.h:93
int nYSize
window height
Definition gdal_rasterband.h:102
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:152
CPLErr
Error category / error level.
Definition cpl_error.h:45
@ CE_None
No error.
Definition cpl_error.h:47
int CPLErrorNum
Error number.
Definition cpl_error.h:103
Core portability definitions for CPL.
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:198
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:1009
#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:1101
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:1035
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:195
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition cpl_virtualmem.h:45
Public (C callable) GDAL entry points.
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:412
GDALAccess
Definition gdal.h:120
@ GA_ReadOnly
Definition gdal.h:121
GDALDataType
Definition gdal.h:48
@ GDT_UInt8
Definition gdal.h:50
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:137
@ GRIORA_NearestNeighbour
Definition gdal.h:138
GDALColorInterp
Types of color interpretation for raster bands.
Definition gdal.h:294
GDALRWFlag
Definition gdal.h:127
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:478
OGRLayer::FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition ogrsf_frmts.h:486
Structure to pass extra arguments to RasterIO() method, must be initialized with INIT_RASTERIO_EXTRA_...
Definition gdal.h:174