15#ifndef GDALRASTERBAND_H_INCLUDED
16#define GDALRASTERBAND_H_INCLUDED
20#include "gdal_majorobject.h"
27#if __cplusplus >= 201703L
30#if __cplusplus >= 202002L
36#if !defined(OPTIONAL_OUTSIDE_GDAL)
37#if defined(GDAL_COMPILATION)
38#define OPTIONAL_OUTSIDE_GDAL(val)
40#define OPTIONAL_OUTSIDE_GDAL(val) = val
49class GDALAbstractBandBlockCache;
52class GDALDoublePointsCache;
68typedef int GDALSuggestedBlockAccessPattern;
71constexpr GDALSuggestedBlockAccessPattern GSBAP_UNKNOWN = 0;
74constexpr GDALSuggestedBlockAccessPattern GSBAP_RANDOM = 1;
77constexpr GDALSuggestedBlockAccessPattern GSBAP_TOP_TO_BOTTOM = 2;
80constexpr GDALSuggestedBlockAccessPattern GSBAP_BOTTOM_TO_TOP = 3;
84constexpr GDALSuggestedBlockAccessPattern GSBAP_LARGEST_CHUNK_POSSIBLE = 0x100;
110 friend class GDALArrayBandBlockCache;
111 friend class GDALHashSetBandBlockCache;
116 GDALAbstractBandBlockCache *poBandBlockCache =
nullptr;
118 CPL_INTERNAL
void SetFlushBlockErr(
CPLErr eErr);
120 CPL_INTERNAL
void IncDirtyBlocks(
int nInc);
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,
128 CPL_INTERNAL
bool HasNoData()
const;
142 int nRasterXSize = 0;
143 int nRasterYSize = 0;
149 int nBlockXSize = -1;
150 int nBlockYSize = -1;
151 int nBlocksPerRow = 0;
152 int nBlocksPerColumn = 0;
155 int bForceCachedIO = 0;
158 friend class GDALComputedDataset;
160 class GDALRasterBandOwnedOrNot
163 GDALRasterBandOwnedOrNot() =
default;
165 GDALRasterBandOwnedOrNot(GDALRasterBandOwnedOrNot &&) =
default;
169 m_poBandOwned.reset();
170 m_poBandRef =
nullptr;
175 m_poBandOwned.reset();
176 m_poBandRef = poBand;
179 void reset(std::unique_ptr<GDALRasterBand> poBand)
181 m_poBandOwned = std::move(poBand);
182 m_poBandRef =
nullptr;
197 return m_poBandOwned !=
nullptr;
202 return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
207 return m_poBandOwned ? m_poBandOwned.get() : m_poBandRef;
212 std::unique_ptr<GDALRasterBand> m_poBandOwned{};
216 GDALRasterBandOwnedOrNot poMask{};
217 bool m_bEnablePixelTypeSignedByteWarning =
221 void InvalidateMaskBand();
223 friend class GDALProxyRasterBand;
224 friend class GDALDefaultOverviews;
227 RasterIOResampled(
GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
228 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
234 void LeaveReadWrite();
238 mutable GDALDoublePointsCache *m_poPointsCache =
nullptr;
244 virtual CPLErr IWriteBlock(
int nBlockXOff,
int nBlockYOff,
void *pData);
247 IRasterIO(
GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
int nYSize,
248 void *pData,
int nBufXSize,
int nBufYSize,
GDALDataType eBufType,
252 virtual int IGetDataCoverageStatus(
int nXOff,
int nYOff,
int nXSize,
253 int nYSize,
int nMaskFlagStop,
257 EmitErrorMessageIfWriteNotSupported(
const char *pszCaller)
const;
261 OverviewRasterIO(
GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
262 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
268 int nXSize,
int nYSize,
void *pData,
269 int nBufXSize,
int nBufYSize,
275 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
284 bool HasBlockCache()
const
286 return poBandBlockCache !=
nullptr;
289 bool HasDirtyBlocks()
const;
296 int GetXSize()
const;
297 int GetYSize()
const;
302 void GetBlockSize(
int *pnXSize,
int *pnYSize)
const;
303 CPLErr GetActualBlockSize(
int nXBlockOff,
int nYBlockOff,
int *pnXValid,
304 int *pnYValid)
const;
306 virtual GDALSuggestedBlockAccessPattern
307 GetSuggestedBlockAccessPattern()
const;
313 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
320 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
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,
331 GDALProgressFunc pfnProgress =
nullptr,
332 void *pProgressData =
nullptr)
const;
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,
339 GDALProgressFunc pfnProgress =
nullptr,
340 void *pProgressData =
nullptr)
const;
342#if __cplusplus >= 202002L
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,
350 GDALProgressFunc pfnProgress =
nullptr,
351 void *pProgressData =
nullptr)
const
353 return ReadRaster(pData.data(), pData.size(), dfXOff, dfYOff, dfXSize,
354 dfYSize, nBufXSize, nBufYSize, eResampleAlg,
355 pfnProgress, pProgressData);
422#pragma GCC diagnostic push
423#pragma GCC diagnostic ignored "-Weffc++"
439#pragma GCC diagnostic pop
448 CPLErr ReadBlock(
int nXBlockOff,
int nYBlockOff,
451 CPLErr WriteBlock(
int nXBlockOff,
int nYBlockOff,
456 GetLockedBlockRef(
int nXBlockOff,
int nYBlockOff,
461 TryGetLockedBlockRef(
int nXBlockOff,
465 virtual
CPLErr FlushBlock(
int nXBlockOff,
int nYBlockOff,
466 int bWriteDirtyBlock = TRUE);
470 unsigned char *pTranslationTable =
nullptr,
471 int *pApproximateMatching =
nullptr);
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);
482#if __cplusplus >= 201703L
483 template <
class T>
inline std::optional<T> GetNoDataValue()
const
485 int bSuccess =
false;
486 if constexpr (std::is_same_v<T, int64_t>)
495 else if constexpr (std::is_same_v<T, uint64_t>)
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();
522 virtual CPLErr Fill(
double dfRealValue,
double dfImaginaryValue = 0);
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();
533 virtual CPLErr SetOffset(
double dfNewOffset);
534 virtual CPLErr SetScale(
double dfNewScale);
535 virtual CPLErr SetUnitType(
const char *pszNewValue);
537 virtual CPLErr GetStatistics(
int bApproxOK,
int bForce,
double *pdfMin,
538 double *pdfMax,
double *pdfMean,
540 virtual CPLErr ComputeStatistics(
int bApproxOK,
double *pdfMin,
541 double *pdfMax,
double *pdfMean,
542 double *pdfStdDev, GDALProgressFunc,
543 void *pProgressData);
544 virtual CPLErr SetStatistics(
double dfMin,
double dfMax,
double dfMean,
546 virtual CPLErr ComputeRasterMinMax(
int bApproxOK,
double *adfMinMax);
547 virtual CPLErr ComputeRasterMinMaxLocation(
double *pdfMin,
double *pdfMax,
548 int *pnMinX,
int *pnMinY,
549 int *pnMaxX,
int *pnMaxY);
555 const char *pszDomain)
override;
558 const char *pszDomain =
"")
override;
560 virtual int HasArbitraryOverviews();
561 virtual int GetOverviewCount();
564 virtual CPLErr BuildOverviews(
const char *pszResampling,
int nOverviews,
565 const int *panOverviewList,
566 GDALProgressFunc pfnProgress,
570 virtual CPLErr AdviseRead(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
571 int nBufXSize,
int nBufYSize,
574 virtual CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
575 GUIntBig *panHistogram,
int bIncludeOutOfRange,
576 int bApproxOK, GDALProgressFunc,
577 void *pProgressData);
579 virtual CPLErr GetDefaultHistogram(
double *pdfMin,
double *pdfMax,
580 int *pnBuckets,
GUIntBig **ppanHistogram,
581 int bForce, GDALProgressFunc,
582 void *pProgressData);
583 virtual CPLErr SetDefaultHistogram(
double dfMin,
double dfMax,
int nBuckets,
590 virtual int GetMaskFlags();
591 virtual CPLErr CreateMaskBand(
int nFlagsIn);
592 virtual bool IsMaskBand()
const;
593 virtual GDALMaskValueRange GetMaskValueRange()
const;
594 bool HasConflictingMaskSources(std::string *posDetailMessage =
nullptr,
595 bool bMentionPrioritarySource =
true)
const;
598 GetVirtualMemAuto(
GDALRWFlag eRWFlag,
int *pnPixelSpace,
602 int GetDataCoverageStatus(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
603 int nMaskFlagStop = 0,
604 double *pdfDataPct =
nullptr);
606 std::shared_ptr<GDALMDArray> AsMDArray()
const;
608 CPLErr InterpolateAtGeolocation(
611 double *pdfImagValue =
nullptr,
614 virtual CPLErr InterpolateAtPoint(
double dfPixel,
double dfLine,
616 double *pdfRealValue,
617 double *pdfImagValue =
nullptr)
const;
620 class CPL_DLL WindowIterator
623 using iterator_category = std::input_iterator_tag;
624 using difference_type = std::ptrdiff_t;
627 using pointer = value_type *;
628 using reference = value_type &;
630 WindowIterator(
int nRasterXSize,
int nRasterYSize,
int nBlockXSize,
631 int nBlockYSize,
int nRow,
int nCol);
633 bool operator==(
const WindowIterator &other)
const;
635 bool operator!=(
const WindowIterator &other)
const;
637 value_type operator*()
const;
639 WindowIterator &operator++();
650 class CPL_DLL WindowIteratorWrapper
660 uint64_t count()
const;
662 WindowIterator
begin()
const;
664 WindowIterator
end()
const;
667 const int m_nRasterXSize;
668 const int m_nRasterYSize;
672 WindowIteratorWrapper(
int nRasterXSize,
int nRasterYSize,
673 int nBlockXSize,
int nBlockYSize,
size_t maxSize);
678 WindowIteratorWrapper IterateWindows(
size_t maxSize = 0)
const;
680 virtual bool MayMultiBlockReadingBeMultiThreaded()
const;
710 virtual void EnablePixelTypeSignedByteWarning(
bool b)
711#ifndef GDAL_COMPILATION
712 CPL_WARN_DEPRECATED(
"Do not use that method outside of GDAL!")
723#define GDAL_EXTERN_TEMPLATE_READ_RASTER(T) \
724 extern template CPLErr GDALRasterBand::ReadRaster<T>( \
725 T * pData, size_t nArrayEltCount, double dfXOff, double dfYOff, \
726 double dfXSize, double dfYSize, size_t nBufXSize, size_t nBufYSize, \
727 GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
728 void *pProgressData) const;
730GDAL_EXTERN_TEMPLATE_READ_RASTER(uint8_t)
731GDAL_EXTERN_TEMPLATE_READ_RASTER(int8_t)
732GDAL_EXTERN_TEMPLATE_READ_RASTER(uint16_t)
733GDAL_EXTERN_TEMPLATE_READ_RASTER(int16_t)
734GDAL_EXTERN_TEMPLATE_READ_RASTER(uint32_t)
735GDAL_EXTERN_TEMPLATE_READ_RASTER(int32_t)
736GDAL_EXTERN_TEMPLATE_READ_RASTER(uint64_t)
737GDAL_EXTERN_TEMPLATE_READ_RASTER(int64_t)
738#ifdef CPL_FLOAT_H_INCLUDED
739GDAL_EXTERN_TEMPLATE_READ_RASTER(GFloat16)
741GDAL_EXTERN_TEMPLATE_READ_RASTER(
float)
742GDAL_EXTERN_TEMPLATE_READ_RASTER(
double)
746GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<float>)
747GDAL_EXTERN_TEMPLATE_READ_RASTER(std::complex<double>)
749#define GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(T) \
750 extern template CPLErr GDALRasterBand::ReadRaster<T>( \
751 std::vector<T> & vData, double dfXOff, double dfYOff, double dfXSize, \
752 double dfYSize, size_t nBufXSize, size_t nBufYSize, \
753 GDALRIOResampleAlg eResampleAlg, GDALProgressFunc pfnProgress, \
754 void *pProgressData) const;
756GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint8_t)
757GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int8_t)
758GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint16_t)
759GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int16_t)
760GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint32_t)
761GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int32_t)
762GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(uint64_t)
763GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(int64_t)
764#ifdef CPL_FLOAT_H_INCLUDED
765GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(GFloat16)
767GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(
float)
768GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(
double)
772GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<float>)
773GDAL_EXTERN_TEMPLATE_READ_RASTER_VECTOR(std::complex<double>)
777#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:77
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:108
void static GDALRasterBandH ToHandle(GDALRasterBand *poBand)
Convert a GDALRasterBand* to a GDALRasterBandH.
Definition gdal_rasterband.h:695
CPLErr SetMetadata(char **papszMetadata, const char *pszDomain) override
Set metadata.
virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData)=0
Default internal implementation ... to be overridden by subclasses that support reading.
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:702
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:90
int nXSize
window width
Definition gdal_rasterband.h:99
int nYOff
top offset of the window
Definition gdal_rasterband.h:96
int nXOff
left offset of the window
Definition gdal_rasterband.h:93
int nYSize
window height
Definition gdal_rasterband.h:102
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:152
CPLErr
Error category / error level.
Definition cpl_error.h:45
@ CE_None
No error.
Definition cpl_error.h:47
int CPLErrorNum
Error number.
Definition cpl_error.h:103
Core portability definitions for CPL.
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:198
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:1009
#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:1101
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:1035
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:195
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition cpl_virtualmem.h:45
Public (C callable) GDAL entry points.
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:412
GDALAccess
Definition gdal.h:120
@ GA_ReadOnly
Definition gdal.h:121
GDALDataType
Definition gdal.h:48
@ GDT_UInt8
Definition gdal.h:50
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:137
@ GRIORA_NearestNeighbour
Definition gdal.h:138
GDALColorInterp
Types of color interpretation for raster bands.
Definition gdal.h:294
GDALRWFlag
Definition gdal.h:127
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:478
OGRLayer::FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition ogrsf_frmts.h:486