Skip to content

Commit

Permalink
gdal vector pipeline steps in standalone mode: allow --of=stream
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Feb 5, 2025
1 parent 7d406c7 commit e298990
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
18 changes: 13 additions & 5 deletions apps/gdalalg_vector_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void GDALVectorPipelineStepAlgorithm::AddInputArgs(bool hiddenForCLI)
void GDALVectorPipelineStepAlgorithm::AddOutputArgs(
bool hiddenForCLI, bool shortNameOutputLayerAllowed)
{
AddOutputFormatArg(&m_format)
AddOutputFormatArg(&m_format, true)
.AddMetadataItem(GAAMDI_REQUIRED_CAPABILITIES,
{GDAL_DCAP_VECTOR, GDAL_DCAP_CREATE})
.SetHiddenForCLI(hiddenForCLI);
Expand Down Expand Up @@ -138,13 +138,21 @@ bool GDALVectorPipelineStepAlgorithm::RunImpl(GDALProgressFunc pfnProgress,
m_outputDataset.Set(nullptr);
if (RunStep(nullptr, nullptr))
{
writeAlg.m_inputDataset.Set(m_outputDataset.GetDatasetRef());
if (writeAlg.Run(pfnProgress, pProgressData))
if (m_format == "stream")
{
m_outputDataset.Set(
writeAlg.m_outputDataset.GetDatasetRef());
ret = true;
}
else
{
writeAlg.m_inputDataset.Set(
m_outputDataset.GetDatasetRef());
if (writeAlg.Run(pfnProgress, pProgressData))
{
m_outputDataset.Set(
writeAlg.m_outputDataset.GetDatasetRef());
ret = true;
}
}
}
}

Expand Down
27 changes: 18 additions & 9 deletions gcore/gdalalgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2328,12 +2328,17 @@ GDALAlgorithm::AddOpenOptionsArg(std::vector<std::string> *pValue)
/* ValidateFormat() */
/************************************************************************/

bool GDALAlgorithm::ValidateFormat(const GDALAlgorithmArg &arg) const
bool GDALAlgorithm::ValidateFormat(const GDALAlgorithmArg &arg,
bool bStreamAllowed) const
{
if (arg.GetChoices().empty())
{
const auto Validate = [this, &arg](const std::string &val)
const auto Validate =
[this, &arg, bStreamAllowed](const std::string &val)
{
if (bStreamAllowed && val == "stream")
return true;

auto hDriver = GDALGetDriverByName(val.c_str());
if (!hDriver)
{
Expand Down Expand Up @@ -2451,7 +2456,8 @@ GDALAlgorithm::AddInputFormatsArg(std::vector<std::string> *pValue)
AddArg(GDAL_ARG_NAME_INPUT_FORMAT, 0, _("Input formats"), pValue)
.AddAlias("if")
.SetCategory(GAAC_ADVANCED);
arg.AddValidationAction([this, &arg]() { return ValidateFormat(arg); });
arg.AddValidationAction([this, &arg]()
{ return ValidateFormat(arg, false); });
arg.SetAutoCompleteFunction([&arg](const std::string &)
{ return FormatAutoCompleteFunction(arg); });
return arg;
Expand All @@ -2462,13 +2468,16 @@ GDALAlgorithm::AddInputFormatsArg(std::vector<std::string> *pValue)
/************************************************************************/

GDALInConstructionAlgorithmArg &
GDALAlgorithm::AddOutputFormatArg(std::string *pValue)
GDALAlgorithm::AddOutputFormatArg(std::string *pValue, bool bStreamAllowed)
{
auto &arg =
AddArg(GDAL_ARG_NAME_OUTPUT_FORMAT, 'f', _("Output format"), pValue)
.AddAlias("of")
.AddAlias("format");
arg.AddValidationAction([this, &arg]() { return ValidateFormat(arg); });
auto &arg = AddArg(GDAL_ARG_NAME_OUTPUT_FORMAT, 'f',
bStreamAllowed ? _("Output format (\"stream\" allowed)")
: _("Output format"),
pValue)
.AddAlias("of")
.AddAlias("format");
arg.AddValidationAction([this, &arg, bStreamAllowed]()
{ return ValidateFormat(arg, bStreamAllowed); });
arg.SetAutoCompleteFunction([&arg](const std::string &)
{ return FormatAutoCompleteFunction(arg); });
return arg;
Expand Down
5 changes: 3 additions & 2 deletions gcore/gdalalgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,8 @@ class CPL_DLL GDALAlgorithmRegistry
GDALInConstructionAlgorithmArg &AddOutputStringArg(std::string *pValue);

/** Add output format argument. */
GDALInConstructionAlgorithmArg &AddOutputFormatArg(std::string *pValue);
GDALInConstructionAlgorithmArg &
AddOutputFormatArg(std::string *pValue, bool bStreamAllowed = false);

/** Add creation option(s) argument. */
GDALInConstructionAlgorithmArg &
Expand Down Expand Up @@ -2241,7 +2242,7 @@ class CPL_DLL GDALAlgorithmRegistry
std::vector<double>, std::vector<GDALArgDatasetValue>>>
&inConstructionValues);

bool ValidateFormat(const GDALAlgorithmArg &arg) const;
bool ValidateFormat(const GDALAlgorithmArg &arg, bool bStreamAllowed) const;

virtual bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) = 0;

Expand Down

0 comments on commit e298990

Please sign in to comment.