LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_roughness.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 25 25 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:  "roughness" 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_roughness.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             : /*       GDALRasterRoughnessAlgorithm::GDALRasterRoughnessAlgorithm()   */
      28             : /************************************************************************/
      29             : 
      30          33 : GDALRasterRoughnessAlgorithm::GDALRasterRoughnessAlgorithm(bool standaloneStep)
      31             :     : GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
      32          33 :                                       standaloneStep)
      33             : {
      34          33 :     SetOutputVRTCompatible(false);
      35             : 
      36          33 :     AddBandArg(&m_band).SetDefault(m_band);
      37             :     AddArg("no-edges", 0,
      38             :            _("Do not try to interpolate values at dataset edges or close to "
      39             :              "nodata values"),
      40          33 :            &m_noEdges);
      41          33 : }
      42             : 
      43             : /************************************************************************/
      44             : /*                GDALRasterRoughnessAlgorithm::RunStep()               */
      45             : /************************************************************************/
      46             : 
      47           6 : bool GDALRasterRoughnessAlgorithm::RunStep(GDALPipelineStepRunContext &)
      48             : {
      49           6 :     auto poSrcDS = m_inputDataset[0].GetDatasetRef();
      50           6 :     CPLAssert(poSrcDS);
      51           6 :     CPLAssert(m_outputDataset.GetName().empty());
      52           6 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      53             : 
      54          12 :     CPLStringList aosOptions;
      55           6 :     aosOptions.AddString("-of");
      56           6 :     aosOptions.AddString("stream");
      57           6 :     aosOptions.AddString("-b");
      58           6 :     aosOptions.AddString(CPLSPrintf("%d", m_band));
      59           6 :     if (!m_noEdges)
      60           5 :         aosOptions.AddString("-compute_edges");
      61             : 
      62             :     GDALDEMProcessingOptions *psOptions =
      63           6 :         GDALDEMProcessingOptionsNew(aosOptions.List(), nullptr);
      64             : 
      65             :     auto poOutDS = std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(
      66             :         GDALDEMProcessing("", GDALDataset::ToHandle(poSrcDS), "roughness",
      67           6 :                           nullptr, psOptions, nullptr)));
      68           6 :     GDALDEMProcessingOptionsFree(psOptions);
      69           6 :     const bool bRet = poOutDS != nullptr;
      70           6 :     if (poOutDS)
      71             :     {
      72           6 :         m_outputDataset.Set(std::move(poOutDS));
      73             :     }
      74             : 
      75          12 :     return bRet;
      76             : }
      77             : 
      78             : GDALRasterRoughnessAlgorithmStandalone::
      79             :     ~GDALRasterRoughnessAlgorithmStandalone() = default;
      80             : 
      81             : //! @endcond

Generated by: LCOV version 1.14