LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_tpi.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 24 24 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:  "tpi" 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_tpi.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             : /*           GDALRasterTPIAlgorithm::GDALRasterTPIAlgorithm()           */
      28             : /************************************************************************/
      29             : 
      30          17 : GDALRasterTPIAlgorithm::GDALRasterTPIAlgorithm(bool standaloneStep)
      31             :     : GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
      32          17 :                                       standaloneStep)
      33             : {
      34          17 :     SetOutputVRTCompatible(false);
      35             : 
      36          17 :     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          17 :            &m_noEdges);
      41          17 : }
      42             : 
      43             : /************************************************************************/
      44             : /*                  GDALRasterTPIAlgorithm::RunStep()                   */
      45             : /************************************************************************/
      46             : 
      47           4 : bool GDALRasterTPIAlgorithm::RunStep(GDALProgressFunc, void *)
      48             : {
      49           4 :     CPLAssert(m_inputDataset.GetDatasetRef());
      50           4 :     CPLAssert(m_outputDataset.GetName().empty());
      51           4 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      52             : 
      53           8 :     CPLStringList aosOptions;
      54           4 :     aosOptions.AddString("-of");
      55           4 :     aosOptions.AddString("stream");
      56           4 :     aosOptions.AddString("-b");
      57           4 :     aosOptions.AddString(CPLSPrintf("%d", m_band));
      58           4 :     if (!m_noEdges)
      59           3 :         aosOptions.AddString("-compute_edges");
      60             : 
      61             :     GDALDEMProcessingOptions *psOptions =
      62           4 :         GDALDEMProcessingOptionsNew(aosOptions.List(), nullptr);
      63             : 
      64             :     auto poOutDS =
      65             :         std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(GDALDEMProcessing(
      66             :             "", GDALDataset::ToHandle(m_inputDataset.GetDatasetRef()), "TPI",
      67           4 :             nullptr, psOptions, nullptr)));
      68           4 :     GDALDEMProcessingOptionsFree(psOptions);
      69           4 :     const bool bRet = poOutDS != nullptr;
      70           4 :     if (poOutDS)
      71             :     {
      72           4 :         m_outputDataset.Set(std::move(poOutDS));
      73             :     }
      74             : 
      75           8 :     return bRet;
      76             : }
      77             : 
      78             : //! @endcond

Generated by: LCOV version 1.14