LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_pipeline.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 10 10 100.0 %
Date: 2025-05-15 18:21:54 Functions: 5 5 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         207 :     virtual bool IsNativelyStreamingCompatible() const
      37             :     {
      38         207 :         return true;
      39             :     }
      40             : 
      41             :     virtual bool RunStep(GDALProgressFunc pfnProgress, void *pProgressData) = 0;
      42             : 
      43             :     void AddInputArgs(bool openForMixedRasterVector, bool hiddenForCLI);
      44             :     void AddOutputArgs(bool hiddenForCLI);
      45             : 
      46             :     void SetOutputVRTCompatible(bool b);
      47             : 
      48             :     bool m_outputVRTCompatible = true;
      49             :     bool m_standaloneStep = false;
      50             : 
      51             :     // Input arguments
      52             :     GDALArgDatasetValue m_inputDataset{};
      53             :     std::vector<std::string> m_openOptions{};
      54             :     std::vector<std::string> m_inputFormats{};
      55             :     std::vector<std::string> m_inputLayerNames{};
      56             : 
      57             :     // Output arguments
      58             :     GDALArgDatasetValue m_outputDataset{};
      59             :     std::string m_format{};
      60             :     std::vector<std::string> m_creationOptions{};
      61             :     bool m_overwrite = false;
      62             :     std::string m_outputLayerName{};
      63             :     GDALInConstructionAlgorithmArg *m_outputFormatArg = nullptr;
      64             : 
      65             :   private:
      66             :     bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override;
      67             :     GDALAlgorithm::ProcessGDALGOutputRet ProcessGDALGOutput() override;
      68             :     bool CheckSafeForStreamOutput() override;
      69             : 
      70             :     CPL_DISALLOW_COPY_ASSIGN(GDALRasterPipelineStepAlgorithm)
      71             : };
      72             : 
      73             : /************************************************************************/
      74             : /*           GDALRasterPipelineNonNativelyStreamingAlgorithm            */
      75             : /************************************************************************/
      76             : 
      77             : class GDALRasterPipelineNonNativelyStreamingAlgorithm /* non-final */
      78             :     : public GDALRasterPipelineStepAlgorithm
      79             : {
      80             :   protected:
      81             :     GDALRasterPipelineNonNativelyStreamingAlgorithm(
      82             :         const std::string &name, const std::string &description,
      83             :         const std::string &helpURL, bool standaloneStep);
      84             : 
      85          98 :     bool IsNativelyStreamingCompatible() const override
      86             :     {
      87          98 :         return false;
      88             :     }
      89             : 
      90             :     std::unique_ptr<GDALDataset>
      91             :     CreateTemporaryDataset(int nWidth, int nHeight, int nBands,
      92             :                            GDALDataType eDT, bool bTiledIfPossible,
      93             :                            GDALDataset *poSrcDSForMetadata,
      94             :                            bool bCopyMetadata = true);
      95             :     std::unique_ptr<GDALDataset>
      96             :     CreateTemporaryCopy(GDALDataset *poSrcDS, int nSingleBand,
      97             :                         bool bTiledIfPossible, GDALProgressFunc pfnProgress,
      98             :                         void *pProgressData);
      99             : };
     100             : 
     101             : /************************************************************************/
     102             : /*                     GDALRasterPipelineAlgorithm                      */
     103             : /************************************************************************/
     104             : 
     105             : // This is an easter egg to pay tribute to PROJ pipeline syntax
     106             : // 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"
     107             : // as an alternative to (recommended):
     108             : // "gdal vector pipeline ! read in.tif ! reproject--dst-crs=EPSG:32632 ! write out.tif --overwrite"
     109             : #ifndef GDAL_PIPELINE_PROJ_NOSTALGIA
     110             : #define GDAL_PIPELINE_PROJ_NOSTALGIA
     111             : #endif
     112             : 
     113             : class GDALRasterPipelineAlgorithm final
     114             :     : public GDALAbstractPipelineAlgorithm<GDALRasterPipelineStepAlgorithm>
     115             : {
     116             :   public:
     117             :     static constexpr const char *NAME = "pipeline";
     118             :     static constexpr const char *DESCRIPTION = "Process a raster dataset.";
     119             :     static constexpr const char *HELP_URL =
     120             :         "/programs/gdal_raster_pipeline.html";
     121             : 
     122         840 :     static std::vector<std::string> GetAliasesStatic()
     123             :     {
     124             :         return {
     125             : #ifdef GDAL_PIPELINE_PROJ_NOSTALGIA
     126             :             GDALAlgorithmRegistry::HIDDEN_ALIAS_SEPARATOR,
     127             :             "+pipeline",
     128             :             "+gdal=pipeline",
     129             : #endif
     130        3360 :         };
     131             :     }
     132             : 
     133             :     explicit GDALRasterPipelineAlgorithm(bool openForMixedRasterVector = false);
     134             : 
     135             :     bool
     136             :     ParseCommandLineArguments(const std::vector<std::string> &args) override;
     137             : 
     138             :     std::string GetUsageForCLI(bool shortUsage,
     139             :                                const UsageOptions &usageOptions) const override;
     140             : 
     141           1 :     GDALDataset *GetDatasetRef()
     142             :     {
     143           1 :         return m_inputDataset.GetDatasetRef();
     144             :     }
     145             : 
     146             :   protected:
     147          60 :     GDALArgDatasetValue &GetOutputDataset() override
     148             :     {
     149          60 :         return m_outputDataset;
     150             :     }
     151             : 
     152             :   private:
     153             :     std::string m_helpDocCategory{};
     154             : };
     155             : 
     156             : //! @endcond
     157             : 
     158             : #endif

Generated by: LCOV version 1.14