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