GDAL
vrtdataset.h
1/******************************************************************************
2 *
3 * Project: Virtual GDAL Datasets
4 * Purpose: Declaration of virtual gdal dataset classes.
5 * Author: Frank Warmerdam, warmerdam@pobox.com
6 *
7 ******************************************************************************
8 * Copyright (c) 2001, Frank Warmerdam <warmerdam@pobox.com>
9 * Copyright (c) 2007-2013, Even Rouault <even dot rouault at spatialys.com>
10 *
11 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14#ifndef VIRTUALDATASET_H_INCLUDED
15#define VIRTUALDATASET_H_INCLUDED
16
17#ifndef DOXYGEN_SKIP
18
19#include "cpl_hash_set.h"
20#include "cpl_minixml.h"
21#include "gdal_driver.h"
22#include "gdal_multidim.h"
23#include "gdal_pam.h"
24#include "gdal_vrt.h"
25#include "gdal_rat.h"
26
27#include <atomic>
28#include <deque>
29#include <functional>
30#include <map>
31#include <memory>
32#include <mutex>
33#include <vector>
34
35CPLErr GDALRegisterDefaultPixelFunc();
36void GDALVRTRegisterDefaultProcessedDatasetFuncs();
37CPLString CPL_DLL VRTSerializeNoData(double dfVal, GDALDataType eDataType,
38 int nPrecision);
39
40#if 0
41int VRTWarpedOverviewTransform( void *pTransformArg, int bDstToSrc,
42 int nPointCount,
43 double *padfX, double *padfY, double *padfZ,
44 int *panSuccess );
45void* VRTDeserializeWarpedOverviewTransformer( CPLXMLNode *psTree );
46#endif
47
48/************************************************************************/
49/* VRTOverviewInfo() */
50/************************************************************************/
51class VRTOverviewInfo
52{
53 CPL_DISALLOW_COPY_ASSIGN(VRTOverviewInfo)
54
55 public:
56 CPLString osFilename{};
57 int nBand = 0;
58 GDALRasterBand *poBand = nullptr;
59 int bTriedToOpen = FALSE;
60
61 VRTOverviewInfo() = default;
62
63 VRTOverviewInfo(VRTOverviewInfo &&oOther) noexcept
64 : osFilename(std::move(oOther.osFilename)), nBand(oOther.nBand),
65 poBand(oOther.poBand), bTriedToOpen(oOther.bTriedToOpen)
66 {
67 oOther.poBand = nullptr;
68 }
69
70 ~VRTOverviewInfo()
71 {
72 CloseDataset();
73 }
74
75 bool CloseDataset()
76 {
77 if (poBand == nullptr)
78 return false;
79
80 GDALDataset *poDS = poBand->GetDataset();
81 // Nullify now, to prevent recursion in some cases !
82 poBand = nullptr;
83 if (poDS->GetShared())
84 GDALClose(/* (GDALDatasetH) */ poDS);
85 else
86 poDS->Dereference();
87
88 return true;
89 }
90};
91
92/************************************************************************/
93/* VRTMapSharedResources */
94/************************************************************************/
95
97class CPL_DLL VRTMapSharedResources
98{
99 public:
100 VRTMapSharedResources() = default;
101
103 GDALDataset *Get(const std::string &osKey) const;
104
108 void Insert(const std::string &osKey, GDALDataset *poDS);
109
113 void InitMutex();
114
115 private:
116 mutable std::mutex m_oMutex{};
117 bool m_bUseMutex = false;
118 std::map<std::string, GDALDataset *> m_oMap{};
119
120 std::unique_ptr<std::lock_guard<std::mutex>> LockGuard() const;
121
122 CPL_DISALLOW_COPY_ASSIGN(VRTMapSharedResources)
123};
124
125/************************************************************************/
126/* VRTSource */
127/************************************************************************/
128
129class CPL_DLL VRTSource
130{
131 public:
132 struct CPL_DLL WorkingState
133 {
134 // GByte whose initialization constructor does nothing
135#ifdef __GNUC__
136#pragma GCC diagnostic push
137#pragma GCC diagnostic ignored "-Weffc++"
138#endif
139 struct NoInitByte
140 {
141#ifdef __COVERITY__
142 GByte value = 0;
143#else
144 GByte value;
145#endif
146
147 // cppcheck-suppress uninitMemberVar
148 NoInitByte()
149 {
150 // do nothing
151 }
152
153 inline operator GByte() const
154 {
155 return value;
156 }
157 };
158#ifdef __GNUC__
159#pragma GCC diagnostic pop
160#endif
161
162 std::vector<NoInitByte> m_abyWrkBuffer{};
163 std::vector<NoInitByte> m_abyWrkBufferMask{};
164 };
165
166 virtual ~VRTSource();
167
168 virtual CPLErr RasterIO(GDALDataType eVRTBandDataType, int nXOff, int nYOff,
169 int nXSize, int nYSize, void *pData, int nBufXSize,
170 int nBufYSize, GDALDataType eBufType,
171 GSpacing nPixelSpace, GSpacing nLineSpace,
172 GDALRasterIOExtraArg *psExtraArg,
173 WorkingState &oWorkingState) = 0;
174
175 virtual double GetMinimum(int nXSize, int nYSize, int *pbSuccess) = 0;
176 virtual double GetMaximum(int nXSize, int nYSize, int *pbSuccess) = 0;
177 virtual CPLErr GetHistogram(int nXSize, int nYSize, double dfMin,
178 double dfMax, int nBuckets,
179 GUIntBig *panHistogram, int bIncludeOutOfRange,
180 int bApproxOK, GDALProgressFunc pfnProgress,
181 void *pProgressData) = 0;
182
183 virtual CPLErr XMLInit(const CPLXMLNode *psTree, const char *,
184 VRTMapSharedResources &) = 0;
185 virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath) = 0;
186
187 virtual void GetFileList(char ***ppapszFileList, int *pnSize,
188 int *pnMaxSize, CPLHashSet *hSetFiles);
189
193 virtual bool IsSimpleSource() const
194 {
195 return false;
196 }
197
198 const std::string &GetName() const
199 {
200 return m_osName;
201 }
202
203 void SetName(const std::string &s)
204 {
205 m_osName = s;
206 }
207
211 virtual const char *GetType() const = 0;
212
213 virtual CPLErr FlushCache(bool /*bAtClosing*/)
214 {
215 return CE_None;
216 }
217
218 protected:
219 std::string m_osName{};
220};
221
222typedef VRTSource *(*VRTSourceParser)(const CPLXMLNode *, const char *,
223 VRTMapSharedResources &oMapSharedSources);
224
225VRTSource *VRTParseCoreSources(const CPLXMLNode *psTree, const char *,
226 VRTMapSharedResources &oMapSharedSources);
227VRTSource *VRTParseFilterSources(const CPLXMLNode *psTree, const char *,
228 VRTMapSharedResources &oMapSharedSources);
229VRTSource *VRTParseArraySource(const CPLXMLNode *psTree, const char *,
230 VRTMapSharedResources &oMapSharedSources);
231
232/************************************************************************/
233/* VRTDataset */
234/************************************************************************/
235
236class VRTRasterBand;
237
238template <class T> struct VRTFlushCacheStruct
239{
240 static CPLErr FlushCache(T &obj, bool bAtClosing);
241};
242
243class VRTWarpedDataset;
244class VRTPansharpenedDataset;
245class VRTProcessedDataset;
246class VRTGroup;
247class VRTSimpleSource;
248
249class CPL_DLL VRTDataset CPL_NON_FINAL : public GDALDataset
250{
251 friend class VRTRasterBand;
252 friend struct VRTFlushCacheStruct<VRTDataset>;
253 friend struct VRTFlushCacheStruct<VRTWarpedDataset>;
254 friend struct VRTFlushCacheStruct<VRTPansharpenedDataset>;
255 friend struct VRTFlushCacheStruct<VRTProcessedDataset>;
256 friend class VRTSourcedRasterBand;
257 friend class VRTDerivedRasterBand;
258 friend class VRTSimpleSource;
259 friend struct VRTSourcedRasterBandRasterIOJob;
260 friend VRTDatasetH CPL_STDCALL VRTCreate(int nXSize, int nYSize);
261
262 std::vector<gdal::GCP> m_asGCPs{};
263 std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser>
264 m_poGCP_SRS{};
265
266 bool m_bNeedsFlush = false;
267 bool m_bWritable = true;
268 bool m_bCanTakeRef = true;
269
270 char *m_pszVRTPath = nullptr;
271
272 std::unique_ptr<VRTRasterBand> m_poMaskBand{};
273
274 mutable int m_nCompatibleForDatasetIO = -1;
275 bool CheckCompatibleForDatasetIO() const;
276
277 // Virtual (ie not materialized) overviews, created either implicitly
278 // when it is cheap to do it, or explicitly.
279 std::vector<GDALDataset *> m_apoOverviews{};
280 std::vector<GDALDataset *> m_apoOverviewsBak{};
281 CPLStringList m_aosOverviewList{}; // only temporarily set during Open()
282 CPLString m_osOverviewResampling{};
283 std::vector<int> m_anOverviewFactors{};
284
285 char **m_papszXMLVRTMetadata = nullptr;
286
287 VRTMapSharedResources m_oMapSharedSources{};
288 std::shared_ptr<VRTGroup> m_poRootGroup{};
289
290 // Used by VRTSourcedRasterBand::IRasterIO() in single-threaded situations
291 VRTSource::WorkingState m_oWorkingState{};
292
293 // Used by VRTSourcedRasterBand::IRasterIO() when using multi-threading
294 struct QueueWorkingStates
295 {
296 std::mutex oMutex{};
297 std::vector<std::unique_ptr<VRTSource::WorkingState>> oStates{};
298 };
299
300 QueueWorkingStates m_oQueueWorkingStates{};
301
302 bool m_bMultiThreadedRasterIOLastUsed = false;
303
304 std::unique_ptr<VRTRasterBand> InitBand(const char *pszSubclass, int nBand,
305 bool bAllowPansharpenedOrProcessed);
306 static GDALDataset *OpenVRTProtocol(const char *pszSpec);
307 bool AddVirtualOverview(int nOvFactor, const char *pszResampling);
308
309 bool GetShiftedDataset(int nXOff, int nYOff, int nXSize, int nYSize,
310 GDALDataset *&poSrcDataset, int &nSrcXOff,
311 int &nSrcYOff);
312
313 static bool IsDefaultBlockSize(int nBlockSize, int nDimension);
314
315 CPL_DISALLOW_COPY_ASSIGN(VRTDataset)
316
317 protected:
318 bool m_bBlockSizeSpecified = false;
319 int m_nBlockXSize = 0;
320 int m_nBlockYSize = 0;
321
322 std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser> m_poSRS{};
323
324 int m_bGeoTransformSet = false;
325 GDALGeoTransform m_gt{};
326
327 int CloseDependentDatasets() override;
328
329 public:
330 VRTDataset(int nXSize, int nYSize, int nBlockXSize = 0,
331 int nBlockYSize = 0);
332 ~VRTDataset() override;
333
334 void SetNeedsFlush()
335 {
336 m_bNeedsFlush = true;
337 }
338
339 CPLErr FlushCache(bool bAtClosing) override;
340
341 void SetWritable(int bWritableIn)
342 {
343 m_bWritable = CPL_TO_BOOL(bWritableIn);
344 }
345
346 CPLErr CreateMaskBand(int nFlags) override;
347 void SetMaskBand(std::unique_ptr<VRTRasterBand> poMaskBand);
348
349 const OGRSpatialReference *GetSpatialRef() const override
350 {
351 return m_poSRS.get();
352 }
353
354 CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
355
356 CPLErr GetGeoTransform(GDALGeoTransform &) const override;
357 CPLErr SetGeoTransform(const GDALGeoTransform &) override;
358
359 CPLErr SetMetadata(char **papszMetadata,
360 const char *pszDomain = "") override;
361 CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
362 const char *pszDomain = "") override;
363
364 char **GetMetadata(const char *pszDomain = "") override;
365 virtual const char *GetMetadataItem(const char *pszName,
366 const char *pszDomain = "") override;
367
368 int GetGCPCount() override;
369
370 const OGRSpatialReference *GetGCPSpatialRef() const override
371 {
372 return m_poGCP_SRS.get();
373 }
374
375 const GDAL_GCP *GetGCPs() override;
377 CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
378 const OGRSpatialReference *poSRS) override;
379
380 virtual CPLErr AddBand(GDALDataType eType,
381 char **papszOptions = nullptr) override;
382
383 char **GetFileList() override;
384
385 CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
386 int nYSize, void *pData, int nBufXSize, int nBufYSize,
387 GDALDataType eBufType, int nBandCount,
388 BANDMAP_TYPE panBandMap, GSpacing nPixelSpace,
389 GSpacing nLineSpace, GSpacing nBandSpace,
390 GDALRasterIOExtraArg *psExtraArg) override;
391
392 virtual CPLStringList
393 GetCompressionFormats(int nXOff, int nYOff, int nXSize, int nYSize,
394 int nBandCount, const int *panBandList) override;
395 virtual CPLErr ReadCompressedData(const char *pszFormat, int nXOff,
396 int nYOff, int nXSize, int nYSize,
397 int nBandCount, const int *panBandList,
398 void **ppBuffer, size_t *pnBufferSize,
399 char **ppszDetailedFormat) override;
400
401 CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
402 int nBufXSize, int nBufYSize, GDALDataType eDT,
403 int nBandCount, int *panBandList,
404 char **papszOptions) override;
405
406 virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath);
407 virtual CPLErr XMLInit(const CPLXMLNode *, const char *);
408
409 CPLErr IBuildOverviews(const char *, int, const int *, int, const int *,
410 GDALProgressFunc, void *,
411 CSLConstList papszOptions) override;
412
413 std::shared_ptr<GDALGroup> GetRootGroup() const override;
414
415 std::shared_ptr<VRTGroup> GetRootVRTGroup() const
416 {
417 return m_poRootGroup;
418 }
419
420 void ClearStatistics() override;
421
423 void SourceAdded()
424 {
425 m_nCompatibleForDatasetIO = -1;
426 }
427
428 /* Used by PDF driver for example */
429 GDALDataset *GetSingleSimpleSource();
430 void BuildVirtualOverviews();
431
432 void UnsetPreservedRelativeFilenames();
433
434 bool IsBlockSizeSpecified() const
435 {
436 return m_bBlockSizeSpecified;
437 }
438
439 int GetBlockXSize() const
440 {
441 return m_nBlockXSize;
442 }
443
444 int GetBlockYSize() const
445 {
446 return m_nBlockYSize;
447 }
448
449 static int Identify(GDALOpenInfo *);
450 static GDALDataset *Open(GDALOpenInfo *);
451 static std::unique_ptr<VRTDataset>
452 OpenXML(const char *, const char * = nullptr,
453 GDALAccess eAccess = GA_ReadOnly);
454 static GDALDataset *Create(const char *pszName, int nXSize, int nYSize,
455 int nBands, GDALDataType eType,
456 char **papszOptions);
457 static std::unique_ptr<VRTDataset>
458 CreateVRTDataset(const char *pszName, int nXSize, int nYSize, int nBands,
459 GDALDataType eType, CSLConstList papszOptions);
460 static GDALDataset *
461 CreateMultiDimensional(const char *pszFilename,
462 CSLConstList papszRootGroupOptions,
463 CSLConstList papszOptions);
464 static std::unique_ptr<VRTDataset>
465 CreateVRTMultiDimensional(const char *pszFilename,
466 CSLConstList papszRootGroupOptions,
467 CSLConstList papszOptions);
468 static CPLErr Delete(const char *pszFilename);
469
470 static int GetNumThreads(GDALDataset *poDS);
471
472 static bool IsRawRasterBandEnabled();
473};
474
475/************************************************************************/
476/* VRTWarpedDataset */
477/************************************************************************/
478
480class VRTWarpedRasterBand;
481
482class CPL_DLL VRTWarpedDataset final : public VRTDataset
483{
484 GDALWarpOperation *m_poWarper;
485
486 bool m_bIsOverview = false;
487 std::vector<VRTWarpedDataset *> m_apoOverviews{};
488 int m_nSrcOvrLevel;
489
490 bool GetOverviewSize(GDALDataset *poSrcDS, int iOvr, int iSrcOvr,
491 int &nOvrXSize, int &nOvrYSize, double &dfSrcRatioX,
492 double &dfSrcRatioY) const;
493 int GetOverviewCount() const;
494 int GetSrcOverviewLevel(int iOvr, bool &bThisLevelOnlyOut) const;
495 VRTWarpedDataset *CreateImplicitOverview(int iOvr) const;
496 void CreateImplicitOverviews();
497
498 friend class VRTWarpedRasterBand;
499
500 CPL_DISALLOW_COPY_ASSIGN(VRTWarpedDataset)
501
502 protected:
503 int CloseDependentDatasets() override;
504
505 public:
506 VRTWarpedDataset(int nXSize, int nYSize, int nBlockXSize = 0,
507 int nBlockYSize = 0);
508 ~VRTWarpedDataset() override;
509
510 CPLErr FlushCache(bool bAtClosing) override;
511
512 CPLErr Initialize(/* GDALWarpOptions */ void *);
513
514 CPLErr IBuildOverviews(const char *, int, const int *, int, const int *,
515 GDALProgressFunc, void *,
516 CSLConstList papszOptions) override;
517
518 CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
519 const char *pszDomain = "") override;
520
521 CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
522 CPLErr XMLInit(const CPLXMLNode *, const char *) override;
523
524 virtual CPLErr AddBand(GDALDataType eType,
525 char **papszOptions = nullptr) override;
526
527 char **GetFileList() override;
528
529 CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
530 int nYSize, void *pData, int nBufXSize, int nBufYSize,
531 GDALDataType eBufType, int nBandCount,
532 BANDMAP_TYPE panBandMap, GSpacing nPixelSpace,
533 GSpacing nLineSpace, GSpacing nBandSpace,
534 GDALRasterIOExtraArg *psExtraArg) override;
535
536 CPLErr ProcessBlock(int iBlockX, int iBlockY);
537
538 void GetBlockSize(int *, int *) const;
539};
540
541/************************************************************************/
542/* VRTPansharpenedDataset */
543/************************************************************************/
544
546
547typedef enum
548{
549 GTAdjust_Union,
550 GTAdjust_Intersection,
551 GTAdjust_None,
552 GTAdjust_NoneWithoutWarning
553} GTAdjustment;
554
555class VRTPansharpenedDataset final : public VRTDataset
556{
557 friend class VRTPansharpenedRasterBand;
558
559 std::unique_ptr<GDALPansharpenOperation> m_poPansharpener{};
560 VRTPansharpenedDataset *m_poMainDataset;
561 std::vector<std::unique_ptr<VRTPansharpenedDataset>>
562 m_apoOverviewDatasets{};
563 // Map from absolute to relative.
564 std::map<CPLString, CPLString> m_oMapToRelativeFilenames{};
565
566 int m_bLoadingOtherBands;
567
568 GByte *m_pabyLastBufferBandRasterIO;
569 int m_nLastBandRasterIOXOff;
570 int m_nLastBandRasterIOYOff;
571 int m_nLastBandRasterIOXSize;
572 int m_nLastBandRasterIOYSize;
573 GDALDataType m_eLastBandRasterIODataType;
574
575 GTAdjustment m_eGTAdjustment;
576 int m_bNoDataDisabled;
577
578 std::vector<std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser>>
579 m_apoDatasetsToReleaseRef{};
580
581 CPL_DISALLOW_COPY_ASSIGN(VRTPansharpenedDataset)
582
583 protected:
584 int CloseDependentDatasets() override;
585
586 public:
587 VRTPansharpenedDataset(int nXSize, int nYSize, int nBlockXSize = 0,
588 int nBlockYSize = 0);
589 ~VRTPansharpenedDataset() override;
590
591 CPLErr FlushCache(bool bAtClosing) override;
592
593 CPLErr XMLInit(const CPLXMLNode *, const char *) override;
594 CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
595
596 CPLErr XMLInit(const CPLXMLNode *psTree, const char *pszVRTPath,
597 GDALRasterBandH hPanchroBandIn, int nInputSpectralBandsIn,
598 GDALRasterBandH *pahInputSpectralBandsIn);
599
600 virtual CPLErr AddBand(GDALDataType eType,
601 char **papszOptions = nullptr) override;
602
603 char **GetFileList() override;
604
605 CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
606 int nYSize, void *pData, int nBufXSize, int nBufYSize,
607 GDALDataType eBufType, int nBandCount,
608 BANDMAP_TYPE panBandMap, GSpacing nPixelSpace,
609 GSpacing nLineSpace, GSpacing nBandSpace,
610 GDALRasterIOExtraArg *psExtraArg) override;
611
612 void GetBlockSize(int *, int *) const;
613
614 GDALPansharpenOperation *GetPansharpener()
615 {
616 return m_poPansharpener.get();
617 }
618};
619
620/************************************************************************/
621/* VRTPansharpenedDataset */
622/************************************************************************/
623
629class VRTProcessedDataset final : public VRTDataset
630{
631 public:
632 VRTProcessedDataset(int nXSize, int nYSize);
633 ~VRTProcessedDataset() override;
634
635 CPLErr FlushCache(bool bAtClosing) override;
636
637 CPLErr XMLInit(const CPLXMLNode *, const char *) override;
638 CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
639
640 void GetBlockSize(int *, int *) const;
641
642 // GByte whose initialization constructor does nothing
643#ifdef __GNUC__
644#pragma GCC diagnostic push
645#pragma GCC diagnostic ignored "-Weffc++"
646#endif
647 struct NoInitByte
648 {
649#ifdef __COVERITY__
650 GByte value = 0;
651#else
652 GByte value;
653#endif
654
655 // cppcheck-suppress uninitMemberVar
656 NoInitByte()
657 {
658 // do nothing
659 }
660
661 inline operator GByte() const
662 {
663 return value;
664 }
665 };
666#ifdef __GNUC__
667#pragma GCC diagnostic pop
668#endif
669
670 protected:
671 CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
672 int nYSize, void *pData, int nBufXSize, int nBufYSize,
673 GDALDataType eBufType, int nBandCount,
674 BANDMAP_TYPE panBandMap, GSpacing nPixelSpace,
675 GSpacing nLineSpace, GSpacing nBandSpace,
676 GDALRasterIOExtraArg *psExtraArg) override;
677
678 private:
679 friend class VRTProcessedRasterBand;
680
682 struct Step
683 {
685 std::string osAlgorithm{};
686
688 CPLStringList aosArguments{};
689
692
694 GDALDataType eOutDT = GDT_Unknown;
695
697 int nInBands = 0;
698
700 int nOutBands = 0;
701
703 std::vector<double> adfInNoData{};
704
706 std::vector<double> adfOutNoData{};
707
709 VRTPDWorkingDataPtr pWorkingData = nullptr;
710
711 // NOTE: if adding a new member, edit the move constructor and
712 // assignment operators!
713
714 Step() = default;
715 ~Step();
716 Step(Step &&);
717 Step &operator=(Step &&);
718
719 private:
720 Step(const Step &) = delete;
721 Step &operator=(const Step &) = delete;
722 void deinit();
723 };
724
726 std::string m_osVRTPath{};
727
729 std::unique_ptr<GDALDataset> m_poVRTSrcDS{};
730
732 std::unique_ptr<GDALDataset> m_poSrcDS{};
733
735 std::vector<Step> m_aoSteps{};
736
738 CPLXMLTreeCloser m_oXMLTree{nullptr};
739
741 std::vector<std::unique_ptr<GDALDataset>> m_apoOverviewDatasets{};
742
744 std::vector<NoInitByte> m_abyInput{};
745
747 std::vector<NoInitByte> m_abyOutput{};
748
750 enum class ValueProvenance
751 {
752 FROM_VRTRASTERBAND,
753 FROM_SOURCE,
754 FROM_LAST_STEP,
755 USER_PROVIDED,
756 };
757
759 ValueProvenance m_outputBandCountProvenance = ValueProvenance::FROM_SOURCE;
760
762 int m_outputBandCountValue = 0;
763
765 ValueProvenance m_outputBandDataTypeProvenance =
766 ValueProvenance::FROM_SOURCE;
767
769 GDALDataType m_outputBandDataTypeValue = GDT_Unknown;
770
772 int m_nWorkingBytesPerPixel = 1;
773
775 GIntBig m_nAllowedRAMUsage = 0;
776
777 CPLErr Init(const CPLXMLNode *, const char *,
778 const VRTProcessedDataset *poParentDS,
779 GDALDataset *poParentSrcDS, int iOvrLevel);
780
781 bool ParseStep(const CPLXMLNode *psStep, bool bIsFinalStep,
782 GDALDataType &eCurrentDT, int &nCurrentBandCount,
783 std::vector<double> &adfInNoData,
784 std::vector<double> &adfOutNoData);
785 bool ProcessRegion(int nXOff, int nYOff, int nBufXSize, int nBufYSize,
786 GDALProgressFunc pfnProgress, void *pProgressData);
787};
788
789/************************************************************************/
790/* VRTRasterBand */
791/* */
792/* Provides support for all the various kinds of metadata but */
793/* no raster access. That is handled by derived classes. */
794/************************************************************************/
795
796constexpr double VRT_DEFAULT_NODATA_VALUE = -10000.0;
797
798class CPL_DLL VRTRasterBand CPL_NON_FINAL : public GDALRasterBand
799{
800 private:
801 void ResetNoDataValues();
802
803 protected:
804 friend class VRTDataset;
805
806 bool m_bIsMaskBand = false;
807
808 bool m_bNoDataValueSet = false;
809 // If set to true, will not report the existence of nodata.
810 int m_bHideNoDataValue = false;
811 double m_dfNoDataValue = VRT_DEFAULT_NODATA_VALUE;
812
813 bool m_bNoDataSetAsInt64 = false;
814 int64_t m_nNoDataValueInt64 = GDAL_PAM_DEFAULT_NODATA_VALUE_INT64;
815
816 bool m_bNoDataSetAsUInt64 = false;
817 uint64_t m_nNoDataValueUInt64 = GDAL_PAM_DEFAULT_NODATA_VALUE_UINT64;
818
819 std::unique_ptr<GDALColorTable> m_poColorTable{};
820
821 GDALColorInterp m_eColorInterp = GCI_Undefined;
822
823 std::string m_osUnitType{};
824 CPLStringList m_aosCategoryNames{};
825
826 double m_dfOffset = 0.0;
827 double m_dfScale = 1.0;
828
829 CPLXMLTreeCloser m_psSavedHistograms{nullptr};
830
831 void Initialize(int nXSize, int nYSize);
832
833 std::vector<VRTOverviewInfo> m_aoOverviewInfos{};
834
835 std::unique_ptr<VRTRasterBand> m_poMaskBand{};
836
837 std::unique_ptr<GDALRasterAttributeTable> m_poRAT{};
838
839 CPL_DISALLOW_COPY_ASSIGN(VRTRasterBand)
840
841 bool IsNoDataValueInDataTypeRange() const;
842
843 public:
844 VRTRasterBand();
845 ~VRTRasterBand() override;
846
847 virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
848 VRTMapSharedResources &);
849 virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
850 bool &bHasWarnedAboutRAMUsage,
851 size_t &nAccRAMUsage);
852
853 CPLErr SetNoDataValue(double) override;
854 CPLErr SetNoDataValueAsInt64(int64_t nNoData) override;
855 CPLErr SetNoDataValueAsUInt64(uint64_t nNoData) override;
856 double GetNoDataValue(int *pbSuccess = nullptr) override;
857 int64_t GetNoDataValueAsInt64(int *pbSuccess = nullptr) override;
858 uint64_t GetNoDataValueAsUInt64(int *pbSuccess = nullptr) override;
859 CPLErr DeleteNoDataValue() override;
860
861 CPLErr SetColorTable(GDALColorTable *) override;
862 GDALColorTable *GetColorTable() override;
863
864 GDALRasterAttributeTable *GetDefaultRAT() override;
865 virtual CPLErr
866 SetDefaultRAT(const GDALRasterAttributeTable *poRAT) override;
867
868 CPLErr SetColorInterpretation(GDALColorInterp) override;
869 GDALColorInterp GetColorInterpretation() override;
870
871 const char *GetUnitType() override;
872 CPLErr SetUnitType(const char *) override;
873
874 char **GetCategoryNames() override;
875 CPLErr SetCategoryNames(char **) override;
876
877 CPLErr SetMetadata(char **papszMD, const char *pszDomain = "") override;
878 CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
879 const char *pszDomain = "") override;
880
881 double GetOffset(int *pbSuccess = nullptr) override;
882 CPLErr SetOffset(double) override;
883 double GetScale(int *pbSuccess = nullptr) override;
884 CPLErr SetScale(double) override;
885
886 int GetOverviewCount() override;
887 GDALRasterBand *GetOverview(int) override;
888
889 CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets,
890 GUIntBig *panHistogram, int bIncludeOutOfRange,
891 int bApproxOK, GDALProgressFunc,
892 void *pProgressData) override;
893
894 CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax, int *pnBuckets,
895 GUIntBig **ppanHistogram, int bForce,
896 GDALProgressFunc, void *pProgressData) override;
897
898 virtual CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets,
899 GUIntBig *panHistogram) override;
900
901 CPLErr CopyCommonInfoFrom(GDALRasterBand *);
902
903 virtual void GetFileList(char ***ppapszFileList, int *pnSize,
904 int *pnMaxSize, CPLHashSet *hSetFiles);
905
906 void SetDescription(const char *) override;
907
908 GDALRasterBand *GetMaskBand() override;
909 int GetMaskFlags() override;
910
911 CPLErr CreateMaskBand(int nFlagsIn) override;
912
913 void SetMaskBand(std::unique_ptr<VRTRasterBand> poMaskBand);
914
915 void SetIsMaskBand();
916
917 bool IsMaskBand() const override;
918
919 CPLErr UnsetNoDataValue();
920
921 virtual int CloseDependentDatasets();
922
923 virtual bool IsSourcedRasterBand()
924 {
925 return false;
926 }
927
928 virtual bool IsPansharpenRasterBand()
929 {
930 return false;
931 }
932};
933
934/************************************************************************/
935/* VRTSourcedRasterBand */
936/************************************************************************/
937
938class VRTSimpleSource;
939
940class CPL_DLL VRTSourcedRasterBand CPL_NON_FINAL : public VRTRasterBand
941{
942 private:
943 CPLString m_osLastLocationInfo{};
944 CPLStringList m_aosSourceList{};
945 int m_nSkipBufferInitialization = -1;
946
947 bool CanUseSourcesMinMaxImplementations();
948
949 bool IsMosaicOfNonOverlappingSimpleSourcesOfFullRasterNoResAndTypeChange(
950 bool bAllowMaxValAdjustment) const;
951
952 CPL_DISALLOW_COPY_ASSIGN(VRTSourcedRasterBand)
953
954 protected:
955 bool SkipBufferInitialization();
956
957 public:
958 std::vector<std::unique_ptr<VRTSource>> m_papoSources{};
959
960 VRTSourcedRasterBand(GDALDataset *poDS, int nBand);
961 VRTSourcedRasterBand(GDALDataType eType, int nXSize, int nYSize);
962 VRTSourcedRasterBand(GDALDataset *poDS, int nBand, GDALDataType eType,
963 int nXSize, int nYSize);
964 VRTSourcedRasterBand(GDALDataset *poDS, int nBand, GDALDataType eType,
965 int nXSize, int nYSize, int nBlockXSizeIn,
966 int nBlockYSizeIn);
967 ~VRTSourcedRasterBand() override;
968
969 CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
970 GDALDataType, GSpacing nPixelSpace, GSpacing nLineSpace,
971 GDALRasterIOExtraArg *psExtraArg) override;
972
973 virtual int IGetDataCoverageStatus(int nXOff, int nYOff, int nXSize,
974 int nYSize, int nMaskFlagStop,
975 double *pdfDataPct) override;
976
977 char **GetMetadataDomainList() override;
978 virtual const char *GetMetadataItem(const char *pszName,
979 const char *pszDomain = "") override;
980 char **GetMetadata(const char *pszDomain = "") override;
981 CPLErr SetMetadata(char **papszMetadata,
982 const char *pszDomain = "") override;
983 CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
984 const char *pszDomain = "") override;
985
986 virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
987 VRTMapSharedResources &) override;
988 virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
989 bool &bHasWarnedAboutRAMUsage,
990 size_t &nAccRAMUsage) override;
991
992 double GetMinimum(int *pbSuccess = nullptr) override;
993 double GetMaximum(int *pbSuccess = nullptr) override;
994 virtual CPLErr ComputeRasterMinMax(int bApproxOK,
995 double *adfMinMax) override;
996 virtual CPLErr ComputeStatistics(int bApproxOK, double *pdfMin,
997 double *pdfMax, double *pdfMean,
998 double *pdfStdDev,
999 GDALProgressFunc pfnProgress,
1000 void *pProgressData) override;
1001 CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets,
1002 GUIntBig *panHistogram, int bIncludeOutOfRange,
1003 int bApproxOK, GDALProgressFunc pfnProgress,
1004 void *pProgressData) override;
1005
1006 CPLErr AddSource(std::unique_ptr<VRTSource>);
1007
1008 CPLErr AddSource(VRTSource *);
1009
1010 CPLErr AddSimpleSource(const char *pszFilename, int nBand,
1011 double dfSrcXOff = -1, double dfSrcYOff = -1,
1012 double dfSrcXSize = -1, double dfSrcYSize = -1,
1013 double dfDstXOff = -1, double dfDstYOff = -1,
1014 double dfDstXSize = -1, double dfDstYSize = -1,
1015 const char *pszResampling = "near",
1016 double dfNoDataValue = VRT_NODATA_UNSET);
1017
1018 CPLErr AddSimpleSource(GDALRasterBand *poSrcBand, double dfSrcXOff = -1,
1019 double dfSrcYOff = -1, double dfSrcXSize = -1,
1020 double dfSrcYSize = -1, double dfDstXOff = -1,
1021 double dfDstYOff = -1, double dfDstXSize = -1,
1022 double dfDstYSize = -1,
1023 const char *pszResampling = "near",
1024 double dfNoDataValue = VRT_NODATA_UNSET);
1025
1026 CPLErr AddComplexSource(const char *pszFilename, int nBand,
1027 double dfSrcXOff = -1, double dfSrcYOff = -1,
1028 double dfSrcXSize = -1, double dfSrcYSize = -1,
1029 double dfDstXOff = -1, double dfDstYOff = -1,
1030 double dfDstXSize = -1, double dfDstYSize = -1,
1031 double dfScaleOff = 0.0, double dfScaleRatio = 1.0,
1032 double dfNoDataValue = VRT_NODATA_UNSET,
1033 int nColorTableComponent = 0);
1034
1035 CPLErr AddComplexSource(GDALRasterBand *poSrcBand, double dfSrcXOff = -1,
1036 double dfSrcYOff = -1, double dfSrcXSize = -1,
1037 double dfSrcYSize = -1, double dfDstXOff = -1,
1038 double dfDstYOff = -1, double dfDstXSize = -1,
1039 double dfDstYSize = -1, double dfScaleOff = 0.0,
1040 double dfScaleRatio = 1.0,
1041 double dfNoDataValue = VRT_NODATA_UNSET,
1042 int nColorTableComponent = 0);
1043
1044 CPLErr AddMaskBandSource(GDALRasterBand *poSrcBand, double dfSrcXOff = -1,
1045 double dfSrcYOff = -1, double dfSrcXSize = -1,
1046 double dfSrcYSize = -1, double dfDstXOff = -1,
1047 double dfDstYOff = -1, double dfDstXSize = -1,
1048 double dfDstYSize = -1);
1049
1050 CPLErr AddFuncSource(VRTImageReadFunc pfnReadFunc, void *hCBData,
1051 double dfNoDataValue = VRT_NODATA_UNSET);
1052
1053 void ConfigureSource(VRTSimpleSource *poSimpleSource,
1054 GDALRasterBand *poSrcBand, int bAddAsMaskBand,
1055 double dfSrcXOff, double dfSrcYOff, double dfSrcXSize,
1056 double dfSrcYSize, double dfDstXOff, double dfDstYOff,
1057 double dfDstXSize, double dfDstYSize);
1058
1059 void RemoveCoveredSources(CSLConstList papszOptions = nullptr);
1060
1061 bool CanIRasterIOBeForwardedToEachSource(
1062 GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize,
1063 int nBufXSize, int nBufYSize, GDALRasterIOExtraArg *psExtraArg) const;
1064
1065 bool CanMultiThreadRasterIO(double dfXOff, double dfYOff, double dfXSize,
1066 double dfYSize,
1067 int &nContributingSources) const;
1068
1069 CPLErr IReadBlock(int, int, void *) override;
1070
1071 virtual void GetFileList(char ***ppapszFileList, int *pnSize,
1072 int *pnMaxSize, CPLHashSet *hSetFiles) override;
1073
1074 int CloseDependentDatasets() override;
1075
1076 bool IsSourcedRasterBand() override
1077 {
1078 return true;
1079 }
1080
1081 CPLErr FlushCache(bool bAtClosing) override;
1082};
1083
1084/************************************************************************/
1085/* VRTWarpedRasterBand */
1086/************************************************************************/
1087
1088class CPL_DLL VRTWarpedRasterBand final : public VRTRasterBand
1089{
1090 public:
1091 VRTWarpedRasterBand(GDALDataset *poDS, int nBand,
1092 GDALDataType eType = GDT_Unknown);
1093 ~VRTWarpedRasterBand() override;
1094
1095 virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
1096 bool &bHasWarnedAboutRAMUsage,
1097 size_t &nAccRAMUsage) override;
1098
1099 CPLErr IReadBlock(int, int, void *) override;
1100 CPLErr IWriteBlock(int, int, void *) override;
1101
1102 CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
1103 int nYSize, void *pData, int nBufXSize, int nBufYSize,
1104 GDALDataType eBufType, GSpacing nPixelSpace,
1105 GSpacing nLineSpace,
1106 GDALRasterIOExtraArg *psExtraArg) override;
1107
1108 int GetOverviewCount() override;
1109 GDALRasterBand *GetOverview(int) override;
1110
1111 bool
1112 EmitErrorMessageIfWriteNotSupported(const char *pszCaller) const override;
1113
1114 private:
1115 int m_nIRasterIOCounter =
1116 0;
1117
1118 int GetBestOverviewLevel(int &nXOff, int &nYOff, int &nXSize, int &nYSize,
1119 int nBufXSize, int nBufYSize,
1120 GDALRasterIOExtraArg *psExtraArg) const;
1121};
1122
1123/************************************************************************/
1124/* VRTPansharpenedRasterBand */
1125/************************************************************************/
1126
1127class VRTPansharpenedRasterBand final : public VRTRasterBand
1128{
1129 int m_nIndexAsPansharpenedBand;
1130
1131 public:
1132 VRTPansharpenedRasterBand(GDALDataset *poDS, int nBand,
1133 GDALDataType eDataType = GDT_Unknown);
1134 ~VRTPansharpenedRasterBand() override;
1135
1136 virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
1137 bool &bHasWarnedAboutRAMUsage,
1138 size_t &nAccRAMUsage) override;
1139
1140 CPLErr IReadBlock(int, int, void *) override;
1141
1142 CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
1143 int nYSize, void *pData, int nBufXSize, int nBufYSize,
1144 GDALDataType eBufType, GSpacing nPixelSpace,
1145 GSpacing nLineSpace,
1146 GDALRasterIOExtraArg *psExtraArg) override;
1147
1148 int GetOverviewCount() override;
1149 GDALRasterBand *GetOverview(int) override;
1150
1151 bool IsPansharpenRasterBand() override
1152 {
1153 return true;
1154 }
1155
1156 void SetIndexAsPansharpenedBand(int nIdx)
1157 {
1158 m_nIndexAsPansharpenedBand = nIdx;
1159 }
1160
1161 int GetIndexAsPansharpenedBand() const
1162 {
1163 return m_nIndexAsPansharpenedBand;
1164 }
1165};
1166
1167/************************************************************************/
1168/* VRTProcessedRasterBand */
1169/************************************************************************/
1170
1171class VRTProcessedRasterBand final : public VRTRasterBand
1172{
1173 public:
1174 VRTProcessedRasterBand(VRTProcessedDataset *poDS, int nBand,
1175 GDALDataType eDataType = GDT_Unknown);
1176
1177 CPLErr IReadBlock(int, int, void *) override;
1178
1179 int GetOverviewCount() override;
1180 GDALRasterBand *GetOverview(int) override;
1181
1182 virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
1183 bool &bHasWarnedAboutRAMUsage,
1184 size_t &nAccRAMUsage) override;
1185};
1186
1187/************************************************************************/
1188/* VRTDerivedRasterBand */
1189/************************************************************************/
1190
1191class VRTDerivedRasterBandPrivateData;
1192
1193class CPL_DLL VRTDerivedRasterBand CPL_NON_FINAL : public VRTSourcedRasterBand
1194{
1195 VRTDerivedRasterBandPrivateData *m_poPrivate;
1196 bool InitializePython();
1197 CPLErr GetPixelFunctionArguments(
1198 const CPLString &, const std::vector<int> &anMapBufferIdxToSourceIdx,
1199 int nXOff, int nYOff, std::vector<std::pair<CPLString, CPLString>> &);
1200
1201 CPL_DISALLOW_COPY_ASSIGN(VRTDerivedRasterBand)
1202
1203 public:
1204 CPLString osFuncName{};
1205 GDALDataType eSourceTransferType;
1206
1207 using PixelFunc =
1208 std::function<CPLErr(void **, int, void *, int, int, GDALDataType,
1209 GDALDataType, int, int, CSLConstList)>;
1210
1211 VRTDerivedRasterBand(GDALDataset *poDS, int nBand);
1212 VRTDerivedRasterBand(GDALDataset *poDS, int nBand, GDALDataType eType,
1213 int nXSize, int nYSize, int nBlockXSizeIn = 0,
1214 int nBlockYSizeIn = 0);
1215 ~VRTDerivedRasterBand() override;
1216
1217 CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
1218 GDALDataType, GSpacing nPixelSpace, GSpacing nLineSpace,
1219 GDALRasterIOExtraArg *psExtraArg) override;
1220
1221 virtual int IGetDataCoverageStatus(int nXOff, int nYOff, int nXSize,
1222 int nYSize, int nMaskFlagStop,
1223 double *pdfDataPct) override;
1224
1225 static CPLErr AddPixelFunction(const char *pszFuncNameIn,
1226 GDALDerivedPixelFunc pfnPixelFunc);
1227 static CPLErr AddPixelFunction(const char *pszFuncNameIn,
1228 GDALDerivedPixelFuncWithArgs pfnPixelFunc,
1229 const char *pszMetadata);
1230
1231 static const std::pair<PixelFunc, std::string> *
1232 GetPixelFunction(const char *pszFuncNameIn);
1233
1234 static std::vector<std::string> GetPixelFunctionNames();
1235
1236 void SetPixelFunctionName(const char *pszFuncNameIn);
1237 void AddPixelFunctionArgument(const char *pszArg, const char *pszValue);
1238 void SetSkipNonContributingSources(bool bSkip);
1239 void SetSourceTransferType(GDALDataType eDataType);
1240 void SetPixelFunctionLanguage(const char *pszLanguage);
1241
1242 virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
1243 VRTMapSharedResources &) override;
1244 virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
1245 bool &bHasWarnedAboutRAMUsage,
1246 size_t &nAccRAMUsage) override;
1247
1248 double GetMinimum(int *pbSuccess = nullptr) override;
1249 double GetMaximum(int *pbSuccess = nullptr) override;
1250 virtual CPLErr ComputeRasterMinMax(int bApproxOK,
1251 double *adfMinMax) override;
1252 virtual CPLErr ComputeStatistics(int bApproxOK, double *pdfMin,
1253 double *pdfMax, double *pdfMean,
1254 double *pdfStdDev,
1255 GDALProgressFunc pfnProgress,
1256 void *pProgressData) override;
1257 CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets,
1258 GUIntBig *panHistogram, int bIncludeOutOfRange,
1259 int bApproxOK, GDALProgressFunc pfnProgress,
1260 void *pProgressData) override;
1261
1262 static void Cleanup();
1263};
1264
1265#ifndef GDAL_VRT_DISABLE_RAWRASTERBAND
1266/************************************************************************/
1267/* VRTRawRasterBand */
1268/************************************************************************/
1269
1270class RawRasterBand;
1271
1272class CPL_DLL VRTRawRasterBand CPL_NON_FINAL : public VRTRasterBand
1273{
1274 RawRasterBand *m_poRawRaster;
1275
1276 char *m_pszSourceFilename;
1277 int m_bRelativeToVRT;
1278
1279 CPL_DISALLOW_COPY_ASSIGN(VRTRawRasterBand)
1280
1281 public:
1282 VRTRawRasterBand(GDALDataset *poDS, int nBand,
1283 GDALDataType eType = GDT_Unknown);
1284 ~VRTRawRasterBand() override;
1285
1286 virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
1287 VRTMapSharedResources &) override;
1288 virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
1289 bool &bHasWarnedAboutRAMUsage,
1290 size_t &nAccRAMUsage) override;
1291
1292 CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
1293 GDALDataType, GSpacing nPixelSpace, GSpacing nLineSpace,
1294 GDALRasterIOExtraArg *psExtraArg) override;
1295
1296 CPLErr IReadBlock(int, int, void *) override;
1297 CPLErr IWriteBlock(int, int, void *) override;
1298
1299 CPLErr SetRawLink(const char *pszFilename, const char *pszVRTPath,
1300 int bRelativeToVRT, vsi_l_offset nImageOffset,
1301 int nPixelOffset, int nLineOffset,
1302 const char *pszByteOrder);
1303
1304 void ClearRawLink();
1305
1306 CPLVirtualMem *GetVirtualMemAuto(GDALRWFlag eRWFlag, int *pnPixelSpace,
1307 GIntBig *pnLineSpace,
1308 char **papszOptions) override;
1309
1310 virtual void GetFileList(char ***ppapszFileList, int *pnSize,
1311 int *pnMaxSize, CPLHashSet *hSetFiles) override;
1312};
1313#endif
1314
1315/************************************************************************/
1316/* VRTDriver */
1317/************************************************************************/
1318
1319class VRTDriver final : public GDALDriver
1320{
1321 CPL_DISALLOW_COPY_ASSIGN(VRTDriver)
1322
1323 std::mutex m_oMutex{};
1324 std::map<std::string, VRTSourceParser> m_oMapSourceParser{};
1325
1326 public:
1327 VRTDriver();
1328 ~VRTDriver() override;
1329
1330 char **papszSourceParsers;
1331
1332 char **GetMetadataDomainList() override;
1333 char **GetMetadata(const char *pszDomain = "") override;
1334 CPLErr SetMetadata(char **papszMetadata,
1335 const char *pszDomain = "") override;
1336
1337 VRTSource *ParseSource(const CPLXMLNode *psSrc, const char *pszVRTPath,
1338 VRTMapSharedResources &oMapSharedSources);
1339 void AddSourceParser(const char *pszElementName, VRTSourceParser pfnParser);
1340};
1341
1342/************************************************************************/
1343/* VRTSimpleSource */
1344/************************************************************************/
1345
1346class CPL_DLL VRTSimpleSource CPL_NON_FINAL : public VRTSource
1347{
1348 CPL_DISALLOW_COPY_ASSIGN(VRTSimpleSource)
1349
1350 private:
1351 // Owned by the VRTDataset
1352 VRTMapSharedResources *m_poMapSharedSources = nullptr;
1353
1354 mutable GDALRasterBand *m_poRasterBand = nullptr;
1355
1356 // When poRasterBand is a mask band, poMaskBandMainBand is the band
1357 // from which the mask band is taken.
1358 mutable GDALRasterBand *m_poMaskBandMainBand = nullptr;
1359
1360 CPLStringList m_aosOpenOptionsOri{}; // as read in the original source XML
1361 CPLStringList
1362 m_aosOpenOptions{}; // same as above, but potentially augmented with ROOT_PATH
1363 bool m_bSrcDSNameFromVRT =
1364 false; // whereas content in m_osSrcDSName is a <VRTDataset> XML node
1365
1366 void OpenSource() const;
1367
1368 GDALDataset *GetSourceDataset() const;
1369
1370 protected:
1371 friend class VRTSourcedRasterBand;
1372 friend class VRTDerivedRasterBand;
1373 friend class VRTDataset;
1374 friend class GDALTileIndexDataset;
1375 friend class GDALTileIndexBand;
1376
1377 int m_nBand = 0;
1378 bool m_bGetMaskBand = false;
1379
1380 /* Value for uninitialized source or destination window. It is chosen such
1381 * that SrcToDst() and DstToSrc() are no-ops if both source and destination
1382 * windows are unset.
1383 */
1384 static constexpr double UNINIT_WINDOW = -1.0;
1385
1386 double m_dfSrcXOff = UNINIT_WINDOW;
1387 double m_dfSrcYOff = UNINIT_WINDOW;
1388 double m_dfSrcXSize = UNINIT_WINDOW;
1389 double m_dfSrcYSize = UNINIT_WINDOW;
1390
1391 double m_dfDstXOff = UNINIT_WINDOW;
1392 double m_dfDstYOff = UNINIT_WINDOW;
1393 double m_dfDstXSize = UNINIT_WINDOW;
1394 double m_dfDstYSize = UNINIT_WINDOW;
1395
1396 CPLString m_osResampling{};
1397
1398 int m_nMaxValue = 0;
1399
1400 int m_bRelativeToVRTOri = -1;
1401 CPLString m_osSourceFileNameOri{};
1402 int m_nExplicitSharedStatus = -1; // -1 unknown, 0 = unshared, 1 = shared
1403 CPLString m_osSrcDSName{};
1404
1405 bool m_bDropRefOnSrcBand = true;
1406
1407 int NeedMaxValAdjustment() const;
1408
1409 GDALRasterBand *GetRasterBandNoOpen() const
1410 {
1411 return m_poRasterBand;
1412 }
1413
1414 void SetRasterBand(GDALRasterBand *poBand, bool bDropRef)
1415 {
1416 m_poRasterBand = poBand;
1417 m_bDropRefOnSrcBand = bDropRef;
1418 }
1419
1420 virtual bool ValidateOpenedBand(GDALRasterBand * /*poBand*/) const
1421 {
1422 return true;
1423 }
1424
1426 bool IsSrcWinSet() const
1427 {
1428 return m_dfSrcXOff != UNINIT_WINDOW || m_dfSrcYOff != UNINIT_WINDOW ||
1429 m_dfSrcXSize != UNINIT_WINDOW || m_dfSrcYSize != UNINIT_WINDOW;
1430 }
1431
1433 bool IsDstWinSet() const
1434 {
1435 return m_dfDstXOff != UNINIT_WINDOW || m_dfDstYOff != UNINIT_WINDOW ||
1436 m_dfDstXSize != UNINIT_WINDOW || m_dfDstYSize != UNINIT_WINDOW;
1437 }
1438
1439 void AddSourceFilenameNode(const char *pszVRTPath, CPLXMLNode *psSrc);
1440
1441 public:
1442 VRTSimpleSource();
1443 VRTSimpleSource(const VRTSimpleSource *poSrcSource, double dfXDstRatio,
1444 double dfYDstRatio);
1445 ~VRTSimpleSource() override;
1446
1447 virtual CPLErr XMLInit(const CPLXMLNode *psTree, const char *,
1448 VRTMapSharedResources &) override;
1449 CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
1450
1451 CPLErr ParseSrcRectAndDstRect(const CPLXMLNode *psSrc);
1452
1453 void SetSrcBand(const char *pszFilename, int nBand);
1454 void SetSrcBand(GDALRasterBand *);
1455 void SetSrcMaskBand(GDALRasterBand *);
1456 void SetSrcWindow(double, double, double, double);
1457 void SetDstWindow(double, double, double, double);
1458 void GetDstWindow(double &, double &, double &, double &) const;
1459 bool DstWindowIntersects(double dfXOff, double dfYOff, double dfXSize,
1460 double dfYSize) const;
1461
1462 const std::string &GetSourceDatasetName() const
1463 {
1464 return m_osSrcDSName;
1465 }
1466
1467 // Must be called after SetSrcBand()
1468 void SetSourceDatasetName(const char *pszFilename, bool bRelativeToVRT);
1469
1470 const CPLString &GetResampling() const
1471 {
1472 return m_osResampling;
1473 }
1474
1475 void SetResampling(const char *pszResampling);
1476
1477 int GetSrcDstWindow(double, double, double, double, int, int,
1478 double *pdfReqXOff, double *pdfReqYOff,
1479 double *pdfReqXSize, double *pdfReqYSize, int *, int *,
1480 int *, int *, int *, int *, int *, int *,
1481 bool &bErrorOut);
1482
1483 int GetSrcDstWindow(double, double, double, double, int, int,
1484 GDALRIOResampleAlg eResampleAlg, double *pdfReqXOff,
1485 double *pdfReqYOff, double *pdfReqXSize,
1486 double *pdfReqYSize, int *, int *, int *, int *, int *,
1487 int *, int *, int *, bool &bErrorOut);
1488
1489 virtual CPLErr RasterIO(GDALDataType eVRTBandDataType, int nXOff, int nYOff,
1490 int nXSize, int nYSize, void *pData, int nBufXSize,
1491 int nBufYSize, GDALDataType eBufType,
1492 GSpacing nPixelSpace, GSpacing nLineSpace,
1493 GDALRasterIOExtraArg *psExtraArgIn,
1494 WorkingState &oWorkingState) override;
1495
1496 double GetMinimum(int nXSize, int nYSize, int *pbSuccess) override;
1497 double GetMaximum(int nXSize, int nYSize, int *pbSuccess) override;
1498 CPLErr GetHistogram(int nXSize, int nYSize, double dfMin, double dfMax,
1499 int nBuckets, GUIntBig *panHistogram,
1500 int bIncludeOutOfRange, int bApproxOK,
1501 GDALProgressFunc pfnProgress,
1502 void *pProgressData) override;
1503
1504 void DstToSrc(double dfX, double dfY, double &dfXOut, double &dfYOut) const;
1505 void SrcToDst(double dfX, double dfY, double &dfXOut, double &dfYOut) const;
1506
1507 virtual void GetFileList(char ***ppapszFileList, int *pnSize,
1508 int *pnMaxSize, CPLHashSet *hSetFiles) override;
1509
1510 bool IsSimpleSource() const override
1511 {
1512 return true;
1513 }
1514
1518 static const char *GetTypeStatic();
1519
1520 const char *GetType() const override;
1521
1522 CPLErr FlushCache(bool bAtClosing) override;
1523
1524 GDALRasterBand *GetRasterBand() const;
1525 GDALRasterBand *GetMaskBandMainBand();
1526 bool IsSameExceptBandNumber(const VRTSimpleSource *poOtherSource) const;
1527 CPLErr DatasetRasterIO(GDALDataType eVRTBandDataType, int nXOff, int nYOff,
1528 int nXSize, int nYSize, void *pData, int nBufXSize,
1529 int nBufYSize, GDALDataType eBufType, int nBandCount,
1530 const int *panBandMap, GSpacing nPixelSpace,
1531 GSpacing nLineSpace, GSpacing nBandSpace,
1532 GDALRasterIOExtraArg *psExtraArg);
1533
1534 void UnsetPreservedRelativeFilenames();
1535
1536 void SetMaxValue(int nVal)
1537 {
1538 m_nMaxValue = nVal;
1539 }
1540};
1541
1542/************************************************************************/
1543/* VRTAveragedSource */
1544/************************************************************************/
1545
1546class VRTAveragedSource final : public VRTSimpleSource
1547{
1548 CPL_DISALLOW_COPY_ASSIGN(VRTAveragedSource)
1549
1550 int m_bNoDataSet = false;
1551 double m_dfNoDataValue = VRT_NODATA_UNSET;
1552
1553 public:
1554 VRTAveragedSource();
1555 virtual CPLErr RasterIO(GDALDataType eVRTBandDataType, int nXOff, int nYOff,
1556 int nXSize, int nYSize, void *pData, int nBufXSize,
1557 int nBufYSize, GDALDataType eBufType,
1558 GSpacing nPixelSpace, GSpacing nLineSpace,
1559 GDALRasterIOExtraArg *psExtraArgIn,
1560 WorkingState &oWorkingState) override;
1561
1562 double GetMinimum(int nXSize, int nYSize, int *pbSuccess) override;
1563 double GetMaximum(int nXSize, int nYSize, int *pbSuccess) override;
1564 CPLErr GetHistogram(int nXSize, int nYSize, double dfMin, double dfMax,
1565 int nBuckets, GUIntBig *panHistogram,
1566 int bIncludeOutOfRange, int bApproxOK,
1567 GDALProgressFunc pfnProgress,
1568 void *pProgressData) override;
1569
1570 void SetNoDataValue(double dfNoDataValue);
1571
1572 CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
1573
1577 static const char *GetTypeStatic();
1578
1579 const char *GetType() const override;
1580};
1581
1582/************************************************************************/
1583/* VRTNoDataFromMaskSource */
1584/************************************************************************/
1585
1586class VRTNoDataFromMaskSource final : public VRTSimpleSource
1587{
1588 CPL_DISALLOW_COPY_ASSIGN(VRTNoDataFromMaskSource)
1589
1590 bool m_bNoDataSet = false;
1591 double m_dfNoDataValue = 0;
1592 double m_dfMaskValueThreshold = 0;
1593 bool m_bHasRemappedValue = false;
1594 double m_dfRemappedValue = 0;
1595
1596 public:
1597 VRTNoDataFromMaskSource();
1598 virtual CPLErr RasterIO(GDALDataType eVRTBandDataType, int nXOff, int nYOff,
1599 int nXSize, int nYSize, void *pData, int nBufXSize,
1600 int nBufYSize, GDALDataType eBufType,
1601 GSpacing nPixelSpace, GSpacing nLineSpace,
1602 GDALRasterIOExtraArg *psExtraArgIn,
1603 WorkingState &oWorkingState) override;
1604
1605 double GetMinimum(int nXSize, int nYSize, int *pbSuccess) override;
1606 double GetMaximum(int nXSize, int nYSize, int *pbSuccess) override;
1607 CPLErr GetHistogram(int nXSize, int nYSize, double dfMin, double dfMax,
1608 int nBuckets, GUIntBig *panHistogram,
1609 int bIncludeOutOfRange, int bApproxOK,
1610 GDALProgressFunc pfnProgress,
1611 void *pProgressData) override;
1612
1613 void SetParameters(double dfNoDataValue, double dfMaskValueThreshold);
1614 void SetParameters(double dfNoDataValue, double dfMaskValueThreshold,
1615 double dfRemappedValue);
1616
1617 virtual CPLErr XMLInit(const CPLXMLNode *psTree, const char *,
1618 VRTMapSharedResources &) override;
1619 CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
1620
1624 static const char *GetTypeStatic();
1625
1626 const char *GetType() const override;
1627};
1628
1629/************************************************************************/
1630/* VRTComplexSource */
1631/************************************************************************/
1632
1633class CPL_DLL VRTComplexSource CPL_NON_FINAL : public VRTSimpleSource
1634{
1635 CPL_DISALLOW_COPY_ASSIGN(VRTComplexSource)
1636
1637 protected:
1638 static constexpr int PROCESSING_FLAG_NODATA = 1 << 0;
1639 static constexpr int PROCESSING_FLAG_USE_MASK_BAND =
1640 1 << 1; // Mutually exclusive with NODATA
1641 static constexpr int PROCESSING_FLAG_SCALING_LINEAR = 1 << 2;
1642 static constexpr int PROCESSING_FLAG_SCALING_EXPONENTIAL =
1643 1 << 3; // Mutually exclusive with SCALING_LINEAR
1644 static constexpr int PROCESSING_FLAG_COLOR_TABLE_EXPANSION = 1 << 4;
1645 static constexpr int PROCESSING_FLAG_LUT = 1 << 5;
1646
1647 int m_nProcessingFlags = 0;
1648
1649 // adjusted value should be read with GetAdjustedNoDataValue()
1650 double m_dfNoDataValue = VRT_NODATA_UNSET;
1651 std::string
1652 m_osNoDataValueOri{}; // string value read in XML deserialization
1653
1654 double m_dfScaleOff = 0; // For linear scaling.
1655 double m_dfScaleRatio = 1; // For linear scaling.
1656
1657 // For non-linear scaling with a power function.
1658 bool m_bSrcMinMaxDefined = false;
1659 double m_dfSrcMin = 0;
1660 double m_dfSrcMax = 0;
1661 double m_dfDstMin = 0;
1662 double m_dfDstMax = 0;
1663 double m_dfExponent = 1;
1664 bool m_bClip = true; // Only taken into account for non-linear scaling
1665
1666 int m_nColorTableComponent = 0;
1667
1668 std::vector<double> m_adfLUTInputs{};
1669 std::vector<double> m_adfLUTOutputs{};
1670
1671 double GetAdjustedNoDataValue() const;
1672
1673 template <class WorkingDT>
1674 CPLErr
1675 RasterIOInternal(GDALRasterBand *poSourceBand,
1676 GDALDataType eVRTBandDataType, int nReqXOff, int nReqYOff,
1677 int nReqXSize, int nReqYSize, void *pData, int nOutXSize,
1678 int nOutYSize, GDALDataType eBufType, GSpacing nPixelSpace,
1679 GSpacing nLineSpace, GDALRasterIOExtraArg *psExtraArg,
1680 GDALDataType eWrkDataType, WorkingState &oWorkingState);
1681
1682 template <class SourceDT, GDALDataType eSourceType>
1683 CPLErr RasterIOProcessNoData(GDALRasterBand *poSourceBand,
1684 GDALDataType eVRTBandDataType, int nReqXOff,
1685 int nReqYOff, int nReqXSize, int nReqYSize,
1686 void *pData, int nOutXSize, int nOutYSize,
1687 GDALDataType eBufType, GSpacing nPixelSpace,
1688 GSpacing nLineSpace,
1689 GDALRasterIOExtraArg *psExtraArg,
1690 WorkingState &oWorkingState);
1691
1692 public:
1693 VRTComplexSource() = default;
1694 VRTComplexSource(const VRTComplexSource *poSrcSource, double dfXDstRatio,
1695 double dfYDstRatio);
1696
1697 virtual CPLErr RasterIO(GDALDataType eVRTBandDataType, int nXOff, int nYOff,
1698 int nXSize, int nYSize, void *pData, int nBufXSize,
1699 int nBufYSize, GDALDataType eBufType,
1700 GSpacing nPixelSpace, GSpacing nLineSpace,
1701 GDALRasterIOExtraArg *psExtraArgIn,
1702 WorkingState &oWorkingState) override;
1703
1704 double GetMinimum(int nXSize, int nYSize, int *pbSuccess) override;
1705 double GetMaximum(int nXSize, int nYSize, int *pbSuccess) override;
1706 CPLErr GetHistogram(int nXSize, int nYSize, double dfMin, double dfMax,
1707 int nBuckets, GUIntBig *panHistogram,
1708 int bIncludeOutOfRange, int bApproxOK,
1709 GDALProgressFunc pfnProgress,
1710 void *pProgressData) override;
1711
1712 CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
1713 virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
1714 VRTMapSharedResources &) override;
1715
1719 static const char *GetTypeStatic();
1720
1721 const char *GetType() const override;
1722
1723 bool AreValuesUnchanged() const;
1724
1725 double LookupValue(double dfInput);
1726
1727 void SetNoDataValue(double dfNoDataValue);
1728
1729 void SetUseMaskBand(bool bUseMaskBand)
1730 {
1731 if (bUseMaskBand)
1732 m_nProcessingFlags |= PROCESSING_FLAG_USE_MASK_BAND;
1733 else
1734 m_nProcessingFlags &= ~PROCESSING_FLAG_USE_MASK_BAND;
1735 }
1736
1737 void SetLinearScaling(double dfOffset, double dfScale);
1738 void SetPowerScaling(double dfExponent, double dfSrcMin, double dfSrcMax,
1739 double dfDstMin, double dfDstMax, bool bClip = true);
1740 void SetColorTableComponent(int nComponent);
1741
1742 void SetLUT(const std::vector<double> &adfLUTInputs,
1743 const std::vector<double> &adfLUTOutputs);
1744};
1745
1746/************************************************************************/
1747/* VRTFilteredSource */
1748/************************************************************************/
1749
1750class VRTFilteredSource CPL_NON_FINAL : public VRTComplexSource
1751{
1752 private:
1753 int IsTypeSupported(GDALDataType eTestType) const;
1754
1755 CPL_DISALLOW_COPY_ASSIGN(VRTFilteredSource)
1756
1757 protected:
1758 int m_nSupportedTypesCount;
1759 GDALDataType m_aeSupportedTypes[20];
1760
1761 int m_nExtraEdgePixels;
1762
1763 public:
1764 VRTFilteredSource();
1765 ~VRTFilteredSource() override;
1766
1767 const char *GetType() const override = 0;
1768
1769 void SetExtraEdgePixels(int);
1770 void SetFilteringDataTypesSupported(int, GDALDataType *);
1771
1772 virtual CPLErr FilterData(int nXSize, int nYSize, GDALDataType eType,
1773 GByte *pabySrcData, GByte *pabyDstData) = 0;
1774
1775 virtual CPLErr RasterIO(GDALDataType eVRTBandDataType, int nXOff, int nYOff,
1776 int nXSize, int nYSize, void *pData, int nBufXSize,
1777 int nBufYSize, GDALDataType eBufType,
1778 GSpacing nPixelSpace, GSpacing nLineSpace,
1779 GDALRasterIOExtraArg *psExtraArg,
1780 WorkingState &oWorkingState) override;
1781};
1782
1783/************************************************************************/
1784/* VRTKernelFilteredSource */
1785/************************************************************************/
1786
1787class VRTKernelFilteredSource CPL_NON_FINAL : public VRTFilteredSource
1788{
1789 CPL_DISALLOW_COPY_ASSIGN(VRTKernelFilteredSource)
1790
1791 protected:
1792 int m_nKernelSize = 0;
1793 bool m_bSeparable = false;
1794 // m_nKernelSize elements if m_bSeparable, m_nKernelSize * m_nKernelSize otherwise
1795 std::vector<double> m_adfKernelCoefs{};
1796 bool m_bNormalized = false;
1797 std::string m_function{};
1798
1799 public:
1800 VRTKernelFilteredSource();
1801
1802 const char *GetType() const override;
1803
1804 virtual CPLErr XMLInit(const CPLXMLNode *psTree, const char *,
1805 VRTMapSharedResources &) override;
1806 CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
1807
1808 virtual CPLErr FilterData(int nXSize, int nYSize, GDALDataType eType,
1809 GByte *pabySrcData, GByte *pabyDstData) override;
1810
1811 CPLErr SetKernel(int nKernelSize, bool bSeparable,
1812 const std::vector<double> &adfNewCoefs);
1813 void SetNormalized(bool);
1814
1815 void SetFunction(const std::string &s)
1816 {
1817 m_function = s;
1818 }
1819};
1820
1821/************************************************************************/
1822/* VRTAverageFilteredSource */
1823/************************************************************************/
1824
1825class VRTAverageFilteredSource final : public VRTKernelFilteredSource
1826{
1827 CPL_DISALLOW_COPY_ASSIGN(VRTAverageFilteredSource)
1828
1829 public:
1830 explicit VRTAverageFilteredSource(int nKernelSize);
1831 ~VRTAverageFilteredSource() override;
1832
1833 const char *GetType() const override;
1834
1835 virtual CPLErr XMLInit(const CPLXMLNode *psTree, const char *,
1836 VRTMapSharedResources &) override;
1837 CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
1838};
1839
1840/************************************************************************/
1841/* VRTFuncSource */
1842/************************************************************************/
1843class VRTFuncSource final : public VRTSource
1844{
1845 CPL_DISALLOW_COPY_ASSIGN(VRTFuncSource)
1846
1847 public:
1848 VRTFuncSource();
1849 ~VRTFuncSource() override;
1850
1851 virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
1852 VRTMapSharedResources &) override
1853 {
1854 return CE_Failure;
1855 }
1856
1857 CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
1858
1859 virtual CPLErr RasterIO(GDALDataType eVRTBandDataType, int nXOff, int nYOff,
1860 int nXSize, int nYSize, void *pData, int nBufXSize,
1861 int nBufYSize, GDALDataType eBufType,
1862 GSpacing nPixelSpace, GSpacing nLineSpace,
1863 GDALRasterIOExtraArg *psExtraArg,
1864 WorkingState &oWorkingState) override;
1865
1866 double GetMinimum(int nXSize, int nYSize, int *pbSuccess) override;
1867 double GetMaximum(int nXSize, int nYSize, int *pbSuccess) override;
1868 CPLErr GetHistogram(int nXSize, int nYSize, double dfMin, double dfMax,
1869 int nBuckets, GUIntBig *panHistogram,
1870 int bIncludeOutOfRange, int bApproxOK,
1871 GDALProgressFunc pfnProgress,
1872 void *pProgressData) override;
1873
1874 const char *GetType() const override;
1875
1876 VRTImageReadFunc pfnReadFunc;
1877 void *pCBData;
1878 GDALDataType eType;
1879
1880 float fNoDataValue;
1881};
1882
1883/************************************************************************/
1884/* VRTGroup */
1885/************************************************************************/
1886
1887#ifdef TMPEXPORT
1888#define TMP_CPL_DLL CPL_DLL
1889#else
1890#define TMP_CPL_DLL
1891#endif
1892
1893class VRTMDArray;
1894class VRTAttribute;
1895class VRTDimension;
1896
1897class VRTGroup final : public GDALGroup
1898{
1899 public:
1900 struct Ref
1901 {
1902 VRTGroup *m_ptr;
1903
1904 explicit Ref(VRTGroup *ptr) : m_ptr(ptr)
1905 {
1906 }
1907
1908 Ref(const Ref &) = delete;
1909 Ref &operator=(const Ref &) = delete;
1910 };
1911
1912 private:
1913 std::shared_ptr<Ref> m_poSharedRefRootGroup{};
1914 std::weak_ptr<Ref> m_poWeakRefRootGroup{};
1915 std::shared_ptr<Ref> m_poRefSelf{};
1916
1917 std::string m_osFilename{};
1918 mutable bool m_bDirty = false;
1919 std::string m_osVRTPath{};
1920 std::vector<std::string> m_aosGroupNames{};
1921 std::map<std::string, std::shared_ptr<VRTGroup>> m_oMapGroups{};
1922 std::vector<std::string> m_aosMDArrayNames{};
1923 std::map<std::string, std::shared_ptr<VRTMDArray>> m_oMapMDArrays{};
1924 std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
1925 std::map<std::string, std::shared_ptr<VRTDimension>> m_oMapDimensions{};
1926
1927 std::shared_ptr<VRTGroup>
1928 OpenGroupInternal(const std::string &osName) const;
1929 void SetRootGroupRef(const std::weak_ptr<Ref> &rgRef);
1930 std::weak_ptr<Ref> GetRootGroupRef() const;
1931
1932 protected:
1933 friend class VRTMDArray;
1934 friend std::shared_ptr<GDALMDArray>
1935 VRTDerivedArrayCreate(const char *pszVRTPath, const CPLXMLNode *psTree);
1936
1937 explicit VRTGroup(const char *pszVRTPath);
1938 VRTGroup(const std::string &osParentName, const std::string &osName);
1939
1940 public:
1941 static std::shared_ptr<VRTGroup> Create(const std::string &osParentName,
1942 const std::string &osName)
1943 {
1944 auto poGroup =
1945 std::shared_ptr<VRTGroup>(new VRTGroup(osParentName, osName));
1946 poGroup->SetSelf(poGroup);
1947 return poGroup;
1948 }
1949
1950 ~VRTGroup() override;
1951
1952 bool XMLInit(const std::shared_ptr<VRTGroup> &poRoot,
1953 const std::shared_ptr<VRTGroup> &poThisGroup,
1954 const CPLXMLNode *psNode, const char *pszVRTPath);
1955
1956 std::vector<std::string>
1957 GetMDArrayNames(CSLConstList papszOptions) const override;
1958 std::shared_ptr<GDALMDArray>
1959 OpenMDArray(const std::string &osName,
1960 CSLConstList papszOptions = nullptr) const override;
1961
1962 std::vector<std::string>
1963 GetGroupNames(CSLConstList papszOptions) const override;
1964
1965 std::shared_ptr<GDALGroup> OpenGroup(const std::string &osName,
1966 CSLConstList) const override
1967 {
1968 return OpenGroupInternal(osName);
1969 }
1970
1971 std::vector<std::shared_ptr<GDALDimension>>
1972 GetDimensions(CSLConstList) const override;
1973
1974 std::vector<std::shared_ptr<GDALAttribute>>
1975 GetAttributes(CSLConstList) const override;
1976
1977 std::shared_ptr<VRTDimension> GetDimension(const std::string &name) const
1978 {
1979 auto oIter = m_oMapDimensions.find(name);
1980 return oIter == m_oMapDimensions.end() ? nullptr : oIter->second;
1981 }
1982
1983 std::shared_ptr<VRTDimension>
1984 GetDimensionFromFullName(const std::string &name, bool bEmitError) const;
1985
1986 std::shared_ptr<GDALGroup>
1987 CreateGroup(const std::string &osName,
1988 CSLConstList papszOptions = nullptr) override;
1989
1990 std::shared_ptr<VRTGroup>
1991 CreateVRTGroup(const std::string &osName,
1992 CSLConstList papszOptions = nullptr);
1993
1994 std::shared_ptr<GDALDimension>
1995 CreateDimension(const std::string &osName, const std::string &osType,
1996 const std::string &osDirection, GUInt64 nSize,
1997 CSLConstList papszOptions = nullptr) override;
1998
1999 std::shared_ptr<GDALAttribute>
2000 CreateAttribute(const std::string &osName,
2001 const std::vector<GUInt64> &anDimensions,
2002 const GDALExtendedDataType &oDataType,
2003 CSLConstList papszOptions = nullptr) override;
2004
2005 std::shared_ptr<GDALMDArray> CreateMDArray(
2006 const std::string &osName,
2007 const std::vector<std::shared_ptr<GDALDimension>> &aoDimensions,
2008 const GDALExtendedDataType &oDataType,
2009 CSLConstList papszOptions = nullptr) override;
2010
2011 std::shared_ptr<VRTMDArray> CreateVRTMDArray(
2012 const std::string &osName,
2013 const std::vector<std::shared_ptr<GDALDimension>> &aoDimensions,
2014 const GDALExtendedDataType &oDataType,
2015 CSLConstList papszOptions = nullptr);
2016
2017 void SetIsRootGroup();
2018
2019 const std::shared_ptr<Ref> &GetRef() const
2020 {
2021 return m_poRefSelf;
2022 }
2023
2024 VRTGroup *GetRootGroup() const;
2025 std::shared_ptr<VRTGroup> GetRootGroupSharedPtr() const;
2026
2027 const std::string &GetVRTPath() const
2028 {
2029 return m_osVRTPath;
2030 }
2031
2032 void SetVRTPath(const std::string &osVRTPath)
2033 {
2034 m_osVRTPath = osVRTPath;
2035 }
2036
2037 void SetDirty();
2038
2039 void SetFilename(const std::string &osFilename)
2040 {
2041 m_osFilename = osFilename;
2042 }
2043
2044 const std::string &GetFilename() const
2045 {
2046 return m_osFilename;
2047 }
2048
2049 bool Serialize() const;
2050 CPLXMLNode *SerializeToXML(const char *pszVRTPathIn) const;
2051 void Serialize(CPLXMLNode *psParent, const char *pszVRTPathIn) const;
2052};
2053
2054/************************************************************************/
2055/* VRTDimension */
2056/************************************************************************/
2057
2058class VRTDimension final : public GDALDimension
2059{
2060 std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
2061 std::string m_osIndexingVariableName;
2062
2063 public:
2064 VRTDimension(const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
2065 const std::string &osParentName, const std::string &osName,
2066 const std::string &osType, const std::string &osDirection,
2067 GUInt64 nSize, const std::string &osIndexingVariableName)
2068 : GDALDimension(osParentName, osName, osType, osDirection, nSize),
2069 m_poGroupRef(poGroupRef),
2070 m_osIndexingVariableName(osIndexingVariableName)
2071 {
2072 }
2073
2074 VRTGroup *GetGroup() const;
2075
2076 static std::shared_ptr<VRTDimension>
2077 Create(const std::shared_ptr<VRTGroup> &poThisGroup,
2078 const std::string &osParentName, const CPLXMLNode *psNode);
2079
2080 std::shared_ptr<GDALMDArray> GetIndexingVariable() const override;
2081
2083 std::shared_ptr<GDALMDArray> poIndexingVariable) override;
2084
2085 void Serialize(CPLXMLNode *psParent) const;
2086};
2087
2088/************************************************************************/
2089/* VRTAttribute */
2090/************************************************************************/
2091
2092class VRTAttribute final : public GDALAttribute
2093{
2094 GDALExtendedDataType m_dt;
2095 std::vector<std::string> m_aosList{};
2096 std::vector<std::shared_ptr<GDALDimension>> m_dims{};
2097
2098 protected:
2099 bool IRead(const GUInt64 *arrayStartIdx, const size_t *count,
2100 const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
2101 const GDALExtendedDataType &bufferDataType,
2102 void *pDstBuffer) const override;
2103
2104 bool IWrite(const GUInt64 *arrayStartIdx, const size_t *count,
2105 const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
2106 const GDALExtendedDataType &bufferDataType,
2107 const void *pSrcBuffer) override;
2108
2109 public:
2110 VRTAttribute(const std::string &osParentName, const std::string &osName,
2111 const GDALExtendedDataType &dt,
2112 std::vector<std::string> &&aosList)
2113 : GDALAbstractMDArray(osParentName, osName),
2114 GDALAttribute(osParentName, osName), m_dt(dt),
2115 m_aosList(std::move(aosList))
2116 {
2117 if (m_aosList.size() > 1)
2118 {
2119 m_dims.emplace_back(std::make_shared<GDALDimension>(
2120 std::string(), "dim", std::string(), std::string(),
2121 m_aosList.size()));
2122 }
2123 }
2124
2125 VRTAttribute(const std::string &osParentName, const std::string &osName,
2126 GUInt64 nDim, const GDALExtendedDataType &dt)
2127 : GDALAbstractMDArray(osParentName, osName),
2128 GDALAttribute(osParentName, osName), m_dt(dt)
2129 {
2130 if (nDim != 0)
2131 {
2132 m_dims.emplace_back(std::make_shared<GDALDimension>(
2133 std::string(), "dim", std::string(), std::string(), nDim));
2134 }
2135 }
2136
2137 static bool CreationCommonChecks(
2138 const std::string &osName, const std::vector<GUInt64> &anDimensions,
2139 const std::map<std::string, std::shared_ptr<VRTAttribute>>
2140 &oMapAttributes);
2141
2142 static std::shared_ptr<VRTAttribute> Create(const std::string &osParentName,
2143 const CPLXMLNode *psNode);
2144
2145 const std::vector<std::shared_ptr<GDALDimension>> &
2146 GetDimensions() const override
2147 {
2148 return m_dims;
2149 }
2150
2151 const GDALExtendedDataType &GetDataType() const override
2152 {
2153 return m_dt;
2154 }
2155
2156 void Serialize(CPLXMLNode *psParent) const;
2157};
2158
2159/************************************************************************/
2160/* VRTMDArraySource */
2161/************************************************************************/
2162
2163class VRTMDArraySource
2164{
2165 public:
2166 virtual ~VRTMDArraySource();
2167
2168 enum class RelationShip
2169 {
2170 NO_INTERSECTION,
2171 PARTIAL_INTERSECTION,
2172 SOURCE_BLOCK_MATCH,
2173 };
2174
2175 virtual RelationShip GetRelationship(const uint64_t *arrayStartIdx,
2176 const size_t *count) const = 0;
2177
2178 virtual bool GetRawBlockInfo(const uint64_t *arrayStartIdx,
2179 const size_t *count,
2180 GDALMDArrayRawBlockInfo &info) const = 0;
2181
2182 virtual bool Read(const GUInt64 *arrayStartIdx, const size_t *count,
2183 const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
2184 const GDALExtendedDataType &bufferDataType,
2185 void *pDstBuffer) const = 0;
2186
2187 virtual void Serialize(CPLXMLNode *psParent,
2188 const char *pszVRTPath) const = 0;
2189};
2190
2191/************************************************************************/
2192/* VRTMDArray */
2193/************************************************************************/
2194
2195class VRTMDArray final : public GDALMDArray
2196{
2197 protected:
2198 friend class VRTGroup; // for access to SetSelf()
2199
2200 std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
2201 std::string m_osVRTPath{};
2202 std::shared_ptr<VRTGroup> m_poDummyOwningGroup{};
2203
2204 GDALExtendedDataType m_dt;
2205 std::vector<std::shared_ptr<GDALDimension>> m_dims;
2206 std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
2207 std::vector<std::unique_ptr<VRTMDArraySource>> m_sources{};
2208 std::shared_ptr<OGRSpatialReference> m_poSRS{};
2209 std::vector<GByte> m_abyNoData{};
2210 std::string m_osUnit{};
2211 double m_dfScale = 1.0;
2212 double m_dfOffset = 0.0;
2213 bool m_bHasScale = false;
2214 bool m_bHasOffset = false;
2215 std::string m_osFilename{};
2216 std::vector<GUInt64> m_anBlockSize{};
2217
2218 bool IRead(const GUInt64 *arrayStartIdx, const size_t *count,
2219 const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
2220 const GDALExtendedDataType &bufferDataType,
2221 void *pDstBuffer) const override;
2222
2223 void SetDirty();
2224
2225 public:
2226 VRTMDArray(
2227 const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
2228 const std::string &osParentName, const std::string &osName,
2229 const GDALExtendedDataType &dt,
2230 std::vector<std::shared_ptr<GDALDimension>> &&dims,
2231 std::map<std::string, std::shared_ptr<VRTAttribute>> &&oMapAttributes,
2232 std::vector<GUInt64> &&anBlockSize)
2233 : GDALAbstractMDArray(osParentName, osName),
2234 GDALMDArray(osParentName, osName), m_poGroupRef(poGroupRef),
2235 m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()), m_dt(dt),
2236 m_dims(std::move(dims)), m_oMapAttributes(std::move(oMapAttributes)),
2237 m_osFilename(poGroupRef->m_ptr->GetFilename()),
2238 m_anBlockSize(std::move(anBlockSize))
2239 {
2240 }
2241
2242 VRTMDArray(const std::shared_ptr<VRTGroup::Ref> &poGroupRef,
2243 const std::string &osParentName, const std::string &osName,
2244 const std::vector<std::shared_ptr<GDALDimension>> &dims,
2245 const GDALExtendedDataType &dt,
2246 const std::vector<GUInt64> &anBlockSize)
2247 : GDALAbstractMDArray(osParentName, osName),
2248 GDALMDArray(osParentName, osName), m_poGroupRef(poGroupRef),
2249 m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()), m_dt(dt), m_dims(dims),
2250 m_osFilename(poGroupRef->m_ptr->GetFilename()),
2251 m_anBlockSize(anBlockSize)
2252 {
2253 }
2254
2255 bool IsWritable() const override
2256 {
2257 return false;
2258 }
2259
2260 const std::string &GetFilename() const override
2261 {
2262 return m_osFilename;
2263 }
2264
2265 static std::shared_ptr<VRTMDArray> Create(const char *pszVRTPath,
2266 const CPLXMLNode *psNode);
2267
2268 static std::shared_ptr<VRTMDArray>
2269 Create(const std::shared_ptr<VRTGroup> &poThisGroup,
2270 const std::string &osParentName, const CPLXMLNode *psNode);
2271
2272 const std::vector<std::shared_ptr<GDALDimension>> &
2273 GetDimensions() const override
2274 {
2275 return m_dims;
2276 }
2277
2278 std::vector<std::shared_ptr<GDALAttribute>>
2279 GetAttributes(CSLConstList) const override;
2280
2281 const GDALExtendedDataType &GetDataType() const override
2282 {
2283 return m_dt;
2284 }
2285
2286 bool SetSpatialRef(const OGRSpatialReference *poSRS) override;
2287
2288 std::shared_ptr<OGRSpatialReference> GetSpatialRef() const override
2289 {
2290 return m_poSRS;
2291 }
2292
2293 const void *GetRawNoDataValue() const override;
2294
2295 bool SetRawNoDataValue(const void *pRawNoData) override;
2296
2297 const std::string &GetUnit() const override
2298 {
2299 return m_osUnit;
2300 }
2301
2302 bool SetUnit(const std::string &osUnit) override
2303 {
2304 m_osUnit = osUnit;
2305 return true;
2306 }
2307
2308 double GetOffset(bool *pbHasOffset,
2309 GDALDataType *peStorageType) const override
2310 {
2311 if (pbHasOffset)
2312 *pbHasOffset = m_bHasOffset;
2313 if (peStorageType)
2314 *peStorageType = GDT_Unknown;
2315 return m_dfOffset;
2316 }
2317
2318 double GetScale(bool *pbHasScale,
2319 GDALDataType *peStorageType) const override
2320 {
2321 if (pbHasScale)
2322 *pbHasScale = m_bHasScale;
2323 if (peStorageType)
2324 *peStorageType = GDT_Unknown;
2325 return m_dfScale;
2326 }
2327
2328 bool SetOffset(double dfOffset,
2329 GDALDataType /* eStorageType */ = GDT_Unknown) override
2330 {
2331 SetDirty();
2332 m_bHasOffset = true;
2333 m_dfOffset = dfOffset;
2334 return true;
2335 }
2336
2337 bool SetScale(double dfScale,
2338 GDALDataType /* eStorageType */ = GDT_Unknown) override
2339 {
2340 SetDirty();
2341 m_bHasScale = true;
2342 m_dfScale = dfScale;
2343 return true;
2344 }
2345
2346 void AddSource(std::unique_ptr<VRTMDArraySource> &&poSource);
2347
2348 std::shared_ptr<GDALAttribute>
2349 CreateAttribute(const std::string &osName,
2350 const std::vector<GUInt64> &anDimensions,
2351 const GDALExtendedDataType &oDataType,
2352 CSLConstList papszOptions = nullptr) override;
2353
2354 bool CopyFrom(GDALDataset *poSrcDS, const GDALMDArray *poSrcArray,
2355 bool bStrict, GUInt64 &nCurCost, const GUInt64 nTotalCost,
2356 GDALProgressFunc pfnProgress, void *pProgressData) override;
2357
2358 void Serialize(CPLXMLNode *psParent, const char *pszVRTPathIn) const;
2359
2360 VRTGroup *GetGroup() const;
2361
2362 const std::string &GetVRTPath() const
2363 {
2364 return m_osVRTPath;
2365 }
2366
2367 std::shared_ptr<VRTGroup> GetRootVRTGroup() const
2368 {
2369 auto poGroup = m_poGroupRef.lock();
2370 if (poGroup)
2371 return poGroup->m_ptr->GetRootGroupSharedPtr();
2372 return nullptr;
2373 }
2374
2375 std::shared_ptr<GDALGroup> GetRootGroup() const override
2376 {
2377 return GetRootVRTGroup();
2378 }
2379
2380 std::vector<GUInt64> GetBlockSize() const override
2381 {
2382 return m_anBlockSize;
2383 }
2384
2385 bool GetRawBlockInfo(const uint64_t *panBlockCoordinates,
2386 GDALMDArrayRawBlockInfo &info) const override;
2387};
2388
2389/************************************************************************/
2390/* VRTMDArraySourceInlinedValues */
2391/************************************************************************/
2392
2393class VRTMDArraySourceInlinedValues final : public VRTMDArraySource
2394{
2395 const VRTMDArray *m_poDstArray = nullptr;
2396 bool m_bIsConstantValue;
2397 std::vector<GUInt64> m_anOffset{};
2398 std::vector<size_t> m_anCount{};
2399 std::vector<GByte> m_abyValues{};
2400 std::vector<size_t> m_anInlinedArrayStrideInBytes{};
2401 GDALExtendedDataType m_dt;
2402
2403 VRTMDArraySourceInlinedValues(const VRTMDArraySourceInlinedValues &) =
2404 delete;
2405 VRTMDArraySourceInlinedValues &
2406 operator=(const VRTMDArraySourceInlinedValues &) = delete;
2407
2408 public:
2409 VRTMDArraySourceInlinedValues(const VRTMDArray *poDstArray,
2410 bool bIsConstantValue,
2411 std::vector<GUInt64> &&anOffset,
2412 std::vector<size_t> &&anCount,
2413 std::vector<GByte> &&abyValues)
2414 : m_poDstArray(poDstArray), m_bIsConstantValue(bIsConstantValue),
2415 m_anOffset(std::move(anOffset)), m_anCount(std::move(anCount)),
2416 m_abyValues(std::move(abyValues)), m_dt(poDstArray->GetDataType())
2417 {
2418 const auto nDims(poDstArray->GetDimensionCount());
2419 m_anInlinedArrayStrideInBytes.resize(nDims);
2420 if (!bIsConstantValue && nDims > 0)
2421 {
2422 m_anInlinedArrayStrideInBytes.back() =
2423 poDstArray->GetDataType().GetSize();
2424 for (size_t i = nDims - 1; i > 0;)
2425 {
2426 --i;
2427 m_anInlinedArrayStrideInBytes[i] =
2428 m_anInlinedArrayStrideInBytes[i + 1] * m_anCount[i + 1];
2429 }
2430 }
2431 }
2432
2433 ~VRTMDArraySourceInlinedValues() override;
2434
2435 static std::unique_ptr<VRTMDArraySourceInlinedValues>
2436 Create(const VRTMDArray *poDstArray, const CPLXMLNode *psNode);
2437
2438 RelationShip GetRelationship(const uint64_t * /*arrayStartIdx*/,
2439 const size_t * /*count*/) const override
2440 {
2441 return RelationShip::PARTIAL_INTERSECTION;
2442 }
2443
2444 bool GetRawBlockInfo(const uint64_t * /*arrayStartIdx*/,
2445 const size_t * /*count*/,
2446 GDALMDArrayRawBlockInfo & /*info*/) const override
2447 {
2448 return false;
2449 }
2450
2451 bool Read(const GUInt64 *arrayStartIdx, const size_t *count,
2452 const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
2453 const GDALExtendedDataType &bufferDataType,
2454 void *pDstBuffer) const override;
2455
2456 void Serialize(CPLXMLNode *psParent, const char *pszVRTPath) const override;
2457};
2458
2459/************************************************************************/
2460/* VRTMDArraySourceRegularlySpaced */
2461/************************************************************************/
2462
2463class VRTMDArraySourceRegularlySpaced final : public VRTMDArraySource
2464{
2465 double m_dfStart;
2466 double m_dfIncrement;
2467
2468 public:
2469 VRTMDArraySourceRegularlySpaced(double dfStart, double dfIncrement)
2470 : m_dfStart(dfStart), m_dfIncrement(dfIncrement)
2471 {
2472 }
2473
2474 RelationShip GetRelationship(const uint64_t * /*arrayStartIdx*/,
2475 const size_t * /*count*/) const override
2476 {
2477 return RelationShip::PARTIAL_INTERSECTION;
2478 }
2479
2480 bool GetRawBlockInfo(const uint64_t * /*arrayStartIdx*/,
2481 const size_t * /*count*/,
2482 GDALMDArrayRawBlockInfo & /*info*/) const override
2483 {
2484 return false;
2485 }
2486
2487 bool Read(const GUInt64 *arrayStartIdx, const size_t *count,
2488 const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
2489 const GDALExtendedDataType &bufferDataType,
2490 void *pDstBuffer) const override;
2491
2492 void Serialize(CPLXMLNode *psParent, const char *pszVRTPath) const override;
2493};
2494
2495/************************************************************************/
2496/* VRTMDArraySourceFromArray */
2497/************************************************************************/
2498
2499struct VRTArrayDatasetWrapper;
2500
2501class VRTMDArraySourceFromArray final : public VRTMDArraySource
2502{
2503 const VRTMDArray *m_poDstArray = nullptr;
2504 bool m_bRelativeToVRTSet = false;
2505 bool m_bRelativeToVRT = false;
2506 std::string m_osFilename{};
2507 std::string m_osArray{};
2508 std::string m_osBand{};
2509 std::vector<int> m_anTransposedAxis{};
2510 std::string m_osViewExpr{};
2511 std::vector<GUInt64> m_anSrcOffset{};
2512 mutable std::vector<GUInt64> m_anCount{};
2513 std::vector<GUInt64> m_anStep{};
2514 std::vector<GUInt64> m_anDstOffset{};
2515
2516 std::pair<std::shared_ptr<VRTArrayDatasetWrapper>,
2517 std::shared_ptr<GDALMDArray>>
2518 GetSourceArray() const;
2519
2520 VRTMDArraySourceFromArray(const VRTMDArraySourceFromArray &) = delete;
2521 VRTMDArraySourceFromArray &
2522 operator=(const VRTMDArraySourceFromArray &) = delete;
2523
2524 public:
2525 VRTMDArraySourceFromArray(
2526 const VRTMDArray *poDstArray, bool bRelativeToVRTSet,
2527 bool bRelativeToVRT, const std::string &osFilename,
2528 const std::string &osArray, const std::string &osBand,
2529 std::vector<int> &&anTransposedAxis, const std::string &osViewExpr,
2530 std::vector<GUInt64> &&anSrcOffset, std::vector<GUInt64> &&anCount,
2531 std::vector<GUInt64> &&anStep, std::vector<GUInt64> &&anDstOffset)
2532 : m_poDstArray(poDstArray), m_bRelativeToVRTSet(bRelativeToVRTSet),
2533 m_bRelativeToVRT(bRelativeToVRT), m_osFilename(osFilename),
2534 m_osArray(osArray), m_osBand(osBand),
2535 m_anTransposedAxis(std::move(anTransposedAxis)),
2536 m_osViewExpr(osViewExpr), m_anSrcOffset(std::move(anSrcOffset)),
2537 m_anCount(std::move(anCount)), m_anStep(std::move(anStep)),
2538 m_anDstOffset(std::move(anDstOffset))
2539 {
2540 }
2541
2542 ~VRTMDArraySourceFromArray() override;
2543
2544 static std::unique_ptr<VRTMDArraySourceFromArray>
2545 Create(const VRTMDArray *poDstArray, const CPLXMLNode *psNode);
2546
2547 RelationShip GetRelationship(const uint64_t *arrayStartIdx,
2548 const size_t *count) const override;
2549
2550 bool GetRawBlockInfo(const uint64_t *arrayStartIdx, const size_t *count,
2551 GDALMDArrayRawBlockInfo &info) const override;
2552
2553 bool Read(const GUInt64 *arrayStartIdx, const size_t *count,
2554 const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
2555 const GDALExtendedDataType &bufferDataType,
2556 void *pDstBuffer) const override;
2557
2558 void Serialize(CPLXMLNode *psParent, const char *pszVRTPath) const override;
2559};
2560
2561#endif /* #ifndef DOXYGEN_SKIP */
2562
2563#endif /* ndef VIRTUALDATASET_H_INCLUDED */
Convenient string class based on std::string.
Definition cpl_string.h:320
virtual const std::vector< std::shared_ptr< GDALDimension > > & GetDimensions() const =0
Return the dimensions of an attribute/array.
virtual std::vector< GUInt64 > GetBlockSize() const
Return the "natural" block size of the array along all dimensions.
Definition gdalmultidim.cpp:2431
virtual const GDALExtendedDataType & GetDataType() const =0
Return the data type of an attribute/array.
Class modeling an attribute that has a name, a value and a type, and is typically used to describe a ...
Definition gdal_multidim.h:729
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
int Dereference()
Subtract one from dataset reference count.
Definition gdaldataset.cpp:1782
virtual CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList, const OGRSpatialReference *poGCP_SRS)
Assign GCPs.
Definition gdaldataset.cpp:2237
int GetShared() const
Returns shared flag.
Definition gdaldataset.cpp:1854
Class modeling a a dimension / axis used to index multidimensional arrays.
Definition gdal_multidim.h:1232
virtual std::shared_ptr< GDALMDArray > GetIndexingVariable() const
Return the variable that is used to index the dimension (if there is one).
Definition gdalmultidim.cpp:11020
virtual bool SetIndexingVariable(std::shared_ptr< GDALMDArray > poIndexingVariable)
Set the variable that is used to index the dimension.
Definition gdalmultidim.cpp:11041
Format specific driver.
Definition gdal_driver.h:63
Class modeling a named container of GDALAttribute, GDALMDArray, OGRLayer or other GDALGroup.
Definition gdal_multidim.h:305
virtual std::shared_ptr< GDALAttribute > CreateAttribute(const std::string &osName, const std::vector< GUInt64 > &anDimensions, const GDALExtendedDataType &oDataType, CSLConstList papszOptions=nullptr)
Create an attribute within a GDALMDArray or GDALGroup.
Definition gdalmultidim.cpp:289
virtual std::vector< std::shared_ptr< GDALAttribute > > GetAttributes(CSLConstList papszOptions=nullptr) const
Return the list of attributes contained in a GDALMDArray or GDALGroup.
Definition gdalmultidim.cpp:258
Class modeling a multi-dimensional array.
Definition gdal_multidim.h:852
virtual bool SetUnit(const std::string &osUnit)
Set the variable unit.
Definition gdalmultidim.cpp:2638
virtual bool CopyFrom(GDALDataset *poSrcDS, const GDALMDArray *poSrcArray, bool bStrict, GUInt64 &nCurCost, const GUInt64 nTotalCost, GDALProgressFunc pfnProgress, void *pProgressData)
Copy the content of an array into a new (generally empty) array.
Definition gdalmultidim.cpp:4041
virtual bool IsWritable() const =0
Return whether an array is writable.
virtual bool SetScale(double dfScale, GDALDataType eStorageType=GDT_Unknown)
Set the scale value to apply to raw values.
Definition gdalmultidim.cpp:2971
virtual bool SetRawNoDataValue(const void *pRawNoData)
Set the nodata value as a "raw" value.
Definition gdalmultidim.cpp:2830
virtual double GetOffset(bool *pbHasOffset=nullptr, GDALDataType *peStorageType=nullptr) const
Get the offset value to apply to raw values.
Definition gdalmultidim.cpp:3058
virtual const void * GetRawNoDataValue() const
Return the nodata value as a "raw" value.
Definition gdalmultidim.cpp:2714
virtual double GetScale(bool *pbHasScale=nullptr, GDALDataType *peStorageType=nullptr) const
Get the scale value to apply to raw values.
Definition gdalmultidim.cpp:3028
virtual std::shared_ptr< OGRSpatialReference > GetSpatialRef() const
Return the spatial reference system object associated with the array.
Definition gdalmultidim.cpp:2688
virtual const std::string & GetFilename() const =0
Return the filename that contains that array.
virtual bool GetRawBlockInfo(const uint64_t *panBlockCoordinates, GDALMDArrayRawBlockInfo &info) const
Return information on a raw block.
Definition gdalmultidim.cpp:15282
virtual bool SetSpatialRef(const OGRSpatialReference *poSRS)
Assign a spatial reference system object to the array.
Definition gdalmultidim.cpp:2674
virtual std::shared_ptr< GDALGroup > GetRootGroup() const
Return the root group to which this arrays belongs too.
Definition gdalmultidim.cpp:4623
virtual bool SetOffset(double dfOffset, GDALDataType eStorageType=GDT_Unknown)
Set the offset value to apply to raw values.
Definition gdalmultidim.cpp:2999
virtual const std::string & GetUnit() const
Return the array unit.
Definition gdalmultidim.cpp:2660
virtual CPLErr SetMetadata(char **papszMetadata, const char *pszDomain="")
Set metadata.
Definition gdalmajorobject.cpp:271
virtual char ** GetMetadataDomainList()
Fetch list of metadata domains.
Definition gdalmajorobject.cpp:143
virtual char ** GetMetadata(const char *pszDomain="")
Fetch metadata.
Definition gdalmajorobject.cpp:228
Pansharpening operation class.
Definition gdalpansharpen.h:176
A single raster band (or channel).
Definition gdal_rasterband.h:105
GDALDataset * GetDataset() const
Fetch the owning dataset handle.
Definition gdalrasterband.cpp:3983
High level image warping class.
Definition gdalwarper.h:504
CPLErr
Error category.
Definition cpl_error.h:37
Hash set implementation.
struct _CPLHashSet CPLHashSet
Opaque type for a hash set.
Definition cpl_hash_set.h:35
Definitions for CPL mini XML Parser/Serializer.
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition cpl_port.h:246
#define CPL_NON_FINAL
Mark that a class is explicitly recognized as non-final.
Definition cpl_port.h:929
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:208
GIntBig GInt64
Signed 64 bit integer type.
Definition cpl_port.h:226
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1087
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition cpl_port.h:228
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:175
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:205
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition cpl_virtualmem.h:45
GUIntBig vsi_l_offset
Type for a file offset.
Definition cpl_vsi.h:136
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:386
GDALAccess
Definition gdal.h:118
@ GA_ReadOnly
Definition gdal.h:119
void * VRTPDWorkingDataPtr
Generic pointer for the working structure of VRTProcessedDataset function.
Definition gdal.h:1789
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:1607
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:135
CPLErr GDALClose(GDALDatasetH)
Close GDAL dataset.
Definition gdaldataset.cpp:4478
GDALColorInterp
Types of color interpretation for raster bands.
Definition gdal.h:270
@ GCI_Undefined
Definition gdal.h:271
GDALRWFlag
Definition gdal.h:125
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:1599
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal_fwd.h:45
Public (C callable) entry points for virtual GDAL dataset objects.
#define VRT_NODATA_UNSET
Special value to indicate that nodata is not set.
Definition gdal_vrt.h:28
void * VRTDatasetH
Opaque type for a VRT dataset.
Definition gdal_vrt.h:57
CPLErr(* VRTImageReadFunc)(void *hCBData, int nXOff, int nYOff, int nXSize, int nYSize, void *pData)
Type for a function that returns the pixel data in a provided window.
Definition gdal_vrt.h:33
VRTDatasetH VRTCreate(int, int)
Definition vrtdataset.cpp:77
Document node structure.
Definition cpl_minixml.h:54