LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_tri.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 29 29 100.0 %
Date: 2025-04-16 00:42:22 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  "tri" 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_tri.h"
      14             : 
      15             : #include "gdal_priv.h"
      16             : #include "gdal_utils.h"
      17             : 
      18             : #include <cmath>
      19             : 
      20             : //! @cond Doxygen_Suppress
      21             : 
      22             : #ifndef _
      23             : #define _(x) (x)
      24             : #endif
      25             : 
      26             : /************************************************************************/
      27             : /*           GDALRasterTRIAlgorithm::GDALRasterTRIAlgorithm()           */
      28             : /************************************************************************/
      29             : 
      30          19 : GDALRasterTRIAlgorithm::GDALRasterTRIAlgorithm(bool standaloneStep)
      31             :     : GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
      32          19 :                                       standaloneStep)
      33             : {
      34          19 :     SetOutputVRTCompatible(false);
      35             : 
      36          19 :     AddBandArg(&m_band).SetDefault(m_band);
      37          38 :     AddArg("algorithm", 0, _("Algorithm to compute TRI"), &m_algorithm)
      38          19 :         .SetChoices("Riley", "Wilson")
      39          19 :         .SetDefault(m_algorithm);
      40             :     AddArg("no-edges", 0,
      41             :            _("Do not try to interpolate values at dataset edges or close to "
      42             :              "nodata values"),
      43          19 :            &m_noEdges);
      44          19 : }
      45             : 
      46             : /************************************************************************/
      47             : /*                  GDALRasterTRIAlgorithm::RunStep()                   */
      48             : /************************************************************************/
      49             : 
      50           6 : bool GDALRasterTRIAlgorithm::RunStep(GDALProgressFunc, void *)
      51             : {
      52           6 :     CPLAssert(m_inputDataset.GetDatasetRef());
      53           6 :     CPLAssert(m_outputDataset.GetName().empty());
      54           6 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      55             : 
      56          12 :     CPLStringList aosOptions;
      57           6 :     aosOptions.AddString("-of");
      58           6 :     aosOptions.AddString("stream");
      59           6 :     aosOptions.AddString("-b");
      60           6 :     aosOptions.AddString(CPLSPrintf("%d", m_band));
      61           6 :     aosOptions.AddString("-alg");
      62           6 :     aosOptions.AddString(m_algorithm.c_str());
      63           6 :     if (!m_noEdges)
      64           5 :         aosOptions.AddString("-compute_edges");
      65             : 
      66             :     GDALDEMProcessingOptions *psOptions =
      67           6 :         GDALDEMProcessingOptionsNew(aosOptions.List(), nullptr);
      68             : 
      69             :     auto poOutDS =
      70             :         std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(GDALDEMProcessing(
      71             :             "", GDALDataset::ToHandle(m_inputDataset.GetDatasetRef()), "TRI",
      72           6 :             nullptr, psOptions, nullptr)));
      73           6 :     GDALDEMProcessingOptionsFree(psOptions);
      74           6 :     const bool bRet = poOutDS != nullptr;
      75           6 :     if (poOutDS)
      76             :     {
      77           6 :         m_outputDataset.Set(std::move(poOutDS));
      78             :     }
      79             : 
      80          12 :     return bRet;
      81             : }
      82             : 
      83             : //! @endcond

Generated by: LCOV version 1.14