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