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 1749920 : GDALRasterBandOwnedOrNot() = default;
164 :
165 : GDALRasterBandOwnedOrNot(GDALRasterBandOwnedOrNot &&) = default;
166 :
167 1750090 : void reset()
168 : {
169 1750090 : m_poBandOwned.reset();
170 1750090 : m_poBandRef = nullptr;
171 1750090 : }
172 :
173 1852 : void resetNotOwned(GDALRasterBand *poBand)
174 : {
175 1852 : m_poBandOwned.reset();
176 1852 : m_poBandRef = poBand;
177 1852 : }
178 :
179 166706 : void reset(std::unique_ptr<GDALRasterBand> poBand)
180 : {
181 166706 : m_poBandOwned = std::move(poBand);
182 166706 : m_poBandRef = nullptr;
183 166706 : }
184 :
185 2 : const GDALRasterBand *get() const
186 : {
187 2 : return static_cast<const GDALRasterBand *>(*this);
188 : }
189 :
190 1562600 : GDALRasterBand *get()
191 : {
192 1562600 : return static_cast<GDALRasterBand *>(*this);
193 : }
194 :
195 734854 : bool IsOwned() const
196 : {
197 734854 : 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 3453990 : operator GDALRasterBand *()
206 : {
207 3453990 : 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 2299320 : bool HasBlockCache() const
285 : {
286 2299320 : 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, int nYBlockOff) CPL_WARN_UNUSED_RESULT;
462 :
463 : // This method should only be overloaded by GDALProxyRasterBand
464 : virtual CPLErr FlushBlock(int nXBlockOff, int nYBlockOff,
465 : int bWriteDirtyBlock = TRUE);
466 :
467 : unsigned char *
468 : GetIndexColorTranslationTo(/* const */ GDALRasterBand *poReferenceBand,
469 : unsigned char *pTranslationTable = nullptr,
470 : int *pApproximateMatching = nullptr);
471 :
472 : // New OpengIS CV_SampleDimension stuff.
473 :
474 : virtual CPLErr FlushCache(bool bAtClosing = false);
475 : virtual CPLErr DropCache();
476 : virtual char **GetCategoryNames();
477 : virtual double GetNoDataValue(int *pbSuccess = nullptr);
478 : virtual int64_t GetNoDataValueAsInt64(int *pbSuccess = nullptr);
479 : virtual uint64_t GetNoDataValueAsUInt64(int *pbSuccess = nullptr);
480 :
481 : #if __cplusplus >= 201703L
482 6 : template <class T> inline std::optional<T> GetNoDataValue() const
483 : {
484 6 : int bSuccess = false;
485 : if constexpr (std::is_same_v<T, int64_t>)
486 : {
487 1 : const int64_t v =
488 1 : const_cast<GDALRasterBand *>(this)->GetNoDataValueAsInt64(
489 : &bSuccess);
490 1 : if (!bSuccess)
491 0 : return {};
492 1 : return v;
493 : }
494 : else if constexpr (std::is_same_v<T, uint64_t>)
495 : {
496 1 : const uint64_t v =
497 1 : const_cast<GDALRasterBand *>(this)->GetNoDataValueAsUInt64(
498 : &bSuccess);
499 1 : if (!bSuccess)
500 0 : return {};
501 1 : return v;
502 : }
503 : else
504 : {
505 : const double v =
506 4 : const_cast<GDALRasterBand *>(this)->GetNoDataValue(&bSuccess);
507 4 : if (!bSuccess)
508 0 : return {};
509 4 : return static_cast<T>(v);
510 : }
511 : }
512 : #endif
513 :
514 : virtual double GetMinimum(int *pbSuccess = nullptr);
515 : virtual double GetMaximum(int *pbSuccess = nullptr);
516 : virtual double GetOffset(int *pbSuccess = nullptr);
517 : virtual double GetScale(int *pbSuccess = nullptr);
518 : virtual const char *GetUnitType();
519 : virtual GDALColorInterp GetColorInterpretation();
520 : virtual GDALColorTable *GetColorTable();
521 : virtual CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0);
522 :
523 : virtual CPLErr SetCategoryNames(char **papszNames);
524 : virtual CPLErr SetNoDataValue(double dfNoData);
525 : virtual CPLErr SetNoDataValueAsInt64(int64_t nNoData);
526 : virtual CPLErr SetNoDataValueAsUInt64(uint64_t nNoData);
527 : CPLErr SetNoDataValueAsString(const char *pszNoData,
528 : bool *pbCannotBeExactlyRepresented = nullptr);
529 : virtual CPLErr DeleteNoDataValue();
530 : virtual CPLErr SetColorTable(GDALColorTable *poCT);
531 : virtual CPLErr SetColorInterpretation(GDALColorInterp eColorInterp);
532 : virtual CPLErr SetOffset(double dfNewOffset);
533 : virtual CPLErr SetScale(double dfNewScale);
534 : virtual CPLErr SetUnitType(const char *pszNewValue);
535 :
536 : virtual CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
537 : double *pdfMax, double *pdfMean,
538 : double *padfStdDev);
539 :
540 : #ifndef DOXYGEN_SKIP
541 : virtual CPLErr
542 : ComputeStatistics(int bApproxOK, double *pdfMin, double *pdfMax,
543 : double *pdfMean, double *pdfStdDev, GDALProgressFunc,
544 : void *pProgressData,
545 : CSLConstList papszOptions OPTIONAL_OUTSIDE_GDAL(nullptr));
546 : #else
547 : virtual CPLErr ComputeStatistics(int bApproxOK, double *pdfMin,
548 : double *pdfMax, double *pdfMean,
549 : double *pdfStdDev, GDALProgressFunc,
550 : void *pProgressData,
551 : CSLConstList papszOptions);
552 : #endif
553 :
554 : virtual CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
555 : double dfStdDev);
556 : virtual CPLErr ComputeRasterMinMax(int bApproxOK, double *adfMinMax);
557 : virtual CPLErr ComputeRasterMinMaxLocation(double *pdfMin, double *pdfMax,
558 : int *pnMinX, int *pnMinY,
559 : int *pnMaxX, int *pnMaxY);
560 :
561 : // Only defined when Doxygen enabled
562 : #ifdef DOXYGEN_SKIP
563 : CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override;
564 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
565 : const char *pszDomain) override;
566 : #endif
567 : virtual const char *GetMetadataItem(const char *pszName,
568 : const char *pszDomain = "") override;
569 :
570 : virtual int HasArbitraryOverviews();
571 : virtual int GetOverviewCount();
572 : virtual GDALRasterBand *GetOverview(int i);
573 : virtual GDALRasterBand *GetRasterSampleOverview(GUIntBig);
574 : virtual CPLErr BuildOverviews(const char *pszResampling, int nOverviews,
575 : const int *panOverviewList,
576 : GDALProgressFunc pfnProgress,
577 : void *pProgressData,
578 : CSLConstList papszOptions);
579 :
580 : virtual CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
581 : int nBufXSize, int nBufYSize,
582 : GDALDataType eBufType, CSLConstList papszOptions);
583 :
584 : virtual CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets,
585 : GUIntBig *panHistogram, int bIncludeOutOfRange,
586 : int bApproxOK, GDALProgressFunc,
587 : void *pProgressData);
588 :
589 : virtual CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax,
590 : int *pnBuckets, GUIntBig **ppanHistogram,
591 : int bForce, GDALProgressFunc,
592 : void *pProgressData);
593 : virtual CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets,
594 : GUIntBig *panHistogram);
595 :
596 : virtual GDALRasterAttributeTable *GetDefaultRAT();
597 : virtual CPLErr SetDefaultRAT(const GDALRasterAttributeTable *poRAT);
598 :
599 : virtual GDALRasterBand *GetMaskBand();
600 : virtual int GetMaskFlags();
601 : virtual CPLErr CreateMaskBand(int nFlagsIn);
602 : virtual bool IsMaskBand() const;
603 : virtual GDALMaskValueRange GetMaskValueRange() const;
604 : bool HasConflictingMaskSources(std::string *posDetailMessage = nullptr,
605 : bool bMentionPrioritarySource = true) const;
606 :
607 : virtual CPLVirtualMem *
608 : GetVirtualMemAuto(GDALRWFlag eRWFlag, int *pnPixelSpace,
609 : GIntBig *pnLineSpace,
610 : CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT;
611 :
612 : int GetDataCoverageStatus(int nXOff, int nYOff, int nXSize, int nYSize,
613 : int nMaskFlagStop = 0,
614 : double *pdfDataPct = nullptr);
615 :
616 : std::shared_ptr<GDALMDArray> AsMDArray() const;
617 :
618 : CPLErr InterpolateAtGeolocation(
619 : double dfGeolocX, double dfGeolocY, const OGRSpatialReference *poSRS,
620 : GDALRIOResampleAlg eInterpolation, double *pdfRealValue,
621 : double *pdfImagValue = nullptr,
622 : CSLConstList papszTransformerOptions = nullptr) const;
623 :
624 : virtual CPLErr InterpolateAtPoint(double dfPixel, double dfLine,
625 : GDALRIOResampleAlg eInterpolation,
626 : double *pdfRealValue,
627 : double *pdfImagValue = nullptr) const;
628 :
629 : //! @cond Doxygen_Suppress
630 : class CPL_DLL WindowIterator
631 : {
632 : public:
633 : using iterator_category = std::input_iterator_tag;
634 : using difference_type = std::ptrdiff_t;
635 :
636 : using value_type = GDALRasterWindow;
637 : using pointer = value_type *;
638 : using reference = value_type &;
639 :
640 : WindowIterator(int nRasterXSize, int nRasterYSize, int nBlockXSize,
641 : int nBlockYSize, int nRow, int nCol);
642 :
643 : bool operator==(const WindowIterator &other) const;
644 :
645 : bool operator!=(const WindowIterator &other) const;
646 :
647 : value_type operator*() const;
648 :
649 : WindowIterator &operator++();
650 :
651 : private:
652 : int m_nRasterXSize;
653 : int m_nRasterYSize;
654 : int m_nBlockXSize;
655 : int m_nBlockYSize;
656 : int m_row;
657 : int m_col;
658 : };
659 :
660 : class CPL_DLL WindowIteratorWrapper
661 : {
662 : public:
663 : explicit WindowIteratorWrapper(const GDALRasterBand &band,
664 : size_t maxSize = 0);
665 :
666 : explicit WindowIteratorWrapper(const GDALRasterBand &band1,
667 : const GDALRasterBand &band2,
668 : size_t maxSize = 0);
669 :
670 : uint64_t count() const;
671 :
672 : WindowIterator begin() const;
673 :
674 : WindowIterator end() const;
675 :
676 : private:
677 : const int m_nRasterXSize;
678 : const int m_nRasterYSize;
679 : int m_nBlockXSize;
680 : int m_nBlockYSize;
681 :
682 : WindowIteratorWrapper(int nRasterXSize, int nRasterYSize,
683 : int nBlockXSize, int nBlockYSize, size_t maxSize);
684 : };
685 :
686 : //! @endcond
687 :
688 : WindowIteratorWrapper IterateWindows(size_t maxSize = 0) const;
689 :
690 : virtual bool MayMultiBlockReadingBeMultiThreaded() const;
691 :
692 : #ifndef DOXYGEN_XML
693 : void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,
694 : ...) const CPL_PRINT_FUNC_FORMAT(4, 5);
695 : #endif
696 :
697 : //! @cond Doxygen_Suppress
698 : static void ThrowIfNotSameDimensions(const GDALRasterBand &first,
699 : const GDALRasterBand &second);
700 :
701 : //! @endcond
702 :
703 : /** Convert a GDALRasterBand* to a GDALRasterBandH.
704 : */
705 463154 : static inline GDALRasterBandH ToHandle(GDALRasterBand *poBand)
706 : {
707 463154 : return static_cast<GDALRasterBandH>(poBand);
708 : }
709 :
710 : /** Convert a GDALRasterBandH to a GDALRasterBand*.
711 : */
712 5516582 : static inline GDALRasterBand *FromHandle(GDALRasterBandH hBand)
713 : {
714 5516582 : return static_cast<GDALRasterBand *>(hBand);
715 : }
716 :
717 : //! @cond Doxygen_Suppress
718 : // Remove me in GDAL 4.0. See GetMetadataItem() implementation
719 : // Internal use in GDAL only !
720 : virtual void EnablePixelTypeSignedByteWarning(bool b)
721 : #ifndef GDAL_COMPILATION
722 : CPL_WARN_DEPRECATED("Do not use that method outside of GDAL!")
723 : #endif
724 : ;
725 :
726 : //! @endcond
727 :
728 : private:
729 : CPL_DISALLOW_COPY_ASSIGN(GDALRasterBand)
730 : };
731 :
732 : //! @cond Doxygen_Suppress
733 : #define GDAL_EXTERN_TEMPLATE_READ_RASTER(T) \
734 : extern template CPLErr GDALRasterBand::ReadRaster<T>( \
735 : T * pData, size_t nArrayEltCount, double dfXOff, double dfYOff, \
736 : double dfXSize, double dfYSize, size_t nBufXSize, size_t nBufYSize, \
737 : GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
738 : void *pProgressData) const;
739 :
740 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint8_t)
741 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int8_t)
742 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint16_t)
743 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int16_t)
744 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint32_t)
745 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int32_t)
746 : GDAL_EXTERN_TEMPLATE_READ_RASTER(uint64_t)
747 : GDAL_EXTERN_TEMPLATE_READ_RASTER(int64_t)
748 : #ifdef CPL_FLOAT_H_INCLUDED
749 : GDAL_EXTERN_TEMPLATE_READ_RASTER(GFloat16)
750 : #endif
751 : GDAL_EXTERN_TEMPLATE_READ_RASTER(float)
752 : GDAL_EXTERN_TEMPLATE_READ_RASTER(double)
753 : // Not allowed by C++ standard
754 : // GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<int16_t>)
755 : // GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<int32_t>)
756 : GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<float>)
757 : GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<double>)
758 :
759 : #define GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(T) \
760 : extern template CPLErr GDALRasterBand::ReadRaster<T>( \
761 : std::vector<T> & vData, double dfXOff, double dfYOff, double dfXSize, \
762 : double dfYSize, size_t nBufXSize, size_t nBufYSize, \
763 : GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
764 : void *pProgressData) const;
765 :
766 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint8_t)
767 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int8_t)
768 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint16_t)
769 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int16_t)
770 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint32_t)
771 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int32_t)
772 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint64_t)
773 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int64_t)
774 : #ifdef CPL_FLOAT_H_INCLUDED
775 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(GFloat16)
776 : #endif
777 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(float)
778 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(double)
779 : // Not allowed by C++ standard
780 : // GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<int16_t>)
781 : // GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<int32_t>)
782 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<float>)
783 : GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<double>)
784 :
785 : //! @endcond
786 :
787 : #include "gdal_computedrasterband.h"
788 :
789 : #endif
|