Coverage Report

Created: 2026-02-14 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/apps/gdalalg_raster_stack.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  GDAL
4
 * Purpose:  gdal "raster stack" subcommand
5
 * Author:   Even Rouault <even dot rouault at spatialys.com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2024, Even Rouault <even dot rouault at spatialys.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#include "gdalalg_raster_stack.h"
14
#include "gdalalg_raster_write.h"
15
16
#include "cpl_conv.h"
17
18
#include "gdal_priv.h"
19
#include "gdal_utils.h"
20
21
//! @cond Doxygen_Suppress
22
23
/************************************************************************/
24
/*         GDALRasterStackAlgorithm::GDALRasterStackAlgorithm()         */
25
/************************************************************************/
26
27
GDALRasterStackAlgorithm::GDALRasterStackAlgorithm(bool bStandalone)
28
0
    : GDALRasterMosaicStackCommonAlgorithm(NAME, DESCRIPTION, HELP_URL,
29
0
                                           bStandalone)
30
0
{
31
0
}
32
33
/************************************************************************/
34
/*                 GDALRasterStackAlgorithm::RunStep()                  */
35
/************************************************************************/
36
37
bool GDALRasterStackAlgorithm::RunStep(GDALPipelineStepRunContext &ctxt)
38
0
{
39
0
    CPLAssert(!m_outputDataset.GetDatasetRef());
40
41
0
    std::vector<GDALDatasetH> ahInputDatasets;
42
0
    CPLStringList aosInputDatasetNames;
43
0
    bool foundByName = false;
44
0
    if (!GetInputDatasetNames(ctxt, ahInputDatasets, aosInputDatasetNames,
45
0
                              foundByName))
46
0
    {
47
        // Error message emitted by GetInputDatasetNames()
48
0
        return false;
49
0
    }
50
51
0
    CPLStringList aosOptions;
52
53
0
    aosOptions.push_back("-strict");
54
55
0
    aosOptions.push_back("-program_name");
56
0
    aosOptions.push_back("gdal raster stack");
57
58
0
    aosOptions.push_back("-separate");
59
60
0
    SetBuildVRTOptions(aosOptions);
61
62
0
    bool bOK = false;
63
0
    GDALBuildVRTOptions *psOptions =
64
0
        GDALBuildVRTOptionsNew(aosOptions.List(), nullptr);
65
0
    if (psOptions)
66
0
    {
67
0
        auto poOutDS =
68
0
            std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(GDALBuildVRT(
69
0
                "",
70
0
                foundByName ? aosInputDatasetNames.size()
71
0
                            : static_cast<int>(m_inputDataset.size()),
72
0
                ahInputDatasets.empty() ? nullptr : ahInputDatasets.data(),
73
0
                aosInputDatasetNames.List(), psOptions, nullptr)));
74
0
        GDALBuildVRTOptionsFree(psOptions);
75
0
        bOK = poOutDS != nullptr;
76
0
        if (bOK)
77
0
        {
78
0
            m_outputDataset.Set(std::move(poOutDS));
79
0
        }
80
0
    }
81
0
    return bOK;
82
0
}
83
84
0
GDALRasterStackAlgorithmStandalone::~GDALRasterStackAlgorithmStandalone() =
85
    default;
86
87
//! @endcond