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