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 GDALRasterAlgorithmStepRegistry; 26 : 27 4240 : class GDALRasterPipelineStepAlgorithm /* non final */ 28 : : public GDALPipelineStepAlgorithm 29 : { 30 : public: 31 : ~GDALRasterPipelineStepAlgorithm() override; 32 : 33 : protected: 34 : GDALRasterPipelineStepAlgorithm(const std::string &name, 35 : const std::string &description, 36 : const std::string &helpURL, 37 : bool standaloneStep); 38 : 39 : GDALRasterPipelineStepAlgorithm(const std::string &name, 40 : const std::string &description, 41 : const std::string &helpURL, 42 : const ConstructorOptions &options); 43 : 44 : friend class GDALRasterPipelineAlgorithm; 45 : friend class GDALRasterMosaicStackCommonAlgorithm; 46 : 47 559 : int GetInputType() const override 48 : { 49 559 : return GDAL_OF_RASTER; 50 : } 51 : 52 538 : int GetOutputType() const override 53 : { 54 538 : return GDAL_OF_RASTER; 55 : } 56 : 57 : void SetOutputVRTCompatible(bool b); 58 : }; 59 : 60 : /************************************************************************/ 61 : /* GDALRasterPipelineNonNativelyStreamingAlgorithm */ 62 : /************************************************************************/ 63 : 64 : class GDALRasterPipelineNonNativelyStreamingAlgorithm /* non-final */ 65 : : public GDALRasterPipelineStepAlgorithm 66 : { 67 : protected: 68 : GDALRasterPipelineNonNativelyStreamingAlgorithm( 69 : const std::string &name, const std::string &description, 70 : const std::string &helpURL, bool standaloneStep); 71 : 72 : bool IsNativelyStreamingCompatible() const override; 73 : 74 : static std::unique_ptr<GDALDataset> 75 : CreateTemporaryDataset(int nWidth, int nHeight, int nBands, 76 : GDALDataType eDT, bool bTiledIfPossible, 77 : GDALDataset *poSrcDSForMetadata, 78 : bool bCopyMetadata = true); 79 : static std::unique_ptr<GDALDataset> 80 : CreateTemporaryCopy(GDALAlgorithm *poAlg, GDALDataset *poSrcDS, 81 : int nSingleBand, bool bTiledIfPossible, 82 : GDALProgressFunc pfnProgress, void *pProgressData); 83 : }; 84 : 85 : /************************************************************************/ 86 : /* GDALRasterAlgorithmStepRegistry */ 87 : /************************************************************************/ 88 : 89 308 : class GDALRasterAlgorithmStepRegistry : public virtual GDALAlgorithmRegistry 90 : { 91 : public: 92 308 : GDALRasterAlgorithmStepRegistry() = default; 93 : ~GDALRasterAlgorithmStepRegistry() override; 94 : 95 : /** Register the algorithm of type MyAlgorithm. 96 : */ 97 : template <class MyAlgorithm> 98 10780 : bool Register(const std::string &name = std::string()) 99 : { 100 : static_assert( 101 : std::is_base_of_v<GDALRasterPipelineStepAlgorithm, MyAlgorithm>, 102 : "Algorithm is not a GDALRasterPipelineStepAlgorithm"); 103 : 104 21560 : AlgInfo info; 105 10780 : info.m_name = name.empty() ? MyAlgorithm::NAME : name; 106 10780 : info.m_aliases = MyAlgorithm::GetAliasesStatic(); 107 12825 : info.m_creationFunc = []() -> std::unique_ptr<GDALAlgorithm> 108 2045 : { return std::make_unique<MyAlgorithm>(); }; 109 21560 : return GDALAlgorithmRegistry::Register(info); 110 : } 111 : }; 112 : 113 : /************************************************************************/ 114 : /* GDALRasterPipelineAlgorithm */ 115 : /************************************************************************/ 116 : 117 : class GDALRasterPipelineAlgorithm final : public GDALAbstractPipelineAlgorithm 118 : { 119 : public: 120 : static constexpr const char *NAME = "pipeline"; 121 : static constexpr const char *DESCRIPTION = 122 : "Process a raster dataset applying several steps."; 123 : static constexpr const char *HELP_URL = 124 : "/programs/gdal_raster_pipeline.html"; 125 : 126 1371 : static std::vector<std::string> GetAliasesStatic() 127 : { 128 : return { 129 : #ifdef GDAL_PIPELINE_PROJ_NOSTALGIA 130 : GDALAlgorithmRegistry::HIDDEN_ALIAS_SEPARATOR, 131 : "+pipeline", 132 : "+gdal=pipeline", 133 : #endif 134 5484 : }; 135 : } 136 : 137 : explicit GDALRasterPipelineAlgorithm(bool openForMixedRasterVector = false); 138 : 139 : std::string GetUsageForCLI(bool shortUsage, 140 : const UsageOptions &usageOptions) const override; 141 : 142 : static void RegisterAlgorithms(GDALRasterAlgorithmStepRegistry ®istry, 143 : bool forMixedPipeline); 144 : 145 125 : int GetInputType() const override 146 : { 147 125 : return GDAL_OF_RASTER; 148 : } 149 : 150 0 : int GetOutputType() const override 151 : { 152 0 : return GDAL_OF_RASTER; 153 : } 154 : 155 : protected: 156 : GDALRasterAlgorithmStepRegistry m_stepRegistry{}; 157 : 158 198 : GDALAlgorithmRegistry &GetStepRegistry() override 159 : { 160 198 : return m_stepRegistry; 161 : } 162 : 163 1003 : const GDALAlgorithmRegistry &GetStepRegistry() const override 164 : { 165 1003 : return m_stepRegistry; 166 : } 167 : 168 : private: 169 : std::unique_ptr<GDALAbstractPipelineAlgorithm> 170 0 : CreateNestedPipeline() const override 171 : { 172 0 : return std::make_unique<GDALRasterPipelineAlgorithm>(); 173 : } 174 : }; 175 : 176 : //! @endcond 177 : 178 : #endif