Coverage Report

Created: 2026-07-25 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/frmts/vrt/vrtdriver.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  Virtual GDAL Datasets
4
 * Purpose:  Implementation of VRTDriver
5
 * Author:   Frank Warmerdam <warmerdam@pobox.com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2003, Frank Warmerdam <warmerdam@pobox.com>
9
 * Copyright (c) 2009-2013, Even Rouault <even dot rouault at spatialys.com>
10
 *
11
 * SPDX-License-Identifier: MIT
12
 ****************************************************************************/
13
14
#include "vrtdataset.h"
15
16
#include "cpl_minixml.h"
17
#include "cpl_string.h"
18
#include "gdal_alg_priv.h"
19
#include "gdal_frmts.h"
20
#include "gdal_priv.h"
21
#include "vrtexpression.h"
22
23
#include <mutex>
24
25
/*! @cond Doxygen_Suppress */
26
27
/************************************************************************/
28
/*                             VRTDriver()                              */
29
/************************************************************************/
30
31
0
VRTDriver::VRTDriver() : papszSourceParsers(nullptr)
32
0
{
33
#if 0
34
    pDeserializerData = GDALRegisterTransformDeserializer(
35
        "WarpedOverviewTransformer",
36
        VRTWarpedOverviewTransform,
37
        VRTDeserializeWarpedOverviewTransformer );
38
#endif
39
0
}
40
41
/************************************************************************/
42
/*                             ~VRTDriver()                             */
43
/************************************************************************/
44
45
VRTDriver::~VRTDriver()
46
47
0
{
48
0
    CSLDestroy(papszSourceParsers);
49
0
    VRTDerivedRasterBand::Cleanup();
50
#if 0
51
    if(  pDeserializerData )
52
    {
53
        GDALUnregisterTransformDeserializer( pDeserializerData );
54
    }
55
#endif
56
0
}
57
58
/************************************************************************/
59
/*                       GetMetadataDomainList()                        */
60
/************************************************************************/
61
62
char **VRTDriver::GetMetadataDomainList()
63
0
{
64
0
    return BuildMetadataDomainList(GDALDriver::GetMetadataDomainList(), TRUE,
65
0
                                   "SourceParsers", nullptr);
66
0
}
67
68
/************************************************************************/
69
/*                            GetMetadata()                             */
70
/************************************************************************/
71
72
CSLConstList VRTDriver::GetMetadata(const char *pszDomain)
73
74
0
{
75
0
    std::lock_guard oLock(m_oMutex);
76
0
    if (pszDomain && EQUAL(pszDomain, "SourceParsers"))
77
0
        return papszSourceParsers;
78
79
0
    return GDALDriver::GetMetadata(pszDomain);
80
0
}
81
82
/************************************************************************/
83
/*                            SetMetadata()                             */
84
/************************************************************************/
85
86
CPLErr VRTDriver::SetMetadata(CSLConstList papszMetadata, const char *pszDomain)
87
88
0
{
89
0
    std::lock_guard oLock(m_oMutex);
90
0
    if (pszDomain && EQUAL(pszDomain, "SourceParsers"))
91
0
    {
92
0
        m_oMapSourceParser.clear();
93
0
        CSLDestroy(papszSourceParsers);
94
0
        papszSourceParsers = CSLDuplicate(papszMetadata);
95
0
        return CE_None;
96
0
    }
97
98
0
    return GDALDriver::SetMetadata(papszMetadata, pszDomain);
99
0
}
100
101
/************************************************************************/
102
/*                          AddSourceParser()                           */
103
/************************************************************************/
104
105
void VRTDriver::AddSourceParser(const char *pszElementName,
106
                                VRTSourceParser pfnParser)
107
108
0
{
109
0
    m_oMapSourceParser[pszElementName] = pfnParser;
110
111
    // Below won't work on architectures with "capability pointers"
112
113
0
    char szPtrValue[128] = {'\0'};
114
0
    void *ptr;
115
0
    CPL_STATIC_ASSERT(sizeof(pfnParser) == sizeof(void *));
116
0
    memcpy(&ptr, &pfnParser, sizeof(void *));
117
0
    int nRet = CPLPrintPointer(szPtrValue, ptr, sizeof(szPtrValue));
118
0
    szPtrValue[nRet] = 0;
119
120
0
    papszSourceParsers =
121
0
        CSLSetNameValue(papszSourceParsers, pszElementName, szPtrValue);
122
0
}
123
124
/************************************************************************/
125
/*                            ParseSource()                             */
126
/************************************************************************/
127
128
VRTSource *VRTDriver::ParseSource(const CPLXMLNode *psSrc,
129
                                  const char *pszVRTPath,
130
                                  VRTMapSharedResources &oMapSharedSources)
131
132
0
{
133
134
0
    if (psSrc == nullptr || psSrc->eType != CXT_Element)
135
0
    {
136
0
        CPLError(CE_Failure, CPLE_AppDefined,
137
0
                 "Corrupt or empty VRT source XML document.");
138
0
        return nullptr;
139
0
    }
140
141
0
    if (!m_oMapSourceParser.empty())
142
0
    {
143
0
        auto oIter = m_oMapSourceParser.find(psSrc->pszValue);
144
0
        if (oIter != m_oMapSourceParser.end())
145
0
        {
146
0
            return oIter->second(psSrc, pszVRTPath, oMapSharedSources);
147
0
        }
148
0
        return nullptr;
149
0
    }
150
151
    // Below won't work on architectures with "capability pointers"
152
153
0
    const char *pszParserFunc =
154
0
        CSLFetchNameValue(papszSourceParsers, psSrc->pszValue);
155
0
    if (pszParserFunc == nullptr)
156
0
        return nullptr;
157
158
0
    VRTSourceParser pfnParser;
159
0
    CPL_STATIC_ASSERT(sizeof(pfnParser) == sizeof(void *));
160
0
    void *ptr =
161
0
        CPLScanPointer(pszParserFunc, static_cast<int>(strlen(pszParserFunc)));
162
0
    memcpy(&pfnParser, &ptr, sizeof(void *));
163
164
0
    if (pfnParser == nullptr)
165
0
        return nullptr;
166
167
0
    return pfnParser(psSrc, pszVRTPath, oMapSharedSources);
168
0
}
169
170
/************************************************************************/
171
/*                           VRTCreateCopy()                            */
172
/************************************************************************/
173
174
static GDALDataset *VRTCreateCopy(const char *pszFilename, GDALDataset *poSrcDS,
175
                                  int /* bStrict */, CSLConstList papszOptions,
176
                                  GDALProgressFunc pfnProgress,
177
                                  void *pProgressData)
178
0
{
179
0
    CPLAssert(nullptr != poSrcDS);
180
181
0
    VRTDataset *poSrcVRTDS = nullptr;
182
183
0
    void *pHandle = poSrcDS->GetInternalHandle("VRT_DATASET");
184
0
    if (pHandle && poSrcDS->GetInternalHandle(nullptr) == nullptr)
185
0
    {
186
0
        poSrcVRTDS = static_cast<VRTDataset *>(pHandle);
187
0
    }
188
0
    else
189
0
    {
190
0
        poSrcVRTDS = dynamic_cast<VRTDataset *>(poSrcDS);
191
0
    }
192
193
    /* -------------------------------------------------------------------- */
194
    /*      If the source dataset is a virtual dataset then just write      */
195
    /*      it to disk as a special case to avoid extra layers of           */
196
    /*      indirection.                                                    */
197
    /* -------------------------------------------------------------------- */
198
0
    if (poSrcVRTDS)
199
0
    {
200
201
        /* --------------------------------------------------------------------
202
         */
203
        /*      Convert tree to a single block of XML text. */
204
        /* --------------------------------------------------------------------
205
         */
206
0
        char *pszVRTPath = CPLStrdup(CPLGetPathSafe(pszFilename).c_str());
207
0
        poSrcVRTDS->UnsetPreservedRelativeFilenames();
208
0
        CPLXMLNode *psDSTree = poSrcVRTDS->SerializeToXML(pszVRTPath);
209
210
0
        char *pszXML = CPLSerializeXMLTree(psDSTree);
211
212
0
        CPLDestroyXMLNode(psDSTree);
213
214
0
        CPLFree(pszVRTPath);
215
216
        /* --------------------------------------------------------------------
217
         */
218
        /*      Write to disk. */
219
        /* --------------------------------------------------------------------
220
         */
221
0
        GDALDataset *pCopyDS = nullptr;
222
223
0
        if (0 != strlen(pszFilename))
224
0
        {
225
0
            VSILFILE *fpVRT = VSIFOpenL(pszFilename, "wb");
226
0
            if (fpVRT == nullptr)
227
0
            {
228
0
                CPLError(CE_Failure, CPLE_AppDefined, "Cannot create %s",
229
0
                         pszFilename);
230
0
                CPLFree(pszXML);
231
0
                return nullptr;
232
0
            }
233
234
0
            bool bRet = VSIFWriteL(pszXML, strlen(pszXML), 1, fpVRT) > 0;
235
0
            if (VSIFCloseL(fpVRT) != 0)
236
0
                bRet = false;
237
238
0
            if (bRet)
239
0
                pCopyDS = GDALDataset::Open(
240
0
                    pszFilename,
241
0
                    GDAL_OF_RASTER | GDAL_OF_MULTIDIM_RASTER | GDAL_OF_UPDATE);
242
0
        }
243
0
        else
244
0
        {
245
            /* No destination file is given, so pass serialized XML directly. */
246
0
            pCopyDS = GDALDataset::Open(pszXML, GDAL_OF_RASTER |
247
0
                                                    GDAL_OF_MULTIDIM_RASTER |
248
0
                                                    GDAL_OF_UPDATE);
249
0
        }
250
251
0
        CPLFree(pszXML);
252
253
0
        return pCopyDS;
254
0
    }
255
256
    /* -------------------------------------------------------------------- */
257
    /*      Multidimensional raster ?                                       */
258
    /* -------------------------------------------------------------------- */
259
0
    auto poSrcGroup = poSrcDS->GetRootGroup();
260
0
    if (poSrcGroup != nullptr)
261
0
    {
262
0
        auto poDstDS = VRTDataset::CreateVRTMultiDimensional(pszFilename,
263
0
                                                             nullptr, nullptr);
264
0
        if (!poDstDS)
265
0
            return nullptr;
266
0
        auto poDstGroup = poDstDS->GetRootVRTGroup();
267
0
        if (!poDstGroup)
268
0
            return nullptr;
269
0
        poDstGroup->SetGuessRegularlySpacedArrays(
270
0
            CPLTestBool(CSLFetchNameValueDef(
271
0
                papszOptions, "GUESS_REGULARLY_SPACED_ARRAYS", "YES")));
272
0
        if (GDALDriver::DefaultCreateCopyMultiDimensional(
273
0
                poSrcDS, poDstDS.get(), false, nullptr, nullptr, nullptr) !=
274
0
            CE_None)
275
0
            return nullptr;
276
0
        if (pfnProgress)
277
0
            pfnProgress(1.0, "", pProgressData);
278
0
        return poDstDS.release();
279
0
    }
280
281
    /* -------------------------------------------------------------------- */
282
    /*      Create the virtual dataset.                                     */
283
    /* -------------------------------------------------------------------- */
284
0
    auto poVRTDS = VRTDataset::CreateVRTDataset(
285
0
        pszFilename, poSrcDS->GetRasterXSize(), poSrcDS->GetRasterYSize(), 0,
286
0
        GDT_UInt8, papszOptions);
287
0
    if (poVRTDS == nullptr)
288
0
        return nullptr;
289
290
    /* -------------------------------------------------------------------- */
291
    /*      Do we have a geotransform?                                      */
292
    /* -------------------------------------------------------------------- */
293
0
    GDALGeoTransform gt;
294
0
    if (poSrcDS->GetGeoTransform(gt) == CE_None)
295
0
    {
296
0
        poVRTDS->SetGeoTransform(gt);
297
0
    }
298
299
    /* -------------------------------------------------------------------- */
300
    /*      Copy projection                                                 */
301
    /* -------------------------------------------------------------------- */
302
0
    poVRTDS->SetSpatialRef(poSrcDS->GetSpatialRef());
303
304
    /* -------------------------------------------------------------------- */
305
    /*      Emit dataset level metadata.                                    */
306
    /* -------------------------------------------------------------------- */
307
0
    const char *pszCopySrcMDD =
308
0
        CSLFetchNameValueDef(papszOptions, "COPY_SRC_MDD", "AUTO");
309
0
    char **papszSrcMDD = CSLFetchNameValueMultiple(papszOptions, "SRC_MDD");
310
0
    if (EQUAL(pszCopySrcMDD, "AUTO") || CPLTestBool(pszCopySrcMDD) ||
311
0
        papszSrcMDD)
312
0
    {
313
0
        if (!papszSrcMDD || CSLFindString(papszSrcMDD, "") >= 0 ||
314
0
            CSLFindString(papszSrcMDD, "_DEFAULT_") >= 0)
315
0
        {
316
0
            poVRTDS->SetMetadata(poSrcDS->GetMetadata());
317
0
        }
318
319
        /* -------------------------------------------------------------------- */
320
        /*      Copy any special domains that should be transportable.          */
321
        /* -------------------------------------------------------------------- */
322
0
        constexpr const char *apszDefaultDomains[] = {
323
0
            GDAL_MDD_RPC, GDAL_MDD_IMD, GDAL_MDD_GEOLOCATION};
324
0
        for (const char *pszDomain : apszDefaultDomains)
325
0
        {
326
0
            if (!papszSrcMDD || CSLFindString(papszSrcMDD, pszDomain) >= 0)
327
0
            {
328
0
                CSLConstList papszMD = poSrcDS->GetMetadata(pszDomain);
329
0
                if (papszMD)
330
0
                    poVRTDS->SetMetadata(papszMD, pszDomain);
331
0
            }
332
0
        }
333
334
0
        if ((!EQUAL(pszCopySrcMDD, "AUTO") && CPLTestBool(pszCopySrcMDD)) ||
335
0
            papszSrcMDD)
336
0
        {
337
0
            char **papszDomainList = poSrcDS->GetMetadataDomainList();
338
0
            constexpr const char *apszReservedDomains[] = {
339
0
                GDAL_MDD_IMAGE_STRUCTURE, "DERIVED_SUBDATASETS"};
340
0
            for (char **papszIter = papszDomainList; papszIter && *papszIter;
341
0
                 ++papszIter)
342
0
            {
343
0
                const char *pszDomain = *papszIter;
344
0
                if (pszDomain[0] != 0 &&
345
0
                    (!papszSrcMDD ||
346
0
                     CSLFindString(papszSrcMDD, pszDomain) >= 0))
347
0
                {
348
0
                    bool bCanCopy = true;
349
0
                    for (const char *pszOtherDomain : apszDefaultDomains)
350
0
                    {
351
0
                        if (EQUAL(pszDomain, pszOtherDomain))
352
0
                        {
353
0
                            bCanCopy = false;
354
0
                            break;
355
0
                        }
356
0
                    }
357
0
                    if (!papszSrcMDD)
358
0
                    {
359
0
                        for (const char *pszOtherDomain : apszReservedDomains)
360
0
                        {
361
0
                            if (EQUAL(pszDomain, pszOtherDomain))
362
0
                            {
363
0
                                bCanCopy = false;
364
0
                                break;
365
0
                            }
366
0
                        }
367
0
                    }
368
0
                    if (bCanCopy)
369
0
                    {
370
0
                        poVRTDS->SetMetadata(poSrcDS->GetMetadata(pszDomain),
371
0
                                             pszDomain);
372
0
                    }
373
0
                }
374
0
            }
375
0
            CSLDestroy(papszDomainList);
376
0
        }
377
0
    }
378
0
    CSLDestroy(papszSrcMDD);
379
380
0
    {
381
0
        const char *pszInterleave = poSrcDS->GetMetadataItem(
382
0
            GDALMD_INTERLEAVE, GDAL_MDD_IMAGE_STRUCTURE);
383
0
        if (pszInterleave)
384
0
        {
385
0
            poVRTDS->SetMetadataItem(GDALMD_INTERLEAVE, pszInterleave,
386
0
                                     GDAL_MDD_IMAGE_STRUCTURE);
387
0
        }
388
0
    }
389
0
    {
390
0
        const char *pszCompression = poSrcDS->GetMetadataItem(
391
0
            GDALMD_COMPRESSION, GDAL_MDD_IMAGE_STRUCTURE);
392
0
        if (pszCompression)
393
0
        {
394
0
            poVRTDS->SetMetadataItem(GDALMD_COMPRESSION, pszCompression,
395
0
                                     GDAL_MDD_IMAGE_STRUCTURE);
396
0
        }
397
0
    }
398
399
    /* -------------------------------------------------------------------- */
400
    /*      GCPs                                                            */
401
    /* -------------------------------------------------------------------- */
402
0
    if (poSrcDS->GetGCPCount() > 0)
403
0
    {
404
0
        poVRTDS->SetGCPs(poSrcDS->GetGCPCount(), poSrcDS->GetGCPs(),
405
0
                         poSrcDS->GetGCPSpatialRef());
406
0
    }
407
408
    /* -------------------------------------------------------------------- */
409
    /*      Loop over all the bands.                                        */
410
    /* -------------------------------------------------------------------- */
411
0
    for (int iBand = 0; iBand < poSrcDS->GetRasterCount(); iBand++)
412
0
    {
413
0
        GDALRasterBand *poSrcBand = poSrcDS->GetRasterBand(iBand + 1);
414
415
        /* --------------------------------------------------------------------
416
         */
417
        /*      Create the band with the appropriate band type. */
418
        /* --------------------------------------------------------------------
419
         */
420
0
        CPLStringList aosAddBandOptions;
421
0
        int nBlockXSize = poVRTDS->GetBlockXSize();
422
0
        int nBlockYSize = poVRTDS->GetBlockYSize();
423
0
        if (!poVRTDS->IsBlockSizeSpecified())
424
0
        {
425
0
            poSrcBand->GetBlockSize(&nBlockXSize, &nBlockYSize);
426
0
        }
427
0
        aosAddBandOptions.SetNameValue("BLOCKXSIZE",
428
0
                                       CPLSPrintf("%d", nBlockXSize));
429
0
        aosAddBandOptions.SetNameValue("BLOCKYSIZE",
430
0
                                       CPLSPrintf("%d", nBlockYSize));
431
0
        poVRTDS->AddBand(poSrcBand->GetRasterDataType(), aosAddBandOptions);
432
433
0
        VRTSourcedRasterBand *poVRTBand = static_cast<VRTSourcedRasterBand *>(
434
0
            poVRTDS->GetRasterBand(iBand + 1));
435
436
        /* --------------------------------------------------------------------
437
         */
438
        /*      Setup source mapping. */
439
        /* --------------------------------------------------------------------
440
         */
441
0
        poVRTBand->AddSimpleSource(poSrcBand);
442
443
        /* --------------------------------------------------------------------
444
         */
445
        /*      Emit various band level metadata. */
446
        /* --------------------------------------------------------------------
447
         */
448
0
        poVRTBand->CopyCommonInfoFrom(poSrcBand);
449
450
0
        const char *pszCompression = poSrcBand->GetMetadataItem(
451
0
            GDALMD_COMPRESSION, GDAL_MDD_IMAGE_STRUCTURE);
452
0
        if (pszCompression)
453
0
        {
454
0
            poVRTBand->SetMetadataItem(GDALMD_COMPRESSION, pszCompression,
455
0
                                       GDAL_MDD_IMAGE_STRUCTURE);
456
0
        }
457
458
        /* --------------------------------------------------------------------
459
         */
460
        /*      Add specific mask band. */
461
        /* --------------------------------------------------------------------
462
         */
463
0
        if ((poSrcBand->GetMaskFlags() &
464
0
             (GMF_PER_DATASET | GMF_ALL_VALID | GMF_NODATA)) == 0)
465
0
        {
466
0
            auto poVRTMaskBand = std::make_unique<VRTSourcedRasterBand>(
467
0
                poVRTDS.get(), 0, poSrcBand->GetMaskBand()->GetRasterDataType(),
468
0
                poSrcDS->GetRasterXSize(), poSrcDS->GetRasterYSize());
469
0
            poVRTMaskBand->AddMaskBandSource(poSrcBand);
470
0
            poVRTBand->SetMaskBand(std::move(poVRTMaskBand));
471
0
        }
472
0
    }
473
474
    /* -------------------------------------------------------------------- */
475
    /*      Add dataset mask band                                           */
476
    /* -------------------------------------------------------------------- */
477
0
    if (poSrcDS->GetRasterCount() != 0 &&
478
0
        poSrcDS->GetRasterBand(1) != nullptr &&
479
0
        poSrcDS->GetRasterBand(1)->GetMaskFlags() == GMF_PER_DATASET)
480
0
    {
481
0
        GDALRasterBand *poSrcBand = poSrcDS->GetRasterBand(1);
482
0
        auto poVRTMaskBand = std::make_unique<VRTSourcedRasterBand>(
483
0
            poVRTDS.get(), 0, poSrcBand->GetMaskBand()->GetRasterDataType(),
484
0
            poSrcDS->GetRasterXSize(), poSrcDS->GetRasterYSize());
485
0
        poVRTMaskBand->AddMaskBandSource(poSrcBand);
486
0
        poVRTDS->SetMaskBand(std::move(poVRTMaskBand));
487
0
    }
488
489
0
    if (strcmp(pszFilename, "") != 0)
490
0
    {
491
0
        CPLErrorReset();
492
0
        poVRTDS->FlushCache(true);
493
0
        if (CPLGetLastErrorType() != CE_None)
494
0
        {
495
0
            poVRTDS.reset();
496
0
        }
497
0
    }
498
499
0
    if (pfnProgress)
500
0
        pfnProgress(1.0, "", pProgressData);
501
502
0
    return poVRTDS.release();
503
0
}
504
505
/************************************************************************/
506
/*                          GDALRegister_VRT()                          */
507
/************************************************************************/
508
509
void GDALRegister_VRT()
510
511
0
{
512
0
    auto poDM = GetGDALDriverManager();
513
0
    if (poDM->GetDriverByName("VRT") != nullptr)
514
0
        return;
515
516
0
    static std::once_flag flag;
517
0
    std::call_once(flag,
518
0
                   []()
519
0
                   {
520
                       // First register the pixel functions
521
0
                       GDALRegisterDefaultPixelFunc();
522
523
                       // Register functions for VRTProcessedDataset
524
0
                       GDALVRTRegisterDefaultProcessedDatasetFuncs();
525
0
                   });
526
527
0
    VRTDriver *poDriver = new VRTDriver();
528
529
0
    poDriver->SetDescription("VRT");
530
0
    poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
531
0
    poDriver->SetMetadataItem(GDAL_DCAP_MULTIDIM_RASTER, "YES");
532
0
    poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Virtual Raster");
533
0
    poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "vrt");
534
0
    poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/vrt.html");
535
0
    poDriver->SetMetadataItem(
536
0
        GDAL_DMD_CREATIONDATATYPES,
537
0
        "Byte Int8 Int16 UInt16 Int32 UInt32 Int64 UInt64 "
538
0
        "Float16 Float32 Float64 "
539
0
        "CInt16 CInt32 CFloat16 CFloat32 CFloat64");
540
0
    poDriver->SetMetadataItem(
541
0
        GDAL_DMD_CREATIONOPTIONLIST,
542
0
        "<CreationOptionList>\n"
543
0
        "   <Option name='SUBCLASS' type='string-select' "
544
0
        "default='VRTDataset'>\n"
545
0
        "       <Value>VRTDataset</Value>\n"
546
0
        "       <Value>VRTWarpedDataset</Value>\n"
547
0
        "   </Option>\n"
548
0
        "   <Option name='BLOCKXSIZE' type='int' description='Block width'/>\n"
549
0
        "   <Option name='BLOCKYSIZE' type='int' description='Block height'/>\n"
550
0
        "</CreationOptionList>\n");
551
552
0
    auto poGTiffDrv = poDM->GetDriverByName("GTiff");
553
0
    if (poGTiffDrv)
554
0
    {
555
0
        const char *pszGTiffOvrCO =
556
0
            poGTiffDrv->GetMetadataItem(GDAL_DMD_OVERVIEW_CREATIONOPTIONLIST);
557
0
        if (pszGTiffOvrCO &&
558
0
            STARTS_WITH(pszGTiffOvrCO, "<OverviewCreationOptionList>"))
559
0
        {
560
0
            std::string ocoList =
561
0
                "<OverviewCreationOptionList>"
562
0
                "   <Option name='VIRTUAL' type='boolean' "
563
0
                "default='NO' "
564
0
                "description='Whether virtual overviews rather than "
565
0
                "materialized external GeoTIFF .ovr should be created'/>";
566
0
            ocoList += (pszGTiffOvrCO + strlen("<OverviewCreationOptionList>"));
567
0
            poDriver->SetMetadataItem(GDAL_DMD_OVERVIEW_CREATIONOPTIONLIST,
568
0
                                      ocoList.c_str());
569
0
        }
570
0
    }
571
572
0
    poDriver->SetMetadataItem(
573
0
        GDAL_DMD_MULTIDIM_DATASET_CREATIONOPTIONLIST,
574
0
        "<MultiDimDatasetCreationOptionList>"
575
0
        "   <Option name='GUESS_REGULARLY_SPACED_ARRAYS' type='boolean' "
576
0
        "description='Whether content of 1D-arrays should be read to deduce "
577
0
        "if they are regularly spaced. Can be slow on huge remote datasets' "
578
0
        "default='YES'/>"
579
0
        "</MultiDimDatasetCreationOptionList>");
580
581
0
    poDriver->SetMetadataItem(
582
0
        GDAL_DMD_MULTIDIM_ARRAY_CREATIONOPTIONLIST,
583
0
        "<MultiDimArrayCreationOptionList>"
584
0
        "   <Option name='BLOCKSIZE' type='int' description='Block size in "
585
0
        "pixels'/>"
586
0
        "</MultiDimArrayCreationOptionList>");
587
588
0
    poDriver->pfnCreateCopy = VRTCreateCopy;
589
0
    poDriver->pfnCreate = VRTDataset::Create;
590
0
    poDriver->pfnCreateMultiDimensional = VRTDataset::CreateMultiDimensional;
591
592
0
#ifndef NO_OPEN
593
0
    poDriver->pfnOpen = VRTDataset::Open;
594
0
    poDriver->pfnIdentify = VRTDataset::Identify;
595
0
    poDriver->pfnDelete = VRTDataset::Delete;
596
597
0
    poDriver->SetMetadataItem(
598
0
        GDAL_DMD_OPENOPTIONLIST,
599
0
        "<OpenOptionList>"
600
0
        "  <Option name='ROOT_PATH' type='string' description='Root path to "
601
0
        "evaluate "
602
0
        "relative paths inside the VRT. Mainly useful for inlined VRT, or "
603
0
        "in-memory "
604
0
        "VRT, where their own directory does not make sense'/>"
605
0
        "<Option name='NUM_THREADS' type='string' description="
606
0
        "'Number of worker threads for reading. Can be set to ALL_CPUS' "
607
0
        "default='ALL_CPUS'/>"
608
0
        "</OpenOptionList>");
609
0
#endif
610
611
0
    poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
612
0
    poDriver->SetMetadataItem(GDAL_DCAP_COORDINATE_EPOCH, "YES");
613
614
0
    poDriver->SetMetadataItem(GDAL_DCAP_UPDATE, "YES");
615
0
    poDriver->SetMetadataItem(GDAL_DMD_UPDATE_ITEMS,
616
0
                              "GeoTransform SRS GCPs NoData "
617
0
                              "ColorInterpretation "
618
0
                              "DatasetMetadata BandMetadata");
619
620
0
    const char *pszExpressionDialects = "ExpressionDialects";
621
#if defined(GDAL_VRT_ENABLE_MUPARSER) && defined(GDAL_VRT_ENABLE_EXPRTK)
622
    poDriver->SetMetadataItem(pszExpressionDialects, "muparser,exprtk");
623
#elif defined(GDAL_VRT_ENABLE_MUPARSER)
624
    poDriver->SetMetadataItem(pszExpressionDialects, "muparser");
625
#elif defined(GDAL_VRT_ENABLE_EXPRTK)
626
    poDriver->SetMetadataItem(pszExpressionDialects, "exprtk");
627
#else
628
0
    poDriver->SetMetadataItem(pszExpressionDialects, "none");
629
0
#endif
630
631
#ifdef GDAL_VRT_ENABLE_MUPARSER
632
    if (gdal::MuParserHasDefineFunUserData())
633
    {
634
        poDriver->SetMetadataItem("MUPARSER_HAS_DEFINE_FUN_USER_DATA", "YES");
635
    }
636
#endif
637
638
0
#ifdef GDAL_VRT_ENABLE_RAWRASTERBAND
639
0
    poDriver->SetMetadataItem("GDAL_VRT_ENABLE_RAWRASTERBAND", "YES");
640
0
#endif
641
642
0
    poDriver->AddSourceParser("SimpleSource", VRTParseCoreSources);
643
0
    poDriver->AddSourceParser("ComplexSource", VRTParseCoreSources);
644
0
    poDriver->AddSourceParser("AveragedSource", VRTParseCoreSources);
645
0
    poDriver->AddSourceParser("NoDataFromMaskSource", VRTParseCoreSources);
646
0
    poDriver->AddSourceParser("KernelFilteredSource", VRTParseFilterSources);
647
0
    poDriver->AddSourceParser("ArraySource", VRTParseArraySource);
648
649
0
    poDM->RegisterDriver(poDriver);
650
0
}
651
652
/*! @endcond */