LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_zonal_stats.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 8 8 100.0 %
Date: 2026-04-23 19:47:11 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  gdal "raster zonal-stats" subcommand
       5             :  * Author:   Dan Baston
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2025, ISciences LLC
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #ifndef GDALALG_RASTER_ZONAL_STATS_INCLUDED
      14             : #define GDALALG_RASTER_ZONAL_STATS_INCLUDED
      15             : 
      16             : #include "gdalalg_abstract_pipeline.h"
      17             : 
      18             : //! @cond Doxygen_Suppress
      19             : 
      20             : /************************************************************************/
      21             : /*                    GDALRasterZonalStatsAlgorithm                     */
      22             : /************************************************************************/
      23             : 
      24             : class GDALRasterZonalStatsAlgorithm /* non final */
      25             :     : public GDALPipelineStepAlgorithm
      26             : {
      27             :   public:
      28             :     static constexpr const char *NAME = "zonal-stats";
      29             :     static constexpr const char *DESCRIPTION =
      30             :         "Calculate raster zonal statistics";
      31             :     static constexpr const char *HELP_URL =
      32             :         "/programs/gdal_raster_zonal_stats.html";
      33             : 
      34             :     explicit GDALRasterZonalStatsAlgorithm(bool bStandalone = false);
      35             : 
      36           6 :     int GetInputType() const override
      37             :     {
      38           6 :         return GDAL_OF_RASTER;
      39             :     }
      40             : 
      41           4 :     int GetOutputType() const override
      42             :     {
      43           4 :         return GDAL_OF_VECTOR;
      44             :     }
      45             : 
      46             :   private:
      47             :     bool RunStep(GDALPipelineStepRunContext &ctxt) override;
      48             :     bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override;
      49             : 
      50             :     GDALArgDatasetValue m_weights{};
      51             :     GDALArgDatasetValue m_zones{};
      52             :     std::string m_zonesLayer{};
      53             :     int m_zonesBand{0};
      54             :     std::vector<int> m_bands{};
      55             :     std::vector<std::string> m_stats{};
      56             :     std::vector<std::string> m_includeFields{};
      57             :     bool m_includeZoneGeom{false};
      58             :     std::string m_strategy{};
      59             :     std::string m_memoryStr{"5%"};
      60             :     std::string m_pixels{"default"};
      61             :     int m_weightsBand{0};
      62             :     size_t m_memoryBytes{
      63             :         static_cast<size_t>(100) * 1024 *
      64             :         1024};  // FIXME validation action doesn't seem to run if arg isn't specified, so this never gets sets?
      65             : };
      66             : 
      67             : /************************************************************************/
      68             : /*               GDALRasterZonalStatsAlgorithmStandalone                */
      69             : /************************************************************************/
      70             : 
      71         416 : class GDALRasterZonalStatsAlgorithmStandalone final
      72             :     : public GDALRasterZonalStatsAlgorithm
      73             : {
      74             :   public:
      75         208 :     GDALRasterZonalStatsAlgorithmStandalone()
      76         208 :         : GDALRasterZonalStatsAlgorithm(/* standaloneStep = */ true)
      77             :     {
      78         208 :     }
      79             : 
      80             :     ~GDALRasterZonalStatsAlgorithmStandalone() override;
      81             : };
      82             : 
      83             : //! @endcond
      84             : 
      85             : #endif

Generated by: LCOV version 1.14