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

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  gdal "vector grid invdist" subcommand
       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_vector_grid_invdist.h"
      14             : 
      15             : #include <limits>
      16             : 
      17             : //! @cond Doxygen_Suppress
      18             : 
      19             : #ifndef _
      20             : #define _(x) (x)
      21             : #endif
      22             : 
      23             : /************************************************************************/
      24             : /*    GDALVectorGridInvdistAlgorithm::GDALVectorGridInvdistAlgorithm()  */
      25             : /************************************************************************/
      26             : 
      27          44 : GDALVectorGridInvdistAlgorithm::GDALVectorGridInvdistAlgorithm()
      28          44 :     : GDALVectorGridAbstractAlgorithm(NAME, DESCRIPTION, HELP_URL)
      29             : {
      30          44 :     AddArg("power", 0, _("Weighting power"), &m_power).SetDefault(m_power);
      31          88 :     AddArg("smoothing", 0, _("Smoothing parameter"), &m_smoothing)
      32          44 :         .SetDefault(m_smoothing);
      33             : 
      34          44 :     AddRadiusArg();
      35          44 :     AddRadius1AndRadius2Arg();
      36          44 :     AddAngleArg();
      37          44 :     AddMinPointsArg();
      38          44 :     AddMaxPointsArg();
      39          44 :     AddMinMaxPointsPerQuadrantArg();
      40          44 :     AddNodataArg();
      41             : 
      42          44 :     AddValidationAction(
      43          92 :         [this]()
      44             :         {
      45          42 :             bool ret = true;
      46             : 
      47          42 :             if (m_minPoints > 0 && m_radius == 0 && m_radius1 == 0)
      48             :             {
      49           1 :                 ReportError(CE_Failure, CPLE_AppDefined,
      50             :                             "'radius' or 'radius1' and 'radius2' should be "
      51             :                             "defined when 'min-points' is.");
      52           1 :                 ret = false;
      53             :             }
      54             : 
      55          42 :             if (m_maxPoints < std::numeric_limits<int>::max() &&
      56          42 :                 m_radius == 0 && m_radius1 == 0)
      57             :             {
      58           1 :                 ReportError(CE_Failure, CPLE_AppDefined,
      59             :                             "'radius' or 'radius1' and 'radius2' should be "
      60             :                             "defined when 'max-points' is.");
      61           1 :                 ret = false;
      62             :             }
      63          42 :             return ret;
      64             :         });
      65          44 : }
      66             : 
      67             : /************************************************************************/
      68             : /*               GDALVectorGridInvdistAlgorithm::RunImpl()              */
      69             : /************************************************************************/
      70             : 
      71          34 : std::string GDALVectorGridInvdistAlgorithm::GetGridAlgorithm() const
      72             : {
      73             :     std::string ret = CPLSPrintf(
      74          34 :         "invdist:power=%.17g:smoothing=%.17g:angle=%.17g:nodata=%.17g", m_power,
      75          34 :         m_smoothing, m_angle, m_nodata);
      76          34 :     if (m_radius > 0)
      77             :     {
      78           7 :         ret += CPLSPrintf(":radius=%.17g", m_radius);
      79             :     }
      80             :     else
      81             :     {
      82          27 :         if (m_radius1 > 0)
      83           3 :             ret += CPLSPrintf(":radius1=%.17g", m_radius1);
      84          27 :         if (m_radius2 > 0)
      85           3 :             ret += CPLSPrintf(":radius2=%.17g", m_radius2);
      86             :     }
      87          34 :     if (m_minPoints > 0)
      88           1 :         ret += CPLSPrintf(":min_points=%d", m_minPoints);
      89          34 :     if (m_maxPoints < std::numeric_limits<int>::max())
      90           1 :         ret += CPLSPrintf(":max_points=%d", m_maxPoints);
      91          34 :     if (m_minPointsPerQuadrant > 0)
      92             :         ret +=
      93           1 :             CPLSPrintf(":min_points_per_quadrant=%d", m_minPointsPerQuadrant);
      94          34 :     if (m_maxPointsPerQuadrant < std::numeric_limits<int>::max())
      95             :         ret +=
      96           1 :             CPLSPrintf(":max_points_per_quadrant=%d", m_maxPointsPerQuadrant);
      97          34 :     return ret;
      98             : }
      99             : 
     100             : //! @endcond

Generated by: LCOV version 1.14