13#ifndef GDALALG_EXTERNAL_INCLUDED
14#define GDALALG_EXTERNAL_INCLUDED
18#include "gdalalg_abstract_pipeline.h"
19#include "gdalalg_raster_pipeline.h"
20#include "gdalalg_vector_pipeline.h"
30class GDALExternalAlgorithmBase
33 GDALExternalAlgorithmBase() =
default;
34 virtual ~GDALExternalAlgorithmBase();
38 std::string m_osTempInputFilename{};
39 std::string m_osTempOutputFilename{};
41 bool Run(
const std::vector<std::string> &inputFormats,
42 std::vector<GDALArgDatasetValue> &inputDataset,
43 const std::string &outputFormat,
51template <
class BaseStepAlgorithm,
int nDatasetType>
52class GDALExternalAlgorithm :
public BaseStepAlgorithm,
53 public GDALExternalAlgorithmBase
56 static constexpr const char *NAME =
"external";
57 static constexpr const char *DESCRIPTION =
58 "Execute an external program as a step of a pipeline";
59 static constexpr const char *HELP_URL =
"/programs/gdal_external.html";
61 GDALExternalAlgorithm()
62 : BaseStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
63 GDALPipelineStepAlgorithm::ConstructorOptions()
64 .SetAddDefaultArguments(false))
66 this->AddArg(
"command", 0,
67 _(
"External command, optionally with <INPUT> and/or "
68 "<OUTPUT> or <INPUT-OUTPUT> placeholders"),
74 this->AddInputFormatsArg(&this->m_inputFormats)
76 .AddMetadataItem(GAAMDI_EXCLUDED_FORMATS, {
"MEM"});
77 this->AddOutputFormatArg(&this->m_format,
false,
79 .AddMetadataItem(GAAMDI_EXCLUDED_FORMATS, {
"MEM"});
82 this->AddInputDatasetArg(&this->m_inputDataset, nDatasetType,
false)
85 .SetDatasetInputFlags(GADV_OBJECT)
87 this->AddOutputDatasetArg(&this->m_outputDataset, nDatasetType,
false)
88 .SetDatasetInputFlags(GADV_OBJECT)
92 int GetInputType()
const override
97 int GetOutputType()
const override
102 bool CanBeFirstStep()
const override
107 bool CanBeMiddleStep()
const override
112 bool CanBeLastStep()
const override
117 bool IsNativelyStreamingCompatible()
const override
123 bool RunStep(GDALPipelineStepRunContext &)
override
125 return GDALExternalAlgorithmBase::Run(
126 this->m_inputFormats, this->m_inputDataset, this->m_format,
127 this->m_outputDataset);
135class GDALExternalRasterOrVectorAlgorithm final
136 :
public GDALExternalAlgorithm<GDALPipelineStepAlgorithm, 0>
139 GDALExternalRasterOrVectorAlgorithm() =
default;
141 ~GDALExternalRasterOrVectorAlgorithm()
override;
148class GDALExternalRasterAlgorithm final
149 :
public GDALExternalAlgorithm<GDALRasterPipelineStepAlgorithm,
153 GDALExternalRasterAlgorithm() =
default;
155 ~GDALExternalRasterAlgorithm()
override;
162class GDALExternalVectorAlgorithm final
163 :
public GDALExternalAlgorithm<GDALVectorPipelineStepAlgorithm,
167 GDALExternalVectorAlgorithm() =
default;
169 ~GDALExternalVectorAlgorithm()
override;
Convenient string class based on std::string.
Definition cpl_string.h:338
Value for an argument that points to a GDALDataset.
Definition gdalalgorithm_cpp.h:163