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 : GDALAlgorithm::ProcessGDALGOutputRet ProcessGDALGOutput() override; 59 : bool CheckSafeForStreamOutput() override; 60 : }; 61 : 62 : /************************************************************************/ 63 : /* GDALRasterPipelineAlgorithm */ 64 : /************************************************************************/ 65 : 66 : // This is an easter egg to pay tribute to PROJ pipeline syntax 67 : // 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" 68 : // as an alternative to (recommended): 69 : // "gdal vector pipeline ! read in.tif ! reproject--dst-crs=EPSG:32632 ! write out.tif --overwrite" 70 : #ifndef GDAL_PIPELINE_PROJ_NOSTALGIA 71 : #define GDAL_PIPELINE_PROJ_NOSTALGIA 72 : #endif 73 : 74 : class GDALRasterPipelineAlgorithm final 75 : : public GDALAbstractPipelineAlgorithm<GDALRasterPipelineStepAlgorithm> 76 : { 77 : public: 78 : static constexpr const char *NAME = "pipeline"; 79 : static constexpr const char *DESCRIPTION = "Process a raster dataset."; 80 : static constexpr const char *HELP_URL = 81 : "/programs/gdal_raster_pipeline.html"; 82 : 83 305 : static std::vector<std::string> GetAliases() 84 : { 85 : return { 86 : #ifdef GDAL_PIPELINE_PROJ_NOSTALGIA 87 : GDALAlgorithmRegistry::HIDDEN_ALIAS_SEPARATOR, 88 : "+pipeline", 89 : "+gdal=pipeline", 90 : #endif 91 1220 : }; 92 : } 93 : 94 : explicit GDALRasterPipelineAlgorithm(bool openForMixedRasterVector = false); 95 : 96 : bool 97 : ParseCommandLineArguments(const std::vector<std::string> &args) override; 98 : 99 : std::string GetUsageForCLI(bool shortUsage, 100 : const UsageOptions &usageOptions) const override; 101 : 102 1 : GDALDataset *GetDatasetRef() 103 : { 104 1 : return m_inputDataset.GetDatasetRef(); 105 : } 106 : 107 : protected: 108 54 : GDALArgDatasetValue &GetOutputDataset() override 109 : { 110 54 : return m_outputDataset; 111 : } 112 : 113 : private: 114 : std::string m_helpDocCategory{}; 115 : }; 116 : 117 : //! @endcond 118 : 119 : #endif