/src/gdal/gcore/gdal_rasterband.h
Line | Count | Source |
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 | 0 | GDALRasterBandOwnedOrNot() = default; |
164 | | |
165 | | GDALRasterBandOwnedOrNot(GDALRasterBandOwnedOrNot &&) = default; |
166 | | |
167 | | void reset() |
168 | 0 | { |
169 | 0 | m_poBandOwned.reset(); |
170 | 0 | m_poBandRef = nullptr; |
171 | 0 | } |
172 | | |
173 | | void resetNotOwned(GDALRasterBand *poBand) |
174 | 0 | { |
175 | 0 | m_poBandOwned.reset(); |
176 | 0 | m_poBandRef = poBand; |
177 | 0 | } |
178 | | |
179 | | void reset(std::unique_ptr<GDALRasterBand> poBand) |
180 | 0 | { |
181 | 0 | m_poBandOwned = std::move(poBand); |
182 | 0 | m_poBandRef = nullptr; |
183 | 0 | } |
184 | | |
185 | | const GDALRasterBand *get() const |
186 | 0 | { |
187 | 0 | return static_cast<const GDALRasterBand *>(*this); |
188 | 0 | } |
189 | | |
190 | | GDALRasterBand *get() |
191 | 0 | { |
192 | 0 | return static_cast<GDALRasterBand *>(*this); |
193 | 0 | } |
194 | | |
195 | | bool IsOwned() const |
196 | 0 | { |
197 | 0 | return m_poBandOwned != nullptr; |
198 | 0 | } |
199 | | |
200 | | operator const GDALRasterBand *() const |
201 | 0 | { |
202 | 0 | return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef; |
203 | 0 | } |
204 | | |
205 | | operator GDALRasterBand *() |
206 | 0 | { |
207 | 0 | return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef; |
208 | 0 | } |
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 | | bool HasBlockCache() const |
285 | 0 | { |
286 | 0 | return poBandBlockCache != nullptr; |
287 | 0 | } |
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 | | |
541 | | #ifndef DOXYGEN_SKIP |
542 | | virtual CPLErr |
543 | | ComputeStatistics(int bApproxOK, double *pdfMin, double *pdfMax, |
544 | | double *pdfMean, double *pdfStdDev, GDALProgressFunc, |
545 | | void *pProgressData, |
546 | | CSLConstList papszOptions OPTIONAL_OUTSIDE_GDAL(nullptr)); |
547 | | #else |
548 | | virtual CPLErr ComputeStatistics(int bApproxOK, double *pdfMin, |
549 | | double *pdfMax, double *pdfMean, |
550 | | double *pdfStdDev, GDALProgressFunc, |
551 | | void *pProgressData, |
552 | | CSLConstList papszOptions); |
553 | | #endif |
554 | | |
555 | | virtual CPLErr SetStatistics(double dfMin, double dfMax, double dfMean, |
556 | | double dfStdDev); |
557 | | virtual CPLErr ComputeRasterMinMax(int bApproxOK, double *adfMinMax); |
558 | | virtual CPLErr ComputeRasterMinMaxLocation(double *pdfMin, double *pdfMax, |
559 | | int *pnMinX, int *pnMinY, |
560 | | int *pnMaxX, int *pnMaxY); |
561 | | |
562 | | // Only defined when Doxygen enabled |
563 | | #ifdef DOXYGEN_SKIP |
564 | | CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override; |
565 | | CPLErr SetMetadataItem(const char *pszName, const char *pszValue, |
566 | | const char *pszDomain) override; |
567 | | #endif |
568 | | virtual const char *GetMetadataItem(const char *pszName, |
569 | | const char *pszDomain = "") override; |
570 | | |
571 | | virtual int HasArbitraryOverviews(); |
572 | | virtual int GetOverviewCount(); |
573 | | virtual GDALRasterBand *GetOverview(int i); |
574 | | virtual GDALRasterBand *GetRasterSampleOverview(GUIntBig); |
575 | | virtual CPLErr BuildOverviews(const char *pszResampling, int nOverviews, |
576 | | const int *panOverviewList, |
577 | | GDALProgressFunc pfnProgress, |
578 | | void *pProgressData, |
579 | | CSLConstList papszOptions); |
580 | | |
581 | | virtual CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize, |
582 | | int nBufXSize, int nBufYSize, |
583 | | GDALDataType eBufType, CSLConstList papszOptions); |
584 | | |
585 | | virtual CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets, |
586 | | GUIntBig *panHistogram, int bIncludeOutOfRange, |
587 | | int bApproxOK, GDALProgressFunc, |
588 | | void *pProgressData); |
589 | | |
590 | | virtual CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax, |
591 | | int *pnBuckets, GUIntBig **ppanHistogram, |
592 | | int bForce, GDALProgressFunc, |
593 | | void *pProgressData); |
594 | | virtual CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets, |
595 | | GUIntBig *panHistogram); |
596 | | |
597 | | virtual GDALRasterAttributeTable *GetDefaultRAT(); |
598 | | virtual CPLErr SetDefaultRAT(const GDALRasterAttributeTable *poRAT); |
599 | | |
600 | | virtual GDALRasterBand *GetMaskBand(); |
601 | | virtual int GetMaskFlags(); |
602 | | virtual CPLErr CreateMaskBand(int nFlagsIn); |
603 | | virtual bool IsMaskBand() const; |
604 | | virtual GDALMaskValueRange GetMaskValueRange() const; |
605 | | bool HasConflictingMaskSources(std::string *posDetailMessage = nullptr, |
606 | | bool bMentionPrioritarySource = true) const; |
607 | | |
608 | | virtual CPLVirtualMem * |
609 | | GetVirtualMemAuto(GDALRWFlag eRWFlag, int *pnPixelSpace, |
610 | | GIntBig *pnLineSpace, |
611 | | CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT; |
612 | | |
613 | | int GetDataCoverageStatus(int nXOff, int nYOff, int nXSize, int nYSize, |
614 | | int nMaskFlagStop = 0, |
615 | | double *pdfDataPct = nullptr); |
616 | | |
617 | | std::shared_ptr<GDALMDArray> AsMDArray() const; |
618 | | |
619 | | CPLErr InterpolateAtGeolocation( |
620 | | double dfGeolocX, double dfGeolocY, const OGRSpatialReference *poSRS, |
621 | | GDALRIOResampleAlg eInterpolation, double *pdfRealValue, |
622 | | double *pdfImagValue = nullptr, |
623 | | CSLConstList papszTransformerOptions = nullptr) const; |
624 | | |
625 | | virtual CPLErr InterpolateAtPoint(double dfPixel, double dfLine, |
626 | | GDALRIOResampleAlg eInterpolation, |
627 | | double *pdfRealValue, |
628 | | double *pdfImagValue = nullptr) const; |
629 | | |
630 | | //! @cond Doxygen_Suppress |
631 | | class CPL_DLL WindowIterator |
632 | | { |
633 | | public: |
634 | | using iterator_category = std::input_iterator_tag; |
635 | | using difference_type = std::ptrdiff_t; |
636 | | |
637 | | using value_type = GDALRasterWindow; |
638 | | using pointer = value_type *; |
639 | | using reference = value_type &; |
640 | | |
641 | | WindowIterator(int nRasterXSize, int nRasterYSize, int nBlockXSize, |
642 | | int nBlockYSize, int nRow, int nCol); |
643 | | |
644 | | bool operator==(const WindowIterator &other) const; |
645 | | |
646 | | bool operator!=(const WindowIterator &other) const; |
647 | | |
648 | | value_type operator*() const; |
649 | | |
650 | | WindowIterator &operator++(); |
651 | | |
652 | | private: |
653 | | int m_nRasterXSize; |
654 | | int m_nRasterYSize; |
655 | | int m_nBlockXSize; |
656 | | int m_nBlockYSize; |
657 | | int m_row; |
658 | | int m_col; |
659 | | }; |
660 | | |
661 | | class CPL_DLL WindowIteratorWrapper |
662 | | { |
663 | | public: |
664 | | explicit WindowIteratorWrapper(const GDALRasterBand &band, |
665 | | size_t maxSize = 0); |
666 | | |
667 | | explicit WindowIteratorWrapper(const GDALRasterBand &band1, |
668 | | const GDALRasterBand &band2, |
669 | | size_t maxSize = 0); |
670 | | |
671 | | uint64_t count() const; |
672 | | |
673 | | WindowIterator begin() const; |
674 | | |
675 | | WindowIterator end() const; |
676 | | |
677 | | private: |
678 | | const int m_nRasterXSize; |
679 | | const int m_nRasterYSize; |
680 | | int m_nBlockXSize; |
681 | | int m_nBlockYSize; |
682 | | |
683 | | WindowIteratorWrapper(int nRasterXSize, int nRasterYSize, |
684 | | int nBlockXSize, int nBlockYSize, size_t maxSize); |
685 | | }; |
686 | | |
687 | | //! @endcond |
688 | | |
689 | | WindowIteratorWrapper IterateWindows(size_t maxSize = 0) const; |
690 | | |
691 | | virtual bool MayMultiBlockReadingBeMultiThreaded() const; |
692 | | |
693 | | #ifndef DOXYGEN_XML |
694 | | void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt, |
695 | | ...) const CPL_PRINT_FUNC_FORMAT(4, 5); |
696 | | #endif |
697 | | |
698 | | //! @cond Doxygen_Suppress |
699 | | static void ThrowIfNotSameDimensions(const GDALRasterBand &first, |
700 | | const GDALRasterBand &second); |
701 | | |
702 | | //! @endcond |
703 | | |
704 | | /** Convert a GDALRasterBand* to a GDALRasterBandH. |
705 | | */ |
706 | | static inline GDALRasterBandH ToHandle(GDALRasterBand *poBand) |
707 | 0 | { |
708 | 0 | return static_cast<GDALRasterBandH>(poBand); |
709 | 0 | } |
710 | | |
711 | | /** Convert a GDALRasterBandH to a GDALRasterBand*. |
712 | | */ |
713 | | static inline GDALRasterBand *FromHandle(GDALRasterBandH hBand) |
714 | 0 | { |
715 | 0 | return static_cast<GDALRasterBand *>(hBand); |
716 | 0 | } |
717 | | |
718 | | //! @cond Doxygen_Suppress |
719 | | // Remove me in GDAL 4.0. See GetMetadataItem() implementation |
720 | | // Internal use in GDAL only ! |
721 | | virtual void EnablePixelTypeSignedByteWarning(bool b) |
722 | | #ifndef GDAL_COMPILATION |
723 | | CPL_WARN_DEPRECATED("Do not use that method outside of GDAL!") |
724 | | #endif |
725 | | ; |
726 | | |
727 | | //! @endcond |
728 | | |
729 | | private: |
730 | | CPL_DISALLOW_COPY_ASSIGN(GDALRasterBand) |
731 | | }; |
732 | | |
733 | | //! @cond Doxygen_Suppress |
734 | | #define GDAL_EXTERN_TEMPLATE_READ_RASTER(T) \ |
735 | | extern template CPLErr GDALRasterBand::ReadRaster<T>( \ |
736 | | T * pData, size_t nArrayEltCount, double dfXOff, double dfYOff, \ |
737 | | double dfXSize, double dfYSize, size_t nBufXSize, size_t nBufYSize, \ |
738 | | GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \ |
739 | | void *pProgressData) const; |
740 | | |
741 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(uint8_t) |
742 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(int8_t) |
743 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(uint16_t) |
744 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(int16_t) |
745 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(uint32_t) |
746 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(int32_t) |
747 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(uint64_t) |
748 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(int64_t) |
749 | | #ifdef CPL_FLOAT_H_INCLUDED |
750 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(GFloat16) |
751 | | #endif |
752 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(float) |
753 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(double) |
754 | | // Not allowed by C++ standard |
755 | | // GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<int16_t>) |
756 | | // GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<int32_t>) |
757 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<float>) |
758 | | GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<double>) |
759 | | |
760 | | #define GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(T) \ |
761 | | extern template CPLErr GDALRasterBand::ReadRaster<T>( \ |
762 | | std::vector<T> & vData, double dfXOff, double dfYOff, double dfXSize, \ |
763 | | double dfYSize, size_t nBufXSize, size_t nBufYSize, \ |
764 | | GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \ |
765 | | void *pProgressData) const; |
766 | | |
767 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint8_t) |
768 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int8_t) |
769 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint16_t) |
770 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int16_t) |
771 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint32_t) |
772 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int32_t) |
773 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint64_t) |
774 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int64_t) |
775 | | #ifdef CPL_FLOAT_H_INCLUDED |
776 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(GFloat16) |
777 | | #endif |
778 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(float) |
779 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(double) |
780 | | // Not allowed by C++ standard |
781 | | // GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<int16_t>) |
782 | | // GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<int32_t>) |
783 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<float>) |
784 | | GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<double>) |
785 | | |
786 | | //! @endcond |
787 | | |
788 | | #include "gdal_computedrasterband.h" |
789 | | |
790 | | #endif |