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