13#ifndef GDALALG_VECTOR_PIPELINE_INCLUDED
14#define GDALALG_VECTOR_PIPELINE_INCLUDED
16#include "gdalalgorithm.h"
17#include "gdalalg_abstract_pipeline.h"
20#include "ogrlayerwithtranslatefeature.h"
31class GDALRasterAlgorithmStepRegistry;
33class GDALVectorPipelineStepAlgorithm
34 :
public GDALPipelineStepAlgorithm
37 ~GDALVectorPipelineStepAlgorithm()
override;
40 GDALVectorPipelineStepAlgorithm(
const std::string &name,
41 const std::string &description,
42 const std::string &helpURL,
45 GDALVectorPipelineStepAlgorithm(
const std::string &name,
46 const std::string &description,
47 const std::string &helpURL,
48 const ConstructorOptions &options);
50 friend class GDALVectorPipelineAlgorithm;
51 friend class GDALVectorConcatAlgorithm;
53 int GetInputType()
const override
58 int GetOutputType()
const override
71 GDALVectorAlgorithmStepRegistry() =
default;
72 ~GDALVectorAlgorithmStepRegistry()
override;
76 template <
class MyAlgorithm>
77 bool Register(
const std::string &name = std::string())
80 std::is_base_of_v<GDALVectorPipelineStepAlgorithm, MyAlgorithm>,
81 "Algorithm is not a GDALVectorPipelineStepAlgorithm");
84 info.m_name = name.empty() ? MyAlgorithm::NAME : name;
85 info.m_aliases = MyAlgorithm::GetAliasesStatic();
86 info.m_creationFunc = []() -> std::unique_ptr<GDALAlgorithm>
87 {
return std::make_unique<MyAlgorithm>(); };
96class GDALVectorPipelineAlgorithm final :
public GDALAbstractPipelineAlgorithm
99 static constexpr const char *NAME =
"pipeline";
100 static constexpr const char *DESCRIPTION =
101 "Process a vector dataset applying several steps.";
102 static constexpr const char *HELP_URL =
103 "/programs/gdal_vector_pipeline.html";
105 static std::vector<std::string> GetAliasesStatic()
108#ifdef GDAL_PIPELINE_PROJ_NOSTALGIA
116 GDALVectorPipelineAlgorithm();
118 std::string GetUsageForCLI(
bool shortUsage,
119 const UsageOptions &usageOptions)
const override;
121 static void RegisterAlgorithms(GDALVectorAlgorithmStepRegistry ®istry,
122 bool forMixedPipeline);
124 int GetInputType()
const override
129 int GetOutputType()
const override
135 GDALVectorAlgorithmStepRegistry m_stepRegistry{};
137 GDALAlgorithmRegistry &GetStepRegistry()
override
139 return m_stepRegistry;
142 const GDALAlgorithmRegistry &GetStepRegistry()
const override
144 return m_stepRegistry;
148 std::unique_ptr<GDALAbstractPipelineAlgorithm>
149 CreateNestedPipeline()
const override
151 auto pipeline = std::make_unique<GDALVectorPipelineAlgorithm>();
152 pipeline->m_bInnerPipeline =
true;
161class GDALVectorOutputDataset final :
public GDALDataset
167 return static_cast<int>(m_layers.size());
170 const OGRLayer *
GetLayer(
int idx)
const override
172 return m_layers[idx].get();
177 void AddLayer(std::unique_ptr<OGRLayer> layer)
179 m_layers.emplace_back(std::move(layer));
183 std::vector<std::unique_ptr<OGRLayer>> m_layers{};
194class GDALVectorPipelineOutputLayer
195 :
public OGRLayerWithTranslateFeature,
199 explicit GDALVectorPipelineOutputLayer(OGRLayer &oSrcLayer);
200 ~GDALVectorPipelineOutputLayer()
override;
204 OGRLayer &m_srcLayer;
206 void FailTranslation()
208 m_translateError =
true;
212 void ResetReading()
override;
213 OGRFeature *GetNextRawFeature();
216 std::vector<std::unique_ptr<OGRFeature>> m_pendingFeatures{};
217 size_t m_idxInPendingFeatures = 0;
218 bool m_translateError =
false;
228class GDALVectorPipelinePassthroughLayer
229 :
public GDALVectorPipelineOutputLayer
232 explicit GDALVectorPipelinePassthroughLayer(OGRLayer &oSrcLayer)
233 : GDALVectorPipelineOutputLayer(oSrcLayer)
237 const OGRFeatureDefn *GetLayerDefn()
const override;
239 int TestCapability(
const char *pszCap)
const override
241 return m_srcLayer.TestCapability(pszCap);
244 void TranslateFeature(
245 std::unique_ptr<OGRFeature> poSrcFeature,
246 std::vector<std::unique_ptr<OGRFeature>> &apoOutFeatures)
override
248 apoOutFeatures.push_back(std::move(poSrcFeature));
262class GDALVectorNonStreamingAlgorithmDataset
266 GDALVectorNonStreamingAlgorithmDataset();
267 ~GDALVectorNonStreamingAlgorithmDataset()
override;
269 virtual bool Process(OGRLayer &srcLayer, OGRLayer &dstLayer) = 0;
271 bool AddProcessedLayer(OGRLayer &srcLayer);
272 bool AddProcessedLayer(OGRLayer &srcLayer, OGRFeatureDefn &dstDefn);
273 void AddPassThroughLayer(OGRLayer &oLayer);
275 OGRLayer *GetLayer(
int idx) const final override;
276 int TestCapability(const
char *pszCap) const override;
279 std::vector<std::unique_ptr<OGRLayer>> m_passthrough_layers{};
280 std::vector<OGRLayer *> m_layers{};
281 std::unique_ptr<MEMDataset> m_ds{};
291class GDALVectorPipelineOutputDataset final :
public GDALDataset
293 GDALDataset &m_srcDS;
294 std::map<OGRLayer *, OGRLayerWithTranslateFeature *>
295 m_mapSrcLayerToNewLayer{};
296 std::vector<std::unique_ptr<OGRLayerWithTranslateFeature>>
298 std::vector<OGRLayerWithTranslateFeature *> m_layers{};
300 OGRLayerWithTranslateFeature *m_belongingLayer =
nullptr;
301 std::vector<std::unique_ptr<OGRFeature>> m_pendingFeatures{};
302 size_t m_idxInPendingFeatures = 0;
307 explicit GDALVectorPipelineOutputDataset(GDALDataset &oSrcDS);
309 void AddLayer(OGRLayer &oSrcLayer,
310 std::unique_ptr<OGRLayerWithTranslateFeature> poNewLayer);
314 OGRLayer *
GetLayer(
int idx)
const override;
321 double *pdfProgressPct,
322 GDALProgressFunc pfnProgress,
323 void *pProgressData)
override;
Registry of GDAL algorithms.
Definition gdalalgorithm_cpp.h:2132
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
bool Register()
Register the algorithm of type MyAlgorithm.
Definition gdalalgorithm_cpp.h:2159
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
virtual const OGRLayer * GetLayer(int iLayer) const
Fetch a layer by index.
Definition gdaldataset.cpp:7864
virtual void ResetReading()
Reset feature reading to start on the first feature.
Definition gdaldataset.cpp:7926
virtual OGRFeature * GetNextFeature(OGRLayer **ppoBelongingLayer, double *pdfProgressPct, GDALProgressFunc pfnProgress, void *pProgressData)
Fetch the next available feature from this dataset.
Definition gdaldataset.cpp:8016
virtual int TestCapability(const char *) const
Test if capability is available.
Definition gdaldataset.cpp:8241
virtual int GetLayerCount() const
Get the number of layers in this dataset.
Definition gdaldataset.cpp:7831
Template class offering a GetNextFeature() implementation relying on GetNextRawFeature().
Definition ogrsf_frmts.h:501
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
#define GDAL_OF_VECTOR
Allow vector drivers to be used.
Definition gdal.h:1091
Classes related to registration of format support, and opening datasets.
#define DEFINE_GET_NEXT_FEATURE_THROUGH_RAW(BaseLayer)
Utility macro to define GetNextFeature() through GetNextRawFeature().
Definition ogrsf_frmts.h:531