31 #ifndef VIRTUALDATASET_H_INCLUDED
32 #define VIRTUALDATASET_H_INCLUDED
49 CPLErr GDALRegisterDefaultPixelFunc();
50 void GDALVRTRegisterDefaultProcessedDatasetFuncs();
55 int VRTWarpedOverviewTransform(
void *pTransformArg,
int bDstToSrc,
57 double *padfX,
double *padfY,
double *padfZ,
59 void* VRTDeserializeWarpedOverviewTransformer(
CPLXMLNode *psTree );
73 int bTriedToOpen = FALSE;
75 VRTOverviewInfo() =
default;
77 VRTOverviewInfo(VRTOverviewInfo &&oOther) noexcept
78 : osFilename(std::move(oOther.osFilename)), nBand(oOther.nBand),
79 poBand(oOther.poBand), bTriedToOpen(oOther.bTriedToOpen)
81 oOther.poBand =
nullptr;
91 if (poBand ==
nullptr)
110 class CPL_DLL VRTSource
113 struct CPL_DLL WorkingState
117 #pragma GCC diagnostic push
118 #pragma GCC diagnostic ignored "-Weffc++"
131 inline operator GByte()
const
137 #pragma GCC diagnostic pop
140 std::vector<NoInitByte> m_abyWrkBuffer{};
141 std::vector<NoInitByte> m_abyWrkBufferMask{};
144 virtual ~VRTSource();
147 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
151 WorkingState &oWorkingState) = 0;
153 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess) = 0;
154 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess) = 0;
155 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
156 double dfMax,
int nBuckets,
157 GUIntBig *panHistogram,
int bIncludeOutOfRange,
158 int bApproxOK, GDALProgressFunc pfnProgress,
159 void *pProgressData) = 0;
162 std::map<CPLString, GDALDataset *> &) = 0;
163 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath) = 0;
165 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
168 virtual int IsSimpleSource()
173 virtual CPLErr FlushCache(
bool )
179 typedef VRTSource *(*VRTSourceParser)(
181 std::map<CPLString, GDALDataset *> &oMapSharedSources);
184 VRTParseCoreSources(
const CPLXMLNode *psTree,
const char *,
185 std::map<CPLString, GDALDataset *> &oMapSharedSources);
187 VRTParseFilterSources(
const CPLXMLNode *psTree,
const char *,
188 std::map<CPLString, GDALDataset *> &oMapSharedSources);
190 VRTParseArraySource(
const CPLXMLNode *psTree,
const char *,
191 std::map<CPLString, GDALDataset *> &oMapSharedSources);
199 template <
class T>
struct VRTFlushCacheStruct
201 static CPLErr FlushCache(T &obj,
bool bAtClosing);
204 class VRTWarpedDataset;
205 class VRTPansharpenedDataset;
206 class VRTProcessedDataset;
211 friend class VRTRasterBand;
212 friend struct VRTFlushCacheStruct<VRTDataset>;
213 friend struct VRTFlushCacheStruct<VRTWarpedDataset>;
214 friend struct VRTFlushCacheStruct<VRTPansharpenedDataset>;
215 friend struct VRTFlushCacheStruct<VRTProcessedDataset>;
216 friend class VRTSourcedRasterBand;
217 friend class VRTSimpleSource;
220 std::vector<gdal::GCP> m_asGCPs{};
221 std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser>
224 bool m_bNeedsFlush =
false;
225 bool m_bWritable =
true;
226 bool m_bCanTakeRef =
true;
228 char *m_pszVRTPath =
nullptr;
230 VRTRasterBand *m_poMaskBand =
nullptr;
232 int m_bCompatibleForDatasetIO = -1;
233 int CheckCompatibleForDatasetIO();
237 std::vector<GDALDataset *> m_apoOverviews{};
238 std::vector<GDALDataset *> m_apoOverviewsBak{};
241 std::vector<int> m_anOverviewFactors{};
243 char **m_papszXMLVRTMetadata =
nullptr;
245 std::map<CPLString, GDALDataset *> m_oMapSharedSources{};
246 std::shared_ptr<VRTGroup> m_poRootGroup{};
248 VRTSource::WorkingState m_oWorkingState{};
250 static constexpr
const char *
const apszSpecialSyntax[] = {
251 "NITF_IM:{ANY}:{FILENAME}",
"PDF:{ANY}:{FILENAME}",
252 "RASTERLITE:{FILENAME},{ANY}",
"TILEDB:\"{FILENAME}\":{ANY}",
253 "TILEDB:{FILENAME}:{ANY}"};
255 VRTRasterBand *InitBand(
const char *pszSubclass,
int nBand,
256 bool bAllowPansharpenedOrProcessed);
257 static GDALDataset *OpenVRTProtocol(
const char *pszSpec);
258 bool AddVirtualOverview(
int nOvFactor,
const char *pszResampling);
260 bool GetShiftedDataset(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
267 bool m_bBlockSizeSpecified =
false;
268 int m_nBlockXSize = 0;
269 int m_nBlockYSize = 0;
271 std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser> m_poSRS{};
273 int m_bGeoTransformSet =
false;
274 double m_adfGeoTransform[6];
276 virtual int CloseDependentDatasets()
override;
279 VRTDataset(
int nXSize,
int nYSize,
int nBlockXSize = 0,
280 int nBlockYSize = 0);
281 virtual ~VRTDataset();
285 m_bNeedsFlush =
true;
288 virtual CPLErr FlushCache(
bool bAtClosing)
override;
290 void SetWritable(
int bWritableIn)
292 m_bWritable = CPL_TO_BOOL(bWritableIn);
295 virtual CPLErr CreateMaskBand(
int nFlags)
override;
296 void SetMaskBand(VRTRasterBand *poMaskBand);
300 return m_poSRS.get();
305 virtual CPLErr GetGeoTransform(
double *)
override;
306 virtual CPLErr SetGeoTransform(
double *)
override;
308 virtual CPLErr SetMetadata(
char **papszMetadata,
309 const char *pszDomain =
"")
override;
310 virtual CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
311 const char *pszDomain =
"")
override;
313 virtual char **GetMetadata(
const char *pszDomain =
"")
override;
315 virtual int GetGCPCount()
override;
319 return m_poGCP_SRS.get();
322 virtual const GDAL_GCP *GetGCPs()
override;
328 char **papszOptions =
nullptr)
override;
330 virtual char **GetFileList()
override;
333 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
335 int nBandCount, BANDMAP_TYPE panBandMap,
341 GetCompressionFormats(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
342 int nBandCount,
const int *panBandList)
override;
343 virtual CPLErr ReadCompressedData(
const char *pszFormat,
int nXOff,
344 int nYOff,
int nXSize,
int nYSize,
345 int nBandCount,
const int *panBandList,
346 void **ppBuffer,
size_t *pnBufferSize,
347 char **ppszDetailedFormat)
override;
349 virtual CPLErr AdviseRead(
int nXOff,
int nYOff,
int nXSize,
int nYSize,
351 int nBandCount,
int *panBandList,
352 char **papszOptions)
override;
354 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath);
357 virtual CPLErr IBuildOverviews(
const char *,
int,
const int *,
int,
358 const int *, GDALProgressFunc,
void *,
361 std::shared_ptr<GDALGroup> GetRootGroup()
const override;
363 void ClearStatistics()
override;
367 void BuildVirtualOverviews();
369 void UnsetPreservedRelativeFilenames();
371 bool IsBlockSizeSpecified()
const
373 return m_bBlockSizeSpecified;
376 int GetBlockXSize()
const
378 return m_nBlockXSize;
381 int GetBlockYSize()
const
383 return m_nBlockYSize;
388 static VRTDataset *OpenXML(
const char *,
const char * =
nullptr,
390 static GDALDataset *Create(
const char *pszName,
int nXSize,
int nYSize,
392 char **papszOptions);
394 CreateMultiDimensional(
const char *pszFilename,
397 static CPLErr Delete(
const char *pszFilename);
399 static std::string BuildSourceFilename(
const char *pszFilename,
400 const char *pszVRTPath,
401 bool bRelativeToVRT);
409 class VRTWarpedRasterBand;
411 class CPL_DLL VRTWarpedDataset final :
public VRTDataset
415 int m_nOverviewCount;
416 VRTWarpedDataset **m_papoOverviews;
419 void CreateImplicitOverviews();
421 friend class VRTWarpedRasterBand;
426 virtual int CloseDependentDatasets()
override;
429 VRTWarpedDataset(
int nXSize,
int nYSize,
int nBlockXSize = 0,
430 int nBlockYSize = 0);
431 virtual ~VRTWarpedDataset();
433 virtual CPLErr FlushCache(
bool bAtClosing)
override;
435 CPLErr Initialize(
void *);
437 virtual CPLErr IBuildOverviews(
const char *,
int,
const int *,
int,
438 const int *, GDALProgressFunc,
void *,
441 virtual CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
442 const char *pszDomain =
"")
override;
444 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
448 char **papszOptions =
nullptr)
override;
450 virtual char **GetFileList()
override;
453 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
455 int nBandCount, BANDMAP_TYPE panBandMap,
460 CPLErr ProcessBlock(
int iBlockX,
int iBlockY);
462 void GetBlockSize(
int *,
int *)
const;
474 GTAdjust_Intersection,
476 GTAdjust_NoneWithoutWarning
479 class VRTPansharpenedDataset final :
public VRTDataset
481 friend class VRTPansharpenedRasterBand;
484 VRTPansharpenedDataset *m_poMainDataset;
485 std::vector<VRTPansharpenedDataset *> m_apoOverviewDatasets{};
487 std::map<CPLString, CPLString> m_oMapToRelativeFilenames{};
489 int m_bLoadingOtherBands;
491 GByte *m_pabyLastBufferBandRasterIO;
492 int m_nLastBandRasterIOXOff;
493 int m_nLastBandRasterIOYOff;
494 int m_nLastBandRasterIOXSize;
495 int m_nLastBandRasterIOYSize;
498 GTAdjustment m_eGTAdjustment;
499 int m_bNoDataDisabled;
501 std::vector<GDALDataset *> m_apoDatasetsToClose{};
506 virtual int CloseDependentDatasets()
override;
509 VRTPansharpenedDataset(
int nXSize,
int nYSize,
int nBlockXSize = 0,
510 int nBlockYSize = 0);
511 virtual ~VRTPansharpenedDataset();
513 virtual CPLErr FlushCache(
bool bAtClosing)
override;
516 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
523 char **papszOptions =
nullptr)
override;
525 virtual char **GetFileList()
override;
528 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
530 int nBandCount, BANDMAP_TYPE panBandMap,
535 void GetBlockSize(
int *,
int *)
const;
539 return m_poPansharpener;
552 class VRTProcessedDataset final :
public VRTDataset
555 VRTProcessedDataset(
int nXSize,
int nYSize);
556 ~VRTProcessedDataset()
override;
558 virtual CPLErr FlushCache(
bool bAtClosing)
override;
561 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
563 void GetBlockSize(
int *,
int *)
const;
567 #pragma GCC diagnostic push
568 #pragma GCC diagnostic ignored "-Weffc++"
581 inline operator GByte()
const
587 #pragma GCC diagnostic pop
591 friend class VRTProcessedRasterBand;
597 std::string osAlgorithm{};
615 std::vector<double> adfInNoData{};
618 std::vector<double> adfOutNoData{};
629 Step &operator=(Step &&);
632 Step(
const Step &) =
delete;
633 Step &operator=(
const Step &) =
delete;
638 std::string m_osVRTPath{};
641 std::unique_ptr<GDALDataset> m_poSrcDS{};
644 std::vector<Step> m_aoSteps{};
650 std::vector<std::unique_ptr<GDALDataset>> m_apoOverviewDatasets{};
653 std::vector<NoInitByte> m_abyInput{};
656 std::vector<NoInitByte> m_abyOutput{};
659 const VRTProcessedDataset *poParentDS,
662 bool ParseStep(
const CPLXMLNode *psStep,
bool bIsFinalStep,
664 std::vector<double> &adfInNoData,
665 std::vector<double> &adfOutNoData);
666 bool ProcessRegion(
int nXOff,
int nYOff,
int nBufXSize,
int nBufYSize);
676 constexpr
double VRT_DEFAULT_NODATA_VALUE = -10000.0;
681 void ResetNoDataValues();
684 friend class VRTDataset;
686 int m_bIsMaskBand = FALSE;
688 int m_bNoDataValueSet = FALSE;
690 int m_bHideNoDataValue = FALSE;
691 double m_dfNoDataValue = VRT_DEFAULT_NODATA_VALUE;
693 bool m_bNoDataSetAsInt64 =
false;
694 int64_t m_nNoDataValueInt64 = GDAL_PAM_DEFAULT_NODATA_VALUE_INT64;
696 bool m_bNoDataSetAsUInt64 =
false;
697 uint64_t m_nNoDataValueUInt64 = GDAL_PAM_DEFAULT_NODATA_VALUE_UINT64;
699 std::unique_ptr<GDALColorTable> m_poColorTable{};
703 char *m_pszUnitType =
nullptr;
706 double m_dfOffset = 0.0;
707 double m_dfScale = 1.0;
711 void Initialize(
int nXSize,
int nYSize);
713 std::vector<VRTOverviewInfo> m_aoOverviewInfos{};
715 VRTRasterBand *m_poMaskBand =
nullptr;
717 std::unique_ptr<GDALRasterAttributeTable> m_poRAT{};
721 bool IsNoDataValueInDataTypeRange()
const;
725 virtual ~VRTRasterBand();
728 std::map<CPLString, GDALDataset *> &);
729 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
730 bool &bHasWarnedAboutRAMUsage,
731 size_t &nAccRAMUsage);
733 CPLErr SetNoDataValue(
double)
override;
734 CPLErr SetNoDataValueAsInt64(int64_t nNoData)
override;
735 CPLErr SetNoDataValueAsUInt64(uint64_t nNoData)
override;
736 double GetNoDataValue(
int *pbSuccess =
nullptr)
override;
737 int64_t GetNoDataValueAsInt64(
int *pbSuccess =
nullptr)
override;
738 uint64_t GetNoDataValueAsUInt64(
int *pbSuccess =
nullptr)
override;
739 CPLErr DeleteNoDataValue()
override;
751 virtual const char *GetUnitType()
override;
752 CPLErr SetUnitType(
const char *)
override;
754 virtual char **GetCategoryNames()
override;
755 virtual CPLErr SetCategoryNames(
char **)
override;
757 virtual CPLErr SetMetadata(
char **papszMD,
758 const char *pszDomain =
"")
override;
759 virtual CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
760 const char *pszDomain =
"")
override;
762 virtual double GetOffset(
int *pbSuccess =
nullptr)
override;
763 CPLErr SetOffset(
double)
override;
764 virtual double GetScale(
int *pbSuccess =
nullptr)
override;
765 CPLErr SetScale(
double)
override;
767 virtual int GetOverviewCount()
override;
770 virtual CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
771 GUIntBig *panHistogram,
int bIncludeOutOfRange,
772 int bApproxOK, GDALProgressFunc,
773 void *pProgressData)
override;
775 virtual CPLErr GetDefaultHistogram(
double *pdfMin,
double *pdfMax,
776 int *pnBuckets,
GUIntBig **ppanHistogram,
777 int bForce, GDALProgressFunc,
778 void *pProgressData)
override;
780 virtual CPLErr SetDefaultHistogram(
double dfMin,
double dfMax,
int nBuckets,
785 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
788 virtual void SetDescription(
const char *)
override;
791 virtual int GetMaskFlags()
override;
793 virtual CPLErr CreateMaskBand(
int nFlagsIn)
override;
795 void SetMaskBand(VRTRasterBand *poMaskBand);
797 void SetIsMaskBand();
799 virtual bool IsMaskBand()
const override;
801 CPLErr UnsetNoDataValue();
803 virtual int CloseDependentDatasets();
805 virtual int IsSourcedRasterBand()
810 virtual int IsPansharpenRasterBand()
820 class VRTSimpleSource;
822 class CPL_DLL VRTSourcedRasterBand
CPL_NON_FINAL :
public VRTRasterBand
826 char **m_papszSourceList =
nullptr;
827 int m_nSkipBufferInitialization = -1;
829 bool CanUseSourcesMinMaxImplementations();
831 bool IsMosaicOfNonOverlappingSimpleSourcesOfFullRasterNoResAndTypeChange(
832 bool bAllowMaxValAdjustment)
const;
837 bool SkipBufferInitialization();
841 VRTSource **papoSources =
nullptr;
843 VRTSourcedRasterBand(
GDALDataset *poDS,
int nBand);
844 VRTSourcedRasterBand(
GDALDataType eType,
int nXSize,
int nYSize);
846 int nXSize,
int nYSize);
848 int nXSize,
int nYSize,
int nBlockXSizeIn,
850 virtual ~VRTSourcedRasterBand();
857 virtual int IGetDataCoverageStatus(
int nXOff,
int nYOff,
int nXSize,
858 int nYSize,
int nMaskFlagStop,
859 double *pdfDataPct)
override;
861 virtual char **GetMetadataDomainList()
override;
862 virtual const char *GetMetadataItem(
const char *pszName,
863 const char *pszDomain =
"")
override;
864 virtual char **GetMetadata(
const char *pszDomain =
"")
override;
865 virtual CPLErr SetMetadata(
char **papszMetadata,
866 const char *pszDomain =
"")
override;
867 virtual CPLErr SetMetadataItem(
const char *pszName,
const char *pszValue,
868 const char *pszDomain =
"")
override;
871 std::map<CPLString, GDALDataset *> &)
override;
872 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
873 bool &bHasWarnedAboutRAMUsage,
874 size_t &nAccRAMUsage)
override;
876 virtual double GetMinimum(
int *pbSuccess =
nullptr)
override;
877 virtual double GetMaximum(
int *pbSuccess =
nullptr)
override;
878 virtual CPLErr ComputeRasterMinMax(
int bApproxOK,
879 double *adfMinMax)
override;
880 virtual CPLErr ComputeStatistics(
int bApproxOK,
double *pdfMin,
881 double *pdfMax,
double *pdfMean,
883 GDALProgressFunc pfnProgress,
884 void *pProgressData)
override;
885 virtual CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
886 GUIntBig *panHistogram,
int bIncludeOutOfRange,
887 int bApproxOK, GDALProgressFunc pfnProgress,
888 void *pProgressData)
override;
890 CPLErr AddSource(VRTSource *);
892 CPLErr AddSimpleSource(
const char *pszFilename,
int nBand,
893 double dfSrcXOff = -1,
double dfSrcYOff = -1,
894 double dfSrcXSize = -1,
double dfSrcYSize = -1,
895 double dfDstXOff = -1,
double dfDstYOff = -1,
896 double dfDstXSize = -1,
double dfDstYSize = -1,
897 const char *pszResampling =
"near",
901 double dfSrcYOff = -1,
double dfSrcXSize = -1,
902 double dfSrcYSize = -1,
double dfDstXOff = -1,
903 double dfDstYOff = -1,
double dfDstXSize = -1,
904 double dfDstYSize = -1,
905 const char *pszResampling =
"near",
908 CPLErr AddComplexSource(
const char *pszFilename,
int nBand,
909 double dfSrcXOff = -1,
double dfSrcYOff = -1,
910 double dfSrcXSize = -1,
double dfSrcYSize = -1,
911 double dfDstXOff = -1,
double dfDstYOff = -1,
912 double dfDstXSize = -1,
double dfDstYSize = -1,
913 double dfScaleOff = 0.0,
double dfScaleRatio = 1.0,
915 int nColorTableComponent = 0);
918 double dfSrcYOff = -1,
double dfSrcXSize = -1,
919 double dfSrcYSize = -1,
double dfDstXOff = -1,
920 double dfDstYOff = -1,
double dfDstXSize = -1,
921 double dfDstYSize = -1,
double dfScaleOff = 0.0,
922 double dfScaleRatio = 1.0,
924 int nColorTableComponent = 0);
927 double dfSrcYOff = -1,
double dfSrcXSize = -1,
928 double dfSrcYSize = -1,
double dfDstXOff = -1,
929 double dfDstYOff = -1,
double dfDstXSize = -1,
930 double dfDstYSize = -1);
935 void ConfigureSource(VRTSimpleSource *poSimpleSource,
937 double dfSrcXOff,
double dfSrcYOff,
double dfSrcXSize,
938 double dfSrcYSize,
double dfDstXOff,
double dfDstYOff,
939 double dfDstXSize,
double dfDstYSize);
941 void RemoveCoveredSources(
CSLConstList papszOptions =
nullptr);
943 bool CanIRasterIOBeForwardedToEachSource(
944 GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
int nYSize,
947 virtual CPLErr IReadBlock(
int,
int,
void *)
override;
949 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
950 int *pnMaxSize,
CPLHashSet *hSetFiles)
override;
952 virtual int CloseDependentDatasets()
override;
954 virtual int IsSourcedRasterBand()
override
959 virtual CPLErr FlushCache(
bool bAtClosing)
override;
966 class CPL_DLL VRTWarpedRasterBand final :
public VRTRasterBand
971 virtual ~VRTWarpedRasterBand();
973 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
974 bool &bHasWarnedAboutRAMUsage,
975 size_t &nAccRAMUsage)
override;
977 virtual CPLErr IReadBlock(
int,
int,
void *)
override;
978 virtual CPLErr IWriteBlock(
int,
int,
void *)
override;
981 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
986 virtual int GetOverviewCount()
override;
990 int m_nIRasterIOCounter =
998 class VRTPansharpenedRasterBand final :
public VRTRasterBand
1000 int m_nIndexAsPansharpenedBand;
1003 VRTPansharpenedRasterBand(
GDALDataset *poDS,
int nBand,
1005 virtual ~VRTPansharpenedRasterBand();
1007 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1008 bool &bHasWarnedAboutRAMUsage,
1009 size_t &nAccRAMUsage)
override;
1011 virtual CPLErr IReadBlock(
int,
int,
void *)
override;
1014 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1019 virtual int GetOverviewCount()
override;
1022 virtual int IsPansharpenRasterBand()
override
1027 void SetIndexAsPansharpenedBand(
int nIdx)
1029 m_nIndexAsPansharpenedBand = nIdx;
1032 int GetIndexAsPansharpenedBand()
const
1034 return m_nIndexAsPansharpenedBand;
1042 class VRTProcessedRasterBand final :
public VRTRasterBand
1045 VRTProcessedRasterBand(VRTProcessedDataset *poDS,
int nBand,
1048 virtual CPLErr IReadBlock(
int,
int,
void *)
override;
1050 virtual int GetOverviewCount()
override;
1053 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1054 bool &bHasWarnedAboutRAMUsage,
1055 size_t &nAccRAMUsage)
override;
1062 class VRTDerivedRasterBandPrivateData;
1064 class CPL_DLL VRTDerivedRasterBand
CPL_NON_FINAL :
public VRTSourcedRasterBand
1066 VRTDerivedRasterBandPrivateData *m_poPrivate;
1067 bool InitializePython();
1069 GetPixelFunctionArguments(
const CPLString &,
1070 std::vector<std::pair<CPLString, CPLString>> &);
1082 VRTDerivedRasterBand(
GDALDataset *poDS,
int nBand);
1084 int nXSize,
int nYSize);
1085 virtual ~VRTDerivedRasterBand();
1092 virtual int IGetDataCoverageStatus(
int nXOff,
int nYOff,
int nXSize,
1093 int nYSize,
int nMaskFlagStop,
1094 double *pdfDataPct)
override;
1096 static CPLErr AddPixelFunction(
const char *pszFuncNameIn,
1098 static CPLErr AddPixelFunction(
const char *pszFuncNameIn,
1100 const char *pszMetadata);
1102 static const std::pair<PixelFunc, std::string> *
1103 GetPixelFunction(
const char *pszFuncNameIn);
1105 void SetPixelFunctionName(
const char *pszFuncNameIn);
1107 void SetPixelFunctionLanguage(
const char *pszLanguage);
1110 std::map<CPLString, GDALDataset *> &)
override;
1111 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1112 bool &bHasWarnedAboutRAMUsage,
1113 size_t &nAccRAMUsage)
override;
1115 virtual double GetMinimum(
int *pbSuccess =
nullptr)
override;
1116 virtual double GetMaximum(
int *pbSuccess =
nullptr)
override;
1117 virtual CPLErr ComputeRasterMinMax(
int bApproxOK,
1118 double *adfMinMax)
override;
1119 virtual CPLErr ComputeStatistics(
int bApproxOK,
double *pdfMin,
1120 double *pdfMax,
double *pdfMean,
1122 GDALProgressFunc pfnProgress,
1123 void *pProgressData)
override;
1124 virtual CPLErr GetHistogram(
double dfMin,
double dfMax,
int nBuckets,
1125 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1126 int bApproxOK, GDALProgressFunc pfnProgress,
1127 void *pProgressData)
override;
1129 static void Cleanup();
1136 class RawRasterBand;
1138 class CPL_DLL VRTRawRasterBand
CPL_NON_FINAL :
public VRTRasterBand
1140 RawRasterBand *m_poRawRaster;
1142 char *m_pszSourceFilename;
1143 int m_bRelativeToVRT;
1150 virtual ~VRTRawRasterBand();
1153 std::map<CPLString, GDALDataset *> &)
override;
1154 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath,
1155 bool &bHasWarnedAboutRAMUsage,
1156 size_t &nAccRAMUsage)
override;
1163 virtual CPLErr IReadBlock(
int,
int,
void *)
override;
1164 virtual CPLErr IWriteBlock(
int,
int,
void *)
override;
1166 CPLErr SetRawLink(
const char *pszFilename,
const char *pszVRTPath,
1168 int nPixelOffset,
int nLineOffset,
1169 const char *pszByteOrder);
1171 void ClearRawLink();
1175 char **papszOptions)
override;
1177 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
1178 int *pnMaxSize,
CPLHashSet *hSetFiles)
override;
1189 std::map<std::string, VRTSourceParser> m_oMapSourceParser{};
1193 virtual ~VRTDriver();
1195 char **papszSourceParsers;
1198 virtual char **
GetMetadata(
const char *pszDomain =
"")
override;
1200 const char *pszDomain =
"")
override;
1203 ParseSource(
const CPLXMLNode *psSrc,
const char *pszVRTPath,
1204 std::map<CPLString, GDALDataset *> &oMapSharedSources);
1205 void AddSourceParser(
const char *pszElementName, VRTSourceParser pfnParser);
1212 class CPL_DLL VRTSimpleSource
CPL_NON_FINAL :
public VRTSource
1218 std::map<CPLString, GDALDataset *> *m_poMapSharedSources =
nullptr;
1228 void OpenSource()
const;
1231 friend class VRTSourcedRasterBand;
1232 friend class VRTDataset;
1233 friend class GDALTileIndexDataset;
1234 friend class GDALTileIndexBand;
1237 bool m_bGetMaskBand =
false;
1239 double m_dfSrcXOff = 0;
1240 double m_dfSrcYOff = 0;
1241 double m_dfSrcXSize = 0;
1242 double m_dfSrcYSize = 0;
1244 double m_dfDstXOff = 0;
1245 double m_dfDstYOff = 0;
1246 double m_dfDstXSize = 0;
1247 double m_dfDstYSize = 0;
1251 int m_nMaxValue = 0;
1253 int m_bRelativeToVRTOri = -1;
1255 int m_nExplicitSharedStatus = -1;
1258 bool m_bDropRefOnSrcBand =
true;
1260 int NeedMaxValAdjustment()
const;
1264 return m_poRasterBand;
1269 m_poRasterBand = poBand;
1270 m_bDropRefOnSrcBand = bDropRef;
1280 VRTSimpleSource(
const VRTSimpleSource *poSrcSource,
double dfXDstRatio,
1281 double dfYDstRatio);
1282 virtual ~VRTSimpleSource();
1285 std::map<CPLString, GDALDataset *> &)
override;
1286 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1290 void SetSrcBand(
const char *pszFilename,
int nBand);
1293 void SetSrcWindow(
double,
double,
double,
double);
1294 void SetDstWindow(
double,
double,
double,
double);
1295 void GetDstWindow(
double &,
double &,
double &,
double &);
1297 const std::string &GetSourceDatasetName()
const
1299 return m_osSrcDSName;
1304 return m_osResampling;
1307 void SetResampling(
const char *pszResampling);
1309 int GetSrcDstWindow(
double,
double,
double,
double,
int,
int,
1310 double *pdfReqXOff,
double *pdfReqYOff,
1311 double *pdfReqXSize,
double *pdfReqYSize,
int *,
int *,
1312 int *,
int *,
int *,
int *,
int *,
int *,
1316 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1320 WorkingState &oWorkingState)
override;
1322 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1323 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1324 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
1325 double dfMax,
int nBuckets,
1326 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1327 int bApproxOK, GDALProgressFunc pfnProgress,
1328 void *pProgressData)
override;
1330 void DstToSrc(
double dfX,
double dfY,
double &dfXOut,
double &dfYOut)
const;
1331 void SrcToDst(
double dfX,
double dfY,
double &dfXOut,
double &dfYOut)
const;
1333 virtual void GetFileList(
char ***ppapszFileList,
int *pnSize,
1334 int *pnMaxSize,
CPLHashSet *hSetFiles)
override;
1336 virtual int IsSimpleSource()
override
1341 virtual const char *GetType()
1343 return "SimpleSource";
1346 virtual CPLErr FlushCache(
bool bAtClosing)
override;
1350 int IsSameExceptBandNumber(VRTSimpleSource *poOtherSource);
1352 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1354 const int *panBandMap,
GSpacing nPixelSpace,
1358 void UnsetPreservedRelativeFilenames();
1360 void SetMaxValue(
int nVal)
1370 class VRTAveragedSource final :
public VRTSimpleSource
1374 int m_bNoDataSet =
false;
1378 VRTAveragedSource();
1380 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1384 WorkingState &oWorkingState)
override;
1386 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1387 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1388 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
1389 double dfMax,
int nBuckets,
1390 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1391 int bApproxOK, GDALProgressFunc pfnProgress,
1392 void *pProgressData)
override;
1394 void SetNoDataValue(
double dfNoDataValue);
1396 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1398 virtual const char *GetType()
override
1400 return "AveragedSource";
1408 class VRTNoDataFromMaskSource final :
public VRTSimpleSource
1412 bool m_bNoDataSet =
false;
1413 double m_dfNoDataValue = 0;
1414 double m_dfMaskValueThreshold = 0;
1415 bool m_bHasRemappedValue =
false;
1416 double m_dfRemappedValue = 0;
1419 VRTNoDataFromMaskSource();
1421 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1425 WorkingState &oWorkingState)
override;
1427 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1428 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1429 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
1430 double dfMax,
int nBuckets,
1431 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1432 int bApproxOK, GDALProgressFunc pfnProgress,
1433 void *pProgressData)
override;
1435 void SetParameters(
double dfNoDataValue,
double dfMaskValueThreshold);
1436 void SetParameters(
double dfNoDataValue,
double dfMaskValueThreshold,
1437 double dfRemappedValue);
1440 std::map<CPLString, GDALDataset *> &)
override;
1441 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1443 virtual const char *GetType()
override
1445 return "VRTNoDataFromMaskSource";
1453 class CPL_DLL VRTComplexSource
CPL_NON_FINAL :
public VRTSimpleSource
1458 static constexpr
int PROCESSING_FLAG_NODATA = 1 << 0;
1459 static constexpr
int PROCESSING_FLAG_USE_MASK_BAND =
1461 static constexpr
int PROCESSING_FLAG_SCALING_LINEAR = 1 << 2;
1462 static constexpr
int PROCESSING_FLAG_SCALING_EXPONENTIAL =
1464 static constexpr
int PROCESSING_FLAG_COLOR_TABLE_EXPANSION = 1 << 4;
1465 static constexpr
int PROCESSING_FLAG_LUT = 1 << 5;
1467 int m_nProcessingFlags = 0;
1472 m_osNoDataValueOri{};
1474 double m_dfScaleOff = 0;
1475 double m_dfScaleRatio = 1;
1478 bool m_bSrcMinMaxDefined =
false;
1479 double m_dfSrcMin = 0;
1480 double m_dfSrcMax = 0;
1481 double m_dfDstMin = 0;
1482 double m_dfDstMax = 0;
1483 double m_dfExponent = 1;
1485 int m_nColorTableComponent = 0;
1487 std::vector<double> m_adfLUTInputs{};
1488 std::vector<double> m_adfLUTOutputs{};
1490 double GetAdjustedNoDataValue()
const;
1492 template <
class WorkingDT>
1495 GDALDataType eVRTBandDataType,
int nReqXOff,
int nReqYOff,
1496 int nReqXSize,
int nReqYSize,
void *pData,
int nOutXSize,
1499 GDALDataType eWrkDataType, WorkingState &oWorkingState);
1501 template <
class SourceDT, GDALDataType eSourceType>
1504 int nReqYOff,
int nReqXSize,
int nReqYSize,
1505 void *pData,
int nOutXSize,
int nOutYSize,
1509 WorkingState &oWorkingState);
1512 VRTComplexSource() =
default;
1513 VRTComplexSource(
const VRTComplexSource *poSrcSource,
double dfXDstRatio,
1514 double dfYDstRatio);
1517 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1521 WorkingState &oWorkingState)
override;
1523 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1524 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1525 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
1526 double dfMax,
int nBuckets,
1527 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1528 int bApproxOK, GDALProgressFunc pfnProgress,
1529 void *pProgressData)
override;
1531 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1533 std::map<CPLString, GDALDataset *> &)
override;
1535 virtual const char *GetType()
override
1537 return "ComplexSource";
1540 bool AreValuesUnchanged()
const;
1542 double LookupValue(
double dfInput);
1544 void SetNoDataValue(
double dfNoDataValue);
1546 void SetUseMaskBand(
bool bUseMaskBand)
1549 m_nProcessingFlags |= PROCESSING_FLAG_USE_MASK_BAND;
1551 m_nProcessingFlags &= ~PROCESSING_FLAG_USE_MASK_BAND;
1554 void SetLinearScaling(
double dfOffset,
double dfScale);
1555 void SetPowerScaling(
double dfExponent,
double dfSrcMin,
double dfSrcMax,
1556 double dfDstMin,
double dfDstMax);
1557 void SetColorTableComponent(
int nComponent);
1564 class VRTFilteredSource
CPL_NON_FINAL :
public VRTComplexSource
1572 int m_nSupportedTypesCount;
1575 int m_nExtraEdgePixels;
1578 VRTFilteredSource();
1579 virtual ~VRTFilteredSource();
1581 void SetExtraEdgePixels(
int);
1582 void SetFilteringDataTypesSupported(
int,
GDALDataType *);
1588 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1592 WorkingState &oWorkingState)
override;
1599 class VRTKernelFilteredSource
CPL_NON_FINAL :
public VRTFilteredSource
1604 int m_nKernelSize = 0;
1605 bool m_bSeparable =
false;
1607 std::vector<double> m_adfKernelCoefs{};
1608 bool m_bNormalized =
false;
1611 VRTKernelFilteredSource();
1614 std::map<CPLString, GDALDataset *> &)
override;
1615 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1618 GByte *pabySrcData,
GByte *pabyDstData)
override;
1620 CPLErr SetKernel(
int nKernelSize,
bool bSeparable,
1621 const std::vector<double> &adfNewCoefs);
1622 void SetNormalized(
bool);
1629 class VRTAverageFilteredSource final :
public VRTKernelFilteredSource
1634 explicit VRTAverageFilteredSource(
int nKernelSize);
1635 virtual ~VRTAverageFilteredSource();
1638 std::map<CPLString, GDALDataset *> &)
override;
1639 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1645 class VRTFuncSource final :
public VRTSource
1651 virtual ~VRTFuncSource();
1654 std::map<CPLString, GDALDataset *> &)
override
1659 virtual CPLXMLNode *SerializeToXML(
const char *pszVRTPath)
override;
1662 int nXSize,
int nYSize,
void *pData,
int nBufXSize,
1666 WorkingState &oWorkingState)
override;
1668 virtual double GetMinimum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1669 virtual double GetMaximum(
int nXSize,
int nYSize,
int *pbSuccess)
override;
1670 virtual CPLErr GetHistogram(
int nXSize,
int nYSize,
double dfMin,
1671 double dfMax,
int nBuckets,
1672 GUIntBig *panHistogram,
int bIncludeOutOfRange,
1673 int bApproxOK, GDALProgressFunc pfnProgress,
1674 void *pProgressData)
override;
1688 #define TMP_CPL_DLL CPL_DLL
1704 explicit Ref(VRTGroup *ptr) : m_ptr(ptr)
1708 Ref(
const Ref &) =
delete;
1709 Ref &operator=(
const Ref &) =
delete;
1713 std::shared_ptr<Ref> m_poSharedRefRootGroup{};
1714 std::weak_ptr<Ref> m_poWeakRefRootGroup{};
1715 std::shared_ptr<Ref> m_poRefSelf{};
1717 std::string m_osFilename{};
1718 mutable bool m_bDirty =
false;
1719 std::string m_osVRTPath{};
1720 std::map<std::string, std::shared_ptr<VRTGroup>> m_oMapGroups{};
1721 std::map<std::string, std::shared_ptr<VRTMDArray>> m_oMapMDArrays{};
1722 std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
1723 std::map<std::string, std::shared_ptr<VRTDimension>> m_oMapDimensions{};
1725 std::shared_ptr<VRTGroup>
1726 OpenGroupInternal(
const std::string &osName)
const;
1727 void SetRootGroupRef(
const std::weak_ptr<Ref> &rgRef);
1728 std::weak_ptr<Ref> GetRootGroupRef()
const;
1731 friend class VRTMDArray;
1732 friend std::shared_ptr<GDALMDArray>
1733 VRTDerivedArrayCreate(
const char *pszVRTPath,
const CPLXMLNode *psTree);
1735 explicit VRTGroup(
const char *pszVRTPath);
1736 VRTGroup(
const std::string &osParentName,
const std::string &osName);
1739 static std::shared_ptr<VRTGroup> Create(
const std::string &osParentName,
1740 const std::string &osName)
1743 std::shared_ptr<VRTGroup>(
new VRTGroup(osParentName, osName));
1744 poGroup->SetSelf(poGroup);
1750 bool XMLInit(
const std::shared_ptr<VRTGroup> &poRoot,
1751 const std::shared_ptr<VRTGroup> &poThisGroup,
1752 const CPLXMLNode *psNode,
const char *pszVRTPath);
1754 std::vector<std::string>
1755 GetMDArrayNames(
CSLConstList papszOptions)
const override;
1756 std::shared_ptr<GDALMDArray>
1757 OpenMDArray(
const std::string &osName,
1760 std::vector<std::string>
1761 GetGroupNames(
CSLConstList papszOptions)
const override;
1763 std::shared_ptr<GDALGroup> OpenGroup(
const std::string &osName,
1766 return OpenGroupInternal(osName);
1769 std::vector<std::shared_ptr<GDALDimension>>
1772 std::vector<std::shared_ptr<GDALAttribute>>
1775 std::shared_ptr<VRTDimension> GetDimension(
const std::string &name)
const
1777 auto oIter = m_oMapDimensions.find(name);
1778 return oIter == m_oMapDimensions.end() ? nullptr : oIter->second;
1781 std::shared_ptr<VRTDimension>
1782 GetDimensionFromFullName(
const std::string &name,
bool bEmitError)
const;
1784 std::shared_ptr<GDALGroup>
1785 CreateGroup(
const std::string &osName,
1788 std::shared_ptr<GDALDimension>
1789 CreateDimension(
const std::string &osName,
const std::string &osType,
1790 const std::string &osDirection,
GUInt64 nSize,
1793 std::shared_ptr<GDALAttribute>
1794 CreateAttribute(
const std::string &osName,
1795 const std::vector<GUInt64> &anDimensions,
1799 std::shared_ptr<GDALMDArray> CreateMDArray(
1800 const std::string &osName,
1801 const std::vector<std::shared_ptr<GDALDimension>> &aoDimensions,
1805 void SetIsRootGroup();
1807 const std::shared_ptr<Ref> &GetRef()
const
1812 VRTGroup *GetRootGroup()
const;
1813 std::shared_ptr<GDALGroup> GetRootGroupSharedPtr()
const;
1815 const std::string &GetVRTPath()
const
1822 void SetFilename(
const std::string &osFilename)
1824 m_osFilename = osFilename;
1827 const std::string &GetFilename()
const
1829 return m_osFilename;
1832 bool Serialize()
const;
1833 CPLXMLNode *SerializeToXML(
const char *pszVRTPathIn)
const;
1834 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPathIn)
const;
1843 std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
1844 std::string m_osIndexingVariableName;
1847 VRTDimension(
const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
1848 const std::string &osParentName,
const std::string &osName,
1849 const std::string &osType,
const std::string &osDirection,
1850 GUInt64 nSize,
const std::string &osIndexingVariableName)
1851 :
GDALDimension(osParentName, osName, osType, osDirection, nSize),
1852 m_poGroupRef(poGroupRef),
1853 m_osIndexingVariableName(osIndexingVariableName)
1857 VRTGroup *GetGroup()
const;
1859 static std::shared_ptr<VRTDimension>
1860 Create(
const std::shared_ptr<VRTGroup> &poThisGroup,
1861 const std::string &osParentName,
const CPLXMLNode *psNode);
1866 std::shared_ptr<GDALMDArray> poIndexingVariable)
override;
1878 std::vector<std::string> m_aosList{};
1879 std::vector<std::shared_ptr<GDALDimension>> m_dims{};
1882 bool IRead(
const GUInt64 *arrayStartIdx,
const size_t *count,
1885 void *pDstBuffer)
const override;
1887 bool IWrite(
const GUInt64 *arrayStartIdx,
const size_t *count,
1890 const void *pSrcBuffer)
override;
1893 VRTAttribute(
const std::string &osParentName,
const std::string &osName,
1895 std::vector<std::string> &&aosList)
1898 m_aosList(std::move(aosList))
1900 if (m_aosList.size() > 1)
1902 m_dims.emplace_back(std::make_shared<GDALDimension>(
1903 std::string(),
"dim", std::string(), std::string(),
1908 VRTAttribute(
const std::string &osParentName,
const std::string &osName,
1915 m_dims.emplace_back(std::make_shared<GDALDimension>(
1916 std::string(),
"dim", std::string(), std::string(), nDim));
1920 static bool CreationCommonChecks(
1921 const std::string &osName,
const std::vector<GUInt64> &anDimensions,
1922 const std::map<std::string, std::shared_ptr<VRTAttribute>>
1925 static std::shared_ptr<VRTAttribute> Create(
const std::string &osParentName,
1928 const std::vector<std::shared_ptr<GDALDimension>> &
1946 class VRTMDArraySource
1949 virtual ~VRTMDArraySource() =
default;
1951 virtual bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
1954 void *pDstBuffer)
const = 0;
1957 const char *pszVRTPath)
const = 0;
1967 friend class VRTGroup;
1969 std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
1970 std::string m_osVRTPath{};
1971 std::shared_ptr<VRTGroup> m_poDummyOwningGroup{};
1974 std::vector<std::shared_ptr<GDALDimension>> m_dims;
1975 std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
1976 std::vector<std::unique_ptr<VRTMDArraySource>> m_sources{};
1977 std::shared_ptr<OGRSpatialReference> m_poSRS{};
1978 std::vector<GByte> m_abyNoData{};
1979 std::string m_osUnit{};
1980 double m_dfScale = 1.0;
1981 double m_dfOffset = 0.0;
1982 bool m_bHasScale =
false;
1983 bool m_bHasOffset =
false;
1984 std::string m_osFilename{};
1986 bool IRead(
const GUInt64 *arrayStartIdx,
const size_t *count,
1989 void *pDstBuffer)
const override;
1995 const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
1996 const std::string &osParentName,
const std::string &osName,
1998 std::vector<std::shared_ptr<GDALDimension>> &&dims,
1999 std::map<std::string, std::shared_ptr<VRTAttribute>> &&oMapAttributes)
2001 GDALMDArray(osParentName, osName), m_poGroupRef(poGroupRef),
2002 m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()), m_dt(dt),
2003 m_dims(std::move(dims)), m_oMapAttributes(std::move(oMapAttributes)),
2004 m_osFilename(poGroupRef->m_ptr->GetFilename())
2008 VRTMDArray(
const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
2009 const std::string &osParentName,
const std::string &osName,
2010 const std::vector<std::shared_ptr<GDALDimension>> &dims,
2013 GDALMDArray(osParentName, osName), m_poGroupRef(poGroupRef),
2014 m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()), m_dt(dt), m_dims(dims),
2015 m_osFilename(poGroupRef->m_ptr->GetFilename())
2026 return m_osFilename;
2029 static std::shared_ptr<VRTMDArray> Create(
const char *pszVRTPath,
2032 static std::shared_ptr<VRTMDArray>
2033 Create(
const std::shared_ptr<VRTGroup> &poThisGroup,
2034 const std::string &osParentName,
const CPLXMLNode *psNode);
2036 const std::vector<std::shared_ptr<GDALDimension>> &
2042 std::vector<std::shared_ptr<GDALAttribute>>
2052 std::shared_ptr<OGRSpatialReference>
GetSpatialRef()
const override
2061 const std::string &
GetUnit()
const override
2066 bool SetUnit(
const std::string &osUnit)
override
2076 *pbHasOffset = m_bHasOffset;
2086 *pbHasScale = m_bHasScale;
2096 m_bHasOffset =
true;
2097 m_dfOffset = dfOffset;
2106 m_dfScale = dfScale;
2110 void AddSource(std::unique_ptr<VRTMDArraySource> &&poSource);
2112 std::shared_ptr<GDALAttribute>
2114 const std::vector<GUInt64> &anDimensions,
2120 GDALProgressFunc pfnProgress,
void *pProgressData)
override;
2122 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPathIn)
const;
2124 VRTGroup *GetGroup()
const;
2126 const std::string &GetVRTPath()
const
2131 std::shared_ptr<GDALGroup>
GetRootGroup()
const override
2133 auto poGroup = m_poGroupRef.lock();
2135 return poGroup->m_ptr->GetRootGroupSharedPtr();
2144 class VRTMDArraySourceInlinedValues final :
public VRTMDArraySource
2146 const VRTMDArray *m_poDstArray =
nullptr;
2147 bool m_bIsConstantValue;
2148 std::vector<GUInt64> m_anOffset{};
2149 std::vector<size_t> m_anCount{};
2150 std::vector<GByte> m_abyValues{};
2151 std::vector<size_t> m_anInlinedArrayStrideInBytes{};
2154 VRTMDArraySourceInlinedValues(
const VRTMDArraySourceInlinedValues &) =
2156 VRTMDArraySourceInlinedValues &
2157 operator=(
const VRTMDArraySourceInlinedValues &) =
delete;
2160 VRTMDArraySourceInlinedValues(
const VRTMDArray *poDstArray,
2161 bool bIsConstantValue,
2162 std::vector<GUInt64> &&anOffset,
2163 std::vector<size_t> &&anCount,
2164 std::vector<GByte> &&abyValues)
2165 : m_poDstArray(poDstArray), m_bIsConstantValue(bIsConstantValue),
2166 m_anOffset(std::move(anOffset)), m_anCount(std::move(anCount)),
2167 m_abyValues(std::move(abyValues)), m_dt(poDstArray->GetDataType())
2169 const auto nDims(poDstArray->GetDimensionCount());
2170 m_anInlinedArrayStrideInBytes.resize(nDims);
2171 if (!bIsConstantValue && nDims > 0)
2173 m_anInlinedArrayStrideInBytes.back() =
2174 poDstArray->GetDataType().GetSize();
2175 for (
size_t i = nDims - 1; i > 0;)
2178 m_anInlinedArrayStrideInBytes[i] =
2179 m_anInlinedArrayStrideInBytes[i + 1] * m_anCount[i + 1];
2184 ~VRTMDArraySourceInlinedValues();
2186 static std::unique_ptr<VRTMDArraySourceInlinedValues>
2187 Create(
const VRTMDArray *poDstArray,
const CPLXMLNode *psNode);
2189 bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2192 void *pDstBuffer)
const override;
2194 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPath)
const override;
2201 class VRTMDArraySourceRegularlySpaced final :
public VRTMDArraySource
2204 double m_dfIncrement;
2207 VRTMDArraySourceRegularlySpaced(
double dfStart,
double dfIncrement)
2208 : m_dfStart(dfStart), m_dfIncrement(dfIncrement)
2212 bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2215 void *pDstBuffer)
const override;
2217 void Serialize(
CPLXMLNode *psParent,
const char *pszVRTPath)
const override;
2224 class VRTMDArraySourceFromArray final :
public VRTMDArraySource
2226 const VRTMDArray *m_poDstArray =
nullptr;
2227 bool m_bRelativeToVRTSet =
false;
2228 bool m_bRelativeToVRT =
false;
2229 std::string m_osFilename{};
2230 std::string m_osArray{};
2231 std::string m_osBand{};
2232 std::vector<int> m_anTransposedAxis{};
2233 std::string m_osViewExpr{};
2234 std::vector<GUInt64> m_anSrcOffset{};
2235 mutable std::vector<GUInt64> m_anCount{};
2236 std::vector<GUInt64> m_anStep{};
2237 std::vector<GUInt64> m_anDstOffset{};
2239 VRTMDArraySourceFromArray(
const VRTMDArraySourceFromArray &) =
delete;
2240 VRTMDArraySourceFromArray &
2241 operator=(
const VRTMDArraySourceFromArray &) =
delete;
2244 VRTMDArraySourceFromArray(
2245 const VRTMDArray *poDstArray,
bool bRelativeToVRTSet,
2246 bool bRelativeToVRT,
const std::string &osFilename,
2247 const std::string &osArray,
const std::string &osBand,
2248 std::vector<int> &&anTransposedAxis,
const std::string &osViewExpr,
2249 std::vector<GUInt64> &&anSrcOffset, std::vector<GUInt64> &&anCount,
2250 std::vector<GUInt64> &&anStep, std::vector<GUInt64> &&anDstOffset)
2251 : m_poDstArray(poDstArray), m_bRelativeToVRTSet(bRelativeToVRTSet),
2252 m_bRelativeToVRT(bRelativeToVRT), m_osFilename(osFilename),
2253 m_osArray(osArray), m_osBand(osBand),
2254 m_anTransposedAxis(std::move(anTransposedAxis)),
2255 m_osViewExpr(osViewExpr), m_anSrcOffset(std::move(anSrcOffset)),
2256 m_anCount(std::move(anCount)), m_anStep(std::move(anStep)),
2257 m_anDstOffset(std::move(anDstOffset))
2261 ~VRTMDArraySourceFromArray()
override;
2263 static std::unique_ptr<VRTMDArraySourceFromArray>
2264 Create(
const VRTMDArray *poDstArray,
const CPLXMLNode *psNode);
2266 bool Read(
const GUInt64 *arrayStartIdx,
const size_t *count,
2269 void *pDstBuffer)
const override;
2271 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:449
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:210
Abstract class, implemented by GDALAttribute and GDALMDArray.
Definition: gdal_priv.h:2995
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:3226
A color table / palette.
Definition: gdal_priv.h:1348
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:503
int Dereference()
Subtract one from dataset reference count.
Definition: gdaldataset.cpp:1591
virtual CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList, const OGRSpatialReference *poGCP_SRS)
Assign GCPs.
Definition: gdaldataset.cpp:2022
int GetShared() const
Returns shared flag.
Definition: gdaldataset.cpp:1665
Class modeling a a dimension / axis used to index multidimensional arrays.
Definition: gdal_priv.h:3715
virtual std::shared_ptr< GDALMDArray > GetIndexingVariable() const
Return the variable that is used to index the dimension (if there is one).
Definition: gdalmultidim.cpp:10364
virtual bool SetIndexingVariable(std::shared_ptr< GDALMDArray > poIndexingVariable)
Set the variable that is used to index the dimension.
Definition: gdalmultidim.cpp:10385
Format specific driver.
Definition: gdal_priv.h:2001
Class used to represent potentially complex data types.
Definition: gdal_priv.h:2597
Class modeling a named container of GDALAttribute, GDALMDArray, OGRLayer or other GDALGroup.
Definition: gdal_priv.h:2826
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:301
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:270
Class modeling a multi-dimensional array.
Definition: gdal_priv.h:3345
virtual bool SetUnit(const std::string &osUnit)
Set the variable unit.
Definition: gdalmultidim.cpp:2539
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:3940
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:2872
virtual bool SetRawNoDataValue(const void *pRawNoData)
Set the nodata value as a "raw" value.
Definition: gdalmultidim.cpp:2731
virtual double GetOffset(bool *pbHasOffset=nullptr, GDALDataType *peStorageType=nullptr) const
Get the offset value to apply to raw values.
Definition: gdalmultidim.cpp:2959
virtual const std::string & GetFilename() const =0
Return the filename that contains that array.
virtual const void * GetRawNoDataValue() const
Return the nodata value as a "raw" value.
Definition: gdalmultidim.cpp:2615
virtual double GetScale(bool *pbHasScale=nullptr, GDALDataType *peStorageType=nullptr) const
Get the scale value to apply to raw values.
Definition: gdalmultidim.cpp:2929
virtual std::shared_ptr< OGRSpatialReference > GetSpatialRef() const
Return the spatial reference system object associated with the array.
Definition: gdalmultidim.cpp:2589
virtual bool SetSpatialRef(const OGRSpatialReference *poSRS)
Assign a spatial reference system object to the array.
Definition: gdalmultidim.cpp:2575
virtual std::shared_ptr< GDALGroup > GetRootGroup() const
Return the root group to which this arrays belongs too.
Definition: gdalmultidim.cpp:4511
virtual bool SetOffset(double dfOffset, GDALDataType eStorageType=GDT_Unknown)
Set the offset value to apply to raw values.
Definition: gdalmultidim.cpp:2900
virtual const std::string & GetUnit() const
Return the array unit.
Definition: gdalmultidim.cpp:2561
virtual CPLErr SetMetadata(char **papszMetadata, const char *pszDomain="")
Set metadata.
Definition: gdalmajorobject.cpp:290
virtual char ** GetMetadataDomainList()
Fetch list of metadata domains.
Definition: gdalmajorobject.cpp:160
virtual char ** GetMetadata(const char *pszDomain="")
Fetch metadata.
Definition: gdalmajorobject.cpp:247
Class for dataset open functions.
Definition: gdal_priv.h:301
Pansharpening operation class.
Definition: gdalpansharpen.h:190
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_priv.h:1504
GDALDataset * GetDataset()
Fetch the owning dataset handle.
Definition: gdalrasterband.cpp:3337
High level image warping class.
Definition: gdalwarper.h:502
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:169
CPLErr
Error category.
Definition: cpl_error.h:53
struct _CPLHashSet CPLHashSet
Opaque type for a hash set.
Definition: cpl_hash_set.h:52
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:256
#define CPL_NON_FINAL
Mark that a class is explicitly recognized as non-final.
Definition: cpl_port.h:1035
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:218
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:236
#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:1042
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1183
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:238
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:185
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:215
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition: cpl_virtualmem.h:62
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:146
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:315
GDALAccess
Definition: gdal.h:125
@ GA_ReadOnly
Definition: gdal.h:126
void * VRTPDWorkingDataPtr
Generic pointer for the working structure of VRTProcessedDataset function.
Definition: gdal.h:1643
GDALDataType
Definition: gdal.h:64
@ GDT_Unknown
Definition: gdal.h:65
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:1477
CPLErr GDALClose(GDALDatasetH)
Close GDAL dataset.
Definition: gdaldataset.cpp:4119
GDALColorInterp
Definition: gdal.h:227
@ GCI_Undefined
Definition: gdal.h:228
GDALRWFlag
Definition: gdal.h:132
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:1469
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:294
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:45
void * VRTDatasetH
Opaque type for a VRT dataset.
Definition: gdal_vrt.h:74
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:50
VRTDatasetH VRTCreate(int, int)
Definition: vrtdataset.cpp:82
Document node structure.
Definition: cpl_minixml.h:71
Ground Control Point.
Definition: gdal.h:1075