LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_aspect.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 37 37 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:  "aspect" 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_aspect.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             : /*         GDALRasterAspectAlgorithm::GDALRasterAspectAlgorithm()       */
      28             : /************************************************************************/
      29             : 
      30          21 : GDALRasterAspectAlgorithm::GDALRasterAspectAlgorithm(bool standaloneStep)
      31             :     : GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
      32          21 :                                       standaloneStep)
      33             : {
      34          21 :     SetOutputVRTCompatible(false);
      35             : 
      36          21 :     AddBandArg(&m_band).SetDefault(m_band);
      37          42 :     AddArg("convention", 0, _("Convention for output angles"), &m_convention)
      38          21 :         .SetChoices("azimuth", "trigonometric-angle")
      39          21 :         .SetDefault(m_convention);
      40             :     AddArg("gradient-alg", 0, _("Algorithm used to compute terrain gradient"),
      41          42 :            &m_gradientAlg)
      42          21 :         .SetChoices("Horn", "ZevenbergenThorne")
      43          21 :         .SetDefault(m_gradientAlg);
      44             :     AddArg("zero-for-flat", 0, _("Whether to output zero for flat areas"),
      45          21 :            &m_zeroForFlat);
      46             :     AddArg("no-edges", 0,
      47             :            _("Do not try to interpolate values at dataset edges or close to "
      48             :              "nodata values"),
      49          21 :            &m_noEdges);
      50          21 : }
      51             : 
      52             : /************************************************************************/
      53             : /*                GDALRasterAspectAlgorithm::RunStep()                  */
      54             : /************************************************************************/
      55             : 
      56           8 : bool GDALRasterAspectAlgorithm::RunStep(GDALProgressFunc, void *)
      57             : {
      58           8 :     CPLAssert(m_inputDataset.GetDatasetRef());
      59           8 :     CPLAssert(m_outputDataset.GetName().empty());
      60           8 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      61             : 
      62          16 :     CPLStringList aosOptions;
      63           8 :     aosOptions.AddString("-of");
      64           8 :     aosOptions.AddString("stream");
      65           8 :     aosOptions.AddString("-b");
      66           8 :     aosOptions.AddString(CPLSPrintf("%d", m_band));
      67           8 :     if (m_convention == "trigonometric-angle")
      68           1 :         aosOptions.AddString("-trigonometric");
      69           8 :     aosOptions.AddString("-alg");
      70           8 :     aosOptions.AddString(m_gradientAlg.c_str());
      71           8 :     if (m_zeroForFlat)
      72           1 :         aosOptions.AddString("-zero_for_flat");
      73           8 :     if (!m_noEdges)
      74           6 :         aosOptions.AddString("-compute_edges");
      75             : 
      76             :     GDALDEMProcessingOptions *psOptions =
      77           8 :         GDALDEMProcessingOptionsNew(aosOptions.List(), nullptr);
      78             : 
      79             :     auto poOutDS =
      80             :         std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(GDALDEMProcessing(
      81             :             "", GDALDataset::ToHandle(m_inputDataset.GetDatasetRef()), "aspect",
      82           8 :             nullptr, psOptions, nullptr)));
      83           8 :     GDALDEMProcessingOptionsFree(psOptions);
      84           8 :     const bool bRet = poOutDS != nullptr;
      85           8 :     if (poOutDS)
      86             :     {
      87           8 :         m_outputDataset.Set(std::move(poOutDS));
      88             :     }
      89             : 
      90          16 :     return bRet;
      91             : }
      92             : 
      93             : //! @endcond

Generated by: LCOV version 1.14