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