GDAL

gdalalg_raster_pipeline.h
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
20
21/************************************************************************/
22/* GDALRasterPipelineStepAlgorithm */
23/************************************************************************/
24
25 class GDALRasterAlgorithmStepRegistry;
26
27 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 int GetInputType() const override
48 {
49 return GDAL_OF_RASTER;
50 }
51
52 int GetOutputType() const override
53 {
54 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 class GDALRasterAlgorithmStepRegistry : public virtual GDALAlgorithmRegistry
90{
91 public:
92 GDALRasterAlgorithmStepRegistry() = default;
93 ~GDALRasterAlgorithmStepRegistry() override;
94
97 template <class MyAlgorithm>
98 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 AlgInfo info;
105 info.m_name = name.empty() ? MyAlgorithm::NAME : name;
106 info.m_aliases = MyAlgorithm::GetAliasesStatic();
107 info.m_creationFunc = []() -> std::unique_ptr<GDALAlgorithm>
108 { return std::make_unique<MyAlgorithm>(); };
109 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 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 };
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 &registry,
143 bool forMixedPipeline);
144
145 int GetInputType() const override
146 {
147 return GDAL_OF_RASTER;
148 }
149
150 int GetOutputType() const override
151 {
152 return GDAL_OF_RASTER;
153 }
154
155 protected:
156 GDALRasterAlgorithmStepRegistry m_stepRegistry{};
157
158 GDALAlgorithmRegistry &GetStepRegistry() override
159 {
160 return m_stepRegistry;
161 }
162
163 const GDALAlgorithmRegistry &GetStepRegistry() const override
164 {
165 return m_stepRegistry;
166 }
167
168 private:
169 std::unique_ptr<GDALAbstractPipelineAlgorithm>
170 CreateNestedPipeline() const override
171 {
172 auto pipeline = std::make_unique<GDALRasterPipelineAlgorithm>();
173 pipeline->m_bInnerPipeline = true;
174 return pipeline;
175 }
176};
177
179
180#endif
GDALAlgorithmRegistry
Registry of GDAL algorithms.
Definition gdalalgorithm_cpp.h:2132
GDALAlgorithmRegistry::HIDDEN_ALIAS_SEPARATOR
static constexpr const char * HIDDEN_ALIAS_SEPARATOR
Special value to put in m_aliases to separate public alias from hidden aliases.
Definition gdalalgorithm_cpp.h:2136
GDALAlgorithmRegistry::Register
bool Register()
Register the algorithm of type MyAlgorithm.
Definition gdalalgorithm_cpp.h:2159
GDALAlgorithm
GDAL algorithm.
Definition gdalalgorithm_cpp.h:2261
GDALDataset
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
GDALDataType
GDALDataType
Definition gdal.h:48
GDAL_OF_RASTER
#define GDAL_OF_RASTER
Allow raster drivers to be used.
Definition gdal.h:1086