LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_mosaic.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 37 38 97.4 %
Date: 2025-06-19 12:30:01 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  gdal "raster mosaic" 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_mosaic.h"
      14             : 
      15             : #include "cpl_conv.h"
      16             : 
      17             : #include "gdal_priv.h"
      18             : #include "gdal_utils.h"
      19             : 
      20             : //! @cond Doxygen_Suppress
      21             : 
      22             : #ifndef _
      23             : #define _(x) (x)
      24             : #endif
      25             : 
      26             : /************************************************************************/
      27             : /*        GDALRasterMosaicAlgorithm::GDALRasterMosaicAlgorithm()        */
      28             : /************************************************************************/
      29             : 
      30          63 : GDALRasterMosaicAlgorithm::GDALRasterMosaicAlgorithm(bool bStandalone)
      31             :     : GDALRasterMosaicStackCommonAlgorithm(NAME, DESCRIPTION, HELP_URL,
      32          63 :                                            bStandalone)
      33             : {
      34             :     AddArg("add-alpha", 0,
      35             :            _("Adds an alpha mask band to the destination when the source "
      36             :              "raster have "
      37             :              "none."),
      38          63 :            &m_addAlpha);
      39          63 :     AddPixelFunctionNameArg(&m_pixelFunction);
      40          63 :     AddPixelFunctionArgsArg(&m_pixelFunctionArgs);
      41          63 : }
      42             : 
      43             : /************************************************************************/
      44             : /*                   GDALRasterMosaicAlgorithm::RunStep()               */
      45             : /************************************************************************/
      46             : 
      47          28 : bool GDALRasterMosaicAlgorithm::RunStep(GDALPipelineStepRunContext &ctxt)
      48             : {
      49          28 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      50             : 
      51          56 :     std::vector<GDALDatasetH> ahInputDatasets;
      52          56 :     CPLStringList aosInputDatasetNames;
      53          28 :     bool foundByName = false;
      54          28 :     if (!GetInputDatasetNames(ctxt, ahInputDatasets, aosInputDatasetNames,
      55             :                               foundByName))
      56             :     {
      57             :         // Error message emitted by GetInputDatasetNames()
      58           1 :         return false;
      59             :     }
      60             : 
      61          27 :     CPLStringList aosOptions;
      62          27 :     aosOptions.push_back("-strict");
      63             : 
      64          27 :     aosOptions.push_back("-program_name");
      65          27 :     aosOptions.push_back("gdal raster mosaic");
      66             : 
      67          27 :     SetBuildVRTOptions(aosOptions);
      68             : 
      69          27 :     if (m_addAlpha)
      70             :     {
      71           0 :         aosOptions.push_back("-addalpha");
      72             :     }
      73          27 :     if (!m_pixelFunction.empty())
      74             :     {
      75           2 :         aosOptions.push_back("-pixel-function");
      76           2 :         aosOptions.push_back(m_pixelFunction);
      77             :     }
      78             : 
      79          28 :     for (const auto &arg : m_pixelFunctionArgs)
      80             :     {
      81           1 :         aosOptions.push_back("-pixel-function-arg");
      82           1 :         aosOptions.push_back(arg);
      83             :     }
      84             : 
      85          27 :     bool bOK = false;
      86             :     GDALBuildVRTOptions *psOptions =
      87          27 :         GDALBuildVRTOptionsNew(aosOptions.List(), nullptr);
      88          27 :     if (psOptions)
      89             :     {
      90             :         auto poOutDS =
      91             :             std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(GDALBuildVRT(
      92             :                 "",
      93          13 :                 foundByName ? aosInputDatasetNames.size()
      94          14 :                             : static_cast<int>(m_inputDataset.size()),
      95          41 :                 ahInputDatasets.empty() ? nullptr : ahInputDatasets.data(),
      96         122 :                 aosInputDatasetNames.List(), psOptions, nullptr)));
      97          27 :         GDALBuildVRTOptionsFree(psOptions);
      98          27 :         bOK = poOutDS != nullptr;
      99          27 :         if (bOK)
     100             :         {
     101          25 :             m_outputDataset.Set(std::move(poOutDS));
     102             :         }
     103             :     }
     104          27 :     return bOK;
     105             : }
     106             : 
     107             : GDALRasterMosaicAlgorithmStandalone::~GDALRasterMosaicAlgorithmStandalone() =
     108             :     default;
     109             : 
     110             : //! @endcond

Generated by: LCOV version 1.14