14#ifndef VIRTUALDATASET_H_INCLUDED
15#define VIRTUALDATASET_H_INCLUDED
21#include "gdal_driver.h"
22#include "gdal_multidim.h"
35CPLErr GDALRegisterDefaultPixelFunc();
36void GDALVRTRegisterDefaultProcessedDatasetFuncs();
41int VRTWarpedOverviewTransform(
void *pTransformArg,
int bDstToSrc,
43 double *padfX,
double *padfY,
double *padfZ,
45void* VRTDeserializeWarpedOverviewTransformer(
CPLXMLNode *psTree );
59 int bTriedToOpen = FALSE;
61 VRTOverviewInfo() =
default;
63 VRTOverviewInfo(VRTOverviewInfo &&oOther) noexcept
64 : osFilename(std::move(oOther.osFilename)), nBand(oOther.nBand),
65 poBand(oOther.poBand), bTriedToOpen(oOther.bTriedToOpen)
67 oOther.poBand =
nullptr;
77 if (poBand ==
nullptr)
97class CPL_DLL VRTMapSharedResources
100 VRTMapSharedResources() =
default;
108 void Insert(
const std::string &osKey,
GDALDataset *poDS);
116 mutable std::mutex m_oMutex{};
117 bool m_bUseMutex =
false;
118 std::map<std::string, GDALDataset *> m_oMap{};
120 std::unique_ptr<std::lock_guard<std::mutex>> LockGuard()
const;
129class CPL_DLL VRTSource
132 struct CPL_DLL WorkingState
136#pragma GCC diagnostic push
137#pragma GCC diagnostic ignored "-Weffc++"
153 inline operator GByte()
const
159#pragma GCC diagnostic pop
162 std::vector<NoInitByte> m_abyWrkBuffer{};
163 std::vector<NoInitByte> m_abyWrkBufferMask{};
166 virtual ~VRTSource();
169 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
173 WorkingState &oWorkingState) = 0;
175 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess) = 0;
176 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess) = 0;
177 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
178 double dfMax,
int nBuckets,
179 GUIntBig *panHistogram,
int bIncludeOutOfRange,
180 int bApproxOK, GDALProgressFunc pfnProgress,
181 void *pProgressData) = 0;
184 VRTMapSharedResources &) = 0;
185 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath) = 0;
187 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
193 virtual bool IsSimpleSource()
const
198 const std::string &GetName()
const
203 void SetName(
const std::string &s)
211 virtual const char *GetType()
const = 0;
213 virtual CPLErr FlushCache(
bool )
219 std::string m_osName{};
222typedef VRTSource *(*VRTSourceParser)(
const CPLXMLNode *,
const char *,
223 VRTMapSharedResources &oMapSharedSources);
225VRTSource *VRTParseCoreSources(
const CPLXMLNode *psTree,
const char *,
226 VRTMapSharedResources &oMapSharedSources);
227VRTSource *VRTParseFilterSources(
const CPLXMLNode *psTree,
const char *,
228 VRTMapSharedResources &oMapSharedSources);
229VRTSource *VRTParseArraySource(
const CPLXMLNode *psTree,
const char *,
230 VRTMapSharedResources &oMapSharedSources);
238template <
class T>
struct VRTFlushCacheStruct
240 static CPLErr FlushCache(T &obj,
bool bAtClosing);
243class VRTWarpedDataset;
244class VRTPansharpenedDataset;
245class VRTProcessedDataset;
247class VRTSimpleSource;
251 friend class VRTRasterBand;
252 friend struct VRTFlushCacheStruct<VRTDataset>;
253 friend struct VRTFlushCacheStruct<VRTWarpedDataset>;
254 friend struct VRTFlushCacheStruct<VRTPansharpenedDataset>;
255 friend struct VRTFlushCacheStruct<VRTProcessedDataset>;
256 friend class VRTSourcedRasterBand;
257 friend class VRTDerivedRasterBand;
258 friend class VRTSimpleSource;
259 friend struct VRTSourcedRasterBandRasterIOJob;
262 std::vector<gdal::GCP> m_asGCPs{};
263 std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser>
266 bool m_bNeedsFlush =
false;
267 bool m_bWritable =
true;
268 bool m_bCanTakeRef =
true;
270 char *m_pszVRTPath =
nullptr;
272 std::unique_ptr<VRTRasterBand> m_poMaskBand{};
274 mutable int m_nCompatibleForDatasetIO = -1;
275 bool CheckCompatibleForDatasetIO()
const;
279 std::vector<GDALDataset *> m_apoOverviews{};
280 std::vector<GDALDataset *> m_apoOverviewsBak{};
283 std::vector<int> m_anOverviewFactors{};
285 char **m_papszXMLVRTMetadata =
nullptr;
287 VRTMapSharedResources m_oMapSharedSources{};
288 std::shared_ptr<VRTGroup> m_poRootGroup{};
291 VRTSource::WorkingState m_oWorkingState{};
294 struct QueueWorkingStates
297 std::vector<std::unique_ptr<VRTSource::WorkingState>> oStates{};
300 QueueWorkingStates m_oQueueWorkingStates{};
302 bool m_bMultiThreadedRasterIOLastUsed =
false;
304 std::unique_ptr<VRTRasterBand> InitBand(
const char *pszSubclass,
int nBand,
305 bool bAllowPansharpenedOrProcessed);
306 static GDALDataset *OpenVRTProtocol(
const char *pszSpec);
307 bool AddVirtualOverview(
int nOvFactor,
const char *pszResampling);
309 bool GetShiftedDataset(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
313 static bool IsDefaultBlockSize(
int nBlockSize,
int nDimension);
318 bool m_bBlockSizeSpecified =
false;
319 int m_nBlockXSize = 0;
320 int m_nBlockYSize = 0;
322 std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser> m_poSRS{};
324 int m_bGeoTransformSet =
false;
327 int CloseDependentDatasets()
override;
330 VRTDataset(
int nXSize,
int nYSize,
int nBlockXSize = 0,
331 int nBlockYSize = 0);
332 ~VRTDataset()
override;
336 m_bNeedsFlush =
true;
339 CPLErr FlushCache(
bool bAtClosing)
override;
341 void SetWritable(
int bWritableIn)
343 m_bWritable = CPL_TO_BOOL(bWritableIn);
346 CPLErr CreateMaskBand(
int nFlags)
override;
347 void SetMaskBand(std::unique_ptr<VRTRasterBand> poMaskBand);
351 return m_poSRS.get();
359 CPLErr SetMetadata(
char **papszMetadata,
360 const char *pszDomain =
"")
override;
361 CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
362 const char *pszDomain =
"")
override;
364 char **GetMetadata(
const char *pszDomain =
"")
override;
365 virtual const char *GetMetadataItem(
const char *pszName,
366 const char *pszDomain =
"")
override;
368 int GetGCPCount()
override;
372 return m_poGCP_SRS.get();
381 char **papszOptions =
nullptr)
override;
383 char **GetFileList()
override;
386 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
388 BANDMAP_TYPE panBandMap,
GSpacing nPixelSpace,
393 GetCompressionFormats(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
394 int nBandCount,
const int *panBandList)
override;
395 virtual CPLErr ReadCompressedData(
const char *pszFormat,
int nXOff,
396 int nYOff,
int nXSize,
int nYSize,
397 int nBandCount,
const int *panBandList,
398 void **ppBuffer,
size_t *pnBufferSize,
399 char **ppszDetailedFormat)
override;
401 CPLErr AdviseRead(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
403 int nBandCount,
int *panBandList,
404 char **papszOptions)
override;
406 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath);
409 CPLErr IBuildOverviews(
const char *,
int,
const int *,
int,
const int *,
410 GDALProgressFunc,
void *,
413 std::shared_ptr<GDALGroup> GetRootGroup()
const override;
415 std::shared_ptr<VRTGroup> GetRootVRTGroup()
const
417 return m_poRootGroup;
420 void ClearStatistics()
override;
425 m_nCompatibleForDatasetIO = -1;
430 void BuildVirtualOverviews();
432 void UnsetPreservedRelativeFilenames();
434 bool IsBlockSizeSpecified()
const
436 return m_bBlockSizeSpecified;
439 int GetBlockXSize()
const
441 return m_nBlockXSize;
444 int GetBlockYSize()
const
446 return m_nBlockYSize;
451 static std::unique_ptr<VRTDataset>
452 OpenXML(
const char *,
const char * =
nullptr,
454 static GDALDataset *Create(
const char *pszName,
int nXSize,
int nYSize,
456 char **papszOptions);
457 static std::unique_ptr<VRTDataset>
458 CreateVRTDataset(
const char *pszName,
int nXSize,
int nYSize,
int nBands,
461 CreateMultiDimensional(
const char *pszFilename,
464 static std::unique_ptr<VRTDataset>
465 CreateVRTMultiDimensional(
const char *pszFilename,
468 static CPLErr Delete(
const char *pszFilename);
472 static bool IsRawRasterBandEnabled();
480class VRTWarpedRasterBand;
482class CPL_DLL VRTWarpedDataset final :
public VRTDataset
486 bool m_bIsOverview =
false;
487 std::vector<VRTWarpedDataset *> m_apoOverviews{};
490 bool GetOverviewSize(
GDALDataset *poSrcDS,
int iOvr,
int iSrcOvr,
491 int &nOvrXSize,
int &nOvrYSize,
double &dfSrcRatioX,
492 double &dfSrcRatioY)
const;
493 int GetOverviewCount()
const;
494 int GetSrcOverviewLevel(
int iOvr,
bool &bThisLevelOnlyOut)
const;
495 VRTWarpedDataset *CreateImplicitOverview(
int iOvr)
const;
496 void CreateImplicitOverviews();
498 friend class VRTWarpedRasterBand;
503 int CloseDependentDatasets()
override;
506 VRTWarpedDataset(
int nXSize,
int nYSize,
int nBlockXSize = 0,
507 int nBlockYSize = 0);
508 ~VRTWarpedDataset()
override;
510 CPLErr FlushCache(
bool bAtClosing)
override;
512 CPLErr Initialize(
void *);
514 CPLErr IBuildOverviews(
const char *,
int,
const int *,
int,
const int *,
515 GDALProgressFunc,
void *,
518 CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
519 const char *pszDomain =
"")
override;
521 CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
525 char **papszOptions =
nullptr)
override;
527 char **GetFileList()
override;
530 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
532 BANDMAP_TYPE panBandMap,
GSpacing nPixelSpace,
536 CPLErr ProcessBlock(
int iBlockX,
int iBlockY);
538 void GetBlockSize(
int *,
int *)
const;
550 GTAdjust_Intersection,
552 GTAdjust_NoneWithoutWarning
555class VRTPansharpenedDataset final :
public VRTDataset
557 friend class VRTPansharpenedRasterBand;
559 std::unique_ptr<GDALPansharpenOperation> m_poPansharpener{};
560 VRTPansharpenedDataset *m_poMainDataset;
561 std::vector<std::unique_ptr<VRTPansharpenedDataset>>
562 m_apoOverviewDatasets{};
564 std::map<CPLString, CPLString> m_oMapToRelativeFilenames{};
566 int m_bLoadingOtherBands;
568 GByte *m_pabyLastBufferBandRasterIO;
569 int m_nLastBandRasterIOXOff;
570 int m_nLastBandRasterIOYOff;
571 int m_nLastBandRasterIOXSize;
572 int m_nLastBandRasterIOYSize;
575 GTAdjustment m_eGTAdjustment;
576 int m_bNoDataDisabled;
578 std::vector<std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser>>
579 m_apoDatasetsToReleaseRef{};
584 int CloseDependentDatasets()
override;
587 VRTPansharpenedDataset(
int nXSize,
int nYSize,
int nBlockXSize = 0,
588 int nBlockYSize = 0);
589 ~VRTPansharpenedDataset()
override;
591 CPLErr FlushCache(
bool bAtClosing)
override;
594 CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
601 char **papszOptions =
nullptr)
override;
603 char **GetFileList()
override;
606 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
608 BANDMAP_TYPE panBandMap,
GSpacing nPixelSpace,
612 void GetBlockSize(
int *,
int *)
const;
616 return m_poPansharpener.get();
629class VRTProcessedDataset final :
public VRTDataset
632 VRTProcessedDataset(
int nXSize,
int nYSize);
633 ~VRTProcessedDataset()
override;
635 CPLErr FlushCache(
bool bAtClosing)
override;
638 CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
640 void GetBlockSize(
int *,
int *)
const;
644#pragma GCC diagnostic push
645#pragma GCC diagnostic ignored "-Weffc++"
661 inline operator GByte()
const
667#pragma GCC diagnostic pop
672 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
674 BANDMAP_TYPE panBandMap,
GSpacing nPixelSpace,
679 friend class VRTProcessedRasterBand;
685 std::string osAlgorithm{};
703 std::vector<double> adfInNoData{};
706 std::vector<double> adfOutNoData{};
717 Step &operator=(Step &&);
720 Step(
const Step &) =
delete;
721 Step &operator=(
const Step &) =
delete;
726 std::string m_osVRTPath{};
729 std::unique_ptr<GDALDataset> m_poVRTSrcDS{};
732 std::unique_ptr<GDALDataset> m_poSrcDS{};
735 std::vector<Step> m_aoSteps{};
741 std::vector<std::unique_ptr<GDALDataset>> m_apoOverviewDatasets{};
744 std::vector<NoInitByte> m_abyInput{};
747 std::vector<NoInitByte> m_abyOutput{};
750 enum class ValueProvenance
759 ValueProvenance m_outputBandCountProvenance = ValueProvenance::FROM_SOURCE;
762 int m_outputBandCountValue = 0;
765 ValueProvenance m_outputBandDataTypeProvenance =
766 ValueProvenance::FROM_SOURCE;
772 int m_nWorkingBytesPerPixel = 1;
775 GIntBig m_nAllowedRAMUsage = 0;
778 const VRTProcessedDataset *poParentDS,
781 bool ParseStep(
const CPLXMLNode *psStep,
bool bIsFinalStep,
783 std::vector<double> &adfInNoData,
784 std::vector<double> &adfOutNoData);
785 bool ProcessRegion(
int nXOff,
int nYOff,
int nBufXSize,
int nBufYSize,
786 GDALProgressFunc pfnProgress,
void *pProgressData);
796constexpr double VRT_DEFAULT_NODATA_VALUE = -10000.0;
801 void ResetNoDataValues();
804 friend class VRTDataset;
806 bool m_bIsMaskBand =
false;
808 bool m_bNoDataValueSet =
false;
810 int m_bHideNoDataValue =
false;
811 double m_dfNoDataValue = VRT_DEFAULT_NODATA_VALUE;
813 bool m_bNoDataSetAsInt64 =
false;
814 int64_t m_nNoDataValueInt64 = GDAL_PAM_DEFAULT_NODATA_VALUE_INT64;
816 bool m_bNoDataSetAsUInt64 =
false;
817 uint64_t m_nNoDataValueUInt64 = GDAL_PAM_DEFAULT_NODATA_VALUE_UINT64;
819 std::unique_ptr<GDALColorTable> m_poColorTable{};
823 std::string m_osUnitType{};
826 double m_dfOffset = 0.0;
827 double m_dfScale = 1.0;
831 void Initialize(
int nXSize,
int nYSize);
833 std::vector<VRTOverviewInfo> m_aoOverviewInfos{};
835 std::unique_ptr<VRTRasterBand> m_poMaskBand{};
837 std::unique_ptr<GDALRasterAttributeTable> m_poRAT{};
841 bool IsNoDataValueInDataTypeRange()
const;
845 ~VRTRasterBand()
override;
848 VRTMapSharedResources &);
849 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
850 bool &bHasWarnedAboutRAMUsage,
851 size_t &nAccRAMUsage);
853 CPLErr SetNoDataValue(
double)
override;
854 CPLErr SetNoDataValueAsInt64(int64_t nNoData)
override;
855 CPLErr SetNoDataValueAsUInt64(uint64_t nNoData)
override;
856 double GetNoDataValue(
int *pbSuccess =
nullptr)
override;
857 int64_t GetNoDataValueAsInt64(
int *pbSuccess =
nullptr)
override;
858 uint64_t GetNoDataValueAsUInt64(
int *pbSuccess =
nullptr)
override;
859 CPLErr DeleteNoDataValue()
override;
871 const char *GetUnitType()
override;
872 CPLErr SetUnitType(
const char *)
override;
874 char **GetCategoryNames()
override;
875 CPLErr SetCategoryNames(
char **)
override;
877 CPLErr SetMetadata(
char **papszMD,
const char *pszDomain =
"")
override;
878 CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
879 const char *pszDomain =
"")
override;
881 double GetOffset(
int *pbSuccess =
nullptr)
override;
882 CPLErr SetOffset(
double)
override;
883 double GetScale(
int *pbSuccess =
nullptr)
override;
884 CPLErr SetScale(
double)
override;
886 int GetOverviewCount()
override;
889 CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
890 GUIntBig *panHistogram,
int bIncludeOutOfRange,
891 int bApproxOK, GDALProgressFunc,
892 void *pProgressData)
override;
894 CPLErr GetDefaultHistogram(
double *pdfMin,
double *pdfMax,
int *pnBuckets,
895 GUIntBig **ppanHistogram,
int bForce,
896 GDALProgressFunc,
void *pProgressData)
override;
898 virtual CPLErr SetDefaultHistogram(
double dfMin,
double dfMax,
int nBuckets,
903 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
906 void SetDescription(
const char *)
override;
909 int GetMaskFlags()
override;
911 CPLErr CreateMaskBand(
int nFlagsIn)
override;
913 void SetMaskBand(std::unique_ptr<VRTRasterBand> poMaskBand);
915 void SetIsMaskBand();
917 bool IsMaskBand()
const override;
919 CPLErr UnsetNoDataValue();
921 virtual int CloseDependentDatasets();
923 virtual bool IsSourcedRasterBand()
928 virtual bool IsPansharpenRasterBand()
938class VRTSimpleSource;
940class CPL_DLL VRTSourcedRasterBand
CPL_NON_FINAL :
public VRTRasterBand
945 int m_nSkipBufferInitialization = -1;
947 bool CanUseSourcesMinMaxImplementations();
949 bool IsMosaicOfNonOverlappingSimpleSourcesOfFullRasterNoResAndTypeChange(
950 bool bAllowMaxValAdjustment)
const;
955 bool SkipBufferInitialization();
958 std::vector<std::unique_ptr<VRTSource>> m_papoSources{};
960 VRTSourcedRasterBand(
GDALDataset *poDS,
int nBand);
961 VRTSourcedRasterBand(
GDALDataType eType,
int nXSize,
int nYSize);
963 int nXSize,
int nYSize);
965 int nXSize,
int nYSize,
int nBlockXSizeIn,
967 ~VRTSourcedRasterBand()
override;
973 virtual int IGetDataCoverageStatus(
int nXOff,
int nYOff,
int nXSize,
974 int nYSize,
int nMaskFlagStop,
975 double *pdfDataPct)
override;
977 char **GetMetadataDomainList()
override;
978 virtual const char *GetMetadataItem(
const char *pszName,
979 const char *pszDomain =
"")
override;
980 char **GetMetadata(
const char *pszDomain =
"")
override;
981 CPLErr SetMetadata(
char **papszMetadata,
982 const char *pszDomain =
"")
override;
983 CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
984 const char *pszDomain =
"")
override;
987 VRTMapSharedResources &)
override;
988 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
989 bool &bHasWarnedAboutRAMUsage,
990 size_t &nAccRAMUsage)
override;
992 double GetMinimum(
int *pbSuccess =
nullptr)
override;
993 double GetMaximum(
int *pbSuccess =
nullptr)
override;
994 virtual CPLErr ComputeRasterMinMax(
int bApproxOK,
995 double *adfMinMax)
override;
996 virtual CPLErr ComputeStatistics(
int bApproxOK,
double *pdfMin,
997 double *pdfMax,
double *pdfMean,
999 GDALProgressFunc pfnProgress,
1000 void *pProgressData)
override;
1001 CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
1002 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1003 int bApproxOK, GDALProgressFunc pfnProgress,
1004 void *pProgressData)
override;
1006 CPLErr AddSource(std::unique_ptr<VRTSource>);
1008 CPLErr AddSource(VRTSource *);
1010 CPLErr AddSimpleSource(
const char *pszFilename,
int nBand,
1011 double dfSrcXOff = -1,
double dfSrcYOff = -1,
1012 double dfSrcXSize = -1,
double dfSrcYSize = -1,
1013 double dfDstXOff = -1,
double dfDstYOff = -1,
1014 double dfDstXSize = -1,
double dfDstYSize = -1,
1015 const char *pszResampling =
"near",
1019 double dfSrcYOff = -1,
double dfSrcXSize = -1,
1020 double dfSrcYSize = -1,
double dfDstXOff = -1,
1021 double dfDstYOff = -1,
double dfDstXSize = -1,
1022 double dfDstYSize = -1,
1023 const char *pszResampling =
"near",
1026 CPLErr AddComplexSource(
const char *pszFilename,
int nBand,
1027 double dfSrcXOff = -1,
double dfSrcYOff = -1,
1028 double dfSrcXSize = -1,
double dfSrcYSize = -1,
1029 double dfDstXOff = -1,
double dfDstYOff = -1,
1030 double dfDstXSize = -1,
double dfDstYSize = -1,
1031 double dfScaleOff = 0.0,
double dfScaleRatio = 1.0,
1033 int nColorTableComponent = 0);
1036 double dfSrcYOff = -1,
double dfSrcXSize = -1,
1037 double dfSrcYSize = -1,
double dfDstXOff = -1,
1038 double dfDstYOff = -1,
double dfDstXSize = -1,
1039 double dfDstYSize = -1,
double dfScaleOff = 0.0,
1040 double dfScaleRatio = 1.0,
1042 int nColorTableComponent = 0);
1045 double dfSrcYOff = -1,
double dfSrcXSize = -1,
1046 double dfSrcYSize = -1,
double dfDstXOff = -1,
1047 double dfDstYOff = -1,
double dfDstXSize = -1,
1048 double dfDstYSize = -1);
1053 void ConfigureSource(VRTSimpleSource *poSimpleSource,
1055 double dfSrcXOff,
double dfSrcYOff,
double dfSrcXSize,
1056 double dfSrcYSize,
double dfDstXOff,
double dfDstYOff,
1057 double dfDstXSize,
double dfDstYSize);
1059 void RemoveCoveredSources(
CSLConstList papszOptions =
nullptr);
1061 bool CanIRasterIOBeForwardedToEachSource(
1062 GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
int nYSize,
1065 bool CanMultiThreadRasterIO(
double dfXOff,
double dfYOff,
double dfXSize,
1067 int &nContributingSources)
const;
1069 CPLErr IReadBlock(
int,
int,
void *)
override;
1071 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
1072 int *pnMaxSize,
CPLHashSet *hSetFiles)
override;
1074 int CloseDependentDatasets()
override;
1076 bool IsSourcedRasterBand()
override
1081 CPLErr FlushCache(
bool bAtClosing)
override;
1088class CPL_DLL VRTWarpedRasterBand final :
public VRTRasterBand
1093 ~VRTWarpedRasterBand()
override;
1095 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1096 bool &bHasWarnedAboutRAMUsage,
1097 size_t &nAccRAMUsage)
override;
1099 CPLErr IReadBlock(
int,
int,
void *)
override;
1100 CPLErr IWriteBlock(
int,
int,
void *)
override;
1103 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
1108 int GetOverviewCount()
override;
1112 EmitErrorMessageIfWriteNotSupported(
const char *pszCaller)
const override;
1115 int m_nIRasterIOCounter =
1118 int GetBestOverviewLevel(
int &nXOff,
int &nYOff,
int &nXSize,
int &nYSize,
1119 int nBufXSize,
int nBufYSize,
1127class VRTPansharpenedRasterBand final :
public VRTRasterBand
1129 int m_nIndexAsPansharpenedBand;
1132 VRTPansharpenedRasterBand(
GDALDataset *poDS,
int nBand,
1134 ~VRTPansharpenedRasterBand()
override;
1136 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1137 bool &bHasWarnedAboutRAMUsage,
1138 size_t &nAccRAMUsage)
override;
1140 CPLErr IReadBlock(
int,
int,
void *)
override;
1143 int nYSize,
void *pData,
int nBufXSize,
int nBufYSize,
1148 int GetOverviewCount()
override;
1151 bool IsPansharpenRasterBand()
override
1156 void SetIndexAsPansharpenedBand(
int nIdx)
1158 m_nIndexAsPansharpenedBand = nIdx;
1161 int GetIndexAsPansharpenedBand()
const
1163 return m_nIndexAsPansharpenedBand;
1171class VRTProcessedRasterBand final :
public VRTRasterBand
1174 VRTProcessedRasterBand(VRTProcessedDataset *poDS,
int nBand,
1177 CPLErr IReadBlock(
int,
int,
void *)
override;
1179 int GetOverviewCount()
override;
1182 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1183 bool &bHasWarnedAboutRAMUsage,
1184 size_t &nAccRAMUsage)
override;
1191class VRTDerivedRasterBandPrivateData;
1193class CPL_DLL VRTDerivedRasterBand
CPL_NON_FINAL :
public VRTSourcedRasterBand
1195 VRTDerivedRasterBandPrivateData *m_poPrivate;
1196 bool InitializePython();
1197 CPLErr GetPixelFunctionArguments(
1198 const CPLString &,
const std::vector<int> &anMapBufferIdxToSourceIdx,
1199 int nXOff,
int nYOff, std::vector<std::pair<CPLString, CPLString>> &);
1211 VRTDerivedRasterBand(
GDALDataset *poDS,
int nBand);
1213 int nXSize,
int nYSize,
int nBlockXSizeIn = 0,
1214 int nBlockYSizeIn = 0);
1215 ~VRTDerivedRasterBand()
override;
1221 virtual int IGetDataCoverageStatus(
int nXOff,
int nYOff,
int nXSize,
1222 int nYSize,
int nMaskFlagStop,
1223 double *pdfDataPct)
override;
1225 static CPLErr AddPixelFunction(
const char *pszFuncNameIn,
1227 static CPLErr AddPixelFunction(
const char *pszFuncNameIn,
1229 const char *pszMetadata);
1231 static const std::pair<PixelFunc, std::string> *
1232 GetPixelFunction(
const char *pszFuncNameIn);
1234 static std::vector<std::string> GetPixelFunctionNames();
1236 void SetPixelFunctionName(
const char *pszFuncNameIn);
1237 void AddPixelFunctionArgument(
const char *pszArg,
const char *pszValue);
1238 void SetSkipNonContributingSources(
bool bSkip);
1240 void SetPixelFunctionLanguage(
const char *pszLanguage);
1243 VRTMapSharedResources &)
override;
1244 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1245 bool &bHasWarnedAboutRAMUsage,
1246 size_t &nAccRAMUsage)
override;
1248 double GetMinimum(
int *pbSuccess =
nullptr)
override;
1249 double GetMaximum(
int *pbSuccess =
nullptr)
override;
1250 virtual CPLErr ComputeRasterMinMax(
int bApproxOK,
1251 double *adfMinMax)
override;
1252 virtual CPLErr ComputeStatistics(
int bApproxOK,
double *pdfMin,
1253 double *pdfMax,
double *pdfMean,
1255 GDALProgressFunc pfnProgress,
1256 void *pProgressData)
override;
1257 CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
1258 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1259 int bApproxOK, GDALProgressFunc pfnProgress,
1260 void *pProgressData)
override;
1262 static void Cleanup();
1265#ifndef GDAL_VRT_DISABLE_RAWRASTERBAND
1272class CPL_DLL VRTRawRasterBand
CPL_NON_FINAL :
public VRTRasterBand
1274 RawRasterBand *m_poRawRaster;
1276 char *m_pszSourceFilename;
1277 int m_bRelativeToVRT;
1284 ~VRTRawRasterBand()
override;
1287 VRTMapSharedResources &)
override;
1288 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1289 bool &bHasWarnedAboutRAMUsage,
1290 size_t &nAccRAMUsage)
override;
1296 CPLErr IReadBlock(
int,
int,
void *)
override;
1297 CPLErr IWriteBlock(
int,
int,
void *)
override;
1299 CPLErr SetRawLink(
const char *pszFilename,
const char *pszVRTPath,
1301 int nPixelOffset,
int nLineOffset,
1302 const char *pszByteOrder);
1304 void ClearRawLink();
1308 char **papszOptions)
override;
1310 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
1311 int *pnMaxSize,
CPLHashSet *hSetFiles)
override;
1323 std::mutex m_oMutex{};
1324 std::map<std::string, VRTSourceParser> m_oMapSourceParser{};
1328 ~VRTDriver()
override;
1330 char **papszSourceParsers;
1333 char **
GetMetadata(
const char *pszDomain =
"")
override;
1335 const char *pszDomain =
"")
override;
1337 VRTSource *ParseSource(
const CPLXMLNode *psSrc,
const char *pszVRTPath,
1338 VRTMapSharedResources &oMapSharedSources);
1339 void AddSourceParser(
const char *pszElementName, VRTSourceParser pfnParser);
1346class CPL_DLL VRTSimpleSource
CPL_NON_FINAL :
public VRTSource
1352 VRTMapSharedResources *m_poMapSharedSources =
nullptr;
1363 bool m_bSrcDSNameFromVRT =
1366 void OpenSource()
const;
1371 friend class VRTSourcedRasterBand;
1372 friend class VRTDerivedRasterBand;
1373 friend class VRTDataset;
1374 friend class GDALTileIndexDataset;
1375 friend class GDALTileIndexBand;
1378 bool m_bGetMaskBand =
false;
1384 static constexpr double UNINIT_WINDOW = -1.0;
1386 double m_dfSrcXOff = UNINIT_WINDOW;
1387 double m_dfSrcYOff = UNINIT_WINDOW;
1388 double m_dfSrcXSize = UNINIT_WINDOW;
1389 double m_dfSrcYSize = UNINIT_WINDOW;
1391 double m_dfDstXOff = UNINIT_WINDOW;
1392 double m_dfDstYOff = UNINIT_WINDOW;
1393 double m_dfDstXSize = UNINIT_WINDOW;
1394 double m_dfDstYSize = UNINIT_WINDOW;
1398 int m_nMaxValue = 0;
1400 int m_bRelativeToVRTOri = -1;
1402 int m_nExplicitSharedStatus = -1;
1405 bool m_bDropRefOnSrcBand =
true;
1407 int NeedMaxValAdjustment()
const;
1411 return m_poRasterBand;
1416 m_poRasterBand = poBand;
1417 m_bDropRefOnSrcBand = bDropRef;
1426 bool IsSrcWinSet()
const
1428 return m_dfSrcXOff != UNINIT_WINDOW || m_dfSrcYOff != UNINIT_WINDOW ||
1429 m_dfSrcXSize != UNINIT_WINDOW || m_dfSrcYSize != UNINIT_WINDOW;
1433 bool IsDstWinSet()
const
1435 return m_dfDstXOff != UNINIT_WINDOW || m_dfDstYOff != UNINIT_WINDOW ||
1436 m_dfDstXSize != UNINIT_WINDOW || m_dfDstYSize != UNINIT_WINDOW;
1439 void AddSourceFilenameNode(
const char *pszVRTPath,
CPLXMLNode *psSrc);
1443 VRTSimpleSource(
const VRTSimpleSource *poSrcSource,
double dfXDstRatio,
1444 double dfYDstRatio);
1445 ~VRTSimpleSource()
override;
1448 VRTMapSharedResources &)
override;
1449 CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1453 void SetSrcBand(
const char *pszFilename,
int nBand);
1456 void SetSrcWindow(
double,
double,
double,
double);
1457 void SetDstWindow(
double,
double,
double,
double);
1458 void GetDstWindow(
double &,
double &,
double &,
double &)
const;
1459 bool DstWindowIntersects(
double dfXOff,
double dfYOff,
double dfXSize,
1460 double dfYSize)
const;
1462 const std::string &GetSourceDatasetName()
const
1464 return m_osSrcDSName;
1468 void SetSourceDatasetName(
const char *pszFilename,
bool bRelativeToVRT);
1472 return m_osResampling;
1475 void SetResampling(
const char *pszResampling);
1477 int GetSrcDstWindow(
double,
double,
double,
double,
int,
int,
1478 double *pdfReqXOff,
double *pdfReqYOff,
1479 double *pdfReqXSize,
double *pdfReqYSize,
int *,
int *,
1480 int *,
int *,
int *,
int *,
int *,
int *,
1483 int GetSrcDstWindow(
double,
double,
double,
double,
int,
int,
1485 double *pdfReqYOff,
double *pdfReqXSize,
1486 double *pdfReqYSize,
int *,
int *,
int *,
int *,
int *,
1487 int *,
int *,
int *,
bool &bErrorOut);
1490 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1494 WorkingState &oWorkingState)
override;
1496 double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1497 double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1498 CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
double dfMax,
1499 int nBuckets,
GUIntBig *panHistogram,
1500 int bIncludeOutOfRange,
int bApproxOK,
1501 GDALProgressFunc pfnProgress,
1502 void *pProgressData)
override;
1504 void DstToSrc(
double dfX,
double dfY,
double &dfXOut,
double &dfYOut)
const;
1505 void SrcToDst(
double dfX,
double dfY,
double &dfXOut,
double &dfYOut)
const;
1507 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
1508 int *pnMaxSize,
CPLHashSet *hSetFiles)
override;
1510 bool IsSimpleSource()
const override
1518 static const char *GetTypeStatic();
1520 const char *GetType()
const override;
1522 CPLErr FlushCache(
bool bAtClosing)
override;
1526 bool IsSameExceptBandNumber(
const VRTSimpleSource *poOtherSource)
const;
1528 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1530 const int *panBandMap,
GSpacing nPixelSpace,
1534 void UnsetPreservedRelativeFilenames();
1536 void SetMaxValue(
int nVal)
1546class VRTAveragedSource final :
public VRTSimpleSource
1550 int m_bNoDataSet =
false;
1554 VRTAveragedSource();
1556 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1560 WorkingState &oWorkingState)
override;
1562 double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1563 double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1564 CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
double dfMax,
1565 int nBuckets,
GUIntBig *panHistogram,
1566 int bIncludeOutOfRange,
int bApproxOK,
1567 GDALProgressFunc pfnProgress,
1568 void *pProgressData)
override;
1570 void SetNoDataValue(
double dfNoDataValue);
1572 CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1577 static const char *GetTypeStatic();
1579 const char *GetType()
const override;
1586class VRTNoDataFromMaskSource final :
public VRTSimpleSource
1590 bool m_bNoDataSet =
false;
1591 double m_dfNoDataValue = 0;
1592 double m_dfMaskValueThreshold = 0;
1593 bool m_bHasRemappedValue =
false;
1594 double m_dfRemappedValue = 0;
1597 VRTNoDataFromMaskSource();
1599 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1603 WorkingState &oWorkingState)
override;
1605 double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1606 double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1607 CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
double dfMax,
1608 int nBuckets,
GUIntBig *panHistogram,
1609 int bIncludeOutOfRange,
int bApproxOK,
1610 GDALProgressFunc pfnProgress,
1611 void *pProgressData)
override;
1613 void SetParameters(
double dfNoDataValue,
double dfMaskValueThreshold);
1614 void SetParameters(
double dfNoDataValue,
double dfMaskValueThreshold,
1615 double dfRemappedValue);
1618 VRTMapSharedResources &)
override;
1619 CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1624 static const char *GetTypeStatic();
1626 const char *GetType()
const override;
1633class CPL_DLL VRTComplexSource
CPL_NON_FINAL :
public VRTSimpleSource
1638 static constexpr int PROCESSING_FLAG_NODATA = 1 << 0;
1639 static constexpr int PROCESSING_FLAG_USE_MASK_BAND =
1641 static constexpr int PROCESSING_FLAG_SCALING_LINEAR = 1 << 2;
1642 static constexpr int PROCESSING_FLAG_SCALING_EXPONENTIAL =
1644 static constexpr int PROCESSING_FLAG_COLOR_TABLE_EXPANSION = 1 << 4;
1645 static constexpr int PROCESSING_FLAG_LUT = 1 << 5;
1647 int m_nProcessingFlags = 0;
1652 m_osNoDataValueOri{};
1654 double m_dfScaleOff = 0;
1655 double m_dfScaleRatio = 1;
1658 bool m_bSrcMinMaxDefined =
false;
1659 double m_dfSrcMin = 0;
1660 double m_dfSrcMax = 0;
1661 double m_dfDstMin = 0;
1662 double m_dfDstMax = 0;
1663 double m_dfExponent = 1;
1664 bool m_bClip =
true;
1666 int m_nColorTableComponent = 0;
1668 std::vector<double> m_adfLUTInputs{};
1669 std::vector<double> m_adfLUTOutputs{};
1671 double GetAdjustedNoDataValue()
const;
1673 template <
class WorkingDT>
1676 GDALDataType eVRTBandDataType,
int nReqXOff,
int nReqYOff,
1677 int nReqXSize,
int nReqYSize,
void *pData,
int nOutXSize,
1680 GDALDataType eWrkDataType, WorkingState &oWorkingState);
1682 template <
class SourceDT, GDALDataType eSourceType>
1685 int nReqYOff,
int nReqXSize,
int nReqYSize,
1686 void *pData,
int nOutXSize,
int nOutYSize,
1690 WorkingState &oWorkingState);
1693 VRTComplexSource() =
default;
1694 VRTComplexSource(
const VRTComplexSource *poSrcSource,
double dfXDstRatio,
1695 double dfYDstRatio);
1698 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1702 WorkingState &oWorkingState)
override;
1704 double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1705 double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1706 CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
double dfMax,
1707 int nBuckets,
GUIntBig *panHistogram,
1708 int bIncludeOutOfRange,
int bApproxOK,
1709 GDALProgressFunc pfnProgress,
1710 void *pProgressData)
override;
1712 CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1714 VRTMapSharedResources &)
override;
1719 static const char *GetTypeStatic();
1721 const char *GetType()
const override;
1723 bool AreValuesUnchanged()
const;
1725 double LookupValue(
double dfInput);
1727 void SetNoDataValue(
double dfNoDataValue);
1729 void SetUseMaskBand(
bool bUseMaskBand)
1732 m_nProcessingFlags |= PROCESSING_FLAG_USE_MASK_BAND;
1734 m_nProcessingFlags &= ~PROCESSING_FLAG_USE_MASK_BAND;
1737 void SetLinearScaling(
double dfOffset,
double dfScale);
1738 void SetPowerScaling(
double dfExponent,
double dfSrcMin,
double dfSrcMax,
1739 double dfDstMin,
double dfDstMax,
bool bClip =
true);
1740 void SetColorTableComponent(
int nComponent);
1747class VRTFilteredSource
CPL_NON_FINAL :
public VRTComplexSource
1755 int m_nSupportedTypesCount;
1758 int m_nExtraEdgePixels;
1761 VRTFilteredSource();
1762 ~VRTFilteredSource()
override;
1764 const char *GetType()
const override = 0;
1766 void SetExtraEdgePixels(
int);
1767 void SetFilteringDataTypesSupported(
int,
GDALDataType *);
1773 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1777 WorkingState &oWorkingState)
override;
1784class VRTKernelFilteredSource
CPL_NON_FINAL :
public VRTFilteredSource
1789 int m_nKernelSize = 0;
1790 bool m_bSeparable =
false;
1792 std::vector<double> m_adfKernelCoefs{};
1793 bool m_bNormalized =
false;
1794 std::string m_function{};
1797 VRTKernelFilteredSource();
1799 const char *GetType()
const override;
1802 VRTMapSharedResources &)
override;
1803 CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1806 GByte *pabySrcData,
GByte *pabyDstData)
override;
1808 CPLErr SetKernel(
int nKernelSize,
bool bSeparable,
1809 const std::vector<double> &adfNewCoefs);
1810 void SetNormalized(
bool);
1812 void SetFunction(
const std::string &s)
1822class VRTAverageFilteredSource final :
public VRTKernelFilteredSource
1827 explicit VRTAverageFilteredSource(
int nKernelSize);
1828 ~VRTAverageFilteredSource()
override;
1830 const char *GetType()
const override;
1833 VRTMapSharedResources &)
override;
1834 CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1840class VRTFuncSource final :
public VRTSource
1846 ~VRTFuncSource()
override;
1849 VRTMapSharedResources &)
override
1854 CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1857 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1861 WorkingState &oWorkingState)
override;
1863 double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1864 double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1865 CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
double dfMax,
1866 int nBuckets,
GUIntBig *panHistogram,
1867 int bIncludeOutOfRange,
int bApproxOK,
1868 GDALProgressFunc pfnProgress,
1869 void *pProgressData)
override;
1871 const char *GetType()
const override;
1885#define TMP_CPL_DLL CPL_DLL
1901 explicit Ref(VRTGroup *ptr) : m_ptr(ptr)
1905 Ref(
const Ref &) =
delete;
1906 Ref &operator=(
const Ref &) =
delete;
1910 std::shared_ptr<Ref> m_poSharedRefRootGroup{};
1911 std::weak_ptr<Ref> m_poWeakRefRootGroup{};
1912 std::shared_ptr<Ref> m_poRefSelf{};
1914 std::string m_osFilename{};
1915 mutable bool m_bDirty =
false;
1916 std::string m_osVRTPath{};
1917 std::vector<std::string> m_aosGroupNames{};
1918 std::map<std::string, std::shared_ptr<VRTGroup>> m_oMapGroups{};
1919 std::vector<std::string> m_aosMDArrayNames{};
1920 std::map<std::string, std::shared_ptr<VRTMDArray>> m_oMapMDArrays{};
1921 std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
1922 std::map<std::string, std::shared_ptr<VRTDimension>> m_oMapDimensions{};
1924 std::shared_ptr<VRTGroup>
1925 OpenGroupInternal(
const std::string &osName)
const;
1926 void SetRootGroupRef(
const std::weak_ptr<Ref> &rgRef);
1927 std::weak_ptr<Ref> GetRootGroupRef()
const;
1930 friend class VRTMDArray;
1931 friend std::shared_ptr<GDALMDArray>
1932 VRTDerivedArrayCreate(
const char *pszVRTPath,
const CPLXMLNode *psTree);
1934 explicit VRTGroup(
const char *pszVRTPath);
1935 VRTGroup(
const std::string &osParentName,
const std::string &osName);
1938 static std::shared_ptr<VRTGroup> Create(
const std::string &osParentName,
1939 const std::string &osName)
1942 std::shared_ptr<VRTGroup>(
new VRTGroup(osParentName, osName));
1943 poGroup->SetSelf(poGroup);
1947 ~VRTGroup()
override;
1949 bool XMLInit(
const std::shared_ptr<VRTGroup> &poRoot,
1950 const std::shared_ptr<VRTGroup> &poThisGroup,
1951 const CPLXMLNode *psNode,
const char *pszVRTPath);
1953 std::vector<std::string>
1954 GetMDArrayNames(
CSLConstList papszOptions)
const override;
1955 std::shared_ptr<GDALMDArray>
1956 OpenMDArray(
const std::string &osName,
1959 std::vector<std::string>
1960 GetGroupNames(
CSLConstList papszOptions)
const override;
1962 std::shared_ptr<GDALGroup> OpenGroup(
const std::string &osName,
1965 return OpenGroupInternal(osName);
1968 std::vector<std::shared_ptr<GDALDimension>>
1971 std::vector<std::shared_ptr<GDALAttribute>>
1974 std::shared_ptr<VRTDimension> GetDimension(
const std::string &name)
const
1976 auto oIter = m_oMapDimensions.find(name);
1977 return oIter == m_oMapDimensions.end() ? nullptr : oIter->second;
1980 std::shared_ptr<VRTDimension>
1981 GetDimensionFromFullName(
const std::string &name,
bool bEmitError)
const;
1983 std::shared_ptr<GDALGroup>
1984 CreateGroup(
const std::string &osName,
1987 std::shared_ptr<VRTGroup>
1988 CreateVRTGroup(
const std::string &osName,
1991 std::shared_ptr<GDALDimension>
1992 CreateDimension(
const std::string &osName,
const std::string &osType,
1993 const std::string &osDirection,
GUInt64 nSize,
1996 std::shared_ptr<GDALAttribute>
1997 CreateAttribute(
const std::string &osName,
1998 const std::vector<GUInt64> &anDimensions,
2002 std::shared_ptr<GDALMDArray> CreateMDArray(
2003 const std::string &osName,
2004 const std::vector<std::shared_ptr<GDALDimension>> &aoDimensions,
2008 std::shared_ptr<VRTMDArray> CreateVRTMDArray(
2009 const std::string &osName,
2010 const std::vector<std::shared_ptr<GDALDimension>> &aoDimensions,
2014 void SetIsRootGroup();
2016 const std::shared_ptr<Ref> &GetRef()
const
2021 VRTGroup *GetRootGroup()
const;
2022 std::shared_ptr<VRTGroup> GetRootGroupSharedPtr()
const;
2024 const std::string &GetVRTPath()
const
2029 void SetVRTPath(
const std::string &osVRTPath)
2031 m_osVRTPath = osVRTPath;
2036 void SetFilename(
const std::string &osFilename)
2038 m_osFilename = osFilename;
2041 const std::string &GetFilename()
const
2043 return m_osFilename;
2046 bool Serialize()
const;
2047 CPLXMLNode *SerializeToXML(
const char *pszVRTPathIn)
const;
2048 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPathIn)
const;
2057 std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
2058 std::string m_osIndexingVariableName;
2061 VRTDimension(
const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
2062 const std::string &osParentName,
const std::string &osName,
2063 const std::string &osType,
const std::string &osDirection,
2064 GUInt64 nSize,
const std::string &osIndexingVariableName)
2065 :
GDALDimension(osParentName, osName, osType, osDirection, nSize),
2066 m_poGroupRef(poGroupRef),
2067 m_osIndexingVariableName(osIndexingVariableName)
2071 VRTGroup *GetGroup()
const;
2073 static std::shared_ptr<VRTDimension>
2074 Create(
const std::shared_ptr<VRTGroup> &poThisGroup,
2075 const std::string &osParentName,
const CPLXMLNode *psNode);
2080 std::shared_ptr<GDALMDArray> poIndexingVariable)
override;
2092 std::vector<std::string> m_aosList{};
2093 std::vector<std::shared_ptr<GDALDimension>> m_dims{};
2096 bool IRead(
const GUInt64 *arrayStartIdx,
const size_t *count,
2099 void *pDstBuffer)
const override;
2101 bool IWrite(
const GUInt64 *arrayStartIdx,
const size_t *count,
2104 const void *pSrcBuffer)
override;
2107 VRTAttribute(
const std::string &osParentName,
const std::string &osName,
2109 std::vector<std::string> &&aosList)
2112 m_aosList(std::move(aosList))
2114 if (m_aosList.size() > 1)
2116 m_dims.emplace_back(std::make_shared<GDALDimension>(
2117 std::string(),
"dim", std::string(), std::string(),
2122 VRTAttribute(
const std::string &osParentName,
const std::string &osName,
2129 m_dims.emplace_back(std::make_shared<GDALDimension>(
2130 std::string(),
"dim", std::string(), std::string(), nDim));
2134 static bool CreationCommonChecks(
2135 const std::string &osName,
const std::vector<GUInt64> &anDimensions,
2136 const std::map<std::string, std::shared_ptr<VRTAttribute>>
2139 static std::shared_ptr<VRTAttribute> Create(
const std::string &osParentName,
2142 const std::vector<std::shared_ptr<GDALDimension>> &
2160class VRTMDArraySource
2163 virtual ~VRTMDArraySource();
2165 enum class RelationShip
2168 PARTIAL_INTERSECTION,
2172 virtual RelationShip GetRelationship(
const uint64_t *arrayStartIdx,
2173 const size_t *count)
const = 0;
2175 virtual bool GetRawBlockInfo(
const uint64_t *arrayStartIdx,
2176 const size_t *count,
2179 virtual bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2182 void *pDstBuffer)
const = 0;
2185 const char *pszVRTPath)
const = 0;
2195 friend class VRTGroup;
2198 std::string m_osVRTPath{};
2199 std::shared_ptr<VRTGroup> m_poDummyOwningGroup{};
2202 std::vector<std::shared_ptr<GDALDimension>> m_dims;
2203 std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
2204 std::vector<std::unique_ptr<VRTMDArraySource>> m_sources{};
2205 std::shared_ptr<OGRSpatialReference> m_poSRS{};
2206 std::vector<GByte> m_abyNoData{};
2207 std::string m_osUnit{};
2208 double m_dfScale = 1.0;
2209 double m_dfOffset = 0.0;
2210 bool m_bHasScale =
false;
2211 bool m_bHasOffset =
false;
2212 std::string m_osFilename{};
2213 std::vector<GUInt64> m_anBlockSize{};
2215 bool IRead(
const GUInt64 *arrayStartIdx,
const size_t *count,
2218 void *pDstBuffer)
const override;
2224 const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
2225 const std::string &osParentName,
const std::string &osName,
2227 std::vector<std::shared_ptr<GDALDimension>> &&dims,
2228 std::map<std::string, std::shared_ptr<VRTAttribute>> &&oMapAttributes,
2229 std::vector<GUInt64> &&anBlockSize)
2231 GDALMDArray(osParentName, osName), m_poGroupRef(poGroupRef),
2232 m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()), m_dt(dt),
2233 m_dims(std::move(dims)), m_oMapAttributes(std::move(oMapAttributes)),
2234 m_osFilename(poGroupRef->m_ptr->GetFilename()),
2235 m_anBlockSize(std::move(anBlockSize))
2239 VRTMDArray(
const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
2240 const std::string &osParentName,
const std::string &osName,
2241 const std::vector<std::shared_ptr<GDALDimension>> &dims,
2243 const std::vector<GUInt64> &anBlockSize)
2245 GDALMDArray(osParentName, osName), m_poGroupRef(poGroupRef),
2246 m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()), m_dt(dt), m_dims(dims),
2247 m_osFilename(poGroupRef->m_ptr->GetFilename()),
2248 m_anBlockSize(anBlockSize)
2259 return m_osFilename;
2262 static std::shared_ptr<VRTMDArray> Create(
const char *pszVRTPath,
2265 static std::shared_ptr<VRTMDArray>
2266 Create(
const std::shared_ptr<VRTGroup> &poThisGroup,
2267 const std::string &osParentName,
const CPLXMLNode *psNode);
2269 const std::vector<std::shared_ptr<GDALDimension>> &
2275 std::vector<std::shared_ptr<GDALAttribute>>
2285 std::shared_ptr<OGRSpatialReference>
GetSpatialRef()
const override
2294 const std::string &
GetUnit()
const override
2299 bool SetUnit(
const std::string &osUnit)
override
2329 m_bHasOffset =
true;
2330 m_dfOffset = dfOffset;
2339 m_dfScale = dfScale;
2343 void AddSource(std::unique_ptr<VRTMDArraySource> &&poSource);
2345 std::shared_ptr<GDALAttribute>
2347 const std::vector<GUInt64> &anDimensions,
2353 GDALProgressFunc pfnProgress,
void *pProgressData)
override;
2355 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPathIn)
const;
2357 VRTGroup *GetGroup()
const;
2366 auto poGroup = m_poGroupRef.lock();
2368 return poGroup->m_ptr->GetRootGroupSharedPtr();
2372 std::shared_ptr<GDALGroup>
GetRootGroup()
const override
2379 return m_anBlockSize;
2390class VRTMDArraySourceInlinedValues final :
public VRTMDArraySource
2392 const VRTMDArray *m_poDstArray =
nullptr;
2393 bool m_bIsConstantValue;
2394 std::vector<GUInt64> m_anOffset{};
2395 std::vector<size_t> m_anCount{};
2396 std::vector<GByte> m_abyValues{};
2397 std::vector<size_t> m_anInlinedArrayStrideInBytes{};
2400 VRTMDArraySourceInlinedValues(
const VRTMDArraySourceInlinedValues &) =
2402 VRTMDArraySourceInlinedValues &
2403 operator=(
const VRTMDArraySourceInlinedValues &) =
delete;
2406 VRTMDArraySourceInlinedValues(
const VRTMDArray *poDstArray,
2407 bool bIsConstantValue,
2408 std::vector<GUInt64> &&anOffset,
2409 std::vector<size_t> &&anCount,
2410 std::vector<GByte> &&abyValues)
2411 : m_poDstArray(poDstArray), m_bIsConstantValue(bIsConstantValue),
2412 m_anOffset(std::move(anOffset)), m_anCount(std::move(anCount)),
2413 m_abyValues(std::move(abyValues)), m_dt(poDstArray->GetDataType())
2415 const auto nDims(poDstArray->GetDimensionCount());
2416 m_anInlinedArrayStrideInBytes.resize(nDims);
2417 if (!bIsConstantValue && nDims > 0)
2419 m_anInlinedArrayStrideInBytes.back() =
2420 poDstArray->GetDataType().GetSize();
2421 for (
size_t i = nDims - 1; i > 0;)
2424 m_anInlinedArrayStrideInBytes[i] =
2425 m_anInlinedArrayStrideInBytes[i + 1] * m_anCount[i + 1];
2430 ~VRTMDArraySourceInlinedValues()
override;
2432 static std::unique_ptr<VRTMDArraySourceInlinedValues>
2433 Create(
const VRTMDArray *poDstArray,
const CPLXMLNode *psNode);
2435 RelationShip GetRelationship(
const uint64_t * ,
2436 const size_t * )
const override
2438 return RelationShip::PARTIAL_INTERSECTION;
2441 bool GetRawBlockInfo(
const uint64_t * ,
2448 bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2451 void *pDstBuffer)
const override;
2453 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPath)
const override;
2460class VRTMDArraySourceRegularlySpaced final :
public VRTMDArraySource
2463 double m_dfIncrement;
2466 VRTMDArraySourceRegularlySpaced(
double dfStart,
double dfIncrement)
2467 : m_dfStart(dfStart), m_dfIncrement(dfIncrement)
2471 RelationShip GetRelationship(
const uint64_t * ,
2472 const size_t * )
const override
2474 return RelationShip::PARTIAL_INTERSECTION;
2477 bool GetRawBlockInfo(
const uint64_t * ,
2484 bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2487 void *pDstBuffer)
const override;
2489 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPath)
const override;
2496struct VRTArrayDatasetWrapper;
2498class VRTMDArraySourceFromArray final :
public VRTMDArraySource
2500 const VRTMDArray *m_poDstArray =
nullptr;
2501 bool m_bRelativeToVRTSet =
false;
2502 bool m_bRelativeToVRT =
false;
2503 std::string m_osFilename{};
2504 std::string m_osArray{};
2505 std::string m_osBand{};
2506 std::vector<int> m_anTransposedAxis{};
2507 std::string m_osViewExpr{};
2508 std::vector<GUInt64> m_anSrcOffset{};
2509 mutable std::vector<GUInt64> m_anCount{};
2510 std::vector<GUInt64> m_anStep{};
2511 std::vector<GUInt64> m_anDstOffset{};
2513 std::pair<std::shared_ptr<VRTArrayDatasetWrapper>,
2514 std::shared_ptr<GDALMDArray>>
2515 GetSourceArray()
const;
2517 VRTMDArraySourceFromArray(
const VRTMDArraySourceFromArray &) =
delete;
2518 VRTMDArraySourceFromArray &
2519 operator=(
const VRTMDArraySourceFromArray &) =
delete;
2522 VRTMDArraySourceFromArray(
2523 const VRTMDArray *poDstArray,
bool bRelativeToVRTSet,
2524 bool bRelativeToVRT,
const std::string &osFilename,
2525 const std::string &osArray,
const std::string &osBand,
2526 std::vector<int> &&anTransposedAxis,
const std::string &osViewExpr,
2527 std::vector<GUInt64> &&anSrcOffset, std::vector<GUInt64> &&anCount,
2528 std::vector<GUInt64> &&anStep, std::vector<GUInt64> &&anDstOffset)
2529 : m_poDstArray(poDstArray), m_bRelativeToVRTSet(bRelativeToVRTSet),
2530 m_bRelativeToVRT(bRelativeToVRT), m_osFilename(osFilename),
2531 m_osArray(osArray), m_osBand(osBand),
2532 m_anTransposedAxis(std::move(anTransposedAxis)),
2533 m_osViewExpr(osViewExpr), m_anSrcOffset(std::move(anSrcOffset)),
2534 m_anCount(std::move(anCount)), m_anStep(std::move(anStep)),
2535 m_anDstOffset(std::move(anDstOffset))
2539 ~VRTMDArraySourceFromArray()
override;
2541 static std::unique_ptr<VRTMDArraySourceFromArray>
2542 Create(
const VRTMDArray *poDstArray,
const CPLXMLNode *psNode);
2544 RelationShip GetRelationship(
const uint64_t *arrayStartIdx,
2545 const size_t *count)
const override;
2547 bool GetRawBlockInfo(
const uint64_t *arrayStartIdx,
const size_t *count,
2550 bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2553 void *pDstBuffer)
const override;
2555 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPath)
const override;
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:458
Convenient string class based on std::string.
Definition cpl_string.h:320
Manage a tree of XML nodes so that all nodes are freed when the instance goes out of scope.
Definition cpl_minixml.h:193
Abstract class, implemented by GDALAttribute and GDALMDArray.
Definition gdal_multidim.h:498
virtual std::vector< GUInt64 > GetBlockSize() const
Return the "natural" block size of the array along all dimensions.
Definition gdalmultidim.cpp:2431
virtual const std::vector< std::shared_ptr< GDALDimension > > & GetDimensions() const =0
Return the dimensions of an attribute/array.
virtual const GDALExtendedDataType & GetDataType() const =0
Return the data type of an attribute/array.
Class modeling an attribute that has a name, a value and a type, and is typically used to describe a ...
Definition gdal_multidim.h:729
A color table / palette.
Definition gdal_colortable.h:32
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
int Dereference()
Subtract one from dataset reference count.
Definition gdaldataset.cpp:1782
virtual CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList, const OGRSpatialReference *poGCP_SRS)
Assign GCPs.
Definition gdaldataset.cpp:2237
int GetShared() const
Returns shared flag.
Definition gdaldataset.cpp:1854
Class modeling a a dimension / axis used to index multidimensional arrays.
Definition gdal_multidim.h:1232
virtual std::shared_ptr< GDALMDArray > GetIndexingVariable() const
Return the variable that is used to index the dimension (if there is one).
Definition gdalmultidim.cpp:11022
virtual bool SetIndexingVariable(std::shared_ptr< GDALMDArray > poIndexingVariable)
Set the variable that is used to index the dimension.
Definition gdalmultidim.cpp:11043
Format specific driver.
Definition gdal_driver.h:63
Class used to represent potentially complex data types.
Definition gdal_multidim.h:54
Class modeling a named container of GDALAttribute, GDALMDArray, OGRLayer or other GDALGroup.
Definition gdal_multidim.h:305
virtual std::shared_ptr< GDALAttribute > CreateAttribute(const std::string &osName, const std::vector< GUInt64 > &anDimensions, const GDALExtendedDataType &oDataType, CSLConstList papszOptions=nullptr)
Create an attribute within a GDALMDArray or GDALGroup.
Definition gdalmultidim.cpp:289
virtual std::vector< std::shared_ptr< GDALAttribute > > GetAttributes(CSLConstList papszOptions=nullptr) const
Return the list of attributes contained in a GDALMDArray or GDALGroup.
Definition gdalmultidim.cpp:258
Class modeling a multi-dimensional array.
Definition gdal_multidim.h:852
virtual bool SetUnit(const std::string &osUnit)
Set the variable unit.
Definition gdalmultidim.cpp:2638
virtual bool CopyFrom(GDALDataset *poSrcDS, const GDALMDArray *poSrcArray, bool bStrict, GUInt64 &nCurCost, const GUInt64 nTotalCost, GDALProgressFunc pfnProgress, void *pProgressData)
Copy the content of an array into a new (generally empty) array.
Definition gdalmultidim.cpp:4041
virtual bool IsWritable() const =0
Return whether an array is writable.
virtual bool SetScale(double dfScale, GDALDataType eStorageType=GDT_Unknown)
Set the scale value to apply to raw values.
Definition gdalmultidim.cpp:2971
virtual bool SetRawNoDataValue(const void *pRawNoData)
Set the nodata value as a "raw" value.
Definition gdalmultidim.cpp:2830
virtual double GetOffset(bool *pbHasOffset=nullptr, GDALDataType *peStorageType=nullptr) const
Get the offset value to apply to raw values.
Definition gdalmultidim.cpp:3058
virtual const void * GetRawNoDataValue() const
Return the nodata value as a "raw" value.
Definition gdalmultidim.cpp:2714
virtual double GetScale(bool *pbHasScale=nullptr, GDALDataType *peStorageType=nullptr) const
Get the scale value to apply to raw values.
Definition gdalmultidim.cpp:3028
virtual std::shared_ptr< OGRSpatialReference > GetSpatialRef() const
Return the spatial reference system object associated with the array.
Definition gdalmultidim.cpp:2688
virtual const std::string & GetFilename() const =0
Return the filename that contains that array.
virtual bool GetRawBlockInfo(const uint64_t *panBlockCoordinates, GDALMDArrayRawBlockInfo &info) const
Return information on a raw block.
Definition gdalmultidim.cpp:15284
virtual bool SetSpatialRef(const OGRSpatialReference *poSRS)
Assign a spatial reference system object to the array.
Definition gdalmultidim.cpp:2674
virtual std::shared_ptr< GDALGroup > GetRootGroup() const
Return the root group to which this arrays belongs too.
Definition gdalmultidim.cpp:4623
virtual bool SetOffset(double dfOffset, GDALDataType eStorageType=GDT_Unknown)
Set the offset value to apply to raw values.
Definition gdalmultidim.cpp:2999
bool Cache(CSLConstList papszOptions=nullptr) const
Cache the content of the array into an auxiliary filename.
Definition gdalmultidim.cpp:4455
virtual const std::string & GetUnit() const
Return the array unit.
Definition gdalmultidim.cpp:2660
virtual CPLErr SetMetadata(char **papszMetadata, const char *pszDomain="")
Set metadata.
Definition gdalmajorobject.cpp:271
virtual char ** GetMetadataDomainList()
Fetch list of metadata domains.
Definition gdalmajorobject.cpp:143
virtual char ** GetMetadata(const char *pszDomain="")
Fetch metadata.
Definition gdalmajorobject.cpp:228
Class for dataset open functions.
Definition gdal_openinfo.h:28
Pansharpening operation class.
Definition gdalpansharpen.h:176
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
GDALDataset * GetDataset() const
Fetch the owning dataset handle.
Definition gdalrasterband.cpp:3983
High level image warping class.
Definition gdalwarper.h:504
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
struct _CPLHashSet CPLHashSet
Opaque type for a hash set.
Definition cpl_hash_set.h:35
Definitions for CPL mini XML Parser/Serializer.
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition cpl_port.h:246
#define CPL_NON_FINAL
Mark that a class is explicitly recognized as non-final.
Definition cpl_port.h:929
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:208
GIntBig GInt64
Signed 64 bit integer type.
Definition cpl_port.h:226
#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
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition cpl_port.h:228
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:175
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:205
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition cpl_virtualmem.h:45
GUIntBig vsi_l_offset
Type for a file offset.
Definition cpl_vsi.h:136
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:388
GDALAccess
Definition gdal.h:120
@ GA_ReadOnly
Definition gdal.h:121
void * VRTPDWorkingDataPtr
Generic pointer for the working structure of VRTProcessedDataset function.
Definition gdal.h:1791
GDALDataType
Definition gdal.h:48
@ GDT_Unknown
Definition gdal.h:49
CPLErr(* GDALDerivedPixelFuncWithArgs)(void **papoSources, int nSources, void *pData, int nBufXSize, int nBufYSize, GDALDataType eSrcType, GDALDataType eBufType, int nPixelSpace, int nLineSpace, CSLConstList papszFunctionArgs)
Type of functions to pass to GDALAddDerivedBandPixelFuncWithArgs.
Definition gdal.h:1609
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:137
CPLErr GDALClose(GDALDatasetH)
Close GDAL dataset.
Definition gdaldataset.cpp:4478
GDALColorInterp
Types of color interpretation for raster bands.
Definition gdal.h:272
@ GCI_Undefined
Definition gdal.h:273
GDALRWFlag
Definition gdal.h:127
CPLErr(* GDALDerivedPixelFunc)(void **papoSources, int nSources, void *pData, int nBufXSize, int nBufYSize, GDALDataType eSrcType, GDALDataType eBufType, int nPixelSpace, int nLineSpace)
Type of functions to pass to GDALAddDerivedBandPixelFunc.
Definition gdal.h:1601
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal_fwd.h:45
Public (C callable) entry points for virtual GDAL dataset objects.
#define VRT_NODATA_UNSET
Special value to indicate that nodata is not set.
Definition gdal_vrt.h:28
void * VRTDatasetH
Opaque type for a VRT dataset.
Definition gdal_vrt.h:57
CPLErr(* VRTImageReadFunc)(void *hCBData, int nXOff, int nYOff, int nXSize, int nYSize, void *pData)
Type for a function that returns the pixel data in a provided window.
Definition gdal_vrt.h:33
VRTDatasetH VRTCreate(int, int)
Definition vrtdataset.cpp:77
Document node structure.
Definition cpl_minixml.h:54
Information on a raw block of a GDALMDArray.
Definition gdal.h:2830
Ground Control Point.
Definition gdal.h:1223