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