GDAL
vrtdataset.h
1 /******************************************************************************
2  * $Id: vrtdataset.h 4b46f534fed80d31c3e15c1517169f40694a4a3e 2021-10-14 19:17:37 +0200 Even Rouault $
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  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #ifndef VIRTUALDATASET_H_INCLUDED
32 #define VIRTUALDATASET_H_INCLUDED
33 
34 #ifndef DOXYGEN_SKIP
35 
36 #include "cpl_hash_set.h"
37 #include "cpl_minixml.h"
38 #include "gdal_pam.h"
39 #include "gdal_priv.h"
40 #include "gdal_rat.h"
41 #include "gdal_vrt.h"
42 #include "gdal_rat.h"
43 
44 #include <functional>
45 #include <map>
46 #include <memory>
47 #include <vector>
48 
49 int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * );
50 CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * );
51 CPLErr GDALRegisterDefaultPixelFunc();
52 CPLString VRTSerializeNoData(double dfVal, GDALDataType eDataType, int nPrecision);
53 #if 0
54 int VRTWarpedOverviewTransform( void *pTransformArg, int bDstToSrc,
55  int nPointCount,
56  double *padfX, double *padfY, double *padfZ,
57  int *panSuccess );
58 void* VRTDeserializeWarpedOverviewTransformer( CPLXMLNode *psTree );
59 #endif
60 
61 /************************************************************************/
62 /* VRTOverviewInfo() */
63 /************************************************************************/
64 class VRTOverviewInfo
65 {
66  CPL_DISALLOW_COPY_ASSIGN(VRTOverviewInfo)
67 
68 public:
69  CPLString osFilename{};
70  int nBand = 0;
71  GDALRasterBand *poBand = nullptr;
72  int bTriedToOpen = FALSE;
73 
74  VRTOverviewInfo() = default;
75  VRTOverviewInfo(VRTOverviewInfo&& oOther) noexcept:
76  osFilename(std::move(oOther.osFilename)),
77  nBand(oOther.nBand),
78  poBand(oOther.poBand),
79  bTriedToOpen(oOther.bTriedToOpen)
80  {
81  oOther.poBand = nullptr;
82  }
83 
84  ~VRTOverviewInfo() {
85  CloseDataset();
86  }
87 
88  bool CloseDataset()
89  {
90  if( poBand == nullptr )
91  return false;
92 
93  GDALDataset* poDS = poBand->GetDataset();
94  // Nullify now, to prevent recursion in some cases !
95  poBand = nullptr;
96  if( poDS->GetShared() )
97  GDALClose( /* (GDALDatasetH) */ poDS );
98  else
99  poDS->Dereference();
100 
101  return true;
102  }
103 };
104 
105 /************************************************************************/
106 /* VRTSource */
107 /************************************************************************/
108 
109 class CPL_DLL VRTSource
110 {
111 public:
112  virtual ~VRTSource();
113 
114  virtual CPLErr RasterIO( GDALDataType eBandDataType,
115  int nXOff, int nYOff, int nXSize, int nYSize,
116  void *pData, int nBufXSize, int nBufYSize,
117  GDALDataType eBufType,
118  GSpacing nPixelSpace, GSpacing nLineSpace,
119  GDALRasterIOExtraArg* psExtraArg ) = 0;
120 
121  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) = 0;
122  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) = 0;
123  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK,
124  double* adfMinMax ) = 0;
125  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
126  int bApproxOK,
127  double *pdfMin, double *pdfMax,
128  double *pdfMean, double *pdfStdDev,
129  GDALProgressFunc pfnProgress,
130  void *pProgressData ) = 0;
131  virtual CPLErr GetHistogram( int nXSize, int nYSize,
132  double dfMin, double dfMax,
133  int nBuckets, GUIntBig * panHistogram,
134  int bIncludeOutOfRange, int bApproxOK,
135  GDALProgressFunc pfnProgress,
136  void *pProgressData ) = 0;
137 
138  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char *,
139  std::map<CPLString, GDALDataset*>& ) = 0;
140  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0;
141 
142  virtual void GetFileList(char*** ppapszFileList, int *pnSize,
143  int *pnMaxSize, CPLHashSet* hSetFiles);
144 
145  virtual int IsSimpleSource() { return FALSE; }
146  virtual CPLErr FlushCache(bool /*bAtClosing*/) { return CE_None; }
147 };
148 
149 typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *,
150  std::map<CPLString, GDALDataset*>& oMapSharedSources);
151 
152 VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char *,
153  std::map<CPLString, GDALDataset*>& oMapSharedSources);
154 VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char *,
155  std::map<CPLString, GDALDataset*>& oMapSharedSources );
156 
157 /************************************************************************/
158 /* VRTDataset */
159 /************************************************************************/
160 
161 class VRTRasterBand;
162 
163 template<class T> struct VRTFlushCacheStruct
164 {
165  static void FlushCache(T& obj, bool bAtClosing);
166 };
167 
168 class VRTWarpedDataset;
169 class VRTPansharpenedDataset;
170 class VRTGroup;
171 
172 class CPL_DLL VRTDataset CPL_NON_FINAL: public GDALDataset
173 {
174  friend class VRTRasterBand;
175  friend struct VRTFlushCacheStruct<VRTDataset>;
176  friend struct VRTFlushCacheStruct<VRTWarpedDataset>;
177  friend struct VRTFlushCacheStruct<VRTPansharpenedDataset>;
178  friend class VRTSourcedRasterBand;
179  friend VRTDatasetH CPL_STDCALL VRTCreate(int nXSize, int nYSize);
180 
181  OGRSpatialReference* m_poSRS = nullptr;
182 
183  int m_bGeoTransformSet = false;
184  double m_adfGeoTransform[6];
185 
186  int m_nGCPCount = 0;
187  GDAL_GCP *m_pasGCPList = nullptr;
188  OGRSpatialReference *m_poGCP_SRS = nullptr;
189 
190  bool m_bNeedsFlush = false;
191  bool m_bWritable = true;
192  bool m_bCanTakeRef = true;
193 
194  char *m_pszVRTPath = nullptr;
195 
196  VRTRasterBand *m_poMaskBand = nullptr;
197 
198  int m_bCompatibleForDatasetIO = -1;
199  int CheckCompatibleForDatasetIO();
200 
201  // Virtual (ie not materialized) overviews, created either implicitly
202  // when it is cheap to do it, or explicitly.
203  std::vector<GDALDataset*> m_apoOverviews{};
204  std::vector<GDALDataset*> m_apoOverviewsBak{};
205  CPLString m_osOverviewResampling{};
206  std::vector<int> m_anOverviewFactors{};
207 
208  char **m_papszXMLVRTMetadata = nullptr;
209 
210  std::map<CPLString, GDALDataset*> m_oMapSharedSources{};
211  std::shared_ptr<VRTGroup> m_poRootGroup{};
212 
213  VRTRasterBand* InitBand(const char* pszSubclass, int nBand,
214  bool bAllowPansharpened);
215  static GDALDataset *OpenVRTProtocol( const char* pszSpec );
216  bool AddVirtualOverview(int nOvFactor,
217  const char* pszResampling);
218 
219  CPL_DISALLOW_COPY_ASSIGN(VRTDataset)
220 
221  protected:
222  virtual int CloseDependentDatasets() override;
223 
224  public:
225  VRTDataset(int nXSize, int nYSize);
226  virtual ~VRTDataset();
227 
228  void SetNeedsFlush() { m_bNeedsFlush = true; }
229  virtual void FlushCache(bool bAtClosing) override;
230 
231  void SetWritable(int bWritableIn) { m_bWritable = CPL_TO_BOOL(bWritableIn); }
232 
233  virtual CPLErr CreateMaskBand( int nFlags ) override;
234  void SetMaskBand(VRTRasterBand* poMaskBand);
235 
236  const OGRSpatialReference* GetSpatialRef() const override { return m_poSRS; }
237  CPLErr SetSpatialRef(const OGRSpatialReference* poSRS) override;
238 
239  virtual CPLErr GetGeoTransform( double * ) override;
240  virtual CPLErr SetGeoTransform( double * ) override;
241 
242  virtual CPLErr SetMetadata( char **papszMetadata,
243  const char *pszDomain = "" ) override;
244  virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
245  const char *pszDomain = "" ) override;
246 
247  virtual char** GetMetadata( const char *pszDomain = "" ) override;
248 
249  virtual int GetGCPCount() override;
250  const OGRSpatialReference* GetGCPSpatialRef() const override { return m_poGCP_SRS; }
251  virtual const GDAL_GCP *GetGCPs() override;
252  using GDALDataset::SetGCPs;
253  CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
254  const OGRSpatialReference* poSRS ) override;
255 
256  virtual CPLErr AddBand( GDALDataType eType,
257  char **papszOptions=nullptr ) override;
258 
259  virtual char **GetFileList() override;
260 
261  virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
262  int nXOff, int nYOff, int nXSize, int nYSize,
263  void * pData, int nBufXSize, int nBufYSize,
264  GDALDataType eBufType,
265  int nBandCount, int *panBandMap,
266  GSpacing nPixelSpace, GSpacing nLineSpace,
267  GSpacing nBandSpace,
268  GDALRasterIOExtraArg* psExtraArg) override;
269 
270  virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
271  int nBufXSize, int nBufYSize,
272  GDALDataType eDT,
273  int nBandCount, int *panBandList,
274  char **papszOptions ) override;
275 
276  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath);
277  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
278 
279  virtual CPLErr IBuildOverviews( const char *, int, int *,
280  int, int *, GDALProgressFunc, void * ) override;
281 
282  std::shared_ptr<GDALGroup> GetRootGroup() const override;
283 
284  /* Used by PDF driver for example */
285  GDALDataset* GetSingleSimpleSource();
286  void BuildVirtualOverviews();
287 
288  void UnsetPreservedRelativeFilenames();
289 
290  static int Identify( GDALOpenInfo * );
291  static GDALDataset *Open( GDALOpenInfo * );
292  static GDALDataset *OpenXML( const char *, const char * = nullptr,
293  GDALAccess eAccess = GA_ReadOnly );
294  static GDALDataset *Create( const char * pszName,
295  int nXSize, int nYSize, int nBands,
296  GDALDataType eType, char ** papszOptions );
297  static GDALDataset *CreateMultiDimensional( const char * pszFilename,
298  CSLConstList papszRootGroupOptions,
299  CSLConstList papszOptions );
300  static CPLErr Delete( const char * pszFilename );
301 };
302 
303 /************************************************************************/
304 /* VRTWarpedDataset */
305 /************************************************************************/
306 
307 class GDALWarpOperation;
308 class VRTWarpedRasterBand;
309 
310 class CPL_DLL VRTWarpedDataset final: public VRTDataset
311 {
312  int m_nBlockXSize;
313  int m_nBlockYSize;
314  GDALWarpOperation *m_poWarper;
315 
316  int m_nOverviewCount;
317  VRTWarpedDataset **m_papoOverviews;
318  int m_nSrcOvrLevel;
319 
320  void CreateImplicitOverviews();
321 
322  friend class VRTWarpedRasterBand;
323 
324  CPL_DISALLOW_COPY_ASSIGN(VRTWarpedDataset)
325 
326  protected:
327  virtual int CloseDependentDatasets() override;
328 
329 public:
330  VRTWarpedDataset( int nXSize, int nYSize );
331  virtual ~VRTWarpedDataset();
332 
333  virtual void FlushCache(bool bAtClosing) override;
334 
335  CPLErr Initialize( /* GDALWarpOptions */ void * );
336 
337  virtual CPLErr IBuildOverviews( const char *, int, int *,
338  int, int *, GDALProgressFunc, void * ) override;
339 
340  virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
341  const char *pszDomain = "" ) override;
342 
343  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
344  virtual CPLErr XMLInit( CPLXMLNode *, const char * ) override;
345 
346  virtual CPLErr AddBand( GDALDataType eType,
347  char **papszOptions=nullptr ) override;
348 
349  virtual char **GetFileList() override;
350 
351  CPLErr ProcessBlock( int iBlockX, int iBlockY );
352 
353  void GetBlockSize( int *, int * ) const;
354 };
355 
356 /************************************************************************/
357 /* VRTPansharpenedDataset */
358 /************************************************************************/
359 
361 
362 typedef enum
363 {
364  GTAdjust_Union,
365  GTAdjust_Intersection,
366  GTAdjust_None,
367  GTAdjust_NoneWithoutWarning
368 } GTAdjustment;
369 
370 class VRTPansharpenedDataset final: public VRTDataset
371 {
372  friend class VRTPansharpenedRasterBand;
373 
374  int m_nBlockXSize;
375  int m_nBlockYSize;
376  GDALPansharpenOperation* m_poPansharpener;
377  VRTPansharpenedDataset* m_poMainDataset;
378  std::vector<VRTPansharpenedDataset*> m_apoOverviewDatasets{};
379  // Map from absolute to relative.
380  std::map<CPLString,CPLString> m_oMapToRelativeFilenames{};
381 
382  int m_bLoadingOtherBands;
383 
384  GByte *m_pabyLastBufferBandRasterIO;
385  int m_nLastBandRasterIOXOff;
386  int m_nLastBandRasterIOYOff;
387  int m_nLastBandRasterIOXSize;
388  int m_nLastBandRasterIOYSize;
389  GDALDataType m_eLastBandRasterIODataType;
390 
391  GTAdjustment m_eGTAdjustment;
392  int m_bNoDataDisabled;
393 
394  std::vector<GDALDataset*> m_apoDatasetsToClose{};
395 
396  CPL_DISALLOW_COPY_ASSIGN(VRTPansharpenedDataset)
397 
398  protected:
399  virtual int CloseDependentDatasets() override;
400 
401 public:
402  VRTPansharpenedDataset( int nXSize, int nYSize );
403  virtual ~VRTPansharpenedDataset();
404 
405  virtual void FlushCache(bool bAtClosing) override;
406 
407  virtual CPLErr XMLInit( CPLXMLNode *, const char * ) override;
408  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
409 
410  CPLErr XMLInit( CPLXMLNode *psTree, const char *pszVRTPath,
411  GDALRasterBandH hPanchroBandIn,
412  int nInputSpectralBandsIn,
413  GDALRasterBandH* pahInputSpectralBandsIn );
414 
415  virtual CPLErr AddBand( GDALDataType eType,
416  char **papszOptions=nullptr ) override;
417 
418  virtual char **GetFileList() override;
419 
420  virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
421  int nXOff, int nYOff, int nXSize, int nYSize,
422  void * pData, int nBufXSize, int nBufYSize,
423  GDALDataType eBufType,
424  int nBandCount, int *panBandMap,
425  GSpacing nPixelSpace, GSpacing nLineSpace,
426  GSpacing nBandSpace,
427  GDALRasterIOExtraArg* psExtraArg) override;
428 
429  void GetBlockSize( int *, int * ) const;
430 
431  GDALPansharpenOperation* GetPansharpener() { return m_poPansharpener; }
432 };
433 
434 /************************************************************************/
435 /* VRTRasterBand */
436 /* */
437 /* Provides support for all the various kinds of metadata but */
438 /* no raster access. That is handled by derived classes. */
439 /************************************************************************/
440 
441 class CPL_DLL VRTRasterBand CPL_NON_FINAL: public GDALRasterBand
442 {
443  protected:
444  friend class VRTDataset;
445 
446  int m_bIsMaskBand;
447 
448  int m_bNoDataValueSet;
449  // If set to true, will not report the existence of nodata.
450  int m_bHideNoDataValue;
451  double m_dfNoDataValue;
452 
453  std::unique_ptr<GDALColorTable> m_poColorTable{};
454 
455  GDALColorInterp m_eColorInterp;
456 
457  char *m_pszUnitType;
458  char **m_papszCategoryNames;
459 
460  double m_dfOffset;
461  double m_dfScale;
462 
463  CPLXMLNode *m_psSavedHistograms;
464 
465  void Initialize( int nXSize, int nYSize );
466 
467  std::vector<VRTOverviewInfo> m_aoOverviewInfos{};
468 
469  VRTRasterBand *m_poMaskBand;
470 
471  std::unique_ptr<GDALRasterAttributeTable> m_poRAT{};
472 
473  CPL_DISALLOW_COPY_ASSIGN(VRTRasterBand)
474 
475  public:
476 
477  VRTRasterBand();
478  virtual ~VRTRasterBand();
479 
480  virtual CPLErr XMLInit( CPLXMLNode *, const char *,
481  std::map<CPLString, GDALDataset*>& );
482  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
483 
484  virtual CPLErr SetNoDataValue( double ) override;
485  virtual double GetNoDataValue( int *pbSuccess = nullptr ) override;
486  virtual CPLErr DeleteNoDataValue() override;
487 
488  virtual CPLErr SetColorTable( GDALColorTable * ) override;
489  virtual GDALColorTable *GetColorTable() override;
490 
491  virtual GDALRasterAttributeTable *GetDefaultRAT() override;
492  virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * poRAT ) override;
493 
494  virtual CPLErr SetColorInterpretation( GDALColorInterp ) override;
495  virtual GDALColorInterp GetColorInterpretation() override;
496 
497  virtual const char *GetUnitType() override;
498  CPLErr SetUnitType( const char * ) override;
499 
500  virtual char **GetCategoryNames() override;
501  virtual CPLErr SetCategoryNames( char ** ) override;
502 
503  virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" ) override;
504  virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
505  const char *pszDomain = "" ) override;
506 
507  virtual double GetOffset( int *pbSuccess = nullptr ) override;
508  CPLErr SetOffset( double ) override;
509  virtual double GetScale( int *pbSuccess = nullptr ) override;
510  CPLErr SetScale( double ) override;
511 
512  virtual int GetOverviewCount() override;
513  virtual GDALRasterBand *GetOverview(int) override;
514 
515  virtual CPLErr GetHistogram( double dfMin, double dfMax,
516  int nBuckets, GUIntBig * panHistogram,
517  int bIncludeOutOfRange, int bApproxOK,
518  GDALProgressFunc, void *pProgressData ) override;
519 
520  virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
521  int *pnBuckets, GUIntBig ** ppanHistogram,
522  int bForce,
523  GDALProgressFunc, void *pProgressData) override;
524 
525  virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
526  int nBuckets, GUIntBig *panHistogram ) override;
527 
528  CPLErr CopyCommonInfoFrom( GDALRasterBand * );
529 
530  virtual void GetFileList(char*** ppapszFileList, int *pnSize,
531  int *pnMaxSize, CPLHashSet* hSetFiles);
532 
533  virtual void SetDescription( const char * ) override;
534 
535  virtual GDALRasterBand *GetMaskBand() override;
536  virtual int GetMaskFlags() override;
537 
538  virtual CPLErr CreateMaskBand( int nFlagsIn ) override;
539 
540  void SetMaskBand(VRTRasterBand* poMaskBand);
541 
542  void SetIsMaskBand();
543 
544  CPLErr UnsetNoDataValue();
545 
546  virtual int CloseDependentDatasets();
547 
548  virtual int IsSourcedRasterBand() { return FALSE; }
549  virtual int IsPansharpenRasterBand() { return FALSE; }
550 };
551 
552 /************************************************************************/
553 /* VRTSourcedRasterBand */
554 /************************************************************************/
555 
556 class VRTSimpleSource;
557 
558 class CPL_DLL VRTSourcedRasterBand CPL_NON_FINAL: public VRTRasterBand
559 {
560  private:
561  CPLString m_osLastLocationInfo{};
562  char **m_papszSourceList = nullptr;
563  int m_nSkipBufferInitialization = -1;
564 
565  bool CanUseSourcesMinMaxImplementations();
566 
567  CPL_DISALLOW_COPY_ASSIGN(VRTSourcedRasterBand)
568 
569  protected:
570  bool SkipBufferInitialization();
571 
572  public:
573  int nSources = 0;
574  VRTSource **papoSources = nullptr;
575 
576  VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
577  VRTSourcedRasterBand( GDALDataType eType,
578  int nXSize, int nYSize );
579  VRTSourcedRasterBand( GDALDataset *poDS, int nBand,
580  GDALDataType eType,
581  int nXSize, int nYSize );
582  VRTSourcedRasterBand( GDALDataset *poDS, int nBand,
583  GDALDataType eType,
584  int nXSize, int nYSize,
585  int nBlockXSizeIn, int nBlockYSizeIn );
586  virtual ~VRTSourcedRasterBand();
587 
588  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
589  void *, int, int, GDALDataType,
590  GSpacing nPixelSpace, GSpacing nLineSpace,
591  GDALRasterIOExtraArg* psExtraArg) override;
592 
593  virtual int IGetDataCoverageStatus( int nXOff, int nYOff,
594  int nXSize, int nYSize,
595  int nMaskFlagStop,
596  double* pdfDataPct) override;
597 
598  virtual char **GetMetadataDomainList() override;
599  virtual const char *GetMetadataItem( const char * pszName,
600  const char * pszDomain = "" ) override;
601  virtual char **GetMetadata( const char * pszDomain = "" ) override;
602  virtual CPLErr SetMetadata( char ** papszMetadata,
603  const char * pszDomain = "" ) override;
604  virtual CPLErr SetMetadataItem( const char * pszName,
605  const char * pszValue,
606  const char * pszDomain = "" ) override;
607 
608  virtual CPLErr XMLInit( CPLXMLNode *, const char *,
609  std::map<CPLString, GDALDataset*>& ) override;
610  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
611 
612  virtual double GetMinimum( int *pbSuccess = nullptr ) override;
613  virtual double GetMaximum(int *pbSuccess = nullptr ) override;
614  virtual CPLErr ComputeRasterMinMax( int bApproxOK, double* adfMinMax ) override;
615  virtual CPLErr ComputeStatistics( int bApproxOK,
616  double *pdfMin, double *pdfMax,
617  double *pdfMean, double *pdfStdDev,
618  GDALProgressFunc pfnProgress,
619  void *pProgressData ) override;
620  virtual CPLErr GetHistogram( double dfMin, double dfMax,
621  int nBuckets, GUIntBig * panHistogram,
622  int bIncludeOutOfRange, int bApproxOK,
623  GDALProgressFunc pfnProgress,
624  void *pProgressData ) override;
625 
626  CPLErr AddSource( VRTSource * );
627 
628  CPLErr AddSimpleSource( const char* pszFilename,
629  int nBand,
630  double dfSrcXOff=-1, double dfSrcYOff=-1,
631  double dfSrcXSize=-1, double dfSrcYSize=-1,
632  double dfDstXOff=-1, double dfDstYOff=-1,
633  double dfDstXSize=-1, double dfDstYSize=-1,
634  const char *pszResampling = "near",
635  double dfNoDataValue = VRT_NODATA_UNSET);
636 
637  CPLErr AddSimpleSource( GDALRasterBand *poSrcBand,
638  double dfSrcXOff=-1, double dfSrcYOff=-1,
639  double dfSrcXSize=-1, double dfSrcYSize=-1,
640  double dfDstXOff=-1, double dfDstYOff=-1,
641  double dfDstXSize=-1, double dfDstYSize=-1,
642  const char *pszResampling = "near",
643  double dfNoDataValue = VRT_NODATA_UNSET);
644 
645  CPLErr AddComplexSource( const char* pszFilename,
646  int nBand,
647  double dfSrcXOff=-1, double dfSrcYOff=-1,
648  double dfSrcXSize=-1, double dfSrcYSize=-1,
649  double dfDstXOff=-1, double dfDstYOff=-1,
650  double dfDstXSize=-1, double dfDstYSize=-1,
651  double dfScaleOff=0.0,
652  double dfScaleRatio=1.0,
653  double dfNoDataValue = VRT_NODATA_UNSET,
654  int nColorTableComponent = 0);
655 
656  CPLErr AddComplexSource( GDALRasterBand *poSrcBand,
657  double dfSrcXOff=-1, double dfSrcYOff=-1,
658  double dfSrcXSize=-1, double dfSrcYSize=-1,
659  double dfDstXOff=-1, double dfDstYOff=-1,
660  double dfDstXSize=-1, double dfDstYSize=-1,
661  double dfScaleOff=0.0,
662  double dfScaleRatio=1.0,
663  double dfNoDataValue = VRT_NODATA_UNSET,
664  int nColorTableComponent = 0);
665 
666  CPLErr AddMaskBandSource( GDALRasterBand *poSrcBand,
667  double dfSrcXOff=-1, double dfSrcYOff=-1,
668  double dfSrcXSize=-1,
669  double dfSrcYSize=-1,
670  double dfDstXOff=-1, double dfDstYOff=-1,
671  double dfDstXSize=-1,
672  double dfDstYSize=-1 );
673 
674  CPLErr AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
675  double dfNoDataValue = VRT_NODATA_UNSET );
676 
677  void ConfigureSource(VRTSimpleSource *poSimpleSource,
678  GDALRasterBand *poSrcBand,
679  int bAddAsMaskBand,
680  double dfSrcXOff, double dfSrcYOff,
681  double dfSrcXSize, double dfSrcYSize,
682  double dfDstXOff, double dfDstYOff,
683  double dfDstXSize, double dfDstYSize );
684 
685  void RemoveCoveredSources(CSLConstList papszOptions = nullptr);
686 
687  virtual CPLErr IReadBlock( int, int, void * ) override;
688 
689  virtual void GetFileList(char*** ppapszFileList, int *pnSize,
690  int *pnMaxSize, CPLHashSet* hSetFiles) override;
691 
692  virtual int CloseDependentDatasets() override;
693 
694  virtual int IsSourcedRasterBand() override { return TRUE; }
695 
696  virtual CPLErr FlushCache(bool bAtClosing) override;
697 };
698 
699 /************************************************************************/
700 /* VRTWarpedRasterBand */
701 /************************************************************************/
702 
703 class CPL_DLL VRTWarpedRasterBand final: public VRTRasterBand
704 {
705  public:
706  VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
707  GDALDataType eType = GDT_Unknown );
708  virtual ~VRTWarpedRasterBand();
709 
710  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
711 
712  virtual CPLErr IReadBlock( int, int, void * ) override;
713  virtual CPLErr IWriteBlock( int, int, void * ) override;
714 
715  virtual int GetOverviewCount() override;
716  virtual GDALRasterBand *GetOverview(int) override;
717 };
718 /************************************************************************/
719 /* VRTPansharpenedRasterBand */
720 /************************************************************************/
721 
722 class VRTPansharpenedRasterBand final: public VRTRasterBand
723 {
724  int m_nIndexAsPansharpenedBand;
725 
726  public:
727  VRTPansharpenedRasterBand(
728  GDALDataset *poDS, int nBand,
729  GDALDataType eDataType = GDT_Unknown );
730  virtual ~VRTPansharpenedRasterBand();
731 
732  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
733 
734  virtual CPLErr IReadBlock( int, int, void * ) override;
735 
736  virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
737  int nXOff, int nYOff, int nXSize, int nYSize,
738  void * pData, int nBufXSize, int nBufYSize,
739  GDALDataType eBufType,
740  GSpacing nPixelSpace, GSpacing nLineSpace,
741  GDALRasterIOExtraArg* psExtraArg) override;
742 
743  virtual int GetOverviewCount() override;
744  virtual GDALRasterBand *GetOverview(int) override;
745 
746  virtual int IsPansharpenRasterBand() override { return TRUE; }
747 
748  void SetIndexAsPansharpenedBand( int nIdx )
749  { m_nIndexAsPansharpenedBand = nIdx; }
750  int GetIndexAsPansharpenedBand() const
751  { return m_nIndexAsPansharpenedBand; }
752 };
753 
754 /************************************************************************/
755 /* VRTDerivedRasterBand */
756 /************************************************************************/
757 
758 class VRTDerivedRasterBandPrivateData;
759 
760 class CPL_DLL VRTDerivedRasterBand CPL_NON_FINAL: public VRTSourcedRasterBand
761 {
762  VRTDerivedRasterBandPrivateData* m_poPrivate;
763  bool InitializePython();
764 
765  CPL_DISALLOW_COPY_ASSIGN(VRTDerivedRasterBand)
766 
767  public:
768  char *pszFuncName;
769  GDALDataType eSourceTransferType;
770 
771  using PixelFunc = std::function<CPLErr(void**, int, void*, int, int, GDALDataType, GDALDataType, int, int, CSLConstList)>;
772 
773  VRTDerivedRasterBand( GDALDataset *poDS, int nBand );
774  VRTDerivedRasterBand( GDALDataset *poDS, int nBand,
775  GDALDataType eType, int nXSize, int nYSize );
776  virtual ~VRTDerivedRasterBand();
777 
778  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
779  void *, int, int, GDALDataType,
780  GSpacing nPixelSpace, GSpacing nLineSpace,
781  GDALRasterIOExtraArg* psExtraArg ) override;
782 
783  virtual int IGetDataCoverageStatus( int nXOff, int nYOff,
784  int nXSize, int nYSize,
785  int nMaskFlagStop,
786  double* pdfDataPct) override;
787 
788  static CPLErr AddPixelFunction( const char *pszFuncName,
789  GDALDerivedPixelFunc pfnPixelFunc );
790  static CPLErr AddPixelFunction( const char *pszFuncName,
791  GDALDerivedPixelFuncWithArgs pfnPixelFunc,
792  const char *pszMetadata);
793 
794  static PixelFunc* GetPixelFunction( const char *pszFuncName );
795 
796  void SetPixelFunctionName( const char *pszFuncName );
797  void SetSourceTransferType( GDALDataType eDataType );
798  void SetPixelFunctionLanguage( const char* pszLanguage );
799 
800  virtual CPLErr XMLInit( CPLXMLNode *, const char *,
801  std::map<CPLString, GDALDataset*>& ) override;
802  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
803 
804  virtual double GetMinimum( int *pbSuccess = nullptr ) override;
805  virtual double GetMaximum(int *pbSuccess = nullptr ) override;
806  virtual CPLErr ComputeRasterMinMax( int bApproxOK, double* adfMinMax ) override;
807  virtual CPLErr ComputeStatistics( int bApproxOK,
808  double *pdfMin, double *pdfMax,
809  double *pdfMean, double *pdfStdDev,
810  GDALProgressFunc pfnProgress,
811  void *pProgressData ) override;
812  virtual CPLErr GetHistogram( double dfMin, double dfMax,
813  int nBuckets, GUIntBig * panHistogram,
814  int bIncludeOutOfRange, int bApproxOK,
815  GDALProgressFunc pfnProgress,
816  void *pProgressData ) override;
817 
818  static void Cleanup();
819 };
820 
821 /************************************************************************/
822 /* VRTRawRasterBand */
823 /************************************************************************/
824 
825 class RawRasterBand;
826 
827 class CPL_DLL VRTRawRasterBand CPL_NON_FINAL: public VRTRasterBand
828 {
829  RawRasterBand *m_poRawRaster;
830 
831  char *m_pszSourceFilename;
832  int m_bRelativeToVRT;
833 
834  CPL_DISALLOW_COPY_ASSIGN(VRTRawRasterBand)
835 
836  public:
837  VRTRawRasterBand( GDALDataset *poDS, int nBand,
838  GDALDataType eType = GDT_Unknown );
839  virtual ~VRTRawRasterBand();
840 
841  virtual CPLErr XMLInit( CPLXMLNode *, const char *,
842  std::map<CPLString, GDALDataset*>& ) override;
843  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
844 
845  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
846  void *, int, int, GDALDataType,
847  GSpacing nPixelSpace, GSpacing nLineSpace,
848  GDALRasterIOExtraArg* psExtraArg ) override;
849 
850  virtual CPLErr IReadBlock( int, int, void * ) override;
851  virtual CPLErr IWriteBlock( int, int, void * ) override;
852 
853  CPLErr SetRawLink( const char *pszFilename,
854  const char *pszVRTPath,
855  int bRelativeToVRT,
856  vsi_l_offset nImageOffset,
857  int nPixelOffset, int nLineOffset,
858  const char *pszByteOrder );
859 
860  void ClearRawLink();
861 
862  CPLVirtualMem *GetVirtualMemAuto( GDALRWFlag eRWFlag,
863  int *pnPixelSpace,
864  GIntBig *pnLineSpace,
865  char **papszOptions ) override;
866 
867  virtual void GetFileList( char*** ppapszFileList, int *pnSize,
868  int *pnMaxSize, CPLHashSet* hSetFiles ) override;
869 };
870 
871 /************************************************************************/
872 /* VRTDriver */
873 /************************************************************************/
874 
875 class VRTDriver final: public GDALDriver
876 {
877  CPL_DISALLOW_COPY_ASSIGN(VRTDriver)
878 
879  public:
880  VRTDriver();
881  virtual ~VRTDriver();
882 
883  char **papszSourceParsers;
884 
885  virtual char **GetMetadataDomainList() override;
886  virtual char **GetMetadata( const char * pszDomain = "" ) override;
887  virtual CPLErr SetMetadata( char ** papszMetadata,
888  const char * pszDomain = "" ) override;
889 
890  VRTSource *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath,
891  std::map<CPLString, GDALDataset*>& oMapSharedSources );
892  void AddSourceParser( const char *pszElementName,
893  VRTSourceParser pfnParser );
894 };
895 
896 /************************************************************************/
897 /* VRTSimpleSource */
898 /************************************************************************/
899 
900 class CPL_DLL VRTSimpleSource CPL_NON_FINAL: public VRTSource
901 {
902  CPL_DISALLOW_COPY_ASSIGN(VRTSimpleSource)
903 
904 private:
905  // Owned by the VRTDataset
906  std::map<CPLString, GDALDataset*>* m_poMapSharedSources = nullptr;
907 
908  mutable GDALRasterBand *m_poRasterBand = nullptr;
909 
910  // When poRasterBand is a mask band, poMaskBandMainBand is the band
911  // from which the mask band is taken.
912  mutable GDALRasterBand *m_poMaskBandMainBand = nullptr;
913 
914  CPLStringList m_aosOpenOptions{};
915 
916  void OpenSource() const;
917 
918 protected:
919  friend class VRTSourcedRasterBand;
920  friend class VRTDataset;
921 
922  int m_nBand = 0;
923  bool m_bGetMaskBand = false;
924 
925  double m_dfSrcXOff = 0;
926  double m_dfSrcYOff = 0;
927  double m_dfSrcXSize = 0;
928  double m_dfSrcYSize = 0;
929 
930  double m_dfDstXOff = 0;
931  double m_dfDstYOff = 0;
932  double m_dfDstXSize = 0;
933  double m_dfDstYSize = 0;
934 
935  // should really be a member of VRTComplexSource as only taken into account by it
936  int m_bNoDataSet = false;
937 
938  // same as above. adjusted value should be read with GetAdjustedNoDataValue()
939  double m_dfNoDataValue = VRT_NODATA_UNSET;
940  CPLString m_osResampling{};
941 
942  int m_nMaxValue = 0;
943 
944  int m_bRelativeToVRTOri = -1;
945  CPLString m_osSourceFileNameOri{};
946  int m_nExplicitSharedStatus = -1; // -1 unknown, 0 = unshared, 1 = shared
947  CPLString m_osSrcDSName{};
948 
949  bool m_bDropRefOnSrcBand = true;
950 
951  int NeedMaxValAdjustment() const;
952 
953  double GetAdjustedNoDataValue() const;
954 
955 public:
956  VRTSimpleSource();
957  VRTSimpleSource( const VRTSimpleSource* poSrcSource,
958  double dfXDstRatio, double dfYDstRatio );
959  virtual ~VRTSimpleSource();
960 
961  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char *,
962  std::map<CPLString, GDALDataset*>& ) override;
963  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
964 
965  void SetSrcBand( const char* pszFilename, int nBand );
966  void SetSrcBand( GDALRasterBand * );
967  void SetSrcMaskBand( GDALRasterBand * );
968  void SetSrcWindow( double, double, double, double );
969  void SetDstWindow( double, double, double, double );
970  void SetNoDataValue( double dfNoDataValue ); // should really be a member of VRTComplexSource
971  const CPLString& GetResampling() const { return m_osResampling; }
972  void SetResampling( const char* pszResampling );
973 
974  int GetSrcDstWindow( double, double, double, double,
975  int, int,
976  double *pdfReqXOff, double *pdfReqYOff,
977  double *pdfReqXSize, double *pdfReqYSize,
978  int *, int *, int *, int *,
979  int *, int *, int *, int *,
980  bool& bErrorOut );
981 
982  virtual CPLErr RasterIO( GDALDataType eBandDataType,
983  int nXOff, int nYOff, int nXSize, int nYSize,
984  void *pData, int nBufXSize, int nBufYSize,
985  GDALDataType eBufType,
986  GSpacing nPixelSpace, GSpacing nLineSpace,
987  GDALRasterIOExtraArg* psExtraArgIn ) override;
988 
989  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) override;
990  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) override;
991  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK,
992  double* adfMinMax ) override;
993  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
994  int bApproxOK,
995  double *pdfMin, double *pdfMax,
996  double *pdfMean, double *pdfStdDev,
997  GDALProgressFunc pfnProgress,
998  void *pProgressData ) override;
999  virtual CPLErr GetHistogram( int nXSize, int nYSize,
1000  double dfMin, double dfMax,
1001  int nBuckets, GUIntBig * panHistogram,
1002  int bIncludeOutOfRange, int bApproxOK,
1003  GDALProgressFunc pfnProgress,
1004  void *pProgressData ) override;
1005 
1006  void DstToSrc( double dfX, double dfY,
1007  double &dfXOut, double &dfYOut ) const;
1008  void SrcToDst( double dfX, double dfY,
1009  double &dfXOut, double &dfYOut ) const;
1010 
1011  virtual void GetFileList( char*** ppapszFileList, int *pnSize,
1012  int *pnMaxSize, CPLHashSet* hSetFiles ) override;
1013 
1014  virtual int IsSimpleSource() override { return TRUE; }
1015  virtual const char* GetType() { return "SimpleSource"; }
1016  virtual CPLErr FlushCache(bool bAtClosing) override;
1017 
1018  GDALRasterBand* GetRasterBand() const;
1019  GDALRasterBand* GetMaskBandMainBand();
1020  int IsSameExceptBandNumber( VRTSimpleSource* poOtherSource );
1021  CPLErr DatasetRasterIO(
1022  GDALDataType eBandDataType,
1023  int nXOff, int nYOff, int nXSize, int nYSize,
1024  void * pData, int nBufXSize, int nBufYSize,
1025  GDALDataType eBufType,
1026  int nBandCount, int *panBandMap,
1027  GSpacing nPixelSpace, GSpacing nLineSpace,
1028  GSpacing nBandSpace,
1029  GDALRasterIOExtraArg* psExtraArg );
1030 
1031  void UnsetPreservedRelativeFilenames();
1032 
1033  void SetMaxValue( int nVal ) { m_nMaxValue = nVal; }
1034 };
1035 
1036 /************************************************************************/
1037 /* VRTAveragedSource */
1038 /************************************************************************/
1039 
1040 class VRTAveragedSource final: public VRTSimpleSource
1041 {
1042  CPL_DISALLOW_COPY_ASSIGN(VRTAveragedSource)
1043 
1044 public:
1045  VRTAveragedSource();
1046  virtual CPLErr RasterIO( GDALDataType eBandDataType,
1047  int nXOff, int nYOff, int nXSize, int nYSize,
1048  void *pData, int nBufXSize, int nBufYSize,
1049  GDALDataType eBufType,
1050  GSpacing nPixelSpace, GSpacing nLineSpace,
1051  GDALRasterIOExtraArg* psExtraArgIn ) override;
1052 
1053  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) override;
1054  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) override;
1055  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK,
1056  double* adfMinMax ) override;
1057  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
1058  int bApproxOK,
1059  double *pdfMin, double *pdfMax,
1060  double *pdfMean, double *pdfStdDev,
1061  GDALProgressFunc pfnProgress,
1062  void *pProgressData ) override;
1063  virtual CPLErr GetHistogram( int nXSize, int nYSize,
1064  double dfMin, double dfMax,
1065  int nBuckets, GUIntBig * panHistogram,
1066  int bIncludeOutOfRange, int bApproxOK,
1067  GDALProgressFunc pfnProgress,
1068  void *pProgressData ) override;
1069 
1070  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
1071  virtual const char* GetType() override { return "AveragedSource"; }
1072 };
1073 
1074 /************************************************************************/
1075 /* VRTComplexSource */
1076 /************************************************************************/
1077 
1078 typedef enum
1079 {
1080  VRT_SCALING_NONE,
1081  VRT_SCALING_LINEAR,
1082  VRT_SCALING_EXPONENTIAL,
1083 } VRTComplexSourceScaling;
1084 
1085 class CPL_DLL VRTComplexSource CPL_NON_FINAL: public VRTSimpleSource
1086 {
1087  CPL_DISALLOW_COPY_ASSIGN(VRTComplexSource)
1088  bool AreValuesUnchanged() const;
1089 
1090 protected:
1091  VRTComplexSourceScaling m_eScalingType;
1092  double m_dfScaleOff; // For linear scaling.
1093  double m_dfScaleRatio; // For linear scaling.
1094 
1095  // For non-linear scaling with a power function.
1096  int m_bSrcMinMaxDefined;
1097  double m_dfSrcMin;
1098  double m_dfSrcMax;
1099  double m_dfDstMin;
1100  double m_dfDstMax;
1101  double m_dfExponent;
1102 
1103  int m_nColorTableComponent;
1104 
1105  bool m_bUseMaskBand = false;
1106 
1107  template <class WorkingDT>
1108  CPLErr RasterIOInternal( int nReqXOff, int nReqYOff,
1109  int nReqXSize, int nReqYSize,
1110  void *pData, int nOutXSize, int nOutYSize,
1111  GDALDataType eBufType,
1112  GSpacing nPixelSpace, GSpacing nLineSpace,
1113  GDALRasterIOExtraArg* psExtraArg,
1114  GDALDataType eWrkDataType );
1115 
1116 public:
1117  VRTComplexSource();
1118  VRTComplexSource(const VRTComplexSource* poSrcSource,
1119  double dfXDstRatio, double dfYDstRatio);
1120  virtual ~VRTComplexSource();
1121 
1122  virtual CPLErr RasterIO( GDALDataType eBandDataType,
1123  int nXOff, int nYOff, int nXSize, int nYSize,
1124  void *pData, int nBufXSize, int nBufYSize,
1125  GDALDataType eBufType,
1126  GSpacing nPixelSpace, GSpacing nLineSpace,
1127  GDALRasterIOExtraArg* psExtraArgIn ) override;
1128 
1129  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) override;
1130  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) override;
1131  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK,
1132  double* adfMinMax ) override;
1133  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
1134  int bApproxOK,
1135  double *pdfMin, double *pdfMax,
1136  double *pdfMean, double *pdfStdDev,
1137  GDALProgressFunc pfnProgress,
1138  void *pProgressData ) override;
1139  virtual CPLErr GetHistogram( int nXSize, int nYSize,
1140  double dfMin, double dfMax,
1141  int nBuckets, GUIntBig * panHistogram,
1142  int bIncludeOutOfRange, int bApproxOK,
1143  GDALProgressFunc pfnProgress,
1144  void *pProgressData ) override;
1145 
1146  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
1147  virtual CPLErr XMLInit( CPLXMLNode *, const char *,
1148  std::map<CPLString, GDALDataset*>& ) override;
1149  virtual const char* GetType() override { return "ComplexSource"; }
1150 
1151  double LookupValue( double dfInput );
1152 
1153  void SetUseMaskBand(bool bUseMaskBand) { m_bUseMaskBand = bUseMaskBand; }
1154 
1155  void SetLinearScaling( double dfOffset, double dfScale );
1156  void SetPowerScaling( double dfExponent,
1157  double dfSrcMin,
1158  double dfSrcMax,
1159  double dfDstMin,
1160  double dfDstMax );
1161  void SetColorTableComponent( int nComponent );
1162 
1163  double *m_padfLUTInputs;
1164  double *m_padfLUTOutputs;
1165  int m_nLUTItemCount;
1166 };
1167 
1168 /************************************************************************/
1169 /* VRTFilteredSource */
1170 /************************************************************************/
1171 
1172 class VRTFilteredSource CPL_NON_FINAL: public VRTComplexSource
1173 {
1174 private:
1175  int IsTypeSupported( GDALDataType eTestType ) const;
1176 
1177  CPL_DISALLOW_COPY_ASSIGN(VRTFilteredSource)
1178 
1179 protected:
1180  int m_nSupportedTypesCount;
1181  GDALDataType m_aeSupportedTypes[20];
1182 
1183  int m_nExtraEdgePixels;
1184 
1185 public:
1186  VRTFilteredSource();
1187  virtual ~VRTFilteredSource();
1188 
1189  void SetExtraEdgePixels( int );
1190  void SetFilteringDataTypesSupported( int, GDALDataType * );
1191 
1192  virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
1193  GByte *pabySrcData, GByte *pabyDstData ) = 0;
1194 
1195  virtual CPLErr RasterIO( GDALDataType eBandDataType,
1196  int nXOff, int nYOff, int nXSize, int nYSize,
1197  void *pData, int nBufXSize, int nBufYSize,
1198  GDALDataType eBufType,
1199  GSpacing nPixelSpace, GSpacing nLineSpace,
1200  GDALRasterIOExtraArg* psExtraArg ) override;
1201 };
1202 
1203 /************************************************************************/
1204 /* VRTKernelFilteredSource */
1205 /************************************************************************/
1206 
1207 class VRTKernelFilteredSource CPL_NON_FINAL: public VRTFilteredSource
1208 {
1209  CPL_DISALLOW_COPY_ASSIGN(VRTKernelFilteredSource)
1210 
1211 protected:
1212  int m_nKernelSize;
1213 
1214  bool m_bSeparable;
1215 
1216  double *m_padfKernelCoefs;
1217 
1218  int m_bNormalized;
1219 
1220 public:
1221  VRTKernelFilteredSource();
1222  virtual ~VRTKernelFilteredSource();
1223 
1224  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char *,
1225  std::map<CPLString, GDALDataset*>& ) override;
1226  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
1227 
1228  virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
1229  GByte *pabySrcData, GByte *pabyDstData ) override;
1230 
1231  CPLErr SetKernel( int nKernelSize, bool bSeparable, double *padfCoefs );
1232  void SetNormalized( int );
1233 };
1234 
1235 /************************************************************************/
1236 /* VRTAverageFilteredSource */
1237 /************************************************************************/
1238 
1239 class VRTAverageFilteredSource final: public VRTKernelFilteredSource
1240 {
1241  CPL_DISALLOW_COPY_ASSIGN(VRTAverageFilteredSource)
1242 
1243 public:
1244  explicit VRTAverageFilteredSource( int nKernelSize );
1245  virtual ~VRTAverageFilteredSource();
1246 
1247  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char *,
1248  std::map<CPLString, GDALDataset*>& ) override;
1249  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
1250 };
1251 
1252 /************************************************************************/
1253 /* VRTFuncSource */
1254 /************************************************************************/
1255 class VRTFuncSource final: public VRTSource
1256 {
1257  CPL_DISALLOW_COPY_ASSIGN(VRTFuncSource)
1258 
1259 public:
1260  VRTFuncSource();
1261  virtual ~VRTFuncSource();
1262 
1263  virtual CPLErr XMLInit( CPLXMLNode *, const char *,
1264  std::map<CPLString, GDALDataset*>& ) override { return CE_Failure; }
1265  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
1266 
1267  virtual CPLErr RasterIO( GDALDataType eBandDataType,
1268  int nXOff, int nYOff, int nXSize, int nYSize,
1269  void *pData, int nBufXSize, int nBufYSize,
1270  GDALDataType eBufType,
1271  GSpacing nPixelSpace, GSpacing nLineSpace,
1272  GDALRasterIOExtraArg* psExtraArg ) override;
1273 
1274  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) override;
1275  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) override;
1276  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK,
1277  double* adfMinMax ) override;
1278  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
1279  int bApproxOK,
1280  double *pdfMin, double *pdfMax,
1281  double *pdfMean, double *pdfStdDev,
1282  GDALProgressFunc pfnProgress,
1283  void *pProgressData ) override;
1284  virtual CPLErr GetHistogram( int nXSize, int nYSize,
1285  double dfMin, double dfMax,
1286  int nBuckets, GUIntBig * panHistogram,
1287  int bIncludeOutOfRange, int bApproxOK,
1288  GDALProgressFunc pfnProgress,
1289  void *pProgressData ) override;
1290 
1291  VRTImageReadFunc pfnReadFunc;
1292  void *pCBData;
1293  GDALDataType eType;
1294 
1295  float fNoDataValue;
1296 };
1297 
1298 /************************************************************************/
1299 /* VRTGroup */
1300 /************************************************************************/
1301 
1302 #ifdef TMPEXPORT
1303 #define TMP_CPL_DLL CPL_DLL
1304 #else
1305 #define TMP_CPL_DLL
1306 #endif
1307 
1308 class VRTMDArray;
1309 class VRTAttribute;
1310 class VRTDimension;
1311 
1312 class VRTGroup final: public GDALGroup
1313 {
1314 public:
1315  struct Ref
1316  {
1317  VRTGroup* m_ptr;
1318  explicit Ref(VRTGroup* ptr): m_ptr(ptr) {}
1319  Ref(const Ref&) = delete;
1320  Ref& operator=(const Ref&) = delete;
1321  };
1322 
1323 private:
1324  std::shared_ptr<Ref> m_poSharedRefRootGroup{};
1325  std::weak_ptr<Ref> m_poWeakRefRootGroup{};
1326  std::shared_ptr<Ref> m_poRefSelf{};
1327 
1328  std::string m_osFilename{};
1329  mutable bool m_bDirty = false;
1330  std::string m_osVRTPath{};
1331  std::map<std::string, std::shared_ptr<VRTGroup>> m_oMapGroups{};
1332  std::map<std::string, std::shared_ptr<VRTMDArray>> m_oMapMDArrays{};
1333  std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
1334  std::map<std::string, std::shared_ptr<VRTDimension>> m_oMapDimensions{};
1335 
1336  std::shared_ptr<VRTGroup> OpenGroupInternal(const std::string& osName) const;
1337  void SetRootGroupRef(const std::weak_ptr<Ref>& rgRef);
1338  std::weak_ptr<Ref> GetRootGroupRef() const;
1339 
1340 public:
1341 
1342  VRTGroup(const std::string& osParentName, const std::string& osName);
1343  ~VRTGroup();
1344 
1345  bool XMLInit(const std::shared_ptr<VRTGroup>& poRoot,
1346  const std::shared_ptr<VRTGroup>& poThisGroup,
1347  const CPLXMLNode* psNode,
1348  const char* pszVRTPath);
1349 
1350  std::vector<std::string> GetMDArrayNames(CSLConstList papszOptions) const override;
1351  std::shared_ptr<GDALMDArray> OpenMDArray(const std::string& osName,
1352  CSLConstList papszOptions = nullptr) const override;
1353 
1354  std::vector<std::string> GetGroupNames(CSLConstList papszOptions) const override;
1355  std::shared_ptr<GDALGroup> OpenGroup(const std::string& osName,
1356  CSLConstList) const override
1357  {
1358  return OpenGroupInternal(osName);
1359  }
1360 
1361  std::vector<std::shared_ptr<GDALDimension>> GetDimensions(CSLConstList) const override;
1362 
1363  std::vector<std::shared_ptr<GDALAttribute>> GetAttributes(CSLConstList) const override;
1364 
1365  std::shared_ptr<VRTDimension> GetDimension(const std::string& name) const {
1366  auto oIter = m_oMapDimensions.find(name);
1367  return oIter == m_oMapDimensions.end() ? nullptr : oIter->second;
1368  }
1369  std::shared_ptr<VRTDimension> GetDimensionFromFullName(const std::string& name,
1370  bool bEmitError) const;
1371 
1372  std::shared_ptr<GDALGroup> CreateGroup(const std::string& osName,
1373  CSLConstList papszOptions = nullptr) override;
1374 
1375  std::shared_ptr<GDALDimension> CreateDimension(const std::string& osName,
1376  const std::string& osType,
1377  const std::string& osDirection,
1378  GUInt64 nSize,
1379  CSLConstList papszOptions = nullptr) override;
1380 
1381  std::shared_ptr<GDALAttribute> CreateAttribute(
1382  const std::string& osName,
1383  const std::vector<GUInt64>& anDimensions,
1384  const GDALExtendedDataType& oDataType,
1385  CSLConstList papszOptions = nullptr) override;
1386 
1387  std::shared_ptr<GDALMDArray> CreateMDArray(const std::string& osName,
1388  const std::vector<std::shared_ptr<GDALDimension>>& aoDimensions,
1389  const GDALExtendedDataType& oDataType,
1390  CSLConstList papszOptions) override;
1391 
1392  void SetIsRootGroup();
1393 
1394  const std::shared_ptr<Ref>& GetRef() const { return m_poRefSelf; }
1395  VRTGroup* GetRootGroup() const;
1396 
1397  const std::string& GetVRTPath() const { return m_osVRTPath; }
1398  void SetDirty();
1399  void SetFilename(const std::string& osFilename) { m_osFilename = osFilename; }
1400  const std::string& GetFilename() const { return m_osFilename; }
1401  void Serialize() const;
1402  CPLXMLNode* SerializeToXML( const char *pszVRTPathIn ) const;
1403  void Serialize(CPLXMLNode* psParent, const char *pszVRTPathIn) const;
1404 };
1405 
1406 /************************************************************************/
1407 /* VRTDimension */
1408 /************************************************************************/
1409 
1410 class VRTDimension final: public GDALDimension
1411 {
1412  std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
1413  std::string m_osIndexingVariableName;
1414 
1415 public:
1416  VRTDimension(const std::shared_ptr<VRTGroup::Ref>& poGroupRef,
1417  const std::string& osParentName,
1418  const std::string& osName,
1419  const std::string& osType,
1420  const std::string& osDirection,
1421  GUInt64 nSize,
1422  const std::string& osIndexingVariableName):
1423  GDALDimension(osParentName, osName, osType, osDirection, nSize),
1424  m_poGroupRef(poGroupRef),
1425  m_osIndexingVariableName(osIndexingVariableName)
1426  {}
1427 
1428  VRTGroup* GetGroup() const;
1429 
1430  static std::shared_ptr<VRTDimension> Create(const std::shared_ptr<VRTGroup>& poThisGroup,
1431  const std::string& osParentName,
1432  const CPLXMLNode* psNode);
1433 
1434  std::shared_ptr<GDALMDArray> GetIndexingVariable() const override;
1435 
1436  bool SetIndexingVariable(std::shared_ptr<GDALMDArray> poIndexingVariable) override;
1437 
1438  void Serialize(CPLXMLNode* psParent) const;
1439 };
1440 
1441 /************************************************************************/
1442 /* VRTAttribute */
1443 /************************************************************************/
1444 
1445 class VRTAttribute final: public GDALAttribute
1446 {
1447  GDALExtendedDataType m_dt;
1448  std::vector<std::string> m_aosList{};
1449  std::vector<std::shared_ptr<GDALDimension>> m_dims{};
1450 
1451 protected:
1452 
1453  bool IRead(const GUInt64* arrayStartIdx,
1454  const size_t* count,
1455  const GInt64* arrayStep,
1456  const GPtrDiff_t* bufferStride,
1457  const GDALExtendedDataType& bufferDataType,
1458  void* pDstBuffer) const override;
1459 
1460  bool IWrite(const GUInt64* arrayStartIdx,
1461  const size_t* count,
1462  const GInt64* arrayStep,
1463  const GPtrDiff_t* bufferStride,
1464  const GDALExtendedDataType& bufferDataType,
1465  const void* pSrcBuffer) override;
1466 
1467 
1468 public:
1469  VRTAttribute(const std::string& osParentName,
1470  const std::string& osName,
1471  const GDALExtendedDataType& dt,
1472  std::vector<std::string>&& aosList):
1473  GDALAbstractMDArray(osParentName, osName),
1474  GDALAttribute(osParentName, osName),
1475  m_dt(dt),
1476  m_aosList(std::move(aosList))
1477  {
1478  if( m_aosList.size() > 1 )
1479  {
1480  m_dims.emplace_back(std::make_shared<GDALDimension>(
1481  std::string(), "dim",
1482  std::string(), std::string(), m_aosList.size()));
1483  }
1484  }
1485 
1486  VRTAttribute(const std::string& osParentName,
1487  const std::string& osName,
1488  GUInt64 nDim,
1489  const GDALExtendedDataType& dt):
1490  GDALAbstractMDArray(osParentName, osName),
1491  GDALAttribute(osParentName, osName),
1492  m_dt(dt)
1493  {
1494  if( nDim != 0 )
1495  {
1496  m_dims.emplace_back(std::make_shared<GDALDimension>(
1497  std::string(), "dim",
1498  std::string(), std::string(), nDim));
1499  }
1500  }
1501 
1502  static bool CreationCommonChecks(const std::string& osName,
1503  const std::vector<GUInt64>& anDimensions,
1504  const std::map<std::string, std::shared_ptr<VRTAttribute>>& oMapAttributes);
1505 
1506  static std::shared_ptr<VRTAttribute> Create(const std::string& osParentName,
1507  const CPLXMLNode* psNode);
1508 
1509  const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const override { return m_dims; }
1510 
1511  const GDALExtendedDataType &GetDataType() const override { return m_dt; }
1512 
1513  void Serialize(CPLXMLNode* psParent) const;
1514 };
1515 
1516 /************************************************************************/
1517 /* VRTMDArraySource */
1518 /************************************************************************/
1519 
1520 class VRTMDArraySource
1521 {
1522 public:
1523  virtual ~VRTMDArraySource() = default;
1524 
1525  virtual bool Read(const GUInt64* arrayStartIdx,
1526  const size_t* count,
1527  const GInt64* arrayStep,
1528  const GPtrDiff_t* bufferStride,
1529  const GDALExtendedDataType& bufferDataType,
1530  void* pDstBuffer) const = 0;
1531 
1532  virtual void Serialize(CPLXMLNode* psParent, const char* pszVRTPath) const = 0;
1533 };
1534 
1535 /************************************************************************/
1536 /* VRTMDArray */
1537 /************************************************************************/
1538 
1539 class VRTMDArray final: public GDALMDArray
1540 {
1541 protected:
1542  friend class VRTGroup; // for access to SetSelf()
1543 
1544  std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
1545  std::string m_osVRTPath{};
1546 
1547  GDALExtendedDataType m_dt;
1548  std::vector<std::shared_ptr<GDALDimension>> m_dims;
1549  std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
1550  std::vector<std::unique_ptr<VRTMDArraySource>> m_sources{};
1551  std::shared_ptr<OGRSpatialReference> m_poSRS{};
1552  std::vector<GByte> m_abyNoData{};
1553  std::string m_osUnit{};
1554  double m_dfScale = 1.0;
1555  double m_dfOffset = 0.0;
1556  bool m_bHasScale = false;
1557  bool m_bHasOffset = false;
1558  std::string m_osFilename{};
1559 
1560  bool IRead(const GUInt64* arrayStartIdx,
1561  const size_t* count,
1562  const GInt64* arrayStep,
1563  const GPtrDiff_t* bufferStride,
1564  const GDALExtendedDataType& bufferDataType,
1565  void* pDstBuffer) const override;
1566 
1567  void SetDirty();
1568 
1569 public:
1570  VRTMDArray(const std::shared_ptr<VRTGroup::Ref>& poGroupRef,
1571  const std::string& osParentName,
1572  const std::string& osName,
1573  const GDALExtendedDataType& dt,
1574  std::vector<std::shared_ptr<GDALDimension>>&& dims,
1575  std::map<std::string, std::shared_ptr<VRTAttribute>>&& oMapAttributes) :
1576  GDALAbstractMDArray(osParentName, osName),
1577  GDALMDArray(osParentName, osName),
1578  m_poGroupRef(poGroupRef),
1579  m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()),
1580  m_dt(dt),
1581  m_dims(std::move(dims)),
1582  m_oMapAttributes(std::move(oMapAttributes)),
1583  m_osFilename(poGroupRef->m_ptr->GetFilename())
1584  {
1585  }
1586 
1587  VRTMDArray(const std::shared_ptr<VRTGroup::Ref>& poGroupRef,
1588  const std::string& osParentName,
1589  const std::string& osName,
1590  const std::vector<std::shared_ptr<GDALDimension>>& dims,
1591  const GDALExtendedDataType& dt) :
1592  GDALAbstractMDArray(osParentName, osName),
1593  GDALMDArray(osParentName, osName),
1594  m_poGroupRef(poGroupRef),
1595  m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()),
1596  m_dt(dt),
1597  m_dims(dims),
1598  m_osFilename(poGroupRef->m_ptr->GetFilename())
1599  {
1600  }
1601 
1602  bool IsWritable() const override { return false; }
1603 
1604  const std::string& GetFilename() const override { return m_osFilename; }
1605 
1606  static std::shared_ptr<VRTMDArray> Create(const std::shared_ptr<VRTGroup>& poThisGroup,
1607  const std::string& osParentName,
1608  const CPLXMLNode* psNode);
1609 
1610  const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const override { return m_dims; }
1611 
1612  std::vector<std::shared_ptr<GDALAttribute>> GetAttributes(CSLConstList) const override;
1613 
1614  const GDALExtendedDataType &GetDataType() const override { return m_dt; }
1615 
1616  bool SetSpatialRef(const OGRSpatialReference* poSRS) override;
1617 
1618  std::shared_ptr<OGRSpatialReference> GetSpatialRef() const override { return m_poSRS; }
1619 
1620  const void* GetRawNoDataValue() const override;
1621 
1622  bool SetRawNoDataValue(const void* pRawNoData) override;
1623 
1624  const std::string& GetUnit() const override { return m_osUnit; }
1625 
1626  bool SetUnit(const std::string& osUnit) override {
1627  m_osUnit = osUnit; return true; }
1628 
1629  double GetOffset(bool* pbHasOffset, GDALDataType* peStorageType) const override
1630  {
1631  if( pbHasOffset) *pbHasOffset = m_bHasOffset;
1632  if( peStorageType ) *peStorageType = GDT_Unknown;
1633  return m_dfOffset;
1634  }
1635 
1636  double GetScale(bool* pbHasScale, GDALDataType* peStorageType) const override
1637  {
1638  if( pbHasScale) *pbHasScale = m_bHasScale;
1639  if( peStorageType ) *peStorageType = GDT_Unknown;
1640  return m_dfScale;
1641  }
1642 
1643  bool SetOffset(double dfOffset, GDALDataType /* eStorageType */ = GDT_Unknown) override
1644  { SetDirty(); m_bHasOffset = true; m_dfOffset = dfOffset; return true; }
1645 
1646  bool SetScale(double dfScale, GDALDataType /* eStorageType */ = GDT_Unknown) override
1647  { SetDirty(); m_bHasScale = true; m_dfScale = dfScale; return true; }
1648 
1649  void AddSource(std::unique_ptr<VRTMDArraySource>&& poSource);
1650 
1651  std::shared_ptr<GDALAttribute> CreateAttribute(
1652  const std::string& osName,
1653  const std::vector<GUInt64>& anDimensions,
1654  const GDALExtendedDataType& oDataType,
1655  CSLConstList papszOptions = nullptr) override;
1656 
1657  bool CopyFrom(GDALDataset* poSrcDS,
1658  const GDALMDArray* poSrcArray,
1659  bool bStrict,
1660  GUInt64& nCurCost,
1661  const GUInt64 nTotalCost,
1662  GDALProgressFunc pfnProgress,
1663  void * pProgressData) override;
1664 
1665  void Serialize(CPLXMLNode* psParent, const char *pszVRTPathIn ) const;
1666 
1667  VRTGroup* GetGroup() const;
1668 
1669  const std::string& GetVRTPath() const { return m_osVRTPath; }
1670 };
1671 
1672 /************************************************************************/
1673 /* VRTMDArraySourceInlinedValues */
1674 /************************************************************************/
1675 
1676 class VRTMDArraySourceInlinedValues final: public VRTMDArraySource
1677 {
1678  const VRTMDArray* m_poDstArray = nullptr;
1679  bool m_bIsConstantValue;
1680  std::vector<GUInt64> m_anOffset{};
1681  std::vector<size_t> m_anCount{};
1682  std::vector<GByte> m_abyValues{};
1683  std::vector<size_t> m_anInlinedArrayStrideInBytes{};
1684  GDALExtendedDataType m_dt;
1685 
1686  VRTMDArraySourceInlinedValues(const VRTMDArraySourceInlinedValues&) = delete;
1687  VRTMDArraySourceInlinedValues& operator=(const VRTMDArraySourceInlinedValues&) = delete;
1688 
1689 public:
1690  VRTMDArraySourceInlinedValues(const VRTMDArray* poDstArray,
1691  bool bIsConstantValue,
1692  std::vector<GUInt64>&& anOffset,
1693  std::vector<size_t>&& anCount,
1694  std::vector<GByte>&& abyValues):
1695  m_poDstArray(poDstArray),
1696  m_bIsConstantValue(bIsConstantValue),
1697  m_anOffset(std::move(anOffset)),
1698  m_anCount(std::move(anCount)),
1699  m_abyValues(std::move(abyValues)),
1700  m_dt(poDstArray->GetDataType())
1701  {
1702  const auto nDims(poDstArray->GetDimensionCount());
1703  m_anInlinedArrayStrideInBytes.resize(nDims);
1704  if( !bIsConstantValue && nDims > 0 )
1705  {
1706  m_anInlinedArrayStrideInBytes.back() = poDstArray->GetDataType().GetSize();
1707  for(size_t i = nDims - 1; i > 0; )
1708  {
1709  --i;
1710  m_anInlinedArrayStrideInBytes[i] =
1711  m_anInlinedArrayStrideInBytes[i+1] * m_anCount[i+1];
1712  }
1713  }
1714  }
1715 
1716  ~VRTMDArraySourceInlinedValues();
1717 
1718  static std::unique_ptr<VRTMDArraySourceInlinedValues> Create(
1719  const VRTMDArray* poDstArray,
1720  const CPLXMLNode* psNode);
1721 
1722  bool Read(const GUInt64* arrayStartIdx,
1723  const size_t* count,
1724  const GInt64* arrayStep,
1725  const GPtrDiff_t* bufferStride,
1726  const GDALExtendedDataType& bufferDataType,
1727  void* pDstBuffer) const override;
1728 
1729  void Serialize(CPLXMLNode* psParent, const char* pszVRTPath) const override;
1730 };
1731 
1732 /************************************************************************/
1733 /* VRTMDArraySourceRegularlySpaced */
1734 /************************************************************************/
1735 
1736 class VRTMDArraySourceRegularlySpaced final: public VRTMDArraySource
1737 {
1738  double m_dfStart;
1739  double m_dfIncrement;
1740 
1741 public:
1742  VRTMDArraySourceRegularlySpaced(
1743  double dfStart, double dfIncrement):
1744  m_dfStart(dfStart),
1745  m_dfIncrement(dfIncrement)
1746  {
1747  }
1748 
1749  bool Read(const GUInt64* arrayStartIdx,
1750  const size_t* count,
1751  const GInt64* arrayStep,
1752  const GPtrDiff_t* bufferStride,
1753  const GDALExtendedDataType& bufferDataType,
1754  void* pDstBuffer) const override;
1755 
1756  void Serialize(CPLXMLNode* psParent, const char* pszVRTPath) const override;
1757 };
1758 
1759 /************************************************************************/
1760 /* VRTMDArraySourceFromArray */
1761 /************************************************************************/
1762 
1763 class VRTMDArraySourceFromArray final: public VRTMDArraySource
1764 {
1765  const VRTMDArray* m_poDstArray = nullptr;
1766  bool m_bRelativeToVRTSet = false;
1767  bool m_bRelativeToVRT = false;
1768  std::string m_osFilename{};
1769  std::string m_osArray{};
1770  std::string m_osBand{};
1771  std::vector<int> m_anTransposedAxis{};
1772  std::string m_osViewExpr{};
1773  std::vector<GUInt64> m_anSrcOffset{};
1774  mutable std::vector<GUInt64> m_anCount{};
1775  std::vector<GUInt64> m_anStep{};
1776  std::vector<GUInt64> m_anDstOffset{};
1777 
1778  VRTMDArraySourceFromArray(const VRTMDArraySourceFromArray&) = delete;
1779  VRTMDArraySourceFromArray& operator=(const VRTMDArraySourceFromArray&) = delete;
1780 
1781 public:
1782  VRTMDArraySourceFromArray(const VRTMDArray* poDstArray,
1783  bool bRelativeToVRTSet,
1784  bool bRelativeToVRT,
1785  const std::string& osFilename,
1786  const std::string& osArray,
1787  const std::string& osBand,
1788  std::vector<int>&& anTransposedAxis,
1789  const std::string& osViewExpr,
1790  std::vector<GUInt64>&& anSrcOffset,
1791  std::vector<GUInt64>&& anCount,
1792  std::vector<GUInt64>&& anStep,
1793  std::vector<GUInt64>&& anDstOffset):
1794  m_poDstArray(poDstArray),
1795  m_bRelativeToVRTSet(bRelativeToVRTSet),
1796  m_bRelativeToVRT(bRelativeToVRT),
1797  m_osFilename(osFilename),
1798  m_osArray(osArray),
1799  m_osBand(osBand),
1800  m_anTransposedAxis(std::move(anTransposedAxis)),
1801  m_osViewExpr(osViewExpr),
1802  m_anSrcOffset(std::move(anSrcOffset)),
1803  m_anCount(std::move(anCount)),
1804  m_anStep(std::move(anStep)),
1805  m_anDstOffset(std::move(anDstOffset))
1806  {
1807  }
1808 
1809  ~VRTMDArraySourceFromArray() override;
1810 
1811  static std::unique_ptr<VRTMDArraySourceFromArray> Create(
1812  const VRTMDArray* poDstArray,
1813  const CPLXMLNode* psNode);
1814 
1815  bool Read(const GUInt64* arrayStartIdx,
1816  const size_t* count,
1817  const GInt64* arrayStep,
1818  const GPtrDiff_t* bufferStride,
1819  const GDALExtendedDataType& bufferDataType,
1820  void* pDstBuffer) const override;
1821 
1822  void Serialize(CPLXMLNode* psParent, const char* pszVRTPath) const override;
1823 };
1824 
1825 #endif /* #ifndef DOXYGEN_SKIP */
1826 
1827 #endif /* ndef VIRTUALDATASET_H_INCLUDED */
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:442
Convenient string class based on std::string.
Definition: cpl_string.h:333
Abstract class, implemented by GDALAttribute and GDALMDArray.
Definition: gdal_priv.h:2079
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:2255
A color table / palette.
Definition: gdal_priv.h:1023
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:340
int Dereference()
Subtract one from dataset reference count.
Definition: gdaldataset.cpp:1385
virtual CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList, const OGRSpatialReference *poGCP_SRS)
Assign GCPs.
Definition: gdaldataset.cpp:1804
int GetShared() const
Returns shared flag.
Definition: gdaldataset.cpp:1457
Class modeling a a dimension / axis used to index multidimensional arrays.
Definition: gdal_priv.h:2649
virtual std::shared_ptr< GDALMDArray > GetIndexingVariable() const
Return the variable that is used to index the dimension (if there is one).
Definition: gdalmultidim.cpp:8033
virtual bool SetIndexingVariable(std::shared_ptr< GDALMDArray > poIndexingVariable)
Set the variable that is used to index the dimension.
Definition: gdalmultidim.cpp:8054
Format specific driver.
Definition: gdal_priv.h:1486
Class used to represent potentially complex data types.
Definition: gdal_priv.h:1803
Class modeling a named container of GDALAttribute, GDALMDArray, OGRLayer or other GDALGroup.
Definition: gdal_priv.h:1977
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:254
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:223
Class modeling a multi-dimensional array.
Definition: gdal_priv.h:2373
virtual bool SetUnit(const std::string &osUnit)
Set the variable unit.
Definition: gdalmultidim.cpp:2064
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:3180
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:2260
virtual bool SetRawNoDataValue(const void *pRawNoData)
Set the nodata value as a "raw" value.
Definition: gdalmultidim.cpp:2205
virtual double GetOffset(bool *pbHasOffset=nullptr, GDALDataType *peStorageType=nullptr) const
Get the offset value to apply to raw values.
Definition: gdalmultidim.cpp:2348
virtual const std::string & GetFilename() const =0
Return the filename that contains that array.
virtual const void * GetRawNoDataValue() const
Return the nodata value as a "raw" value.
Definition: gdalmultidim.cpp:2140
virtual double GetScale(bool *pbHasScale=nullptr, GDALDataType *peStorageType=nullptr) const
Get the scale value to apply to raw values.
Definition: gdalmultidim.cpp:2318
virtual std::shared_ptr< OGRSpatialReference > GetSpatialRef() const
Return the spatial reference system object associated with the array.
Definition: gdalmultidim.cpp:2114
virtual bool SetSpatialRef(const OGRSpatialReference *poSRS)
Assign a spatial reference system object to the the array.
Definition: gdalmultidim.cpp:2100
virtual bool SetOffset(double dfOffset, GDALDataType eStorageType=GDT_Unknown)
Set the offset value to apply to raw values.
Definition: gdalmultidim.cpp:2289
virtual const std::string & GetUnit() const
Return the array unit.
Definition: gdalmultidim.cpp:2086
Object with metadata.
Definition: gdal_priv.h:136
virtual CPLErr SetMetadata(char **papszMetadata, const char *pszDomain="")
Set metadata.
Definition: gdalmajorobject.cpp:292
virtual char ** GetMetadataDomainList()
Fetch list of metadata domains.
Definition: gdalmajorobject.cpp:161
virtual char ** GetMetadata(const char *pszDomain="")
Fetch metadata.
Definition: gdalmajorobject.cpp:249
Class for dataset open functions.
Definition: gdal_priv.h:269
Pansharpening operation class.
Definition: gdalpansharpen.h:189
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition: gdal_rat.h:48
A single raster band (or channel).
Definition: gdal_priv.h:1131
GDALDataset * GetDataset()
Fetch the owning dataset handle.
Definition: gdalrasterband.cpp:2847
High level image warping class.
Definition: gdalwarper.h:463
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:158
CPLErr
Error category.
Definition: cpl_error.h:53
Hash set implementation.
struct _CPLHashSet CPLHashSet
Opaque type for a hash set.
Definition: cpl_hash_set.h:52
Definitions for CPL mini XML Parser/Serializer.
#define CPL_NON_FINAL
Mark that a class is explicitly recognized as non-final.
Definition: cpl_port.h:948
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:247
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:263
GIntBig GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:282
#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:955
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1169
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:265
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:244
struct CPLVirtualMem CPLVirtualMem
Opaque type that represents a virtual memory mapping.
Definition: cpl_virtualmem.h:62
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:140
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:286
GDALAccess
Definition: gdal.h:115
@ GA_ReadOnly
Definition: gdal.h:116
void GDALClose(GDALDatasetH)
Close GDAL dataset.
Definition: gdaldataset.cpp:3727
GDALDataType
Definition: gdal.h:62
@ GDT_Unknown
Definition: gdal.h:63
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:941
GDALColorInterp
Definition: gdal.h:204
GDALRWFlag
Definition: gdal.h:121
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:933
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:271
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:45
void * VRTDatasetH
Opaque type for a VRT dataset.
Definition: gdal_vrt.h:76
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:51
VRTDatasetH VRTCreate(int, int)
Definition: vrtdataset.cpp:79
Document node structure.
Definition: cpl_minixml.h:70
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:711