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 RunImpl(GDALProgressFunc pfnProgress,
void *pProgressData)
override;
368 :
public GDALPipelineStepAlgorithm
371 std::vector<std::string> GetAutoComplete(std::vector<std::string> &args,
372 bool lastWordIsComplete,
375 bool Finalize()
override;
377 std::string GetUsageAsJSON()
const override;
380 ParseCommandLineArguments(
const std::vector<std::string> &args)
override;
382 bool HasSteps()
const
384 return !m_steps.empty();
387 static constexpr const char *OPEN_NESTED_PIPELINE =
"[";
388 static constexpr const char *CLOSE_NESTED_PIPELINE =
"]";
390 static constexpr const char *RASTER_SUFFIX =
"-raster";
391 static constexpr const char *VECTOR_SUFFIX =
"-vector";
394 friend class GDALTeeStepAlgorithmAbstract;
396 GDALAbstractPipelineAlgorithm(
397 const std::string &name,
const std::string &description,
398 const std::string &helpURL,
399 const GDALPipelineStepAlgorithm::ConstructorOptions &options)
400 : GDALPipelineStepAlgorithm(
401 name, description, helpURL,
402 ConstructorOptions(options).SetAutoOpenInputDatasets(false))
406 std::string m_pipeline{};
408 virtual GDALAlgorithmRegistry &GetStepRegistry() = 0;
410 virtual const GDALAlgorithmRegistry &GetStepRegistry()
const = 0;
412 std::unique_ptr<GDALPipelineStepAlgorithm>
413 GetStepAlg(
const std::string &name)
const;
415 bool HasOutputString()
const override;
417 static bool IsReadSpecificArgument(
const char *pszArgName);
418 static bool IsWriteSpecificArgument(
const char *pszArgName);
421 friend class GDALPipelineAlgorithm;
422 friend class GDALRasterPipelineAlgorithm;
423 friend class GDALVectorPipelineAlgorithm;
425 std::vector<std::unique_ptr<GDALPipelineStepAlgorithm>> m_steps{};
427 std::unique_ptr<GDALPipelineStepAlgorithm> m_stepOnWhichHelpIsRequested{};
429 bool m_bInnerPipeline =
false;
430 bool m_bExpectReadStep =
true;
432 enum class StepConstraint
439 StepConstraint m_eLastStepAsWrite = StepConstraint::CAN_BE;
441 std::vector<std::unique_ptr<GDALAbstractPipelineAlgorithm>>
442 m_apoNestedPipelines{};
445 static constexpr int MAX_NESTING_LEVEL = 3;
448 CheckFirstAndLastStep(
const std::vector<GDALPipelineStepAlgorithm *> &steps,
449 bool forAutoComplete)
const;
451 bool ParseCommandLineArguments(
const std::vector<std::string> &args,
452 bool forAutoComplete);
454 bool RunStep(GDALPipelineStepRunContext &ctxt)
override;
457 BuildNestedPipeline(GDALPipelineStepAlgorithm *curAlg,
458 std::vector<std::string> &nestedPipelineArgs,
459 bool forAutoComplete);
461 bool SaveGDALGFile(
const std::string &outFilename,
462 std::string &outString)
const;
464 virtual std::unique_ptr<GDALAbstractPipelineAlgorithm>
465 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:5768
ProcessGDALGOutputRet
Return value for ProcessGDALGOutput.
Definition gdalalgorithm_cpp.h:2926
virtual bool CheckSafeForStreamOutput()
Method executed by Run() when m_executionForStreamOutput is set to ensure the command is safe to exec...
Definition gdalalgorithm.cpp:5745
virtual ProcessGDALGOutputRet ProcessGDALGOutput()
Process output to a .gdalg file.
Definition gdalalgorithm.cpp:5181
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....