15#ifndef VIRTUALDATASET_H_INCLUDED
16#define VIRTUALDATASET_H_INCLUDED
36CPLErr GDALRegisterDefaultPixelFunc();
37void GDALVRTRegisterDefaultProcessedDatasetFuncs();
42int VRTWarpedOverviewTransform(
void *pTransformArg,
int bDstToSrc,
44 double *padfX,
double *padfY,
double *padfZ,
46void* VRTDeserializeWarpedOverviewTransformer(
CPLXMLNode *psTree );
60 int bTriedToOpen = FALSE;
62 VRTOverviewInfo() =
default;
64 VRTOverviewInfo(VRTOverviewInfo &&oOther) noexcept
65 : osFilename(std::move(oOther.osFilename)), nBand(oOther.nBand),
66 poBand(oOther.poBand), bTriedToOpen(oOther.bTriedToOpen)
68 oOther.poBand =
nullptr;
78 if (poBand ==
nullptr)
98class CPL_DLL VRTMapSharedResources
101 VRTMapSharedResources() =
default;
109 void Insert(
const std::string &osKey,
GDALDataset *poDS);
118 std::mutex *poMutex =
nullptr;
119 std::map<std::string, GDALDataset *> oMap{};
128class CPL_DLL VRTSource
131 struct CPL_DLL WorkingState
135#pragma GCC diagnostic push
136#pragma GCC diagnostic ignored "-Weffc++"
149 inline operator GByte()
const
155#pragma GCC diagnostic pop
158 std::vector<NoInitByte> m_abyWrkBuffer{};
159 std::vector<NoInitByte> m_abyWrkBufferMask{};
162 virtual ~VRTSource();
165 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
169 WorkingState &oWorkingState) = 0;
171 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess) = 0;
172 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess) = 0;
173 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
174 double dfMax,
int nBuckets,
175 GUIntBig *panHistogram,
int bIncludeOutOfRange,
176 int bApproxOK, GDALProgressFunc pfnProgress,
177 void *pProgressData) = 0;
180 VRTMapSharedResources &) = 0;
181 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath) = 0;
183 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
189 virtual bool IsSimpleSource()
const
197 virtual const char *GetType()
const = 0;
199 virtual CPLErr FlushCache(
bool )
205typedef VRTSource *(*VRTSourceParser)(
const CPLXMLNode *,
const char *,
206 VRTMapSharedResources &oMapSharedSources);
208VRTSource *VRTParseCoreSources(
const CPLXMLNode *psTree,
const char *,
209 VRTMapSharedResources &oMapSharedSources);
210VRTSource *VRTParseFilterSources(
const CPLXMLNode *psTree,
const char *,
211 VRTMapSharedResources &oMapSharedSources);
212VRTSource *VRTParseArraySource(
const CPLXMLNode *psTree,
const char *,
213 VRTMapSharedResources &oMapSharedSources);
221template <
class T>
struct VRTFlushCacheStruct
223 static CPLErr FlushCache(T &obj,
bool bAtClosing);
226class VRTWarpedDataset;
227class VRTPansharpenedDataset;
228class VRTProcessedDataset;
230class VRTSimpleSource;
234 friend class VRTRasterBand;
235 friend struct VRTFlushCacheStruct<VRTDataset>;
236 friend struct VRTFlushCacheStruct<VRTWarpedDataset>;
237 friend struct VRTFlushCacheStruct<VRTPansharpenedDataset>;
238 friend struct VRTFlushCacheStruct<VRTProcessedDataset>;
239 friend class VRTSourcedRasterBand;
240 friend class VRTSimpleSource;
243 std::vector<gdal::GCP> m_asGCPs{};
244 std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser>
247 bool m_bNeedsFlush =
false;
248 bool m_bWritable =
true;
249 bool m_bCanTakeRef =
true;
251 char *m_pszVRTPath =
nullptr;
253 VRTRasterBand *m_poMaskBand =
nullptr;
255 mutable int m_nCompatibleForDatasetIO = -1;
256 bool CheckCompatibleForDatasetIO()
const;
260 std::vector<GDALDataset *> m_apoOverviews{};
261 std::vector<GDALDataset *> m_apoOverviewsBak{};
264 std::vector<int> m_anOverviewFactors{};
266 char **m_papszXMLVRTMetadata =
nullptr;
268 VRTMapSharedResources m_oMapSharedSources{};
269 std::shared_ptr<VRTGroup> m_poRootGroup{};
272 VRTSource::WorkingState m_oWorkingState{};
275 struct QueueWorkingStates
278 std::vector<std::unique_ptr<VRTSource::WorkingState>> oStates{};
281 QueueWorkingStates m_oQueueWorkingStates{};
283 bool m_bMultiThreadedRasterIOLastUsed =
false;
285 static constexpr const char *
const apszSpecialSyntax[] = {
286 "NITF_IM:{ANY}:{FILENAME}",
"PDF:{ANY}:{FILENAME}",
287 "RASTERLITE:{FILENAME},{ANY}",
"TILEDB:\"{FILENAME}\":{ANY}",
288 "TILEDB:{FILENAME}:{ANY}"};
290 VRTRasterBand *InitBand(
const char *pszSubclass,
int nBand,
291 bool bAllowPansharpenedOrProcessed);
292 static GDALDataset *OpenVRTProtocol(
const char *pszSpec);
293 bool AddVirtualOverview(
int nOvFactor,
const char *pszResampling);
295 bool GetShiftedDataset(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
304 std::atomic<int> *pnCompletedJobs =
nullptr;
305 std::atomic<bool> *pbSuccess =
nullptr;
312 void *pData =
nullptr;
316 BANDMAP_TYPE panBandMap =
nullptr;
322 VRTSimpleSource *poSource =
nullptr;
324 static void Func(
void *pData);
330 bool m_bBlockSizeSpecified =
false;
331 int m_nBlockXSize = 0;
332 int m_nBlockYSize = 0;
334 std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser> m_poSRS{};
336 int m_bGeoTransformSet =
false;
337 double m_adfGeoTransform[6];
339 virtual int CloseDependentDatasets()
override;
342 VRTDataset(
int nXSize,
int nYSize,
int nBlockXSize = 0,
343 int nBlockYSize = 0);
344 virtual ~VRTDataset();
348 m_bNeedsFlush =
true;
351 virtual CPLErr FlushCache(
bool bAtClosing)
override;
353 void SetWritable(
int bWritableIn)
355 m_bWritable = CPL_TO_BOOL(bWritableIn);
358 virtual CPLErr CreateMaskBand(
int nFlags)
override;
359 void SetMaskBand(VRTRasterBand *poMaskBand);
363 return m_poSRS.get();
368 virtual CPLErr GetGeoTransform(
double *)
override;
369 virtual CPLErr SetGeoTransform(
double *)
override;
371 virtual CPLErr SetMetadata(
char **papszMetadata,
372 const char *pszDomain =
"")
override;
373 virtual CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
374 const char *pszDomain =
"")
override;
376 virtual char **GetMetadata(
const char *pszDomain =
"")
override;
377 virtual const char *GetMetadataItem(
const char *pszName,
378 const char *pszDomain =
"")
override;
380 virtual int GetGCPCount()
override;
384 return m_poGCP_SRS.get();
387 virtual const GDAL_GCP *GetGCPs()
override;
393 char **papszOptions =
nullptr)
override;
395 virtual char **GetFileList()
override;
398 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
400 int nBandCount, BANDMAP_TYPE panBandMap,
406 GetCompressionFormats(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
407 int nBandCount,
const int *panBandList)
override;
408 virtual CPLErr ReadCompressedData(
const char *pszFormat,
int nXOff,
409 int nYOff,
int nXSize,
int nYSize,
410 int nBandCount,
const int *panBandList,
411 void **ppBuffer,
size_t *pnBufferSize,
412 char **ppszDetailedFormat)
override;
414 virtual CPLErr AdviseRead(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
416 int nBandCount,
int *panBandList,
417 char **papszOptions)
override;
419 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath);
422 virtual CPLErr IBuildOverviews(
const char *,
int,
const int *,
int,
423 const int *, GDALProgressFunc,
void *,
426 std::shared_ptr<GDALGroup> GetRootGroup()
const override;
428 void ClearStatistics()
override;
433 m_nCompatibleForDatasetIO = -1;
438 void BuildVirtualOverviews();
440 void UnsetPreservedRelativeFilenames();
442 bool IsBlockSizeSpecified()
const
444 return m_bBlockSizeSpecified;
447 int GetBlockXSize()
const
449 return m_nBlockXSize;
452 int GetBlockYSize()
const
454 return m_nBlockYSize;
459 static VRTDataset *OpenXML(
const char *,
const char * =
nullptr,
461 static GDALDataset *Create(
const char *pszName,
int nXSize,
int nYSize,
463 char **papszOptions);
465 CreateMultiDimensional(
const char *pszFilename,
468 static CPLErr Delete(
const char *pszFilename);
470 static std::string BuildSourceFilename(
const char *pszFilename,
471 const char *pszVRTPath,
472 bool bRelativeToVRT);
482class VRTWarpedRasterBand;
484class CPL_DLL VRTWarpedDataset final :
public VRTDataset
488 bool m_bIsOverview =
false;
489 std::vector<VRTWarpedDataset *> m_apoOverviews{};
492 bool GetOverviewSize(
GDALDataset *poSrcDS,
int iOvr,
int iSrcOvr,
493 int &nOvrXSize,
int &nOvrYSize,
double &dfSrcRatioX,
494 double &dfSrcRatioY)
const;
495 int GetOverviewCount()
const;
496 int GetSrcOverviewLevel(
int iOvr,
bool &bThisLevelOnlyOut)
const;
497 VRTWarpedDataset *CreateImplicitOverview(
int iOvr)
const;
498 void CreateImplicitOverviews();
500 friend class VRTWarpedRasterBand;
505 virtual int CloseDependentDatasets()
override;
508 VRTWarpedDataset(
int nXSize,
int nYSize,
int nBlockXSize = 0,
509 int nBlockYSize = 0);
510 virtual ~VRTWarpedDataset();
512 virtual CPLErr FlushCache(
bool bAtClosing)
override;
514 CPLErr Initialize(
void *);
516 virtual CPLErr IBuildOverviews(
const char *,
int,
const int *,
int,
517 const int *, GDALProgressFunc,
void *,
520 virtual CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
521 const char *pszDomain =
"")
override;
523 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
527 char **papszOptions =
nullptr)
override;
529 virtual char **GetFileList()
override;
532 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
534 int nBandCount, BANDMAP_TYPE panBandMap,
539 CPLErr ProcessBlock(
int iBlockX,
int iBlockY);
541 void GetBlockSize(
int *,
int *)
const;
553 GTAdjust_Intersection,
555 GTAdjust_NoneWithoutWarning
558class VRTPansharpenedDataset final :
public VRTDataset
560 friend class VRTPansharpenedRasterBand;
563 VRTPansharpenedDataset *m_poMainDataset;
564 std::vector<VRTPansharpenedDataset *> m_apoOverviewDatasets{};
566 std::map<CPLString, CPLString> m_oMapToRelativeFilenames{};
568 int m_bLoadingOtherBands;
570 GByte *m_pabyLastBufferBandRasterIO;
571 int m_nLastBandRasterIOXOff;
572 int m_nLastBandRasterIOYOff;
573 int m_nLastBandRasterIOXSize;
574 int m_nLastBandRasterIOYSize;
577 GTAdjustment m_eGTAdjustment;
578 int m_bNoDataDisabled;
580 std::vector<GDALDataset *> m_apoDatasetsToClose{};
585 virtual int CloseDependentDatasets()
override;
588 VRTPansharpenedDataset(
int nXSize,
int nYSize,
int nBlockXSize = 0,
589 int nBlockYSize = 0);
590 virtual ~VRTPansharpenedDataset();
592 virtual CPLErr FlushCache(
bool bAtClosing)
override;
595 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
602 char **papszOptions =
nullptr)
override;
604 virtual char **GetFileList()
override;
607 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
609 int nBandCount, BANDMAP_TYPE panBandMap,
614 void GetBlockSize(
int *,
int *)
const;
618 return m_poPansharpener;
631class VRTProcessedDataset final :
public VRTDataset
634 VRTProcessedDataset(
int nXSize,
int nYSize);
635 ~VRTProcessedDataset()
override;
637 virtual CPLErr FlushCache(
bool bAtClosing)
override;
640 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
642 void GetBlockSize(
int *,
int *)
const;
646#pragma GCC diagnostic push
647#pragma GCC diagnostic ignored "-Weffc++"
660 inline operator GByte()
const
666#pragma GCC diagnostic pop
670 friend class VRTProcessedRasterBand;
676 std::string osAlgorithm{};
694 std::vector<double> adfInNoData{};
697 std::vector<double> adfOutNoData{};
708 Step &operator=(Step &&);
711 Step(
const Step &) =
delete;
712 Step &operator=(
const Step &) =
delete;
717 std::string m_osVRTPath{};
720 std::unique_ptr<GDALDataset> m_poSrcDS{};
723 std::vector<Step> m_aoSteps{};
729 std::vector<std::unique_ptr<GDALDataset>> m_apoOverviewDatasets{};
732 std::vector<NoInitByte> m_abyInput{};
735 std::vector<NoInitByte> m_abyOutput{};
738 const VRTProcessedDataset *poParentDS,
741 bool ParseStep(
const CPLXMLNode *psStep,
bool bIsFinalStep,
743 std::vector<double> &adfInNoData,
744 std::vector<double> &adfOutNoData);
745 bool ProcessRegion(
int nXOff,
int nYOff,
int nBufXSize,
int nBufYSize);
755constexpr double VRT_DEFAULT_NODATA_VALUE = -10000.0;
760 void ResetNoDataValues();
763 friend class VRTDataset;
765 int m_bIsMaskBand = FALSE;
767 int m_bNoDataValueSet = FALSE;
769 int m_bHideNoDataValue = FALSE;
770 double m_dfNoDataValue = VRT_DEFAULT_NODATA_VALUE;
772 bool m_bNoDataSetAsInt64 =
false;
773 int64_t m_nNoDataValueInt64 = GDAL_PAM_DEFAULT_NODATA_VALUE_INT64;
775 bool m_bNoDataSetAsUInt64 =
false;
776 uint64_t m_nNoDataValueUInt64 = GDAL_PAM_DEFAULT_NODATA_VALUE_UINT64;
778 std::unique_ptr<GDALColorTable> m_poColorTable{};
782 char *m_pszUnitType =
nullptr;
785 double m_dfOffset = 0.0;
786 double m_dfScale = 1.0;
790 void Initialize(
int nXSize,
int nYSize);
792 std::vector<VRTOverviewInfo> m_aoOverviewInfos{};
794 VRTRasterBand *m_poMaskBand =
nullptr;
796 std::unique_ptr<GDALRasterAttributeTable> m_poRAT{};
800 bool IsNoDataValueInDataTypeRange()
const;
804 virtual ~VRTRasterBand();
807 VRTMapSharedResources &);
808 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
809 bool &bHasWarnedAboutRAMUsage,
810 size_t &nAccRAMUsage);
812 CPLErr SetNoDataValue(
double)
override;
813 CPLErr SetNoDataValueAsInt64(int64_t nNoData)
override;
814 CPLErr SetNoDataValueAsUInt64(uint64_t nNoData)
override;
815 double GetNoDataValue(
int *pbSuccess =
nullptr)
override;
816 int64_t GetNoDataValueAsInt64(
int *pbSuccess =
nullptr)
override;
817 uint64_t GetNoDataValueAsUInt64(
int *pbSuccess =
nullptr)
override;
818 CPLErr DeleteNoDataValue()
override;
830 virtual const char *GetUnitType()
override;
831 CPLErr SetUnitType(
const char *)
override;
833 virtual char **GetCategoryNames()
override;
834 virtual CPLErr SetCategoryNames(
char **)
override;
836 virtual CPLErr SetMetadata(
char **papszMD,
837 const char *pszDomain =
"")
override;
838 virtual CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
839 const char *pszDomain =
"")
override;
841 virtual double GetOffset(
int *pbSuccess =
nullptr)
override;
842 CPLErr SetOffset(
double)
override;
843 virtual double GetScale(
int *pbSuccess =
nullptr)
override;
844 CPLErr SetScale(
double)
override;
846 virtual int GetOverviewCount()
override;
849 virtual CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
850 GUIntBig *panHistogram,
int bIncludeOutOfRange,
851 int bApproxOK, GDALProgressFunc,
852 void *pProgressData)
override;
854 virtual CPLErr GetDefaultHistogram(
double *pdfMin,
double *pdfMax,
855 int *pnBuckets,
GUIntBig **ppanHistogram,
856 int bForce, GDALProgressFunc,
857 void *pProgressData)
override;
859 virtual CPLErr SetDefaultHistogram(
double dfMin,
double dfMax,
int nBuckets,
864 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
867 virtual void SetDescription(
const char *)
override;
870 virtual int GetMaskFlags()
override;
872 virtual CPLErr CreateMaskBand(
int nFlagsIn)
override;
874 void SetMaskBand(VRTRasterBand *poMaskBand);
876 void SetIsMaskBand();
878 virtual bool IsMaskBand()
const override;
880 CPLErr UnsetNoDataValue();
882 virtual int CloseDependentDatasets();
884 virtual int IsSourcedRasterBand()
889 virtual int IsPansharpenRasterBand()
899class VRTSimpleSource;
901class CPL_DLL VRTSourcedRasterBand
CPL_NON_FINAL :
public VRTRasterBand
905 char **m_papszSourceList =
nullptr;
906 int m_nSkipBufferInitialization = -1;
908 bool CanUseSourcesMinMaxImplementations();
910 bool IsMosaicOfNonOverlappingSimpleSourcesOfFullRasterNoResAndTypeChange(
911 bool bAllowMaxValAdjustment)
const;
918 std::atomic<int> *pnCompletedJobs =
nullptr;
919 std::atomic<bool> *pbSuccess =
nullptr;
920 VRTDataset::QueueWorkingStates *poQueueWorkingStates =
nullptr;
927 void *pData =
nullptr;
934 VRTSimpleSource *poSource =
nullptr;
936 static void Func(
void *pData);
942 bool SkipBufferInitialization();
946 VRTSource **papoSources =
nullptr;
948 VRTSourcedRasterBand(
GDALDataset *poDS,
int nBand);
949 VRTSourcedRasterBand(
GDALDataType eType,
int nXSize,
int nYSize);
951 int nXSize,
int nYSize);
953 int nXSize,
int nYSize,
int nBlockXSizeIn,
955 virtual ~VRTSourcedRasterBand();
962 virtual int IGetDataCoverageStatus(
int nXOff,
int nYOff,
int nXSize,
963 int nYSize,
int nMaskFlagStop,
964 double *pdfDataPct)
override;
966 virtual char **GetMetadataDomainList()
override;
967 virtual const char *GetMetadataItem(
const char *pszName,
968 const char *pszDomain =
"")
override;
969 virtual char **GetMetadata(
const char *pszDomain =
"")
override;
970 virtual CPLErr SetMetadata(
char **papszMetadata,
971 const char *pszDomain =
"")
override;
972 virtual CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
973 const char *pszDomain =
"")
override;
976 VRTMapSharedResources &)
override;
977 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
978 bool &bHasWarnedAboutRAMUsage,
979 size_t &nAccRAMUsage)
override;
981 virtual double GetMinimum(
int *pbSuccess =
nullptr)
override;
982 virtual double GetMaximum(
int *pbSuccess =
nullptr)
override;
983 virtual CPLErr ComputeRasterMinMax(
int bApproxOK,
984 double *adfMinMax)
override;
985 virtual CPLErr ComputeStatistics(
int bApproxOK,
double *pdfMin,
986 double *pdfMax,
double *pdfMean,
988 GDALProgressFunc pfnProgress,
989 void *pProgressData)
override;
990 virtual CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
991 GUIntBig *panHistogram,
int bIncludeOutOfRange,
992 int bApproxOK, GDALProgressFunc pfnProgress,
993 void *pProgressData)
override;
995 CPLErr AddSource(VRTSource *);
997 CPLErr AddSimpleSource(
const char *pszFilename,
int nBand,
998 double dfSrcXOff = -1,
double dfSrcYOff = -1,
999 double dfSrcXSize = -1,
double dfSrcYSize = -1,
1000 double dfDstXOff = -1,
double dfDstYOff = -1,
1001 double dfDstXSize = -1,
double dfDstYSize = -1,
1002 const char *pszResampling =
"near",
1006 double dfSrcYOff = -1,
double dfSrcXSize = -1,
1007 double dfSrcYSize = -1,
double dfDstXOff = -1,
1008 double dfDstYOff = -1,
double dfDstXSize = -1,
1009 double dfDstYSize = -1,
1010 const char *pszResampling =
"near",
1013 CPLErr AddComplexSource(
const char *pszFilename,
int nBand,
1014 double dfSrcXOff = -1,
double dfSrcYOff = -1,
1015 double dfSrcXSize = -1,
double dfSrcYSize = -1,
1016 double dfDstXOff = -1,
double dfDstYOff = -1,
1017 double dfDstXSize = -1,
double dfDstYSize = -1,
1018 double dfScaleOff = 0.0,
double dfScaleRatio = 1.0,
1020 int nColorTableComponent = 0);
1023 double dfSrcYOff = -1,
double dfSrcXSize = -1,
1024 double dfSrcYSize = -1,
double dfDstXOff = -1,
1025 double dfDstYOff = -1,
double dfDstXSize = -1,
1026 double dfDstYSize = -1,
double dfScaleOff = 0.0,
1027 double dfScaleRatio = 1.0,
1029 int nColorTableComponent = 0);
1032 double dfSrcYOff = -1,
double dfSrcXSize = -1,
1033 double dfSrcYSize = -1,
double dfDstXOff = -1,
1034 double dfDstYOff = -1,
double dfDstXSize = -1,
1035 double dfDstYSize = -1);
1040 void ConfigureSource(VRTSimpleSource *poSimpleSource,
1042 double dfSrcXOff,
double dfSrcYOff,
double dfSrcXSize,
1043 double dfSrcYSize,
double dfDstXOff,
double dfDstYOff,
1044 double dfDstXSize,
double dfDstYSize);
1046 void RemoveCoveredSources(
CSLConstList papszOptions =
nullptr);
1048 bool CanIRasterIOBeForwardedToEachSource(
1049 GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
int nYSize,
1052 bool CanMultiThreadRasterIO(
double dfXOff,
double dfYOff,
double dfXSize,
1054 int &nContributingSources)
const;
1056 virtual CPLErr IReadBlock(
int,
int,
void *)
override;
1058 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
1059 int *pnMaxSize,
CPLHashSet *hSetFiles)
override;
1061 virtual int CloseDependentDatasets()
override;
1063 virtual int IsSourcedRasterBand()
override
1068 virtual CPLErr FlushCache(
bool bAtClosing)
override;
1075class CPL_DLL VRTWarpedRasterBand final :
public VRTRasterBand
1080 virtual ~VRTWarpedRasterBand();
1082 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1083 bool &bHasWarnedAboutRAMUsage,
1084 size_t &nAccRAMUsage)
override;
1086 virtual CPLErr IReadBlock(
int,
int,
void *)
override;
1087 virtual CPLErr IWriteBlock(
int,
int,
void *)
override;
1090 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1095 virtual int GetOverviewCount()
override;
1099 int m_nIRasterIOCounter =
1102 int GetBestOverviewLevel(
int &nXOff,
int &nYOff,
int &nXSize,
int &nYSize,
1103 int nBufXSize,
int nBufYSize,
1111class VRTPansharpenedRasterBand final :
public VRTRasterBand
1113 int m_nIndexAsPansharpenedBand;
1116 VRTPansharpenedRasterBand(
GDALDataset *poDS,
int nBand,
1118 virtual ~VRTPansharpenedRasterBand();
1120 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1121 bool &bHasWarnedAboutRAMUsage,
1122 size_t &nAccRAMUsage)
override;
1124 virtual CPLErr IReadBlock(
int,
int,
void *)
override;
1127 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1132 virtual int GetOverviewCount()
override;
1135 virtual int IsPansharpenRasterBand()
override
1140 void SetIndexAsPansharpenedBand(
int nIdx)
1142 m_nIndexAsPansharpenedBand = nIdx;
1145 int GetIndexAsPansharpenedBand()
const
1147 return m_nIndexAsPansharpenedBand;
1155class VRTProcessedRasterBand final :
public VRTRasterBand
1158 VRTProcessedRasterBand(VRTProcessedDataset *poDS,
int nBand,
1161 virtual CPLErr IReadBlock(
int,
int,
void *)
override;
1163 virtual int GetOverviewCount()
override;
1166 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1167 bool &bHasWarnedAboutRAMUsage,
1168 size_t &nAccRAMUsage)
override;
1175class VRTDerivedRasterBandPrivateData;
1177class CPL_DLL VRTDerivedRasterBand
CPL_NON_FINAL :
public VRTSourcedRasterBand
1179 VRTDerivedRasterBandPrivateData *m_poPrivate;
1180 bool InitializePython();
1182 GetPixelFunctionArguments(
const CPLString &,
1183 std::vector<std::pair<CPLString, CPLString>> &);
1195 VRTDerivedRasterBand(
GDALDataset *poDS,
int nBand);
1197 int nXSize,
int nYSize);
1198 virtual ~VRTDerivedRasterBand();
1205 virtual int IGetDataCoverageStatus(
int nXOff,
int nYOff,
int nXSize,
1206 int nYSize,
int nMaskFlagStop,
1207 double *pdfDataPct)
override;
1209 static CPLErr AddPixelFunction(
const char *pszFuncNameIn,
1211 static CPLErr AddPixelFunction(
const char *pszFuncNameIn,
1213 const char *pszMetadata);
1215 static const std::pair<PixelFunc, std::string> *
1216 GetPixelFunction(
const char *pszFuncNameIn);
1218 void SetPixelFunctionName(
const char *pszFuncNameIn);
1220 void SetPixelFunctionLanguage(
const char *pszLanguage);
1223 VRTMapSharedResources &)
override;
1224 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1225 bool &bHasWarnedAboutRAMUsage,
1226 size_t &nAccRAMUsage)
override;
1228 virtual double GetMinimum(
int *pbSuccess =
nullptr)
override;
1229 virtual double GetMaximum(
int *pbSuccess =
nullptr)
override;
1230 virtual CPLErr ComputeRasterMinMax(
int bApproxOK,
1231 double *adfMinMax)
override;
1232 virtual CPLErr ComputeStatistics(
int bApproxOK,
double *pdfMin,
1233 double *pdfMax,
double *pdfMean,
1235 GDALProgressFunc pfnProgress,
1236 void *pProgressData)
override;
1237 virtual CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
1238 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1239 int bApproxOK, GDALProgressFunc pfnProgress,
1240 void *pProgressData)
override;
1242 static void Cleanup();
1251class CPL_DLL VRTRawRasterBand
CPL_NON_FINAL :
public VRTRasterBand
1253 RawRasterBand *m_poRawRaster;
1255 char *m_pszSourceFilename;
1256 int m_bRelativeToVRT;
1263 virtual ~VRTRawRasterBand();
1266 VRTMapSharedResources &)
override;
1267 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1268 bool &bHasWarnedAboutRAMUsage,
1269 size_t &nAccRAMUsage)
override;
1276 virtual CPLErr IReadBlock(
int,
int,
void *)
override;
1277 virtual CPLErr IWriteBlock(
int,
int,
void *)
override;
1279 CPLErr SetRawLink(
const char *pszFilename,
const char *pszVRTPath,
1281 int nPixelOffset,
int nLineOffset,
1282 const char *pszByteOrder);
1284 void ClearRawLink();
1288 char **papszOptions)
override;
1290 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
1291 int *pnMaxSize,
CPLHashSet *hSetFiles)
override;
1302 std::map<std::string, VRTSourceParser> m_oMapSourceParser{};
1306 virtual ~VRTDriver();
1308 char **papszSourceParsers;
1311 virtual char **
GetMetadata(
const char *pszDomain =
"")
override;
1313 const char *pszDomain =
"")
override;
1315 VRTSource *ParseSource(
const CPLXMLNode *psSrc,
const char *pszVRTPath,
1316 VRTMapSharedResources &oMapSharedSources);
1317 void AddSourceParser(
const char *pszElementName, VRTSourceParser pfnParser);
1324class CPL_DLL VRTSimpleSource
CPL_NON_FINAL :
public VRTSource
1330 VRTMapSharedResources *m_poMapSharedSources =
nullptr;
1340 void OpenSource()
const;
1343 friend class VRTSourcedRasterBand;
1344 friend class VRTDataset;
1345 friend class GDALTileIndexDataset;
1346 friend class GDALTileIndexBand;
1349 bool m_bGetMaskBand =
false;
1355 static constexpr double UNINIT_WINDOW = -1.0;
1357 double m_dfSrcXOff = UNINIT_WINDOW;
1358 double m_dfSrcYOff = UNINIT_WINDOW;
1359 double m_dfSrcXSize = UNINIT_WINDOW;
1360 double m_dfSrcYSize = UNINIT_WINDOW;
1362 double m_dfDstXOff = UNINIT_WINDOW;
1363 double m_dfDstYOff = UNINIT_WINDOW;
1364 double m_dfDstXSize = UNINIT_WINDOW;
1365 double m_dfDstYSize = UNINIT_WINDOW;
1369 int m_nMaxValue = 0;
1371 int m_bRelativeToVRTOri = -1;
1373 int m_nExplicitSharedStatus = -1;
1376 bool m_bDropRefOnSrcBand =
true;
1378 int NeedMaxValAdjustment()
const;
1382 return m_poRasterBand;
1387 m_poRasterBand = poBand;
1388 m_bDropRefOnSrcBand = bDropRef;
1397 bool IsSrcWinSet()
const
1399 return m_dfSrcXOff != UNINIT_WINDOW || m_dfSrcYOff != UNINIT_WINDOW ||
1400 m_dfSrcXSize != UNINIT_WINDOW || m_dfSrcYSize != UNINIT_WINDOW;
1404 bool IsDstWinSet()
const
1406 return m_dfDstXOff != UNINIT_WINDOW || m_dfDstYOff != UNINIT_WINDOW ||
1407 m_dfDstXSize != UNINIT_WINDOW || m_dfDstYSize != UNINIT_WINDOW;
1412 VRTSimpleSource(
const VRTSimpleSource *poSrcSource,
double dfXDstRatio,
1413 double dfYDstRatio);
1414 virtual ~VRTSimpleSource();
1417 VRTMapSharedResources &)
override;
1418 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1422 void SetSrcBand(
const char *pszFilename,
int nBand);
1425 void SetSrcWindow(
double,
double,
double,
double);
1426 void SetDstWindow(
double,
double,
double,
double);
1427 void GetDstWindow(
double &,
double &,
double &,
double &)
const;
1428 bool DstWindowIntersects(
double dfXOff,
double dfYOff,
double dfXSize,
1429 double dfYSize)
const;
1431 const std::string &GetSourceDatasetName()
const
1433 return m_osSrcDSName;
1438 return m_osResampling;
1441 void SetResampling(
const char *pszResampling);
1443 int GetSrcDstWindow(
double,
double,
double,
double,
int,
int,
1444 double *pdfReqXOff,
double *pdfReqYOff,
1445 double *pdfReqXSize,
double *pdfReqYSize,
int *,
int *,
1446 int *,
int *,
int *,
int *,
int *,
int *,
1450 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1454 WorkingState &oWorkingState)
override;
1456 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1457 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1458 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
1459 double dfMax,
int nBuckets,
1460 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1461 int bApproxOK, GDALProgressFunc pfnProgress,
1462 void *pProgressData)
override;
1464 void DstToSrc(
double dfX,
double dfY,
double &dfXOut,
double &dfYOut)
const;
1465 void SrcToDst(
double dfX,
double dfY,
double &dfXOut,
double &dfYOut)
const;
1467 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
1468 int *pnMaxSize,
CPLHashSet *hSetFiles)
override;
1470 bool IsSimpleSource()
const override
1478 static const char *GetTypeStatic();
1480 const char *GetType()
const override;
1482 virtual CPLErr FlushCache(
bool bAtClosing)
override;
1486 bool IsSameExceptBandNumber(
const VRTSimpleSource *poOtherSource)
const;
1488 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1490 const int *panBandMap,
GSpacing nPixelSpace,
1494 void UnsetPreservedRelativeFilenames();
1496 void SetMaxValue(
int nVal)
1506class VRTAveragedSource final :
public VRTSimpleSource
1510 int m_bNoDataSet =
false;
1514 VRTAveragedSource();
1516 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1520 WorkingState &oWorkingState)
override;
1522 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1523 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1524 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
1525 double dfMax,
int nBuckets,
1526 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1527 int bApproxOK, GDALProgressFunc pfnProgress,
1528 void *pProgressData)
override;
1530 void SetNoDataValue(
double dfNoDataValue);
1532 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1537 static const char *GetTypeStatic();
1539 const char *GetType()
const override;
1546class VRTNoDataFromMaskSource final :
public VRTSimpleSource
1550 bool m_bNoDataSet =
false;
1551 double m_dfNoDataValue = 0;
1552 double m_dfMaskValueThreshold = 0;
1553 bool m_bHasRemappedValue =
false;
1554 double m_dfRemappedValue = 0;
1557 VRTNoDataFromMaskSource();
1559 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1563 WorkingState &oWorkingState)
override;
1565 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1566 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1567 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
1568 double dfMax,
int nBuckets,
1569 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1570 int bApproxOK, GDALProgressFunc pfnProgress,
1571 void *pProgressData)
override;
1573 void SetParameters(
double dfNoDataValue,
double dfMaskValueThreshold);
1574 void SetParameters(
double dfNoDataValue,
double dfMaskValueThreshold,
1575 double dfRemappedValue);
1578 VRTMapSharedResources &)
override;
1579 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1584 static const char *GetTypeStatic();
1586 const char *GetType()
const override;
1593class CPL_DLL VRTComplexSource
CPL_NON_FINAL :
public VRTSimpleSource
1598 static constexpr int PROCESSING_FLAG_NODATA = 1 << 0;
1599 static constexpr int PROCESSING_FLAG_USE_MASK_BAND =
1601 static constexpr int PROCESSING_FLAG_SCALING_LINEAR = 1 << 2;
1602 static constexpr int PROCESSING_FLAG_SCALING_EXPONENTIAL =
1604 static constexpr int PROCESSING_FLAG_COLOR_TABLE_EXPANSION = 1 << 4;
1605 static constexpr int PROCESSING_FLAG_LUT = 1 << 5;
1607 int m_nProcessingFlags = 0;
1612 m_osNoDataValueOri{};
1614 double m_dfScaleOff = 0;
1615 double m_dfScaleRatio = 1;
1618 bool m_bSrcMinMaxDefined =
false;
1619 double m_dfSrcMin = 0;
1620 double m_dfSrcMax = 0;
1621 double m_dfDstMin = 0;
1622 double m_dfDstMax = 0;
1623 double m_dfExponent = 1;
1625 int m_nColorTableComponent = 0;
1627 std::vector<double> m_adfLUTInputs{};
1628 std::vector<double> m_adfLUTOutputs{};
1630 double GetAdjustedNoDataValue()
const;
1632 template <
class WorkingDT>
1635 GDALDataType eVRTBandDataType,
int nReqXOff,
int nReqYOff,
1636 int nReqXSize,
int nReqYSize,
void *pData,
int nOutXSize,
1639 GDALDataType eWrkDataType, WorkingState &oWorkingState);
1641 template <
class SourceDT, GDALDataType eSourceType>
1644 int nReqYOff,
int nReqXSize,
int nReqYSize,
1645 void *pData,
int nOutXSize,
int nOutYSize,
1649 WorkingState &oWorkingState);
1652 VRTComplexSource() =
default;
1653 VRTComplexSource(
const VRTComplexSource *poSrcSource,
double dfXDstRatio,
1654 double dfYDstRatio);
1657 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1661 WorkingState &oWorkingState)
override;
1663 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1664 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1665 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
1666 double dfMax,
int nBuckets,
1667 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1668 int bApproxOK, GDALProgressFunc pfnProgress,
1669 void *pProgressData)
override;
1671 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1673 VRTMapSharedResources &)
override;
1678 static const char *GetTypeStatic();
1680 const char *GetType()
const override;
1682 bool AreValuesUnchanged()
const;
1684 double LookupValue(
double dfInput);
1686 void SetNoDataValue(
double dfNoDataValue);
1688 void SetUseMaskBand(
bool bUseMaskBand)
1691 m_nProcessingFlags |= PROCESSING_FLAG_USE_MASK_BAND;
1693 m_nProcessingFlags &= ~PROCESSING_FLAG_USE_MASK_BAND;
1696 void SetLinearScaling(
double dfOffset,
double dfScale);
1697 void SetPowerScaling(
double dfExponent,
double dfSrcMin,
double dfSrcMax,
1698 double dfDstMin,
double dfDstMax);
1699 void SetColorTableComponent(
int nComponent);
1706class VRTFilteredSource
CPL_NON_FINAL :
public VRTComplexSource
1714 int m_nSupportedTypesCount;
1717 int m_nExtraEdgePixels;
1720 VRTFilteredSource();
1721 virtual ~VRTFilteredSource();
1723 const char *GetType()
const override = 0;
1725 void SetExtraEdgePixels(
int);
1726 void SetFilteringDataTypesSupported(
int,
GDALDataType *);
1732 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1736 WorkingState &oWorkingState)
override;
1743class VRTKernelFilteredSource
CPL_NON_FINAL :
public VRTFilteredSource
1748 int m_nKernelSize = 0;
1749 bool m_bSeparable =
false;
1751 std::vector<double> m_adfKernelCoefs{};
1752 bool m_bNormalized =
false;
1755 VRTKernelFilteredSource();
1757 const char *GetType()
const override;
1760 VRTMapSharedResources &)
override;
1761 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1764 GByte *pabySrcData,
GByte *pabyDstData)
override;
1766 CPLErr SetKernel(
int nKernelSize,
bool bSeparable,
1767 const std::vector<double> &adfNewCoefs);
1768 void SetNormalized(
bool);
1775class VRTAverageFilteredSource final :
public VRTKernelFilteredSource
1780 explicit VRTAverageFilteredSource(
int nKernelSize);
1781 virtual ~VRTAverageFilteredSource();
1783 const char *GetType()
const override;
1786 VRTMapSharedResources &)
override;
1787 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1793class VRTFuncSource final :
public VRTSource
1799 virtual ~VRTFuncSource();
1802 VRTMapSharedResources &)
override
1807 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1810 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1814 WorkingState &oWorkingState)
override;
1816 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1817 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1818 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
1819 double dfMax,
int nBuckets,
1820 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1821 int bApproxOK, GDALProgressFunc pfnProgress,
1822 void *pProgressData)
override;
1824 const char *GetType()
const override;
1838#define TMP_CPL_DLL CPL_DLL
1854 explicit Ref(VRTGroup *ptr) : m_ptr(ptr)
1858 Ref(
const Ref &) =
delete;
1859 Ref &operator=(
const Ref &) =
delete;
1863 std::shared_ptr<Ref> m_poSharedRefRootGroup{};
1864 std::weak_ptr<Ref> m_poWeakRefRootGroup{};
1865 std::shared_ptr<Ref> m_poRefSelf{};
1867 std::string m_osFilename{};
1868 mutable bool m_bDirty =
false;
1869 std::string m_osVRTPath{};
1870 std::map<std::string, std::shared_ptr<VRTGroup>> m_oMapGroups{};
1871 std::map<std::string, std::shared_ptr<VRTMDArray>> m_oMapMDArrays{};
1872 std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
1873 std::map<std::string, std::shared_ptr<VRTDimension>> m_oMapDimensions{};
1875 std::shared_ptr<VRTGroup>
1876 OpenGroupInternal(
const std::string &osName)
const;
1877 void SetRootGroupRef(
const std::weak_ptr<Ref> &rgRef);
1878 std::weak_ptr<Ref> GetRootGroupRef()
const;
1881 friend class VRTMDArray;
1882 friend std::shared_ptr<GDALMDArray>
1883 VRTDerivedArrayCreate(
const char *pszVRTPath,
const CPLXMLNode *psTree);
1885 explicit VRTGroup(
const char *pszVRTPath);
1886 VRTGroup(
const std::string &osParentName,
const std::string &osName);
1889 static std::shared_ptr<VRTGroup> Create(
const std::string &osParentName,
1890 const std::string &osName)
1893 std::shared_ptr<VRTGroup>(
new VRTGroup(osParentName, osName));
1894 poGroup->SetSelf(poGroup);
1900 bool XMLInit(
const std::shared_ptr<VRTGroup> &poRoot,
1901 const std::shared_ptr<VRTGroup> &poThisGroup,
1902 const CPLXMLNode *psNode,
const char *pszVRTPath);
1904 std::vector<std::string>
1905 GetMDArrayNames(
CSLConstList papszOptions)
const override;
1906 std::shared_ptr<GDALMDArray>
1907 OpenMDArray(
const std::string &osName,
1910 std::vector<std::string>
1911 GetGroupNames(
CSLConstList papszOptions)
const override;
1913 std::shared_ptr<GDALGroup> OpenGroup(
const std::string &osName,
1916 return OpenGroupInternal(osName);
1919 std::vector<std::shared_ptr<GDALDimension>>
1922 std::vector<std::shared_ptr<GDALAttribute>>
1925 std::shared_ptr<VRTDimension> GetDimension(
const std::string &name)
const
1927 auto oIter = m_oMapDimensions.find(name);
1928 return oIter == m_oMapDimensions.end() ? nullptr : oIter->second;
1931 std::shared_ptr<VRTDimension>
1932 GetDimensionFromFullName(
const std::string &name,
bool bEmitError)
const;
1934 std::shared_ptr<GDALGroup>
1935 CreateGroup(
const std::string &osName,
1938 std::shared_ptr<GDALDimension>
1939 CreateDimension(
const std::string &osName,
const std::string &osType,
1940 const std::string &osDirection,
GUInt64 nSize,
1943 std::shared_ptr<GDALAttribute>
1944 CreateAttribute(
const std::string &osName,
1945 const std::vector<GUInt64> &anDimensions,
1949 std::shared_ptr<GDALMDArray> CreateMDArray(
1950 const std::string &osName,
1951 const std::vector<std::shared_ptr<GDALDimension>> &aoDimensions,
1955 void SetIsRootGroup();
1957 const std::shared_ptr<Ref> &GetRef()
const
1962 VRTGroup *GetRootGroup()
const;
1963 std::shared_ptr<GDALGroup> GetRootGroupSharedPtr()
const;
1965 const std::string &GetVRTPath()
const
1972 void SetFilename(
const std::string &osFilename)
1974 m_osFilename = osFilename;
1977 const std::string &GetFilename()
const
1979 return m_osFilename;
1982 bool Serialize()
const;
1983 CPLXMLNode *SerializeToXML(
const char *pszVRTPathIn)
const;
1984 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPathIn)
const;
1993 std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
1994 std::string m_osIndexingVariableName;
1997 VRTDimension(
const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
1998 const std::string &osParentName,
const std::string &osName,
1999 const std::string &osType,
const std::string &osDirection,
2000 GUInt64 nSize,
const std::string &osIndexingVariableName)
2001 :
GDALDimension(osParentName, osName, osType, osDirection, nSize),
2002 m_poGroupRef(poGroupRef),
2003 m_osIndexingVariableName(osIndexingVariableName)
2007 VRTGroup *GetGroup()
const;
2009 static std::shared_ptr<VRTDimension>
2010 Create(
const std::shared_ptr<VRTGroup> &poThisGroup,
2011 const std::string &osParentName,
const CPLXMLNode *psNode);
2016 std::shared_ptr<GDALMDArray> poIndexingVariable)
override;
2028 std::vector<std::string> m_aosList{};
2029 std::vector<std::shared_ptr<GDALDimension>> m_dims{};
2032 bool IRead(
const GUInt64 *arrayStartIdx,
const size_t *count,
2035 void *pDstBuffer)
const override;
2037 bool IWrite(
const GUInt64 *arrayStartIdx,
const size_t *count,
2040 const void *pSrcBuffer)
override;
2043 VRTAttribute(
const std::string &osParentName,
const std::string &osName,
2045 std::vector<std::string> &&aosList)
2048 m_aosList(std::move(aosList))
2050 if (m_aosList.size() > 1)
2052 m_dims.emplace_back(std::make_shared<GDALDimension>(
2053 std::string(),
"dim", std::string(), std::string(),
2058 VRTAttribute(
const std::string &osParentName,
const std::string &osName,
2065 m_dims.emplace_back(std::make_shared<GDALDimension>(
2066 std::string(),
"dim", std::string(), std::string(), nDim));
2070 static bool CreationCommonChecks(
2071 const std::string &osName,
const std::vector<GUInt64> &anDimensions,
2072 const std::map<std::string, std::shared_ptr<VRTAttribute>>
2075 static std::shared_ptr<VRTAttribute> Create(
const std::string &osParentName,
2078 const std::vector<std::shared_ptr<GDALDimension>> &
2096class VRTMDArraySource
2099 virtual ~VRTMDArraySource() =
default;
2101 virtual bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2104 void *pDstBuffer)
const = 0;
2107 const char *pszVRTPath)
const = 0;
2117 friend class VRTGroup;
2119 std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
2120 std::string m_osVRTPath{};
2121 std::shared_ptr<VRTGroup> m_poDummyOwningGroup{};
2124 std::vector<std::shared_ptr<GDALDimension>> m_dims;
2125 std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
2126 std::vector<std::unique_ptr<VRTMDArraySource>> m_sources{};
2127 std::shared_ptr<OGRSpatialReference> m_poSRS{};
2128 std::vector<GByte> m_abyNoData{};
2129 std::string m_osUnit{};
2130 double m_dfScale = 1.0;
2131 double m_dfOffset = 0.0;
2132 bool m_bHasScale =
false;
2133 bool m_bHasOffset =
false;
2134 std::string m_osFilename{};
2136 bool IRead(
const GUInt64 *arrayStartIdx,
const size_t *count,
2139 void *pDstBuffer)
const override;
2145 const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
2146 const std::string &osParentName,
const std::string &osName,
2148 std::vector<std::shared_ptr<GDALDimension>> &&dims,
2149 std::map<std::string, std::shared_ptr<VRTAttribute>> &&oMapAttributes)
2151 GDALMDArray(osParentName, osName), m_poGroupRef(poGroupRef),
2152 m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()), m_dt(dt),
2153 m_dims(std::move(dims)), m_oMapAttributes(std::move(oMapAttributes)),
2154 m_osFilename(poGroupRef->m_ptr->GetFilename())
2158 VRTMDArray(
const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
2159 const std::string &osParentName,
const std::string &osName,
2160 const std::vector<std::shared_ptr<GDALDimension>> &dims,
2163 GDALMDArray(osParentName, osName), m_poGroupRef(poGroupRef),
2164 m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()), m_dt(dt), m_dims(dims),
2165 m_osFilename(poGroupRef->m_ptr->GetFilename())
2176 return m_osFilename;
2179 static std::shared_ptr<VRTMDArray> Create(
const char *pszVRTPath,
2182 static std::shared_ptr<VRTMDArray>
2183 Create(
const std::shared_ptr<VRTGroup> &poThisGroup,
2184 const std::string &osParentName,
const CPLXMLNode *psNode);
2186 const std::vector<std::shared_ptr<GDALDimension>> &
2192 std::vector<std::shared_ptr<GDALAttribute>>
2202 std::shared_ptr<OGRSpatialReference>
GetSpatialRef()
const override
2211 const std::string &
GetUnit()
const override
2216 bool SetUnit(
const std::string &osUnit)
override
2226 *pbHasOffset = m_bHasOffset;
2236 *pbHasScale = m_bHasScale;
2246 m_bHasOffset =
true;
2247 m_dfOffset = dfOffset;
2256 m_dfScale = dfScale;
2260 void AddSource(std::unique_ptr<VRTMDArraySource> &&poSource);
2262 std::shared_ptr<GDALAttribute>
2264 const std::vector<GUInt64> &anDimensions,
2270 GDALProgressFunc pfnProgress,
void *pProgressData)
override;
2272 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPathIn)
const;
2274 VRTGroup *GetGroup()
const;
2276 const std::string &GetVRTPath()
const
2281 std::shared_ptr<GDALGroup>
GetRootGroup()
const override
2283 auto poGroup = m_poGroupRef.lock();
2285 return poGroup->m_ptr->GetRootGroupSharedPtr();
2294class VRTMDArraySourceInlinedValues final :
public VRTMDArraySource
2296 const VRTMDArray *m_poDstArray =
nullptr;
2297 bool m_bIsConstantValue;
2298 std::vector<GUInt64> m_anOffset{};
2299 std::vector<size_t> m_anCount{};
2300 std::vector<GByte> m_abyValues{};
2301 std::vector<size_t> m_anInlinedArrayStrideInBytes{};
2304 VRTMDArraySourceInlinedValues(
const VRTMDArraySourceInlinedValues &) =
2306 VRTMDArraySourceInlinedValues &
2307 operator=(
const VRTMDArraySourceInlinedValues &) =
delete;
2310 VRTMDArraySourceInlinedValues(
const VRTMDArray *poDstArray,
2311 bool bIsConstantValue,
2312 std::vector<GUInt64> &&anOffset,
2313 std::vector<size_t> &&anCount,
2314 std::vector<GByte> &&abyValues)
2315 : m_poDstArray(poDstArray), m_bIsConstantValue(bIsConstantValue),
2316 m_anOffset(std::move(anOffset)), m_anCount(std::move(anCount)),
2317 m_abyValues(std::move(abyValues)), m_dt(poDstArray->GetDataType())
2319 const auto nDims(poDstArray->GetDimensionCount());
2320 m_anInlinedArrayStrideInBytes.resize(nDims);
2321 if (!bIsConstantValue && nDims > 0)
2323 m_anInlinedArrayStrideInBytes.back() =
2324 poDstArray->GetDataType().GetSize();
2325 for (
size_t i = nDims - 1; i > 0;)
2328 m_anInlinedArrayStrideInBytes[i] =
2329 m_anInlinedArrayStrideInBytes[i + 1] * m_anCount[i + 1];
2334 ~VRTMDArraySourceInlinedValues();
2336 static std::unique_ptr<VRTMDArraySourceInlinedValues>
2337 Create(
const VRTMDArray *poDstArray,
const CPLXMLNode *psNode);
2339 bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2342 void *pDstBuffer)
const override;
2344 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPath)
const override;
2351class VRTMDArraySourceRegularlySpaced final :
public VRTMDArraySource
2354 double m_dfIncrement;
2357 VRTMDArraySourceRegularlySpaced(
double dfStart,
double dfIncrement)
2358 : m_dfStart(dfStart), m_dfIncrement(dfIncrement)
2362 bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2365 void *pDstBuffer)
const override;
2367 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPath)
const override;
2374class VRTMDArraySourceFromArray final :
public VRTMDArraySource
2376 const VRTMDArray *m_poDstArray =
nullptr;
2377 bool m_bRelativeToVRTSet =
false;
2378 bool m_bRelativeToVRT =
false;
2379 std::string m_osFilename{};
2380 std::string m_osArray{};
2381 std::string m_osBand{};
2382 std::vector<int> m_anTransposedAxis{};
2383 std::string m_osViewExpr{};
2384 std::vector<GUInt64> m_anSrcOffset{};
2385 mutable std::vector<GUInt64> m_anCount{};
2386 std::vector<GUInt64> m_anStep{};
2387 std::vector<GUInt64> m_anDstOffset{};
2389 VRTMDArraySourceFromArray(
const VRTMDArraySourceFromArray &) =
delete;
2390 VRTMDArraySourceFromArray &
2391 operator=(
const VRTMDArraySourceFromArray &) =
delete;
2394 VRTMDArraySourceFromArray(
2395 const VRTMDArray *poDstArray,
bool bRelativeToVRTSet,
2396 bool bRelativeToVRT,
const std::string &osFilename,
2397 const std::string &osArray,
const std::string &osBand,
2398 std::vector<int> &&anTransposedAxis,
const std::string &osViewExpr,
2399 std::vector<GUInt64> &&anSrcOffset, std::vector<GUInt64> &&anCount,
2400 std::vector<GUInt64> &&anStep, std::vector<GUInt64> &&anDstOffset)
2401 : m_poDstArray(poDstArray), m_bRelativeToVRTSet(bRelativeToVRTSet),
2402 m_bRelativeToVRT(bRelativeToVRT), m_osFilename(osFilename),
2403 m_osArray(osArray), m_osBand(osBand),
2404 m_anTransposedAxis(std::move(anTransposedAxis)),
2405 m_osViewExpr(osViewExpr), m_anSrcOffset(std::move(anSrcOffset)),
2406 m_anCount(std::move(anCount)), m_anStep(std::move(anStep)),
2407 m_anDstOffset(std::move(anDstOffset))
2411 ~VRTMDArraySourceFromArray()
override;
2413 static std::unique_ptr<VRTMDArraySourceFromArray>
2414 Create(
const VRTMDArray *poDstArray,
const CPLXMLNode *psNode);
2416 bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2419 void *pDstBuffer)
const override;
2421 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:436
Convenient string class based on std::string.
Definition: cpl_string.h:307
Manage a tree of XML nodes so that all nodes are freed when the instance goes out of scope.
Definition: cpl_minixml.h:194
Abstract class, implemented by GDALAttribute and GDALMDArray.
Definition: gdal_priv.h:3119
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_priv.h:3350
A color table / palette.
Definition: gdal_priv.h:1362
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:495
int Dereference()
Subtract one from dataset reference count.
Definition: gdaldataset.cpp:1592
virtual CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList, const OGRSpatialReference *poGCP_SRS)
Assign GCPs.
Definition: gdaldataset.cpp:2028
int GetShared() const
Returns shared flag.
Definition: gdaldataset.cpp:1666
Class modeling a a dimension / axis used to index multidimensional arrays.
Definition: gdal_priv.h:3843
virtual std::shared_ptr< GDALMDArray > GetIndexingVariable() const
Return the variable that is used to index the dimension (if there is one).
Definition: gdalmultidim.cpp:10365
virtual bool SetIndexingVariable(std::shared_ptr< GDALMDArray > poIndexingVariable)
Set the variable that is used to index the dimension.
Definition: gdalmultidim.cpp:10386
Format specific driver.
Definition: gdal_priv.h:2124
Class used to represent potentially complex data types.
Definition: gdal_priv.h:2721
Class modeling a named container of GDALAttribute, GDALMDArray, OGRLayer or other GDALGroup.
Definition: gdal_priv.h:2950
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:286
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:255
Class modeling a multi-dimensional array.
Definition: gdal_priv.h:3469
virtual bool SetUnit(const std::string &osUnit)
Set the variable unit.
Definition: gdalmultidim.cpp:2521
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:3922
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:2854
virtual bool SetRawNoDataValue(const void *pRawNoData)
Set the nodata value as a "raw" value.
Definition: gdalmultidim.cpp:2713
virtual double GetOffset(bool *pbHasOffset=nullptr, GDALDataType *peStorageType=nullptr) const
Get the offset value to apply to raw values.
Definition: gdalmultidim.cpp:2941
virtual const void * GetRawNoDataValue() const
Return the nodata value as a "raw" value.
Definition: gdalmultidim.cpp:2597
virtual double GetScale(bool *pbHasScale=nullptr, GDALDataType *peStorageType=nullptr) const
Get the scale value to apply to raw values.
Definition: gdalmultidim.cpp:2911
virtual std::shared_ptr< OGRSpatialReference > GetSpatialRef() const
Return the spatial reference system object associated with the array.
Definition: gdalmultidim.cpp:2571
virtual const std::string & GetFilename() const =0
Return the filename that contains that array.
virtual bool SetSpatialRef(const OGRSpatialReference *poSRS)
Assign a spatial reference system object to the array.
Definition: gdalmultidim.cpp:2557
virtual std::shared_ptr< GDALGroup > GetRootGroup() const
Return the root group to which this arrays belongs too.
Definition: gdalmultidim.cpp:4504
virtual bool SetOffset(double dfOffset, GDALDataType eStorageType=GDT_Unknown)
Set the offset value to apply to raw values.
Definition: gdalmultidim.cpp:2882
virtual const std::string & GetUnit() const
Return the array unit.
Definition: gdalmultidim.cpp:2543
virtual CPLErr SetMetadata(char **papszMetadata, const char *pszDomain="")
Set metadata.
Definition: gdalmajorobject.cpp:274
virtual char ** GetMetadataDomainList()
Fetch list of metadata domains.
Definition: gdalmajorobject.cpp:144
virtual char ** GetMetadata(const char *pszDomain="")
Fetch metadata.
Definition: gdalmajorobject.cpp:231
Class for dataset open functions.
Definition: gdal_priv.h:293
Pansharpening operation class.
Definition: gdalpansharpen.h:174
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition: gdal_rat.h:32
A single raster band (or channel).
Definition: gdal_priv.h:1519
GDALDataset * GetDataset() const
Fetch the owning dataset handle.
Definition: gdalrasterband.cpp:3839
High level image warping class.
Definition: gdalwarper.h:486
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:153
CPLErr
Error category.
Definition: cpl_error.h:37
struct _CPLHashSet CPLHashSet
Opaque type for a hash set.
Definition: cpl_hash_set.h:36
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:240
#define CPL_NON_FINAL
Mark that a class is explicitly recognized as non-final.
Definition: cpl_port.h:1023
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:202
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:220
#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:1030
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1179
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:222
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:169
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:199
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition: cpl_virtualmem.h:46
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:130
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:400
GDALAccess
Definition: gdal.h:110
@ GA_ReadOnly
Definition: gdal.h:111
void * VRTPDWorkingDataPtr
Generic pointer for the working structure of VRTProcessedDataset function.
Definition: gdal.h:1747
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:1575
CPLErr GDALClose(GDALDatasetH)
Close GDAL dataset.
Definition: gdaldataset.cpp:4194
GDALColorInterp
Types of color interpretation for raster bands.
Definition: gdal.h:257
@ GCI_Undefined
Definition: gdal.h:258
GDALRWFlag
Definition: gdal.h:117
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:1567
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:379
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:29
void * VRTDatasetH
Opaque type for a VRT dataset.
Definition: gdal_vrt.h:58
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:34
VRTDatasetH VRTCreate(int, int)
Definition: vrtdataset.cpp:68
Document node structure.
Definition: cpl_minixml.h:55
Ground Control Point.
Definition: gdal.h:1168