LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_set_type.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 20 20 100.0 %
Date: 2025-05-15 13:16:46 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          10 : GDALRasterSetTypeAlgorithm::GDALRasterSetTypeAlgorithm(bool standaloneStep)
      29             :     : GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
      30          10 :                                       standaloneStep)
      31             : {
      32          10 :     AddOutputDataTypeArg(&m_type).SetRequired();
      33          10 : }
      34             : 
      35             : /************************************************************************/
      36             : /*             GDALRasterSetTypeAlgorithm::RunStep()                    */
      37             : /************************************************************************/
      38             : 
      39           2 : bool GDALRasterSetTypeAlgorithm::RunStep(GDALProgressFunc, void *)
      40             : {
      41           2 :     CPLAssert(m_inputDataset.GetDatasetRef());
      42           2 :     CPLAssert(m_outputDataset.GetName().empty());
      43           2 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      44             : 
      45           4 :     CPLStringList aosOptions;
      46           2 :     aosOptions.AddString("-of");
      47           2 :     aosOptions.AddString("VRT");
      48           2 :     aosOptions.AddString("-ot");
      49           2 :     aosOptions.AddString(m_type.c_str());
      50             : 
      51             :     GDALTranslateOptions *psOptions =
      52           2 :         GDALTranslateOptionsNew(aosOptions.List(), nullptr);
      53             : 
      54             :     auto poOutDS = std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(
      55             :         GDALTranslate("", GDALDataset::ToHandle(m_inputDataset.GetDatasetRef()),
      56           2 :                       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             : //! @endcond

Generated by: LCOV version 1.14