LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_stack.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 28 28 100.0 %
Date: 2026-06-23 16:35:19 Functions: 2 2 100.0 %

          Line data    Source code
       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          86 : GDALRasterStackAlgorithm::GDALRasterStackAlgorithm(bool bStandalone)
      28             :     : GDALRasterMosaicStackCommonAlgorithm(NAME, DESCRIPTION, HELP_URL,
      29          86 :                                            bStandalone)
      30             : {
      31          86 : }
      32             : 
      33             : /************************************************************************/
      34             : /*                 GDALRasterStackAlgorithm::RunStep()                  */
      35             : /************************************************************************/
      36             : 
      37           6 : bool GDALRasterStackAlgorithm::RunStep(GDALPipelineStepRunContext &ctxt)
      38             : {
      39           6 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      40             : 
      41          12 :     std::vector<GDALDatasetH> ahInputDatasets;
      42          12 :     CPLStringList aosInputDatasetNames;
      43           6 :     bool foundByName = false;
      44           6 :     if (!GetInputDatasetNames(ctxt, ahInputDatasets, aosInputDatasetNames,
      45             :                               foundByName))
      46             :     {
      47             :         // Error message emitted by GetInputDatasetNames()
      48           1 :         return false;
      49             :     }
      50             : 
      51           5 :     CPLStringList aosOptions;
      52             : 
      53           5 :     aosOptions.push_back("-strict");
      54             : 
      55           5 :     aosOptions.push_back("-program_name");
      56           5 :     aosOptions.push_back("gdal raster stack");
      57             : 
      58           5 :     aosOptions.push_back("-separate");
      59             : 
      60           5 :     SetBuildVRTOptions(aosOptions);
      61             : 
      62           5 :     bool bOK = false;
      63             :     GDALBuildVRTOptions *psOptions =
      64           5 :         GDALBuildVRTOptionsNew(aosOptions.List(), nullptr);
      65           5 :     if (psOptions)
      66             :     {
      67             :         auto poOutDS =
      68             :             std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(GDALBuildVRT(
      69             :                 "",
      70           2 :                 foundByName ? aosInputDatasetNames.size()
      71           3 :                             : static_cast<int>(m_inputDataset.size()),
      72           8 :                 ahInputDatasets.empty() ? nullptr : ahInputDatasets.data(),
      73          23 :                 aosInputDatasetNames.List(), psOptions, nullptr)));
      74           5 :         GDALBuildVRTOptionsFree(psOptions);
      75           5 :         bOK = poOutDS != nullptr;
      76           5 :         if (bOK)
      77             :         {
      78           5 :             m_outputDataset.Set(std::move(poOutDS));
      79             :         }
      80             :     }
      81           5 :     return bOK;
      82             : }
      83             : 
      84             : GDALRasterStackAlgorithmStandalone::~GDALRasterStackAlgorithmStandalone() =
      85             :     default;
      86             : 
      87             : //! @endcond

Generated by: LCOV version 1.14