15#ifndef GDALRASTERBAND_H_INCLUDED
16#define GDALRASTERBAND_H_INCLUDED
20#include "gdal_majorobject.h"
27#if __cplusplus >= 202002L
33#if !defined(OPTIONAL_OUTSIDE_GDAL)
34#if defined(GDAL_COMPILATION)
35#define OPTIONAL_OUTSIDE_GDAL(val)
37#define OPTIONAL_OUTSIDE_GDAL(val) = val
46class GDALAbstractBandBlockCache;
49class GDALDoublePointsCache;
65typedef int GDALSuggestedBlockAccessPattern;
68constexpr GDALSuggestedBlockAccessPattern GSBAP_UNKNOWN = 0;
71constexpr GDALSuggestedBlockAccessPattern GSBAP_RANDOM = 1;
74constexpr GDALSuggestedBlockAccessPattern GSBAP_TOP_TO_BOTTOM = 2;
77constexpr GDALSuggestedBlockAccessPattern GSBAP_BOTTOM_TO_TOP = 3;
81constexpr GDALSuggestedBlockAccessPattern GSBAP_LARGEST_CHUNK_POSSIBLE = 0x100;
107 friend class GDALArrayBandBlockCache;
108 friend class GDALHashSetBandBlockCache;
112 CPLErr eFlushBlockErr = CE_None;
113 GDALAbstractBandBlockCache *poBandBlockCache =
nullptr;
115 CPL_INTERNAL
void SetFlushBlockErr(
CPLErr eErr);
117 CPL_INTERNAL
void IncDirtyBlocks(
int nInc);
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,
137 int nRasterXSize = 0;
138 int nRasterYSize = 0;
144 int nBlockXSize = -1;
145 int nBlockYSize = -1;
146 int nBlocksPerRow = 0;
147 int nBlocksPerColumn = 0;
150 int bForceCachedIO = 0;
153 friend class GDALComputedDataset;
155 class GDALRasterBandOwnedOrNot
158 GDALRasterBandOwnedOrNot() =
default;
160 GDALRasterBandOwnedOrNot(GDALRasterBandOwnedOrNot &&) =
default;
164 m_poBandOwned.reset();
165 m_poBandRef =
nullptr;
170 m_poBandOwned.reset();
171 m_poBandRef = poBand;
174 void reset(std::unique_ptr<GDALRasterBand> poBand)
176 m_poBandOwned = std::move(poBand);
177 m_poBandRef =
nullptr;
192 return m_poBandOwned !=
nullptr;
197 return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
202 return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
207 std::unique_ptr<GDALRasterBand> m_poBandOwned{};
211 GDALRasterBandOwnedOrNot poMask{};
212 bool m_bEnablePixelTypeSignedByteWarning =
216 void InvalidateMaskBand();
218 friend class GDALProxyRasterBand;
219 friend class GDALDefaultOverviews;
222 RasterIOResampled(
GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
223 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
229 void LeaveReadWrite();
233 mutable GDALDoublePointsCache *m_poPointsCache =
nullptr;
239 virtual CPLErr IWriteBlock(
int nBlockXOff,
int nBlockYOff,
void *pData);
242 IRasterIO(
GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
int nYSize,
243 void *pData,
int nBufXSize,
int nBufYSize,
GDALDataType eBufType,
247 virtual int IGetDataCoverageStatus(
int nXOff,
int nYOff,
int nXSize,
248 int nYSize,
int nMaskFlagStop,
252 EmitErrorMessageIfWriteNotSupported(
const char *pszCaller)
const;
256 OverviewRasterIO(
GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
257 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
263 int nXSize,
int nYSize,
void *pData,
264 int nBufXSize,
int nBufYSize,
270 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
279 bool HasBlockCache()
const
281 return poBandBlockCache !=
nullptr;
284 bool HasDirtyBlocks()
const;
291 int GetXSize()
const;
292 int GetYSize()
const;
297 void GetBlockSize(
int *pnXSize,
int *pnYSize)
const;
298 CPLErr GetActualBlockSize(
int nXBlockOff,
int nYBlockOff,
int *pnXValid,
299 int *pnYValid)
const;
301 virtual GDALSuggestedBlockAccessPattern
302 GetSuggestedBlockAccessPattern()
const;
308 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
315 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
322 CPLErr ReadRaster(T *pData,
size_t nArrayEltCount = 0,
double dfXOff = 0,
323 double dfYOff = 0,
double dfXSize = 0,
double dfYSize = 0,
324 size_t nBufXSize = 0,
size_t nBufYSize = 0,
326 GDALProgressFunc pfnProgress =
nullptr,
327 void *pProgressData =
nullptr)
const;
330 CPLErr ReadRaster(std::vector<T> &vData,
double dfXOff = 0,
331 double dfYOff = 0,
double dfXSize = 0,
double dfYSize = 0,
332 size_t nBufXSize = 0,
size_t nBufYSize = 0,
334 GDALProgressFunc pfnProgress =
nullptr,
335 void *pProgressData =
nullptr)
const;
337#if __cplusplus >= 202002L
341 ReadRaster(std::span<T> pData,
double dfXOff = 0,
double dfYOff = 0,
342 double dfXSize = 0,
double dfYSize = 0,
size_t nBufXSize = 0,
343 size_t nBufYSize = 0,
345 GDALProgressFunc pfnProgress =
nullptr,
346 void *pProgressData =
nullptr)
const
348 return ReadRaster(pData.data(), pData.size(), dfXOff, dfYOff, dfXSize,
349 dfYSize, nBufXSize, nBufYSize, eResampleAlg,
350 pfnProgress, pProgressData);
417#pragma GCC diagnostic push
418#pragma GCC diagnostic ignored "-Weffc++"
434#pragma GCC diagnostic pop
443 CPLErr ReadBlock(
int nXBlockOff,
int nYBlockOff,
446 CPLErr WriteBlock(
int nXBlockOff,
int nYBlockOff,
451 GetLockedBlockRef(
int nXBlockOff,
int nYBlockOff,
456 TryGetLockedBlockRef(
int nXBlockOff,
460 virtual
CPLErr FlushBlock(
int nXBlockOff,
int nYBlockOff,
461 int bWriteDirtyBlock = TRUE);
465 unsigned char *pTranslationTable =
nullptr,
466 int *pApproximateMatching =
nullptr);
470 virtual
CPLErr FlushCache(
bool bAtClosing = false);
471 virtual
CPLErr DropCache();
472 virtual
char **GetCategoryNames();
473 virtual
double GetNoDataValue(
int *pbSuccess =
nullptr);
474 virtual int64_t GetNoDataValueAsInt64(
int *pbSuccess =
nullptr);
475 virtual uint64_t GetNoDataValueAsUInt64(
int *pbSuccess =
nullptr);
476 virtual
double GetMinimum(
int *pbSuccess =
nullptr);
477 virtual
double GetMaximum(
int *pbSuccess =
nullptr);
478 virtual
double GetOffset(
int *pbSuccess =
nullptr);
479 virtual
double GetScale(
int *pbSuccess =
nullptr);
480 virtual const
char *GetUnitType();
483 virtual
CPLErr Fill(
double dfRealValue,
double dfImaginaryValue = 0);
485 virtual
CPLErr SetCategoryNames(
char **papszNames);
486 virtual
CPLErr SetNoDataValue(
double dfNoData);
487 virtual
CPLErr SetNoDataValueAsInt64(int64_t nNoData);
488 virtual
CPLErr SetNoDataValueAsUInt64(uint64_t nNoData);
489 CPLErr SetNoDataValueAsString(const
char *pszNoData,
490 bool *pbCannotBeExactlyRepresented =
nullptr);
491 virtual
CPLErr DeleteNoDataValue();
494 virtual
CPLErr SetOffset(
double dfNewOffset);
495 virtual
CPLErr SetScale(
double dfNewScale);
496 virtual
CPLErr SetUnitType(const
char *pszNewValue);
498 virtual
CPLErr GetStatistics(
int bApproxOK,
int bForce,
double *pdfMin,
499 double *pdfMax,
double *pdfMean,
501 virtual
CPLErr ComputeStatistics(
int bApproxOK,
double *pdfMin,
502 double *pdfMax,
double *pdfMean,
503 double *pdfStdDev, GDALProgressFunc,
504 void *pProgressData);
505 virtual
CPLErr SetStatistics(
double dfMin,
double dfMax,
double dfMean,
507 virtual
CPLErr ComputeRasterMinMax(
int bApproxOK,
double *adfMinMax);
508 virtual
CPLErr ComputeRasterMinMaxLocation(
double *pdfMin,
double *pdfMax,
509 int *pnMinX,
int *pnMinY,
510 int *pnMaxX,
int *pnMaxY);
516 const char *pszDomain)
override;
519 const char *pszDomain =
"")
override;
521 virtual int HasArbitraryOverviews();
522 virtual int GetOverviewCount();
525 virtual CPLErr BuildOverviews(
const char *pszResampling,
int nOverviews,
526 const int *panOverviewList,
527 GDALProgressFunc pfnProgress,
531 virtual CPLErr AdviseRead(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
532 int nBufXSize,
int nBufYSize,
535 virtual CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
536 GUIntBig *panHistogram,
int bIncludeOutOfRange,
537 int bApproxOK, GDALProgressFunc,
538 void *pProgressData);
540 virtual CPLErr GetDefaultHistogram(
double *pdfMin,
double *pdfMax,
541 int *pnBuckets,
GUIntBig **ppanHistogram,
542 int bForce, GDALProgressFunc,
543 void *pProgressData);
544 virtual CPLErr SetDefaultHistogram(
double dfMin,
double dfMax,
int nBuckets,
551 virtual int GetMaskFlags();
552 virtual CPLErr CreateMaskBand(
int nFlagsIn);
553 virtual bool IsMaskBand()
const;
554 virtual GDALMaskValueRange GetMaskValueRange()
const;
556 virtual CPLVirtualMem *
557 GetVirtualMemAuto(
GDALRWFlag eRWFlag,
int *pnPixelSpace,
561 int GetDataCoverageStatus(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
562 int nMaskFlagStop = 0,
563 double *pdfDataPct =
nullptr);
565 std::shared_ptr<GDALMDArray> AsMDArray()
const;
567 CPLErr InterpolateAtGeolocation(
570 double *pdfImagValue =
nullptr,
573 virtual CPLErr InterpolateAtPoint(
double dfPixel,
double dfLine,
575 double *pdfRealValue,
576 double *pdfImagValue =
nullptr)
const;
579 class CPL_DLL WindowIterator
582 using iterator_category = std::input_iterator_tag;
583 using difference_type = std::ptrdiff_t;
586 using pointer = value_type *;
587 using reference = value_type &;
589 WindowIterator(
int nRasterXSize,
int nRasterYSize,
int nBlockXSize,
590 int nBlockYSize,
int nRow,
int nCol);
592 bool operator==(
const WindowIterator &other)
const;
594 bool operator!=(
const WindowIterator &other)
const;
596 value_type operator*()
const;
598 WindowIterator &operator++();
609 class CPL_DLL WindowIteratorWrapper
615 uint64_t count()
const;
617 WindowIterator
begin()
const;
619 WindowIterator
end()
const;
622 const int m_nRasterXSize;
623 const int m_nRasterYSize;
630 WindowIteratorWrapper IterateWindows(
size_t maxSize = 0)
const;
660 virtual void EnablePixelTypeSignedByteWarning(
bool b)
661#ifndef GDAL_COMPILATION
662 CPL_WARN_DEPRECATED(
"Do not use that method outside of GDAL!")
673#define GDAL_EXTERN_TEMPLATE_READ_RASTER(T) \
674 extern template CPLErr GDALRasterBand::ReadRaster<T>( \
675 T * pData, size_t nArrayEltCount, double dfXOff, double dfYOff, \
676 double dfXSize, double dfYSize, size_t nBufXSize, size_t nBufYSize, \
677 GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
678 void *pProgressData) const;
680GDAL_EXTERN_TEMPLATE_READ_RASTER(uint8_t)
681GDAL_EXTERN_TEMPLATE_READ_RASTER(int8_t)
682GDAL_EXTERN_TEMPLATE_READ_RASTER(uint16_t)
683GDAL_EXTERN_TEMPLATE_READ_RASTER(int16_t)
684GDAL_EXTERN_TEMPLATE_READ_RASTER(uint32_t)
685GDAL_EXTERN_TEMPLATE_READ_RASTER(int32_t)
686GDAL_EXTERN_TEMPLATE_READ_RASTER(uint64_t)
687GDAL_EXTERN_TEMPLATE_READ_RASTER(int64_t)
688#ifdef CPL_FLOAT_H_INCLUDED
689GDAL_EXTERN_TEMPLATE_READ_RASTER(GFloat16)
691GDAL_EXTERN_TEMPLATE_READ_RASTER(
float)
692GDAL_EXTERN_TEMPLATE_READ_RASTER(
double)
696GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<float>)
697GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<double>)
699#define GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(T) \
700 extern template CPLErr GDALRasterBand::ReadRaster<T>( \
701 std::vector<T> & vData, double dfXOff, double dfYOff, double dfXSize, \
702 double dfYSize, size_t nBufXSize, size_t nBufYSize, \
703 GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
704 void *pProgressData) const;
706GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint8_t)
707GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int8_t)
708GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint16_t)
709GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int16_t)
710GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint32_t)
711GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int32_t)
712GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint64_t)
713GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int64_t)
714#ifdef CPL_FLOAT_H_INCLUDED
715GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(GFloat16)
717GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(
float)
718GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(
double)
722GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<float>)
723GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<double>)
727#include "gdal_computedrasterband.h"
A color table / palette.
Definition gdal_colortable.h:32
Class represented the result of an operation on one or two input bands.
Definition gdal_computedrasterband.h:39
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
Class modeling a multi-dimensional array.
Definition gdal_multidim.h:852
Object with metadata.
Definition gdal_majorobject.h:43
virtual const char * GetMetadataItem(const char *pszName, const char *pszDomain="")
Fetch single metadata item.
Definition gdalmajorobject.cpp:322
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition gdal_rat.h:48
A single raster band (or channel).
Definition gdal_rasterband.h:105
void static GDALRasterBandH ToHandle(GDALRasterBand *poBand)
Convert a GDALRasterBand* to a GDALRasterBandH.
Definition gdal_rasterband.h:645
virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData)=0
Default internal implementation ... to be overridden by subclasses that support reading.
CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override
Set metadata.
CPLErr SetMetadataItem(const char *pszName, const char *pszValue, const char *pszDomain) override
Set single metadata item.
static GDALRasterBand * FromHandle(GDALRasterBandH hBand)
Convert a GDALRasterBandH to a GDALRasterBand*.
Definition gdal_rasterband.h:652
A single raster block in the block cache.
Definition gdal_rasterblock.h:33
A rectangular subset of pixels within a raster.
Definition gdal_rasterband.h:87
int nXSize
window width
Definition gdal_rasterband.h:96
int nYOff
top offset of the window
Definition gdal_rasterband.h:93
int nXOff
left offset of the window
Definition gdal_rasterband.h:90
int nYSize
window height
Definition gdal_rasterband.h:99
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:152
CPLErr
Error category.
Definition cpl_error.h:37
int CPLErrorNum
Error number.
Definition cpl_error.h:80
Core portability definitions for CPL.
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:208
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:844
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1087
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:870
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:205
Public (C callable) GDAL entry points.
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:386
GDALAccess
Definition gdal.h:118
@ GA_ReadOnly
Definition gdal.h:119
GDALDataType
Definition gdal.h:48
@ GDT_Byte
Definition gdal.h:50
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:135
@ GRIORA_NearestNeighbour
Definition gdal.h:136
GDALColorInterp
Types of color interpretation for raster bands.
Definition gdal.h:270
GDALRWFlag
Definition gdal.h:125
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal_fwd.h:45
OGRLayer::FeatureIterator begin(OGRLayer *poLayer)
Return begin of feature iterator.
Definition ogrsf_frmts.h:470
OGRLayer::FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition ogrsf_frmts.h:478