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

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  "set-type" step of "raster pipeline"
       5             :  * Author:   Even Rouault <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "gdalalg_raster_set_type.h"
      14             : 
      15             : #include "gdal_priv.h"
      16             : #include "gdal_utils.h"
      17             : 
      18             : //! @cond Doxygen_Suppress
      19             : 
      20             : #ifndef _
      21             : #define _(x) (x)
      22             : #endif
      23             : 
      24             : /************************************************************************/
      25             : /*       GDALRasterSetTypeAlgorithm::GDALRasterSetTypeAlgorithm()       */
      26             : /************************************************************************/
      27             : 
      28          24 : GDALRasterSetTypeAlgorithm::GDALRasterSetTypeAlgorithm(bool standaloneStep)
      29             :     : GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
      30          24 :                                       standaloneStep)
      31             : {
      32          24 :     AddOutputDataTypeArg(&m_type).SetRequired();
      33          24 : }
      34             : 
      35             : /************************************************************************/
      36             : /*             GDALRasterSetTypeAlgorithm::RunStep()                    */
      37             : /************************************************************************/
      38             : 
      39           2 : bool GDALRasterSetTypeAlgorithm::RunStep(GDALPipelineStepRunContext &)
      40             : {
      41           2 :     const auto poSrcDS = m_inputDataset[0].GetDatasetRef();
      42           2 :     CPLAssert(poSrcDS);
      43           2 :     CPLAssert(m_outputDataset.GetName().empty());
      44           2 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      45             : 
      46           4 :     CPLStringList aosOptions;
      47           2 :     aosOptions.AddString("-of");
      48           2 :     aosOptions.AddString("VRT");
      49           2 :     aosOptions.AddString("-ot");
      50           2 :     aosOptions.AddString(m_type.c_str());
      51             : 
      52             :     GDALTranslateOptions *psOptions =
      53           2 :         GDALTranslateOptionsNew(aosOptions.List(), nullptr);
      54             : 
      55             :     auto poOutDS = std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(
      56           2 :         GDALTranslate("", GDALDataset::ToHandle(poSrcDS), psOptions, nullptr)));
      57           2 :     GDALTranslateOptionsFree(psOptions);
      58           2 :     const bool bRet = poOutDS != nullptr;
      59           2 :     if (poOutDS)
      60             :     {
      61           2 :         m_outputDataset.Set(std::move(poOutDS));
      62             :     }
      63             : 
      64           4 :     return bRet;
      65             : }
      66             : 
      67             : GDALRasterSetTypeAlgorithmStandalone::~GDALRasterSetTypeAlgorithmStandalone() =
      68             :     default;
      69             : 
      70             : //! @endcond

Generated by: LCOV version 1.14