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