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