Coverage Report

Created: 2026-02-14 06:52

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