13#ifndef GDALALG_ABSTRACT_PIPELINE_INCLUDED
14#define GDALALG_ABSTRACT_PIPELINE_INCLUDED
20#include "gdalalgorithm.h"
29#ifndef GDAL_PIPELINE_PROJ_NOSTALGIA
30#define GDAL_PIPELINE_PROJ_NOSTALGIA
37class GDALPipelineStepAlgorithm;
39class GDALPipelineStepRunContext
42 GDALPipelineStepRunContext() =
default;
45 GDALProgressFunc m_pfnProgress =
nullptr;
46 void *m_pProgressData =
nullptr;
52 GDALPipelineStepAlgorithm *m_poNextUsableStep =
nullptr;
65 std::vector<GDALArgDatasetValue> &GetInputDatasets()
67 return m_inputDataset;
70 const std::vector<GDALArgDatasetValue> &GetInputDatasets()
const
72 return m_inputDataset;
75 GDALArgDatasetValue &GetOutputDataset()
77 return m_outputDataset;
80 const GDALArgDatasetValue &GetOutputDataset()
const
82 return m_outputDataset;
85 const std::string &GetOutputString()
const
90 const std::string &GetOutputLayerName()
const
92 return m_outputLayerName;
95 const std::string &GetOutputFormat()
const
100 const std::vector<std::string> &GetCreationOptions()
const
102 return m_creationOptions;
105 const std::vector<std::string> &GetLayerCreationOptions()
const
107 return m_layerCreationOptions;
110 bool GetOverwriteLayer()
const
112 return m_overwriteLayer;
115 bool GetAppendLayer()
const
117 return m_appendLayer;
120 virtual int GetInputType()
const = 0;
122 virtual int GetOutputType()
const = 0;
127 GDALDataset *GetInputDatasetRef()
129 return m_inputDataset.empty() ? nullptr
130 : m_inputDataset[0].GetDatasetRef();
134 void SetInputDataset(GDALDataset *poDS);
137 struct ConstructorOptions
139 bool standaloneStep =
false;
140 bool addDefaultArguments =
true;
141 bool autoOpenInputDatasets =
true;
142 bool outputDatasetRequired =
true;
143 bool addInputLayerNameArgument =
true;
144 bool addUpdateArgument =
true;
145 bool addAppendLayerArgument =
true;
146 bool addOverwriteLayerArgument =
true;
147 bool addUpsertArgument =
true;
148 bool addSkipErrorsArgument =
true;
149 bool addOutputLayerNameArgument =
true;
150 int inputDatasetMaxCount = 1;
151 std::string inputDatasetHelpMsg{};
152 std::string inputDatasetAlias{};
153 std::string inputDatasetMetaVar =
"INPUT";
154 std::string outputDatasetHelpMsg{};
157 inline ConstructorOptions &SetStandaloneStep(
bool b)
163 inline ConstructorOptions &SetAddDefaultArguments(
bool b)
165 addDefaultArguments = b;
169 inline ConstructorOptions &SetAddInputLayerNameArgument(
bool b)
171 addInputLayerNameArgument = b;
175 inline ConstructorOptions &SetInputDatasetMaxCount(
int maxCount)
177 inputDatasetMaxCount = maxCount;
181 inline ConstructorOptions &SetInputDatasetHelpMsg(
const std::string &s)
183 inputDatasetHelpMsg = s;
187 inline ConstructorOptions &SetInputDatasetAlias(
const std::string &s)
189 inputDatasetAlias = s;
193 inline ConstructorOptions &SetInputDatasetMetaVar(
const std::string &s)
195 inputDatasetMetaVar = s;
199 inline ConstructorOptions &SetOutputDatasetHelpMsg(
const std::string &s)
201 outputDatasetHelpMsg = s;
205 inline ConstructorOptions &SetAutoOpenInputDatasets(
bool b)
207 autoOpenInputDatasets = b;
211 inline ConstructorOptions &SetOutputDatasetRequired(
bool b)
213 outputDatasetRequired = b;
217 inline ConstructorOptions &
218 SetOutputFormatCreateCapability(
const std::string &capability)
220 outputFormatCreateCapability = capability;
224 inline ConstructorOptions &SetAddAppendLayerArgument(
bool b)
226 addAppendLayerArgument = b;
230 inline ConstructorOptions &SetAddOverwriteLayerArgument(
bool b)
232 addOverwriteLayerArgument = b;
236 inline ConstructorOptions &SetAddUpdateArgument(
bool b)
238 addUpdateArgument = b;
242 inline ConstructorOptions &SetAddUpsertArgument(
bool b)
244 addUpsertArgument = b;
248 inline ConstructorOptions &SetAddSkipErrorsArgument(
bool b)
250 addSkipErrorsArgument = b;
254 inline ConstructorOptions &SetAddOutputLayerNameArgument(
bool b)
256 addOutputLayerNameArgument = b;
261 GDALPipelineStepAlgorithm(
const std::string &name,
262 const std::string &description,
263 const std::string &helpURL,
264 const ConstructorOptions &);
266 friend class GDALPipelineAlgorithm;
267 friend class GDALRasterPipelineAlgorithm;
268 friend class GDALVectorPipelineAlgorithm;
269 friend class GDALAbstractPipelineAlgorithm;
271 virtual bool CanBeFirstStep()
const
276 virtual bool CanBeMiddleStep()
const
278 return !CanBeFirstStep() && !CanBeLastStep();
281 virtual bool CanBeLastStep()
const
287 virtual bool GeneratesFilesFromUserInput()
const
292 virtual bool IsNativelyStreamingCompatible()
const
297 virtual bool SupportsInputMultiThreading()
const
302 virtual bool CanHandleNextStep(GDALPipelineStepAlgorithm *)
const
307 virtual CPLJSONObject Get_OGR_SCHEMA_OpenOption_Layer()
const
314 virtual bool RunStep(GDALPipelineStepRunContext &ctxt) = 0;
316 bool m_standaloneStep =
false;
317 const ConstructorOptions m_constructorOptions;
318 bool m_outputVRTCompatible =
true;
319 std::string m_helpDocCategory{};
322 std::vector<GDALArgDatasetValue> m_inputDataset{};
323 std::vector<std::string> m_openOptions{};
324 std::vector<std::string> m_inputFormats{};
325 std::vector<std::string> m_inputLayerNames{};
328 bool m_stdout =
false;
329 std::string m_output{};
330 GDALArgDatasetValue m_outputDataset{};
331 std::string m_format{};
332 std::vector<std::string> m_outputOpenOptions{};
333 std::vector<std::string> m_creationOptions{};
334 bool m_overwrite =
false;
335 std::string m_outputLayerName{};
336 GDALInConstructionAlgorithmArg *m_outputFormatArg =
nullptr;
337 bool m_appendRaster =
false;
340 std::vector<std::string> m_layerCreationOptions{};
341 bool m_update =
false;
342 bool m_overwriteLayer =
false;
343 bool m_appendLayer =
false;
344 bool m_upsert =
false;
345 bool m_skipErrors =
false;
347 void AddRasterInputArgs(
bool openForMixedRasterVector,
bool hiddenForCLI);
348 void AddRasterOutputArgs(
bool hiddenForCLI);
349 void AddRasterHiddenInputDatasetArg();
351 void AddVectorInputArgs(
bool hiddenForCLI);
352 void AddVectorOutputArgs(
bool hiddenForCLI,
353 bool shortNameOutputLayerAllowed);
356 bool shortNameOutputLayerAllowed);
359 bool RunImpl(GDALProgressFunc pfnProgress,
void *pProgressData)
override;
371 :
public GDALPipelineStepAlgorithm
374 std::vector<std::string> GetAutoComplete(std::vector<std::string> &args,
375 bool lastWordIsComplete,
378 bool Finalize()
override;
380 std::string GetUsageAsJSON()
const override;
383 ParseCommandLineArguments(
const std::vector<std::string> &args)
override;
385 bool HasSteps()
const
387 return !m_steps.empty();
390 static constexpr const char *OPEN_NESTED_PIPELINE =
"[";
391 static constexpr const char *CLOSE_NESTED_PIPELINE =
"]";
393 static constexpr const char *RASTER_SUFFIX =
"-raster";
394 static constexpr const char *VECTOR_SUFFIX =
"-vector";
397 friend class GDALTeeStepAlgorithmAbstract;
399 GDALAbstractPipelineAlgorithm(
400 const std::string &name,
const std::string &description,
401 const std::string &helpURL,
402 const GDALPipelineStepAlgorithm::ConstructorOptions &options)
403 : GDALPipelineStepAlgorithm(
404 name, description, helpURL,
405 ConstructorOptions(options).SetAutoOpenInputDatasets(false))
409 std::string m_pipeline{};
411 virtual GDALAlgorithmRegistry &GetStepRegistry() = 0;
413 virtual const GDALAlgorithmRegistry &GetStepRegistry()
const = 0;
415 std::unique_ptr<GDALPipelineStepAlgorithm>
416 GetStepAlg(
const std::string &name)
const;
418 bool HasOutputString()
const override;
420 static bool IsReadSpecificArgument(
const char *pszArgName);
421 static bool IsWriteSpecificArgument(
const char *pszArgName);
424 friend class GDALPipelineAlgorithm;
425 friend class GDALRasterPipelineAlgorithm;
426 friend class GDALVectorPipelineAlgorithm;
428 std::vector<std::unique_ptr<GDALPipelineStepAlgorithm>> m_steps{};
430 std::unique_ptr<GDALPipelineStepAlgorithm> m_stepOnWhichHelpIsRequested{};
432 bool m_bInnerPipeline =
false;
433 bool m_bExpectReadStep =
true;
435 enum class StepConstraint
442 StepConstraint m_eLastStepAsWrite = StepConstraint::CAN_BE;
444 std::vector<std::unique_ptr<GDALAbstractPipelineAlgorithm>>
445 m_apoNestedPipelines{};
448 static constexpr int MAX_NESTING_LEVEL = 3;
451 CheckFirstAndLastStep(
const std::vector<GDALPipelineStepAlgorithm *> &steps,
452 bool forAutoComplete)
const;
454 bool ParseCommandLineArguments(
const std::vector<std::string> &args,
455 bool forAutoComplete);
457 bool RunStep(GDALPipelineStepRunContext &ctxt)
override;
460 BuildNestedPipeline(GDALPipelineStepAlgorithm *curAlg,
461 std::vector<std::string> &nestedPipelineArgs,
462 bool forAutoComplete);
464 bool SaveGDALGFile(
const std::string &outFilename,
465 std::string &outString)
const;
467 virtual std::unique_ptr<GDALAbstractPipelineAlgorithm>
468 CreateNestedPipeline()
const = 0;
void Deinit()
Decrement reference counter and make pointer NULL.
Definition cpl_json.cpp:1343
GDAL algorithm.
Definition gdalalgorithm_cpp.h:2261
virtual bool Finalize()
Complete any pending actions, and return the final status.
Definition gdalalgorithm.cpp:5819
ProcessGDALGOutputRet
Return value for ProcessGDALGOutput.
Definition gdalalgorithm_cpp.h:2926
GDALInConstructionAlgorithmArg & AddOutputLayerNameArg(std::string *pValue, const char *helpMessage=nullptr)
Add (single) output layer name argument.
Definition gdalalgorithm.cpp:4665
virtual bool CheckSafeForStreamOutput()
Method executed by Run() when m_executionForStreamOutput is set to ensure the command is safe to exec...
Definition gdalalgorithm.cpp:5796
virtual ProcessGDALGOutputRet ProcessGDALGOutput()
Process output to a .gdalg file.
Definition gdalalgorithm.cpp:5232
Interface for read and write JSON documents.
#define CPL_NON_FINAL
Mark that a class is explicitly recognized as non-final.
Definition cpl_port.h:929
#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_DCAP_CREATECOPY
Capability set by a driver that implements the CreateCopy() API.
Definition gdal.h:597
This file is legacy since GDAL 3.12, but will be kept at least in the whole GDAL 3....