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