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 >= 201703L
28 : #include <optional>
29 : #endif
30 : #if __cplusplus >= 202002L
31 : #include <span>
32 : #endif
33 : #include <vector>
34 :
35 : //! @cond Doxygen_Suppress
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
43 : //! @endcond
44 :
45 : /* ******************************************************************** */
46 : /* GDALRasterBand */
47 : /* ******************************************************************** */
48 :
49 : class GDALAbstractBandBlockCache;
50 : class GDALColorTable;
51 : class GDALDataset;
52 : class GDALDoublePointsCache;
53 : class GDALRasterAttributeTable;
54 : class GDALRasterBlock;
55 : class GDALMDArray;
56 : class OGRSpatialReference;
57 :
58 : /** Range of values found in a mask band */
59 : typedef enum
60 : {
61 : GMVR_UNKNOWN, /*! Unknown (can also be used for any values between 0 and 255
62 : for a Byte band) */
63 : GMVR_0_AND_1_ONLY, /*! Only 0 and 1 */
64 : GMVR_0_AND_255_ONLY, /*! Only 0 and 255 */
65 : } GDALMaskValueRange;
66 :
67 : /** Suggested/most efficient access pattern to blocks. */
68 : typedef int GDALSuggestedBlockAccessPattern;
69 :
70 : /** Unknown, or no particular read order is suggested. */
71 : constexpr GDALSuggestedBlockAccessPattern GSBAP_UNKNOWN = 0;
72 :
73 : /** Random access to blocks is efficient. */
74 : constexpr GDALSuggestedBlockAccessPattern GSBAP_RANDOM = 1;
75 :
76 : /** Reading by strips from top to bottom is the most efficient. */
77 : constexpr GDALSuggestedBlockAccessPattern GSBAP_TOP_TO_BOTTOM = 2;
78 :
79 : /** Reading by strips from bottom to top is the most efficient. */
80 : constexpr GDALSuggestedBlockAccessPattern GSBAP_BOTTOM_TO_TOP = 3;
81 :
82 : /** Reading the largest chunk from the raster is the most efficient (can be
83 : * combined with above values). */
84 : constexpr GDALSuggestedBlockAccessPattern GSBAP_LARGEST_CHUNK_POSSIBLE = 0x100;
85 :
86 : class GDALComputedRasterBand;
87 :
88 : /** A rectangular subset of pixels within a raster */
89 : class GDALRasterWindow
90 : {
91 : public:
92 : /** left offset of the window */
93 : int nXOff;
94 :
95 : /** top offset of the window */
96 : int nYOff;
97 :
98 : /** window width */
99 : int nXSize;
100 :
101 : /** window height */
102 : int nYSize;
103 : };
104 :
105 : /** A single raster band (or channel). */
106 :
107 : class 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,
126 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
127 :
128 : CPL_INTERNAL bool HasNoData() const;
129 :
130 : protected:
131 : GDALRasterBand();
132 : explicit GDALRasterBand(int bForceCachedIO);
133 :
134 : //! @cond Doxygen_Suppress
135 : GDALRasterBand(GDALRasterBand &&) = default;
136 : //! @endcond
137 :
138 : //! @cond Doxygen_Suppress
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 1871470 : GDALRasterBandOwnedOrNot() = default;
164 :
165 : GDALRasterBandOwnedOrNot(GDALRasterBandOwnedOrNot &&) = default;
166 :
167 1871650 : void reset()
168 : {
169 1871650 : m_poBandOwned.reset();
170 1871650 : m_poBandRef = nullptr;
171 1871650 : }
172 :
173 1713 : void resetNotOwned(GDALRasterBand *poBand)
174 : {
175 1713 : m_poBandOwned.reset();
176 1713 : m_poBandRef = poBand;
177 1713 : }
178 :
179 165776 : void reset(std::unique_ptr<GDALRasterBand> poBand)
180 : {
181 165776 : m_poBandOwned = std::move(poBand);
182 165776 : m_poBandRef = nullptr;
183 165776 : }
184 :
185 2 : const GDALRasterBand *get() const
186 : {
187 2 : return static_cast<const GDALRasterBand *>(*this);
188 : }
189 :
190 1548280 : GDALRasterBand *get()
191 : {
192 1548280 : return static_cast<GDALRasterBand *>(*this);
193 : }
194 :
195 725313 : bool IsOwned() const
196 : {
197 725313 : return m_poBandOwned != nullptr;
198 : }
199 :
200 2 : operator const GDALRasterBand *() const
201 : {
202 2 : return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
203 : }
204 :
205 3399750 : operator GDALRasterBand *()
206 : {
207 3399750 : 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,
231 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
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 :
240 : //! @endcond
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,
250 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
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 :
259 : //! @cond Doxygen_Suppress
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,
265 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
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)
278 : CPL_WARN_UNUSED_RESULT;
279 :
280 : int InitBlockInfo();
281 :
282 : void AddBlockToFreeList(GDALRasterBlock *);
283 :
284 2298490 : bool HasBlockCache() const
285 : {
286 2298490 : return poBandBlockCache != nullptr;
287 : }
288 :
289 : bool HasDirtyBlocks() const;
290 :
291 : //! @endcond
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,
323 : GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT;
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,
330 : GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour,
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,
338 : GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour,
339 : GDALProgressFunc pfnProgress = nullptr,
340 : void *pProgressData = nullptr) const;
341 :
342 : #if __cplusplus >= 202002L
343 : //! @cond Doxygen_Suppress
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,
349 : GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour,
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 :
358 : //! @endcond
359 : #endif
360 :
361 : GDALComputedRasterBand
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 :
367 : GDALComputedRasterBand
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 :
373 : GDALComputedRasterBand
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 :
379 : GDALComputedRasterBand
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 :
385 : GDALComputedRasterBand
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 :
391 : GDALComputedRasterBand
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 :
397 : GDALComputedRasterBand
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 :
403 : GDALComputedRasterBand
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 :
409 : GDALComputedRasterBand
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 :
415 : GDALComputedRasterBand
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 :
426 : GDALComputedRasterBand
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 :
432 : GDALComputedRasterBand
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 :
442 : GDALComputedRasterBand operator!() const CPL_WARN_UNUSED_RESULT;
443 :
444 : GDALComputedRasterBand operator-() const CPL_WARN_UNUSED_RESULT;
445 :
446 : GDALComputedRasterBand AsType(GDALDataType) const CPL_WARN_UNUSED_RESULT;
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,
600 : CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT;
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 :
619 : //! @cond Doxygen_Suppress
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 :
676 : //! @endcond
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 :
687 : //! @cond Doxygen_Suppress
688 : static void ThrowIfNotSameDimensions(const GDALRasterBand &first,
689 : const GDALRasterBand &second);
690 :
691 : //! @endcond
692 :
693 : /** Convert a GDALRasterBand* to a GDALRasterBandH.
694 : */
695 451913 : static inline GDALRasterBandH ToHandle(GDALRasterBand *poBand)
696 : {
697 451913 : return static_cast<GDALRasterBandH>(poBand);
698 : }
699 :
700 : /** Convert a GDALRasterBandH to a GDALRasterBand*.
701 : */
702 5491032 : static inline GDALRasterBand *FromHandle(GDALRasterBandH hBand)
703 : {
704 5491032 : return static_cast<GDALRasterBand *>(hBand);
705 : }
706 :
707 : //! @cond Doxygen_Suppress
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 :
716 : //! @endcond
717 :
718 : private:
719 : CPL_DISALLOW_COPY_ASSIGN(GDALRasterBand)
720 : };
721 :
722 : //! @cond Doxygen_Suppress
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 :
730 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint8_t)
731 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int8_t)
732 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint16_t)
733 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int16_t)
734 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint32_t)
735 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int32_t)
736 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint64_t)
737 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int64_t)
738 : #ifdef CPL_FLOAT_H_INCLUDED
739 : GDAL_EXTERN_TEMPLATE_READ_RASTER(GFloat16)
740 : #endif
741 : GDAL_EXTERN_TEMPLATE_READ_RASTER(float)
742 : GDAL_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>)
746 : GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<float>)
747 : GDAL_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 :
756 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint8_t)
757 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int8_t)
758 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint16_t)
759 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int16_t)
760 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint32_t)
761 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int32_t)
762 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint64_t)
763 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int64_t)
764 : #ifdef CPL_FLOAT_H_INCLUDED
765 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(GFloat16)
766 : #endif
767 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(float)
768 : GDAL_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>)
772 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<float>)
773 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<double>)
774 :
775 : //! @endcond
776 :
777 : #include "gdal_computedrasterband.h"
778 :
779 : #endif
|