GDAL
vrtdataset.h
1 /******************************************************************************
2  * $Id: vrtdataset.h 507451e25decfeaf7cfa8fd6696a2c4bf9488d76 2020-09-12 15:51:39 +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 <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  friend class VRTDataset;
442 
443  int m_bIsMaskBand;
444 
445  int m_bNoDataValueSet;
446  // If set to true, will not report the existence of nodata.
447  int m_bHideNoDataValue;
448  double m_dfNoDataValue;
449 
450  std::unique_ptr<GDALColorTable> m_poColorTable{};
451 
452  GDALColorInterp m_eColorInterp;
453 
454  char *m_pszUnitType;
455  char **m_papszCategoryNames;
456 
457  double m_dfOffset;
458  double m_dfScale;
459 
460  CPLXMLNode *m_psSavedHistograms;
461 
462  void Initialize( int nXSize, int nYSize );
463 
464  std::vector<VRTOverviewInfo> m_apoOverviews{};
465 
466  VRTRasterBand *m_poMaskBand;
467 
468  std::unique_ptr<GDALRasterAttributeTable> m_poRAT{};
469 
470  CPL_DISALLOW_COPY_ASSIGN(VRTRasterBand)
471 
472  public:
473 
474  VRTRasterBand();
475  virtual ~VRTRasterBand();
476 
477  virtual CPLErr XMLInit( CPLXMLNode *, const char *, void*,
478  std::map<CPLString, GDALDataset*>& );
479  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
480 
481  virtual CPLErr SetNoDataValue( double ) override;
482  virtual double GetNoDataValue( int *pbSuccess = nullptr ) override;
483  virtual CPLErr DeleteNoDataValue() override;
484 
485  virtual CPLErr SetColorTable( GDALColorTable * ) override;
486  virtual GDALColorTable *GetColorTable() override;
487 
488  virtual GDALRasterAttributeTable *GetDefaultRAT() override;
489  virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * poRAT ) override;
490 
491  virtual CPLErr SetColorInterpretation( GDALColorInterp ) override;
492  virtual GDALColorInterp GetColorInterpretation() override;
493 
494  virtual const char *GetUnitType() override;
495  CPLErr SetUnitType( const char * ) override;
496 
497  virtual char **GetCategoryNames() override;
498  virtual CPLErr SetCategoryNames( char ** ) override;
499 
500  virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" ) override;
501  virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
502  const char *pszDomain = "" ) override;
503 
504  virtual double GetOffset( int *pbSuccess = nullptr ) override;
505  CPLErr SetOffset( double ) override;
506  virtual double GetScale( int *pbSuccess = nullptr ) override;
507  CPLErr SetScale( double ) override;
508 
509  virtual int GetOverviewCount() override;
510  virtual GDALRasterBand *GetOverview(int) override;
511 
512  virtual CPLErr GetHistogram( double dfMin, double dfMax,
513  int nBuckets, GUIntBig * panHistogram,
514  int bIncludeOutOfRange, int bApproxOK,
515  GDALProgressFunc, void *pProgressData ) override;
516 
517  virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
518  int *pnBuckets, GUIntBig ** ppanHistogram,
519  int bForce,
520  GDALProgressFunc, void *pProgressData) override;
521 
522  virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
523  int nBuckets, GUIntBig *panHistogram ) override;
524 
525  CPLErr CopyCommonInfoFrom( GDALRasterBand * );
526 
527  virtual void GetFileList(char*** ppapszFileList, int *pnSize,
528  int *pnMaxSize, CPLHashSet* hSetFiles);
529 
530  virtual void SetDescription( const char * ) override;
531 
532  virtual GDALRasterBand *GetMaskBand() override;
533  virtual int GetMaskFlags() override;
534 
535  virtual CPLErr CreateMaskBand( int nFlagsIn ) override;
536 
537  void SetMaskBand(VRTRasterBand* poMaskBand);
538 
539  void SetIsMaskBand();
540 
541  CPLErr UnsetNoDataValue();
542 
543  virtual int CloseDependentDatasets();
544 
545  virtual int IsSourcedRasterBand() { return FALSE; }
546  virtual int IsPansharpenRasterBand() { return FALSE; }
547 };
548 
549 /************************************************************************/
550 /* VRTSourcedRasterBand */
551 /************************************************************************/
552 
553 class VRTSimpleSource;
554 
555 class CPL_DLL VRTSourcedRasterBand CPL_NON_FINAL: public VRTRasterBand
556 {
557  private:
558  int m_nRecursionCounter;
559  CPLString m_osLastLocationInfo{};
560  char **m_papszSourceList;
561 
562  bool CanUseSourcesMinMaxImplementations();
563  void CheckSource( VRTSimpleSource *poSS );
564 
565  CPL_DISALLOW_COPY_ASSIGN(VRTSourcedRasterBand)
566 
567  public:
568  int nSources;
569  VRTSource **papoSources;
570  int bSkipBufferInitialization;
571 
572  VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
573  VRTSourcedRasterBand( GDALDataType eType,
574  int nXSize, int nYSize );
575  VRTSourcedRasterBand( GDALDataset *poDS, int nBand,
576  GDALDataType eType,
577  int nXSize, int nYSize );
578  virtual ~VRTSourcedRasterBand();
579 
580  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
581  void *, int, int, GDALDataType,
582  GSpacing nPixelSpace, GSpacing nLineSpace,
583  GDALRasterIOExtraArg* psExtraArg) override;
584 
585  virtual int IGetDataCoverageStatus( int nXOff, int nYOff,
586  int nXSize, int nYSize,
587  int nMaskFlagStop,
588  double* pdfDataPct) override;
589 
590  virtual char **GetMetadataDomainList() override;
591  virtual const char *GetMetadataItem( const char * pszName,
592  const char * pszDomain = "" ) override;
593  virtual char **GetMetadata( const char * pszDomain = "" ) override;
594  virtual CPLErr SetMetadata( char ** papszMetadata,
595  const char * pszDomain = "" ) override;
596  virtual CPLErr SetMetadataItem( const char * pszName,
597  const char * pszValue,
598  const char * pszDomain = "" ) override;
599 
600  virtual CPLErr XMLInit( CPLXMLNode *, const char *, void*,
601  std::map<CPLString, GDALDataset*>& ) override;
602  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
603 
604  virtual double GetMinimum( int *pbSuccess = nullptr ) override;
605  virtual double GetMaximum(int *pbSuccess = nullptr ) override;
606  virtual CPLErr ComputeRasterMinMax( int bApproxOK, double* adfMinMax ) override;
607  virtual CPLErr ComputeStatistics( int bApproxOK,
608  double *pdfMin, double *pdfMax,
609  double *pdfMean, double *pdfStdDev,
610  GDALProgressFunc pfnProgress,
611  void *pProgressData ) override;
612  virtual CPLErr GetHistogram( double dfMin, double dfMax,
613  int nBuckets, GUIntBig * panHistogram,
614  int bIncludeOutOfRange, int bApproxOK,
615  GDALProgressFunc pfnProgress,
616  void *pProgressData ) override;
617 
618  CPLErr AddSource( VRTSource * );
619  CPLErr AddSimpleSource( GDALRasterBand *poSrcBand,
620  double dfSrcXOff=-1, double dfSrcYOff=-1,
621  double dfSrcXSize=-1, double dfSrcYSize=-1,
622  double dfDstXOff=-1, double dfDstYOff=-1,
623  double dfDstXSize=-1, double dfDstYSize=-1,
624  const char *pszResampling = "near",
625  double dfNoDataValue = VRT_NODATA_UNSET);
626  CPLErr AddComplexSource( GDALRasterBand *poSrcBand,
627  double dfSrcXOff=-1, double dfSrcYOff=-1,
628  double dfSrcXSize=-1, double dfSrcYSize=-1,
629  double dfDstXOff=-1, double dfDstYOff=-1,
630  double dfDstXSize=-1, double dfDstYSize=-1,
631  double dfScaleOff=0.0,
632  double dfScaleRatio=1.0,
633  double dfNoDataValue = VRT_NODATA_UNSET,
634  int nColorTableComponent = 0);
635 
636  CPLErr AddMaskBandSource( GDALRasterBand *poSrcBand,
637  double dfSrcXOff=-1, double dfSrcYOff=-1,
638  double dfSrcXSize=-1,
639  double dfSrcYSize=-1,
640  double dfDstXOff=-1, double dfDstYOff=-1,
641  double dfDstXSize=-1,
642  double dfDstYSize=-1 );
643 
644  CPLErr AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
645  double dfNoDataValue = VRT_NODATA_UNSET );
646 
647  void ConfigureSource(VRTSimpleSource *poSimpleSource,
648  GDALRasterBand *poSrcBand,
649  int bAddAsMaskBand,
650  double dfSrcXOff, double dfSrcYOff,
651  double dfSrcXSize, double dfSrcYSize,
652  double dfDstXOff, double dfDstYOff,
653  double dfDstXSize, double dfDstYSize );
654 
655  virtual CPLErr IReadBlock( int, int, void * ) override;
656 
657  virtual void GetFileList(char*** ppapszFileList, int *pnSize,
658  int *pnMaxSize, CPLHashSet* hSetFiles) override;
659 
660  virtual int CloseDependentDatasets() override;
661 
662  virtual int IsSourcedRasterBand() override { return TRUE; }
663 
664  virtual CPLErr FlushCache() override;
665 };
666 
667 /************************************************************************/
668 /* VRTWarpedRasterBand */
669 /************************************************************************/
670 
671 class CPL_DLL VRTWarpedRasterBand final: public VRTRasterBand
672 {
673  public:
674  VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
675  GDALDataType eType = GDT_Unknown );
676  virtual ~VRTWarpedRasterBand();
677 
678  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
679 
680  virtual CPLErr IReadBlock( int, int, void * ) override;
681  virtual CPLErr IWriteBlock( int, int, void * ) override;
682 
683  virtual int GetOverviewCount() override;
684  virtual GDALRasterBand *GetOverview(int) override;
685 };
686 /************************************************************************/
687 /* VRTPansharpenedRasterBand */
688 /************************************************************************/
689 
690 class VRTPansharpenedRasterBand final: public VRTRasterBand
691 {
692  int m_nIndexAsPansharpenedBand;
693 
694  public:
695  VRTPansharpenedRasterBand(
696  GDALDataset *poDS, int nBand,
697  GDALDataType eDataType = GDT_Unknown );
698  virtual ~VRTPansharpenedRasterBand();
699 
700  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
701 
702  virtual CPLErr IReadBlock( int, int, void * ) override;
703 
704  virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
705  int nXOff, int nYOff, int nXSize, int nYSize,
706  void * pData, int nBufXSize, int nBufYSize,
707  GDALDataType eBufType,
708  GSpacing nPixelSpace, GSpacing nLineSpace,
709  GDALRasterIOExtraArg* psExtraArg) override;
710 
711  virtual int GetOverviewCount() override;
712  virtual GDALRasterBand *GetOverview(int) override;
713 
714  virtual int IsPansharpenRasterBand() override { return TRUE; }
715 
716  void SetIndexAsPansharpenedBand( int nIdx )
717  { m_nIndexAsPansharpenedBand = nIdx; }
718  int GetIndexAsPansharpenedBand() const
719  { return m_nIndexAsPansharpenedBand; }
720 };
721 
722 /************************************************************************/
723 /* VRTDerivedRasterBand */
724 /************************************************************************/
725 
726 class VRTDerivedRasterBandPrivateData;
727 
728 class CPL_DLL VRTDerivedRasterBand CPL_NON_FINAL: public VRTSourcedRasterBand
729 {
730  VRTDerivedRasterBandPrivateData* m_poPrivate;
731  bool InitializePython();
732 
733  CPL_DISALLOW_COPY_ASSIGN(VRTDerivedRasterBand)
734 
735  public:
736  char *pszFuncName;
737  GDALDataType eSourceTransferType;
738 
739  VRTDerivedRasterBand( GDALDataset *poDS, int nBand );
740  VRTDerivedRasterBand( GDALDataset *poDS, int nBand,
741  GDALDataType eType, int nXSize, int nYSize );
742  virtual ~VRTDerivedRasterBand();
743 
744  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
745  void *, int, int, GDALDataType,
746  GSpacing nPixelSpace, GSpacing nLineSpace,
747  GDALRasterIOExtraArg* psExtraArg ) override;
748 
749  virtual int IGetDataCoverageStatus( int nXOff, int nYOff,
750  int nXSize, int nYSize,
751  int nMaskFlagStop,
752  double* pdfDataPct) override;
753 
754  static CPLErr AddPixelFunction( const char *pszFuncName,
755  GDALDerivedPixelFunc pfnPixelFunc );
756  static GDALDerivedPixelFunc GetPixelFunction( const char *pszFuncName );
757 
758  void SetPixelFunctionName( const char *pszFuncName );
759  void SetSourceTransferType( GDALDataType eDataType );
760  void SetPixelFunctionLanguage( const char* pszLanguage );
761 
762  virtual CPLErr XMLInit( CPLXMLNode *, const char *, void*,
763  std::map<CPLString, GDALDataset*>& ) override;
764  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
765 
766  virtual double GetMinimum( int *pbSuccess = nullptr ) override;
767  virtual double GetMaximum(int *pbSuccess = nullptr ) override;
768  virtual CPLErr ComputeRasterMinMax( int bApproxOK, double* adfMinMax ) override;
769  virtual CPLErr ComputeStatistics( int bApproxOK,
770  double *pdfMin, double *pdfMax,
771  double *pdfMean, double *pdfStdDev,
772  GDALProgressFunc pfnProgress,
773  void *pProgressData ) override;
774  virtual CPLErr GetHistogram( double dfMin, double dfMax,
775  int nBuckets, GUIntBig * panHistogram,
776  int bIncludeOutOfRange, int bApproxOK,
777  GDALProgressFunc pfnProgress,
778  void *pProgressData ) override;
779 
780  static void Cleanup();
781 };
782 
783 /************************************************************************/
784 /* VRTRawRasterBand */
785 /************************************************************************/
786 
787 class RawRasterBand;
788 
789 class CPL_DLL VRTRawRasterBand CPL_NON_FINAL: public VRTRasterBand
790 {
791  RawRasterBand *m_poRawRaster;
792 
793  char *m_pszSourceFilename;
794  int m_bRelativeToVRT;
795 
796  CPL_DISALLOW_COPY_ASSIGN(VRTRawRasterBand)
797 
798  public:
799  VRTRawRasterBand( GDALDataset *poDS, int nBand,
800  GDALDataType eType = GDT_Unknown );
801  virtual ~VRTRawRasterBand();
802 
803  virtual CPLErr XMLInit( CPLXMLNode *, const char *, void*,
804  std::map<CPLString, GDALDataset*>& ) override;
805  virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath ) override;
806 
807  virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
808  void *, int, int, GDALDataType,
809  GSpacing nPixelSpace, GSpacing nLineSpace,
810  GDALRasterIOExtraArg* psExtraArg ) override;
811 
812  virtual CPLErr IReadBlock( int, int, void * ) override;
813  virtual CPLErr IWriteBlock( int, int, void * ) override;
814 
815  CPLErr SetRawLink( const char *pszFilename,
816  const char *pszVRTPath,
817  int bRelativeToVRT,
818  vsi_l_offset nImageOffset,
819  int nPixelOffset, int nLineOffset,
820  const char *pszByteOrder );
821 
822  void ClearRawLink();
823 
824  CPLVirtualMem *GetVirtualMemAuto( GDALRWFlag eRWFlag,
825  int *pnPixelSpace,
826  GIntBig *pnLineSpace,
827  char **papszOptions ) override;
828 
829  virtual void GetFileList( char*** ppapszFileList, int *pnSize,
830  int *pnMaxSize, CPLHashSet* hSetFiles ) override;
831 };
832 
833 /************************************************************************/
834 /* VRTDriver */
835 /************************************************************************/
836 
837 class VRTDriver final: public GDALDriver
838 {
839  CPL_DISALLOW_COPY_ASSIGN(VRTDriver)
840 
841  public:
842  VRTDriver();
843  virtual ~VRTDriver();
844 
845  char **papszSourceParsers;
846 
847  virtual char **GetMetadataDomainList() override;
848  virtual char **GetMetadata( const char * pszDomain = "" ) override;
849  virtual CPLErr SetMetadata( char ** papszMetadata,
850  const char * pszDomain = "" ) override;
851 
852  VRTSource *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath,
853  void* pUniqueHandle,
854  std::map<CPLString, GDALDataset*>& oMapSharedSources );
855  void AddSourceParser( const char *pszElementName,
856  VRTSourceParser pfnParser );
857 };
858 
859 /************************************************************************/
860 /* VRTSimpleSource */
861 /************************************************************************/
862 
863 class CPL_DLL VRTSimpleSource CPL_NON_FINAL: public VRTSource
864 {
865  CPL_DISALLOW_COPY_ASSIGN(VRTSimpleSource)
866 
867 protected:
868  friend class VRTSourcedRasterBand;
869 
870  GDALRasterBand *m_poRasterBand;
871 
872  // When poRasterBand is a mask band, poMaskBandMainBand is the band
873  // from which the mask band is taken.
874  GDALRasterBand *m_poMaskBandMainBand;
875 
876  double m_dfSrcXOff;
877  double m_dfSrcYOff;
878  double m_dfSrcXSize;
879  double m_dfSrcYSize;
880 
881  double m_dfDstXOff;
882  double m_dfDstYOff;
883  double m_dfDstXSize;
884  double m_dfDstYSize;
885 
886  int m_bNoDataSet;
887  double m_dfNoDataValue;
888  CPLString m_osResampling{};
889 
890  int m_nMaxValue;
891 
892  int m_bRelativeToVRTOri;
893  CPLString m_osSourceFileNameOri{};
894  int m_nExplicitSharedStatus; // -1 unknown, 0 = unshared, 1 = shared
895 
896  int NeedMaxValAdjustment() const;
897 
898 public:
899  VRTSimpleSource();
900  VRTSimpleSource( const VRTSimpleSource* poSrcSource,
901  double dfXDstRatio, double dfYDstRatio );
902  virtual ~VRTSimpleSource();
903 
904  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char *, void*,
905  std::map<CPLString, GDALDataset*>& ) override;
906  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
907 
908  void SetSrcBand( GDALRasterBand * );
909  void SetSrcMaskBand( GDALRasterBand * );
910  void SetSrcWindow( double, double, double, double );
911  void SetDstWindow( double, double, double, double );
912  void SetNoDataValue( double dfNoDataValue );
913  const CPLString& GetResampling() const { return m_osResampling; }
914  void SetResampling( const char* pszResampling );
915 
916  int GetSrcDstWindow( int, int, int, int, int, int,
917  double *pdfReqXOff, double *pdfReqYOff,
918  double *pdfReqXSize, double *pdfReqYSize,
919  int *, int *, int *, int *,
920  int *, int *, int *, int * );
921 
922  virtual CPLErr RasterIO( GDALDataType eBandDataType,
923  int nXOff, int nYOff, int nXSize, int nYSize,
924  void *pData, int nBufXSize, int nBufYSize,
925  GDALDataType eBufType,
926  GSpacing nPixelSpace, GSpacing nLineSpace,
927  GDALRasterIOExtraArg* psExtraArgIn ) override;
928 
929  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) override;
930  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) override;
931  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK,
932  double* adfMinMax ) override;
933  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
934  int bApproxOK,
935  double *pdfMin, double *pdfMax,
936  double *pdfMean, double *pdfStdDev,
937  GDALProgressFunc pfnProgress,
938  void *pProgressData ) override;
939  virtual CPLErr GetHistogram( int nXSize, int nYSize,
940  double dfMin, double dfMax,
941  int nBuckets, GUIntBig * panHistogram,
942  int bIncludeOutOfRange, int bApproxOK,
943  GDALProgressFunc pfnProgress,
944  void *pProgressData ) override;
945 
946  void DstToSrc( double dfX, double dfY,
947  double &dfXOut, double &dfYOut ) const;
948  void SrcToDst( double dfX, double dfY,
949  double &dfXOut, double &dfYOut ) const;
950 
951  virtual void GetFileList( char*** ppapszFileList, int *pnSize,
952  int *pnMaxSize, CPLHashSet* hSetFiles ) override;
953 
954  virtual int IsSimpleSource() override { return TRUE; }
955  virtual const char* GetType() { return "SimpleSource"; }
956  virtual CPLErr FlushCache() override;
957 
958  GDALRasterBand* GetBand();
959  GDALRasterBand* GetMaskBandMainBand() { return m_poMaskBandMainBand; }
960  int IsSameExceptBandNumber( VRTSimpleSource* poOtherSource );
961  CPLErr DatasetRasterIO(
962  GDALDataType eBandDataType,
963  int nXOff, int nYOff, int nXSize, int nYSize,
964  void * pData, int nBufXSize, int nBufYSize,
965  GDALDataType eBufType,
966  int nBandCount, int *panBandMap,
967  GSpacing nPixelSpace, GSpacing nLineSpace,
968  GSpacing nBandSpace,
969  GDALRasterIOExtraArg* psExtraArg );
970 
971  void UnsetPreservedRelativeFilenames();
972 
973  void SetMaxValue( int nVal ) { m_nMaxValue = nVal; }
974 };
975 
976 /************************************************************************/
977 /* VRTAveragedSource */
978 /************************************************************************/
979 
980 class VRTAveragedSource final: public VRTSimpleSource
981 {
982  CPL_DISALLOW_COPY_ASSIGN(VRTAveragedSource)
983 
984 public:
985  VRTAveragedSource();
986  virtual CPLErr RasterIO( GDALDataType eBandDataType,
987  int nXOff, int nYOff, int nXSize, int nYSize,
988  void *pData, int nBufXSize, int nBufYSize,
989  GDALDataType eBufType,
990  GSpacing nPixelSpace, GSpacing nLineSpace,
991  GDALRasterIOExtraArg* psExtraArgIn ) override;
992 
993  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) override;
994  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) override;
995  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK,
996  double* adfMinMax ) override;
997  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
998  int bApproxOK,
999  double *pdfMin, double *pdfMax,
1000  double *pdfMean, double *pdfStdDev,
1001  GDALProgressFunc pfnProgress,
1002  void *pProgressData ) override;
1003  virtual CPLErr GetHistogram( int nXSize, int nYSize,
1004  double dfMin, double dfMax,
1005  int nBuckets, GUIntBig * panHistogram,
1006  int bIncludeOutOfRange, int bApproxOK,
1007  GDALProgressFunc pfnProgress,
1008  void *pProgressData ) override;
1009 
1010  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
1011  virtual const char* GetType() override { return "AveragedSource"; }
1012 };
1013 
1014 /************************************************************************/
1015 /* VRTComplexSource */
1016 /************************************************************************/
1017 
1018 typedef enum
1019 {
1020  VRT_SCALING_NONE,
1021  VRT_SCALING_LINEAR,
1022  VRT_SCALING_EXPONENTIAL,
1023 } VRTComplexSourceScaling;
1024 
1025 class CPL_DLL VRTComplexSource CPL_NON_FINAL: public VRTSimpleSource
1026 {
1027  CPL_DISALLOW_COPY_ASSIGN(VRTComplexSource)
1028  bool AreValuesUnchanged() const;
1029 
1030 protected:
1031  VRTComplexSourceScaling m_eScalingType;
1032  double m_dfScaleOff; // For linear scaling.
1033  double m_dfScaleRatio; // For linear scaling.
1034 
1035  // For non-linear scaling with a power function.
1036  int m_bSrcMinMaxDefined;
1037  double m_dfSrcMin;
1038  double m_dfSrcMax;
1039  double m_dfDstMin;
1040  double m_dfDstMax;
1041  double m_dfExponent;
1042 
1043  int m_nColorTableComponent;
1044 
1045  template <class WorkingDT>
1046  CPLErr RasterIOInternal( int nReqXOff, int nReqYOff,
1047  int nReqXSize, int nReqYSize,
1048  void *pData, int nOutXSize, int nOutYSize,
1049  GDALDataType eBufType,
1050  GSpacing nPixelSpace, GSpacing nLineSpace,
1051  GDALRasterIOExtraArg* psExtraArg,
1052  GDALDataType eWrkDataType );
1053 
1054 public:
1055  VRTComplexSource();
1056  VRTComplexSource(const VRTComplexSource* poSrcSource,
1057  double dfXDstRatio, double dfYDstRatio);
1058  virtual ~VRTComplexSource();
1059 
1060  virtual CPLErr RasterIO( GDALDataType eBandDataType,
1061  int nXOff, int nYOff, int nXSize, int nYSize,
1062  void *pData, int nBufXSize, int nBufYSize,
1063  GDALDataType eBufType,
1064  GSpacing nPixelSpace, GSpacing nLineSpace,
1065  GDALRasterIOExtraArg* psExtraArgIn ) override;
1066 
1067  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) override;
1068  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) override;
1069  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK,
1070  double* adfMinMax ) override;
1071  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
1072  int bApproxOK,
1073  double *pdfMin, double *pdfMax,
1074  double *pdfMean, double *pdfStdDev,
1075  GDALProgressFunc pfnProgress,
1076  void *pProgressData ) override;
1077  virtual CPLErr GetHistogram( int nXSize, int nYSize,
1078  double dfMin, double dfMax,
1079  int nBuckets, GUIntBig * panHistogram,
1080  int bIncludeOutOfRange, int bApproxOK,
1081  GDALProgressFunc pfnProgress,
1082  void *pProgressData ) override;
1083 
1084  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
1085  virtual CPLErr XMLInit( CPLXMLNode *, const char *, void*,
1086  std::map<CPLString, GDALDataset*>& ) override;
1087  virtual const char* GetType() override { return "ComplexSource"; }
1088 
1089  double LookupValue( double dfInput );
1090 
1091  void SetLinearScaling( double dfOffset, double dfScale );
1092  void SetPowerScaling( double dfExponent,
1093  double dfSrcMin,
1094  double dfSrcMax,
1095  double dfDstMin,
1096  double dfDstMax );
1097  void SetColorTableComponent( int nComponent );
1098 
1099  double *m_padfLUTInputs;
1100  double *m_padfLUTOutputs;
1101  int m_nLUTItemCount;
1102 };
1103 
1104 /************************************************************************/
1105 /* VRTFilteredSource */
1106 /************************************************************************/
1107 
1108 class VRTFilteredSource CPL_NON_FINAL: public VRTComplexSource
1109 {
1110 private:
1111  int IsTypeSupported( GDALDataType eTestType ) const;
1112 
1113  CPL_DISALLOW_COPY_ASSIGN(VRTFilteredSource)
1114 
1115 protected:
1116  int m_nSupportedTypesCount;
1117  GDALDataType m_aeSupportedTypes[20];
1118 
1119  int m_nExtraEdgePixels;
1120 
1121 public:
1122  VRTFilteredSource();
1123  virtual ~VRTFilteredSource();
1124 
1125  void SetExtraEdgePixels( int );
1126  void SetFilteringDataTypesSupported( int, GDALDataType * );
1127 
1128  virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
1129  GByte *pabySrcData, GByte *pabyDstData ) = 0;
1130 
1131  virtual CPLErr RasterIO( GDALDataType eBandDataType,
1132  int nXOff, int nYOff, int nXSize, int nYSize,
1133  void *pData, int nBufXSize, int nBufYSize,
1134  GDALDataType eBufType,
1135  GSpacing nPixelSpace, GSpacing nLineSpace,
1136  GDALRasterIOExtraArg* psExtraArg ) override;
1137 };
1138 
1139 /************************************************************************/
1140 /* VRTKernelFilteredSource */
1141 /************************************************************************/
1142 
1143 class VRTKernelFilteredSource CPL_NON_FINAL: public VRTFilteredSource
1144 {
1145  CPL_DISALLOW_COPY_ASSIGN(VRTKernelFilteredSource)
1146 
1147 protected:
1148  int m_nKernelSize;
1149 
1150  bool m_bSeparable;
1151 
1152  double *m_padfKernelCoefs;
1153 
1154  int m_bNormalized;
1155 
1156 public:
1157  VRTKernelFilteredSource();
1158  virtual ~VRTKernelFilteredSource();
1159 
1160  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char *, void*,
1161  std::map<CPLString, GDALDataset*>& ) override;
1162  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
1163 
1164  virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
1165  GByte *pabySrcData, GByte *pabyDstData ) override;
1166 
1167  CPLErr SetKernel( int nKernelSize, bool bSeparable, double *padfCoefs );
1168  void SetNormalized( int );
1169 };
1170 
1171 /************************************************************************/
1172 /* VRTAverageFilteredSource */
1173 /************************************************************************/
1174 
1175 class VRTAverageFilteredSource final: public VRTKernelFilteredSource
1176 {
1177  CPL_DISALLOW_COPY_ASSIGN(VRTAverageFilteredSource)
1178 
1179 public:
1180  explicit VRTAverageFilteredSource( int nKernelSize );
1181  virtual ~VRTAverageFilteredSource();
1182 
1183  virtual CPLErr XMLInit( CPLXMLNode *psTree, const char *, void*,
1184  std::map<CPLString, GDALDataset*>& ) override;
1185  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
1186 };
1187 
1188 /************************************************************************/
1189 /* VRTFuncSource */
1190 /************************************************************************/
1191 class VRTFuncSource final: public VRTSource
1192 {
1193  CPL_DISALLOW_COPY_ASSIGN(VRTFuncSource)
1194 
1195 public:
1196  VRTFuncSource();
1197  virtual ~VRTFuncSource();
1198 
1199  virtual CPLErr XMLInit( CPLXMLNode *, const char *, void*,
1200  std::map<CPLString, GDALDataset*>& ) override { return CE_Failure; }
1201  virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) override;
1202 
1203  virtual CPLErr RasterIO( GDALDataType eBandDataType,
1204  int nXOff, int nYOff, int nXSize, int nYSize,
1205  void *pData, int nBufXSize, int nBufYSize,
1206  GDALDataType eBufType,
1207  GSpacing nPixelSpace, GSpacing nLineSpace,
1208  GDALRasterIOExtraArg* psExtraArg ) override;
1209 
1210  virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) override;
1211  virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) override;
1212  virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK,
1213  double* adfMinMax ) override;
1214  virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
1215  int bApproxOK,
1216  double *pdfMin, double *pdfMax,
1217  double *pdfMean, double *pdfStdDev,
1218  GDALProgressFunc pfnProgress,
1219  void *pProgressData ) override;
1220  virtual CPLErr GetHistogram( int nXSize, int nYSize,
1221  double dfMin, double dfMax,
1222  int nBuckets, GUIntBig * panHistogram,
1223  int bIncludeOutOfRange, int bApproxOK,
1224  GDALProgressFunc pfnProgress,
1225  void *pProgressData ) override;
1226 
1227  VRTImageReadFunc pfnReadFunc;
1228  void *pCBData;
1229  GDALDataType eType;
1230 
1231  float fNoDataValue;
1232 };
1233 
1234 /************************************************************************/
1235 /* VRTGroup */
1236 /************************************************************************/
1237 
1238 #ifdef TMPEXPORT
1239 #define TMP_CPL_DLL CPL_DLL
1240 #else
1241 #define TMP_CPL_DLL
1242 #endif
1243 
1244 class VRTMDArray;
1245 class VRTAttribute;
1246 class VRTDimension;
1247 
1248 class VRTGroup final: public GDALGroup
1249 {
1250 public:
1251  struct Ref
1252  {
1253  VRTGroup* m_ptr;
1254  explicit Ref(VRTGroup* ptr): m_ptr(ptr) {}
1255  Ref(const Ref&) = delete;
1256  Ref& operator=(const Ref&) = delete;
1257  };
1258 
1259 private:
1260  std::shared_ptr<Ref> m_poSharedRefRootGroup{};
1261  std::weak_ptr<Ref> m_poWeakRefRootGroup{};
1262  std::shared_ptr<Ref> m_poRefSelf{};
1263 
1264  std::string m_osFilename{};
1265  mutable bool m_bDirty = false;
1266  std::string m_osVRTPath{};
1267  std::map<std::string, std::shared_ptr<VRTGroup>> m_oMapGroups{};
1268  std::map<std::string, std::shared_ptr<VRTMDArray>> m_oMapMDArrays{};
1269  std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
1270  std::map<std::string, std::shared_ptr<VRTDimension>> m_oMapDimensions{};
1271 
1272  std::shared_ptr<VRTGroup> OpenGroupInternal(const std::string& osName) const;
1273  void SetRootGroupRef(const std::weak_ptr<Ref>& rgRef);
1274  std::weak_ptr<Ref> GetRootGroupRef() const;
1275 
1276 public:
1277 
1278  VRTGroup(const std::string& osParentName, const std::string& osName);
1279  ~VRTGroup();
1280 
1281  bool XMLInit(const std::shared_ptr<VRTGroup>& poRoot,
1282  const std::shared_ptr<VRTGroup>& poThisGroup,
1283  const CPLXMLNode* psNode,
1284  const char* pszVRTPath);
1285 
1286  std::vector<std::string> GetMDArrayNames(CSLConstList papszOptions) const override;
1287  std::shared_ptr<GDALMDArray> OpenMDArray(const std::string& osName,
1288  CSLConstList papszOptions = nullptr) const override;
1289 
1290  std::vector<std::string> GetGroupNames(CSLConstList papszOptions) const override;
1291  std::shared_ptr<GDALGroup> OpenGroup(const std::string& osName,
1292  CSLConstList) const override
1293  {
1294  return OpenGroupInternal(osName);
1295  }
1296 
1297  std::vector<std::shared_ptr<GDALDimension>> GetDimensions(CSLConstList) const override;
1298 
1299  std::vector<std::shared_ptr<GDALAttribute>> GetAttributes(CSLConstList) const override;
1300 
1301  std::shared_ptr<VRTDimension> GetDimension(const std::string& name) const {
1302  auto oIter = m_oMapDimensions.find(name);
1303  return oIter == m_oMapDimensions.end() ? nullptr : oIter->second;
1304  }
1305  std::shared_ptr<VRTDimension> GetDimensionFromFullName(const std::string& name,
1306  bool bEmitError) const;
1307 
1308  std::shared_ptr<GDALGroup> CreateGroup(const std::string& osName,
1309  CSLConstList papszOptions = nullptr) override;
1310 
1311  std::shared_ptr<GDALDimension> CreateDimension(const std::string& osName,
1312  const std::string& osType,
1313  const std::string& osDirection,
1314  GUInt64 nSize,
1315  CSLConstList papszOptions = nullptr) override;
1316 
1317  std::shared_ptr<GDALAttribute> CreateAttribute(
1318  const std::string& osName,
1319  const std::vector<GUInt64>& anDimensions,
1320  const GDALExtendedDataType& oDataType,
1321  CSLConstList papszOptions = nullptr) override;
1322 
1323  std::shared_ptr<GDALMDArray> CreateMDArray(const std::string& osName,
1324  const std::vector<std::shared_ptr<GDALDimension>>& aoDimensions,
1325  const GDALExtendedDataType& oDataType,
1326  CSLConstList papszOptions) override;
1327 
1328  void SetIsRootGroup();
1329 
1330  const std::shared_ptr<Ref>& GetRef() const { return m_poRefSelf; }
1331  VRTGroup* GetRootGroup() const;
1332 
1333  const std::string& GetVRTPath() const { return m_osVRTPath; }
1334  void SetDirty();
1335  void SetFilename(const std::string& osFilename) { m_osFilename = osFilename; }
1336  void Serialize() const;
1337  CPLXMLNode* SerializeToXML( const char *pszVRTPathIn ) const;
1338  void Serialize(CPLXMLNode* psParent, const char *pszVRTPathIn) const;
1339 };
1340 
1341 /************************************************************************/
1342 /* VRTDimension */
1343 /************************************************************************/
1344 
1345 class VRTDimension final: public GDALDimension
1346 {
1347  std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
1348  std::string m_osIndexingVariableName;
1349 
1350 public:
1351  VRTDimension(const std::shared_ptr<VRTGroup::Ref>& poGroupRef,
1352  const std::string& osParentName,
1353  const std::string& osName,
1354  const std::string& osType,
1355  const std::string& osDirection,
1356  GUInt64 nSize,
1357  const std::string& osIndexingVariableName):
1358  GDALDimension(osParentName, osName, osType, osDirection, nSize),
1359  m_poGroupRef(poGroupRef),
1360  m_osIndexingVariableName(osIndexingVariableName)
1361  {}
1362 
1363  VRTGroup* GetGroup() const;
1364 
1365  static std::shared_ptr<VRTDimension> Create(const std::shared_ptr<VRTGroup>& poThisGroup,
1366  const std::string& osParentName,
1367  const CPLXMLNode* psNode);
1368 
1369  std::shared_ptr<GDALMDArray> GetIndexingVariable() const override;
1370 
1371  bool SetIndexingVariable(std::shared_ptr<GDALMDArray> poIndexingVariable) override;
1372 
1373  void Serialize(CPLXMLNode* psParent) const;
1374 };
1375 
1376 /************************************************************************/
1377 /* VRTAttribute */
1378 /************************************************************************/
1379 
1380 class VRTAttribute final: public GDALAttribute
1381 {
1382  GDALExtendedDataType m_dt;
1383  std::vector<std::string> m_aosList{};
1384  std::vector<std::shared_ptr<GDALDimension>> m_dims{};
1385 
1386 protected:
1387 
1388  bool IRead(const GUInt64* arrayStartIdx,
1389  const size_t* count,
1390  const GInt64* arrayStep,
1391  const GPtrDiff_t* bufferStride,
1392  const GDALExtendedDataType& bufferDataType,
1393  void* pDstBuffer) const override;
1394 
1395  bool IWrite(const GUInt64* arrayStartIdx,
1396  const size_t* count,
1397  const GInt64* arrayStep,
1398  const GPtrDiff_t* bufferStride,
1399  const GDALExtendedDataType& bufferDataType,
1400  const void* pSrcBuffer) override;
1401 
1402 
1403 public:
1404  VRTAttribute(const std::string& osParentName,
1405  const std::string& osName,
1406  const GDALExtendedDataType& dt,
1407  std::vector<std::string>&& aosList):
1408  GDALAbstractMDArray(osParentName, osName),
1409  GDALAttribute(osParentName, osName),
1410  m_dt(dt),
1411  m_aosList(std::move(aosList))
1412  {
1413  if( m_aosList.size() > 1 )
1414  {
1415  m_dims.emplace_back(std::make_shared<GDALDimension>(
1416  std::string(), "dim",
1417  std::string(), std::string(), m_aosList.size()));
1418  }
1419  }
1420 
1421  VRTAttribute(const std::string& osParentName,
1422  const std::string& osName,
1423  GUInt64 nDim,
1424  const GDALExtendedDataType& dt):
1425  GDALAbstractMDArray(osParentName, osName),
1426  GDALAttribute(osParentName, osName),
1427  m_dt(dt)
1428  {
1429  if( nDim != 0 )
1430  {
1431  m_dims.emplace_back(std::make_shared<GDALDimension>(
1432  std::string(), "dim",
1433  std::string(), std::string(), nDim));
1434  }
1435  }
1436 
1437  static bool CreationCommonChecks(const std::string& osName,
1438  const std::vector<GUInt64>& anDimensions,
1439  const std::map<std::string, std::shared_ptr<VRTAttribute>>& oMapAttributes);
1440 
1441  static std::shared_ptr<VRTAttribute> Create(const std::string& osParentName,
1442  const CPLXMLNode* psNode);
1443 
1444  const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const override { return m_dims; }
1445 
1446  const GDALExtendedDataType &GetDataType() const override { return m_dt; }
1447 
1448  void Serialize(CPLXMLNode* psParent) const;
1449 };
1450 
1451 /************************************************************************/
1452 /* VRTMDArraySource */
1453 /************************************************************************/
1454 
1455 class VRTMDArraySource
1456 {
1457 public:
1458  virtual ~VRTMDArraySource() = default;
1459 
1460  virtual bool Read(const GUInt64* arrayStartIdx,
1461  const size_t* count,
1462  const GInt64* arrayStep,
1463  const GPtrDiff_t* bufferStride,
1464  const GDALExtendedDataType& bufferDataType,
1465  void* pDstBuffer) const = 0;
1466 
1467  virtual void Serialize(CPLXMLNode* psParent, const char* pszVRTPath) const = 0;
1468 };
1469 
1470 /************************************************************************/
1471 /* VRTMDArray */
1472 /************************************************************************/
1473 
1474 class VRTMDArray final: public GDALMDArray
1475 {
1476 protected:
1477  friend class VRTGroup; // for access to SetSelf()
1478 
1479  std::weak_ptr<VRTGroup::Ref> m_poGroupRef;
1480  std::string m_osVRTPath{};
1481 
1482  GDALExtendedDataType m_dt;
1483  std::vector<std::shared_ptr<GDALDimension>> m_dims;
1484  std::map<std::string, std::shared_ptr<VRTAttribute>> m_oMapAttributes{};
1485  std::vector<std::unique_ptr<VRTMDArraySource>> m_sources{};
1486  std::shared_ptr<OGRSpatialReference> m_poSRS{};
1487  std::vector<GByte> m_abyNoData{};
1488  std::string m_osUnit{};
1489  double m_dfScale = 1.0;
1490  double m_dfOffset = 0.0;
1491  bool m_bHasScale = false;
1492  bool m_bHasOffset = false;
1493 
1494  bool IRead(const GUInt64* arrayStartIdx,
1495  const size_t* count,
1496  const GInt64* arrayStep,
1497  const GPtrDiff_t* bufferStride,
1498  const GDALExtendedDataType& bufferDataType,
1499  void* pDstBuffer) const override;
1500 
1501  void SetDirty();
1502 
1503 public:
1504  VRTMDArray(const std::shared_ptr<VRTGroup::Ref>& poGroupRef,
1505  const std::string& osParentName,
1506  const std::string& osName,
1507  const GDALExtendedDataType& dt,
1508  std::vector<std::shared_ptr<GDALDimension>>&& dims,
1509  std::map<std::string, std::shared_ptr<VRTAttribute>>&& oMapAttributes) :
1510  GDALAbstractMDArray(osParentName, osName),
1511  GDALMDArray(osParentName, osName),
1512  m_poGroupRef(poGroupRef),
1513  m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()),
1514  m_dt(dt),
1515  m_dims(std::move(dims)),
1516  m_oMapAttributes(std::move(oMapAttributes))
1517  {
1518  }
1519 
1520  VRTMDArray(const std::shared_ptr<VRTGroup::Ref>& poGroupRef,
1521  const std::string& osParentName,
1522  const std::string& osName,
1523  const std::vector<std::shared_ptr<GDALDimension>>& dims,
1524  const GDALExtendedDataType& dt) :
1525  GDALAbstractMDArray(osParentName, osName),
1526  GDALMDArray(osParentName, osName),
1527  m_poGroupRef(poGroupRef),
1528  m_osVRTPath(poGroupRef->m_ptr->GetVRTPath()),
1529  m_dt(dt),
1530  m_dims(dims)
1531  {
1532  }
1533 
1534  bool IsWritable() const override { return false; }
1535 
1536  static std::shared_ptr<VRTMDArray> Create(const std::shared_ptr<VRTGroup>& poThisGroup,
1537  const std::string& osParentName,
1538  const CPLXMLNode* psNode);
1539 
1540  const std::vector<std::shared_ptr<GDALDimension>>& GetDimensions() const override { return m_dims; }
1541 
1542  std::vector<std::shared_ptr<GDALAttribute>> GetAttributes(CSLConstList) const override;
1543 
1544  const GDALExtendedDataType &GetDataType() const override { return m_dt; }
1545 
1546  bool SetSpatialRef(const OGRSpatialReference* poSRS) override;
1547 
1548  std::shared_ptr<OGRSpatialReference> GetSpatialRef() const override { return m_poSRS; }
1549 
1550  const void* GetRawNoDataValue() const override;
1551 
1552  bool SetRawNoDataValue(const void* pRawNoData) override;
1553 
1554  const std::string& GetUnit() const override { return m_osUnit; }
1555 
1556  bool SetUnit(const std::string& osUnit) override {
1557  m_osUnit = osUnit; return true; }
1558 
1559  double GetOffset(bool* pbHasOffset) const override
1560  {
1561  if( pbHasOffset) *pbHasOffset = m_bHasOffset;
1562  return m_dfOffset;
1563  }
1564 
1565  double GetScale(bool* pbHasScale) const override
1566  {
1567  if( pbHasScale) *pbHasScale = m_bHasScale;
1568  return m_dfScale;
1569  }
1570 
1571  bool SetOffset(double dfOffset) override
1572  { SetDirty(); m_bHasOffset = true; m_dfOffset = dfOffset; return true; }
1573 
1574  bool SetScale(double dfScale) override
1575  { SetDirty(); m_bHasScale = true; m_dfScale = dfScale; return true; }
1576 
1577  void AddSource(std::unique_ptr<VRTMDArraySource>&& poSource);
1578 
1579  std::shared_ptr<GDALAttribute> CreateAttribute(
1580  const std::string& osName,
1581  const std::vector<GUInt64>& anDimensions,
1582  const GDALExtendedDataType& oDataType,
1583  CSLConstList papszOptions = nullptr) override;
1584 
1585  bool CopyFrom(GDALDataset* poSrcDS,
1586  const GDALMDArray* poSrcArray,
1587  bool bStrict,
1588  GUInt64& nCurCost,
1589  const GUInt64 nTotalCost,
1590  GDALProgressFunc pfnProgress,
1591  void * pProgressData) override;
1592 
1593  void Serialize(CPLXMLNode* psParent, const char *pszVRTPathIn ) const;
1594 
1595  VRTGroup* GetGroup() const;
1596 
1597  const std::string& GetVRTPath() const { return m_osVRTPath; }
1598 };
1599 
1600 /************************************************************************/
1601 /* VRTMDArraySourceInlinedValues */
1602 /************************************************************************/
1603 
1604 class VRTMDArraySourceInlinedValues final: public VRTMDArraySource
1605 {
1606  const VRTMDArray* m_poDstArray = nullptr;
1607  bool m_bIsConstantValue;
1608  std::vector<GUInt64> m_anOffset{};
1609  std::vector<size_t> m_anCount{};
1610  std::vector<GByte> m_abyValues{};
1611  std::vector<size_t> m_anInlinedArrayStrideInBytes{};
1612  GDALExtendedDataType m_dt;
1613 
1614  VRTMDArraySourceInlinedValues(const VRTMDArraySourceInlinedValues&) = delete;
1615  VRTMDArraySourceInlinedValues& operator=(const VRTMDArraySourceInlinedValues&) = delete;
1616 
1617 public:
1618  VRTMDArraySourceInlinedValues(const VRTMDArray* poDstArray,
1619  bool bIsConstantValue,
1620  std::vector<GUInt64>&& anOffset,
1621  std::vector<size_t>&& anCount,
1622  std::vector<GByte>&& abyValues):
1623  m_poDstArray(poDstArray),
1624  m_bIsConstantValue(bIsConstantValue),
1625  m_anOffset(std::move(anOffset)),
1626  m_anCount(std::move(anCount)),
1627  m_abyValues(std::move(abyValues)),
1628  m_dt(poDstArray->GetDataType())
1629  {
1630  const auto nDims(poDstArray->GetDimensionCount());
1631  m_anInlinedArrayStrideInBytes.resize(nDims);
1632  if( !bIsConstantValue && nDims > 0 )
1633  {
1634  m_anInlinedArrayStrideInBytes.back() = poDstArray->GetDataType().GetSize();
1635  for(size_t i = nDims - 1; i > 0; )
1636  {
1637  --i;
1638  m_anInlinedArrayStrideInBytes[i] =
1639  m_anInlinedArrayStrideInBytes[i+1] * m_anCount[i+1];
1640  }
1641  }
1642  }
1643 
1644  ~VRTMDArraySourceInlinedValues();
1645 
1646  static std::unique_ptr<VRTMDArraySourceInlinedValues> Create(
1647  const VRTMDArray* poDstArray,
1648  const CPLXMLNode* psNode);
1649 
1650  bool Read(const GUInt64* arrayStartIdx,
1651  const size_t* count,
1652  const GInt64* arrayStep,
1653  const GPtrDiff_t* bufferStride,
1654  const GDALExtendedDataType& bufferDataType,
1655  void* pDstBuffer) const override;
1656 
1657  void Serialize(CPLXMLNode* psParent, const char* pszVRTPath) const override;
1658 };
1659 
1660 /************************************************************************/
1661 /* VRTMDArraySourceRegularlySpaced */
1662 /************************************************************************/
1663 
1664 class VRTMDArraySourceRegularlySpaced final: public VRTMDArraySource
1665 {
1666  double m_dfStart;
1667  double m_dfIncrement;
1668 
1669 public:
1670  VRTMDArraySourceRegularlySpaced(
1671  double dfStart, double dfIncrement):
1672  m_dfStart(dfStart),
1673  m_dfIncrement(dfIncrement)
1674  {
1675  }
1676 
1677  bool Read(const GUInt64* arrayStartIdx,
1678  const size_t* count,
1679  const GInt64* arrayStep,
1680  const GPtrDiff_t* bufferStride,
1681  const GDALExtendedDataType& bufferDataType,
1682  void* pDstBuffer) const override;
1683 
1684  void Serialize(CPLXMLNode* psParent, const char* pszVRTPath) const override;
1685 };
1686 
1687 /************************************************************************/
1688 /* VRTMDArraySourceFromArray */
1689 /************************************************************************/
1690 
1691 class VRTMDArraySourceFromArray final: public VRTMDArraySource
1692 {
1693  const VRTMDArray* m_poDstArray = nullptr;
1694  bool m_bRelativeToVRTSet = false;
1695  bool m_bRelativeToVRT = false;
1696  std::string m_osFilename{};
1697  std::string m_osArray{};
1698  std::string m_osBand{};
1699  std::vector<int> m_anTransposedAxis{};
1700  std::string m_osViewExpr{};
1701  std::vector<GUInt64> m_anSrcOffset{};
1702  mutable std::vector<GUInt64> m_anCount{};
1703  std::vector<GUInt64> m_anStep{};
1704  std::vector<GUInt64> m_anDstOffset{};
1705 
1706  VRTMDArraySourceFromArray(const VRTMDArraySourceFromArray&) = delete;
1707  VRTMDArraySourceFromArray& operator=(const VRTMDArraySourceFromArray&) = delete;
1708 
1709 public:
1710  VRTMDArraySourceFromArray(const VRTMDArray* poDstArray,
1711  bool bRelativeToVRTSet,
1712  bool bRelativeToVRT,
1713  const std::string& osFilename,
1714  const std::string& osArray,
1715  const std::string& osBand,
1716  std::vector<int>&& anTransposedAxis,
1717  const std::string& osViewExpr,
1718  std::vector<GUInt64>&& anSrcOffset,
1719  std::vector<GUInt64>&& anCount,
1720  std::vector<GUInt64>&& anStep,
1721  std::vector<GUInt64>&& anDstOffset):
1722  m_poDstArray(poDstArray),
1723  m_bRelativeToVRTSet(bRelativeToVRTSet),
1724  m_bRelativeToVRT(bRelativeToVRT),
1725  m_osFilename(osFilename),
1726  m_osArray(osArray),
1727  m_osBand(osBand),
1728  m_anTransposedAxis(std::move(anTransposedAxis)),
1729  m_osViewExpr(osViewExpr),
1730  m_anSrcOffset(std::move(anSrcOffset)),
1731  m_anCount(std::move(anCount)),
1732  m_anStep(std::move(anStep)),
1733  m_anDstOffset(std::move(anDstOffset))
1734  {
1735  }
1736 
1737  ~VRTMDArraySourceFromArray() override;
1738 
1739  static std::unique_ptr<VRTMDArraySourceFromArray> Create(
1740  const VRTMDArray* poDstArray,
1741  const CPLXMLNode* psNode);
1742 
1743  bool Read(const GUInt64* arrayStartIdx,
1744  const size_t* count,
1745  const GInt64* arrayStep,
1746  const GPtrDiff_t* bufferStride,
1747  const GDALExtendedDataType& bufferDataType,
1748  void* pDstBuffer) const override;
1749 
1750  void Serialize(CPLXMLNode* psParent, const char* pszVRTPath) const override;
1751 };
1752 
1753 #endif /* #ifndef DOXYGEN_SKIP */
1754 
1755 #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
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
GPtrDiff_t
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:289
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