LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_pipeline.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 6 6 100.0 %
Date: 2025-01-18 12:42:00 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  gdal "raster pipeline" subcommand
       5             :  * Author:   Even Rouault <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2024, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #ifndef GDALALG_RASTER_PIPELINE_INCLUDED
      14             : #define GDALALG_RASTER_PIPELINE_INCLUDED
      15             : 
      16             : #include "gdalalgorithm.h"
      17             : #include "gdalalg_abstract_pipeline.h"
      18             : 
      19             : //! @cond Doxygen_Suppress
      20             : 
      21             : /************************************************************************/
      22             : /*                GDALRasterPipelineStepAlgorithm                       */
      23             : /************************************************************************/
      24             : 
      25             : class GDALRasterPipelineStepAlgorithm /* non final */ : public GDALAlgorithm
      26             : {
      27             :   protected:
      28             :     GDALRasterPipelineStepAlgorithm(const std::string &name,
      29             :                                     const std::string &description,
      30             :                                     const std::string &helpURL,
      31             :                                     bool standaloneStep);
      32             : 
      33             :     friend class GDALRasterPipelineAlgorithm;
      34             :     friend class GDALAbstractPipelineAlgorithm<GDALRasterPipelineStepAlgorithm>;
      35             : 
      36             :     virtual bool RunStep(GDALProgressFunc pfnProgress, void *pProgressData) = 0;
      37             : 
      38             :     void AddInputArgs(bool openForMixedRasterVector, bool hiddenForCLI);
      39             :     void AddOutputArgs(bool hiddenForCLI);
      40             : 
      41             :     bool m_standaloneStep = false;
      42             : 
      43             :     // Input arguments
      44             :     GDALArgDatasetValue m_inputDataset{};
      45             :     std::vector<std::string> m_openOptions{};
      46             :     std::vector<std::string> m_inputFormats{};
      47             :     std::vector<std::string> m_inputLayerNames{};
      48             : 
      49             :     // Output arguments
      50             :     GDALArgDatasetValue m_outputDataset{};
      51             :     std::string m_format{};
      52             :     std::vector<std::string> m_creationOptions{};
      53             :     bool m_overwrite = false;
      54             :     std::string m_outputLayerName{};
      55             : 
      56             :   private:
      57             :     bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override;
      58             : };
      59             : 
      60             : /************************************************************************/
      61             : /*                     GDALRasterPipelineAlgorithm                      */
      62             : /************************************************************************/
      63             : 
      64             : // This is an easter egg to pay tribute to PROJ pipeline syntax
      65             : // We accept "gdal vector +gdal=pipeline +step +gdal=read +input=in.tif +step +gdal=reproject +dst-crs=EPSG:32632 +step +gdal=write +output=out.tif +overwrite"
      66             : // as an alternative to (recommended):
      67             : // "gdal vector pipeline ! read in.tif ! reproject--dst-crs=EPSG:32632 ! write out.tif --overwrite"
      68             : #ifndef GDAL_PIPELINE_PROJ_NOSTALGIA
      69             : #define GDAL_PIPELINE_PROJ_NOSTALGIA
      70             : #endif
      71             : 
      72             : class GDALRasterPipelineAlgorithm final
      73             :     : public GDALAbstractPipelineAlgorithm<GDALRasterPipelineStepAlgorithm>
      74             : {
      75             :   public:
      76             :     static constexpr const char *NAME = "pipeline";
      77             :     static constexpr const char *DESCRIPTION = "Process a raster dataset.";
      78             :     static constexpr const char *HELP_URL =
      79             :         "/programs/gdal_raster_pipeline.html";
      80             : 
      81         168 :     static std::vector<std::string> GetAliases()
      82             :     {
      83             :         return {
      84             : #ifdef GDAL_PIPELINE_PROJ_NOSTALGIA
      85             :             GDALAlgorithmRegistry::HIDDEN_ALIAS_SEPARATOR,
      86             :             "+pipeline",
      87             :             "+gdal=pipeline",
      88             : #endif
      89         672 :         };
      90             :     }
      91             : 
      92             :     explicit GDALRasterPipelineAlgorithm(bool openForMixedRasterVector = false);
      93             : 
      94             :     bool
      95             :     ParseCommandLineArguments(const std::vector<std::string> &args) override;
      96             : 
      97             :     std::string GetUsageForCLI(bool shortUsage,
      98             :                                const UsageOptions &usageOptions) const override;
      99             : 
     100           1 :     GDALDataset *GetDatasetRef()
     101             :     {
     102           1 :         return m_inputDataset.GetDatasetRef();
     103             :     }
     104             : 
     105             :   protected:
     106          44 :     GDALArgDatasetValue &GetOutputDataset() override
     107             :     {
     108          44 :         return m_outputDataset;
     109             :     }
     110             : };
     111             : 
     112             : //! @endcond
     113             : 
     114             : #endif

Generated by: LCOV version 1.14