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;
77 return m_outputDataset;
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;
129 return m_inputDataset.empty() ? nullptr
130 : m_inputDataset[0].GetDatasetRef();
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{};
155 std::string updateMutualExclusionGroup{};
156 std::string outputDatasetMutualExclusionGroup{};
159 inline ConstructorOptions &SetStandaloneStep(
bool b)
165 inline ConstructorOptions &SetAddDefaultArguments(
bool b)
167 addDefaultArguments = b;
171 inline ConstructorOptions &SetAddInputLayerNameArgument(
bool b)
173 addInputLayerNameArgument = b;
177 inline ConstructorOptions &SetInputDatasetMaxCount(
int maxCount)
179 inputDatasetMaxCount = maxCount;
183 inline ConstructorOptions &SetInputDatasetHelpMsg(
const std::string &s)
185 inputDatasetHelpMsg = s;
189 inline ConstructorOptions &SetInputDatasetAlias(
const std::string &s)
191 inputDatasetAlias = s;
195 inline ConstructorOptions &SetInputDatasetMetaVar(
const std::string &s)
197 inputDatasetMetaVar = s;
201 inline ConstructorOptions &SetOutputDatasetHelpMsg(
const std::string &s)
203 outputDatasetHelpMsg = s;
207 inline ConstructorOptions &SetAutoOpenInputDatasets(
bool b)
209 autoOpenInputDatasets = b;
213 inline ConstructorOptions &SetOutputDatasetRequired(
bool b)
215 outputDatasetRequired = b;
219 inline ConstructorOptions &
220 SetUpdateMutualExclusionGroup(
const std::string &s)
222 updateMutualExclusionGroup = s;
226 inline ConstructorOptions &
227 SetOutputDatasetMutualExclusionGroup(
const std::string &s)
229 outputDatasetMutualExclusionGroup = s;
233 inline ConstructorOptions &
234 SetOutputFormatCreateCapability(
const std::string &capability)
236 outputFormatCreateCapability = capability;
240 inline ConstructorOptions &SetAddAppendLayerArgument(
bool b)
242 addAppendLayerArgument = b;
246 inline ConstructorOptions &SetAddOverwriteLayerArgument(
bool b)
248 addOverwriteLayerArgument = b;
252 inline ConstructorOptions &SetAddUpdateArgument(
bool b)
254 addUpdateArgument = b;
258 inline ConstructorOptions &SetAddUpsertArgument(
bool b)
260 addUpsertArgument = b;
264 inline ConstructorOptions &SetAddSkipErrorsArgument(
bool b)
266 addSkipErrorsArgument = b;
270 inline ConstructorOptions &SetAddOutputLayerNameArgument(
bool b)
272 addOutputLayerNameArgument = b;
277 GDALPipelineStepAlgorithm(
const std::string &name,
278 const std::string &description,
279 const std::string &helpURL,
280 const ConstructorOptions &);
282 friend class GDALPipelineAlgorithm;
283 friend class GDALRasterPipelineAlgorithm;
284 friend class GDALVectorPipelineAlgorithm;
285 friend class GDALAbstractPipelineAlgorithm;
287 virtual bool CanBeFirstStep()
const
292 virtual bool CanBeMiddleStep()
const
294 return !CanBeFirstStep() && !CanBeLastStep();
297 virtual bool CanBeLastStep()
const
303 virtual bool GeneratesFilesFromUserInput()
const
308 virtual bool IsNativelyStreamingCompatible()
const
313 virtual bool SupportsInputMultiThreading()
const
318 virtual bool CanHandleNextStep(GDALPipelineStepAlgorithm *)
const
323 virtual bool OutputDatasetAllowedBeforeRunningStep()
const
328 virtual CPLJSONObject Get_OGR_SCHEMA_OpenOption_Layer()
const
335 virtual bool RunStep(GDALPipelineStepRunContext &ctxt) = 0;
337 bool m_standaloneStep =
false;
338 const ConstructorOptions m_constructorOptions;
339 bool m_outputVRTCompatible =
true;
340 std::string m_helpDocCategory{};
343 std::vector<GDALArgDatasetValue> m_inputDataset{};
344 std::vector<std::string> m_openOptions{};
345 std::vector<std::string> m_inputFormats{};
346 std::vector<std::string> m_inputLayerNames{};
349 bool m_stdout =
false;
350 std::string m_output{};
352 std::string m_format{};
353 std::vector<std::string> m_outputOpenOptions{};
354 std::vector<std::string> m_creationOptions{};
355 bool m_overwrite =
false;
356 std::string m_outputLayerName{};
358 bool m_appendRaster =
false;
361 std::vector<std::string> m_layerCreationOptions{};
362 bool m_update =
false;
363 bool m_overwriteLayer =
false;
364 bool m_appendLayer =
false;
365 bool m_upsert =
false;
366 bool m_skipErrors =
false;
368 void AddRasterInputArgs(
bool openForMixedRasterVector,
bool hiddenForCLI);
369 void AddRasterOutputArgs(
bool hiddenForCLI);
370 void AddRasterHiddenInputDatasetArg();
372 void AddVectorInputArgs(
bool hiddenForCLI);
373 void AddVectorOutputArgs(
bool hiddenForCLI,
374 bool shortNameOutputLayerAllowed);
377 bool RunImpl(GDALProgressFunc pfnProgress,
void *pProgressData)
override;
389 :
public GDALPipelineStepAlgorithm
392 std::vector<std::string> GetAutoComplete(std::vector<std::string> &args,
393 bool lastWordIsComplete,
396 bool Finalize()
override;
398 std::string GetUsageAsJSON()
const override;
401 ParseCommandLineArguments(
const std::vector<std::string> &args)
override;
403 bool HasSteps()
const
405 return !m_steps.empty();
408 static constexpr const char *OPEN_NESTED_PIPELINE =
"[";
409 static constexpr const char *CLOSE_NESTED_PIPELINE =
"]";
411 static constexpr const char *RASTER_SUFFIX =
"-raster";
412 static constexpr const char *VECTOR_SUFFIX =
"-vector";
415 friend class GDALTeeStepAlgorithmAbstract;
417 GDALAbstractPipelineAlgorithm(
418 const std::string &name,
const std::string &description,
419 const std::string &helpURL,
420 const GDALPipelineStepAlgorithm::ConstructorOptions &options)
421 : GDALPipelineStepAlgorithm(
422 name, description, helpURL,
423 ConstructorOptions(options).SetAutoOpenInputDatasets(false))
427 std::string m_pipeline{};
433 std::unique_ptr<GDALPipelineStepAlgorithm>
434 GetStepAlg(
const std::string &name)
const;
436 bool HasOutputString()
const override;
438 static bool IsReadSpecificArgument(
const char *pszArgName);
439 static bool IsWriteSpecificArgument(
const char *pszArgName);
442 friend class GDALPipelineAlgorithm;
443 friend class GDALRasterPipelineAlgorithm;
444 friend class GDALVectorPipelineAlgorithm;
446 std::vector<std::unique_ptr<GDALPipelineStepAlgorithm>> m_steps{};
448 std::unique_ptr<GDALPipelineStepAlgorithm> m_stepOnWhichHelpIsRequested{};
450 bool m_bInnerPipeline =
false;
451 bool m_bExpectReadStep =
true;
453 enum class StepConstraint
460 StepConstraint m_eLastStepAsWrite = StepConstraint::CAN_BE;
462 std::vector<std::unique_ptr<GDALAbstractPipelineAlgorithm>>
463 m_apoNestedPipelines{};
466 static constexpr int MAX_NESTING_LEVEL = 3;
469 CheckFirstAndLastStep(
const std::vector<GDALPipelineStepAlgorithm *> &steps,
470 bool forAutoComplete)
const;
472 bool ParseCommandLineArguments(
const std::vector<std::string> &args,
473 bool forAutoComplete);
475 bool RunStep(GDALPipelineStepRunContext &ctxt)
override;
478 BuildNestedPipeline(GDALPipelineStepAlgorithm *curAlg,
479 std::vector<std::string> &nestedPipelineArgs,
480 bool forAutoComplete);
482 bool SaveGDALGFile(
const std::string &outFilename,
483 std::string &outString)
const;
485 virtual std::unique_ptr<GDALAbstractPipelineAlgorithm>
486 CreateNestedPipeline()
const = 0;
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition cpl_json.h:56
void Deinit()
Decrement reference counter and make pointer NULL.
Definition cpl_json.cpp:1343
Registry of GDAL algorithms.
Definition gdalalgorithm_cpp.h:2132
GDAL algorithm.
Definition gdalalgorithm_cpp.h:2261
virtual bool Finalize()
Complete any pending actions, and return the final status.
Definition gdalalgorithm.cpp:5790
ProcessGDALGOutputRet
Return value for ProcessGDALGOutput.
Definition gdalalgorithm_cpp.h:2925
virtual bool CheckSafeForStreamOutput()
Method executed by Run() when m_executionForStreamOutput is set to ensure the command is safe to exec...
Definition gdalalgorithm.cpp:5767
virtual ProcessGDALGOutputRet ProcessGDALGOutput()
Process output to a .gdalg file.
Definition gdalalgorithm.cpp:5203
Value for an argument that points to a GDALDataset.
Definition gdalalgorithm_cpp.h:149
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
Technical class used by GDALAlgorithm when constructing argument declarations.
Definition gdalalgorithm_cpp.h:1771
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:599
This file is legacy since GDAL 3.12, but will be kept at least in the whole GDAL 3....