|
28 | 28 | #include "gdalalg_raster_contour.h" |
29 | 29 | #include "gdalalg_raster_footprint.h" |
30 | 30 | #include "gdalalg_raster_polygonize.h" |
| 31 | +#include "gdalalg_raster_info.h" |
31 | 32 | #include "gdalalg_vector_grid.h" |
| 33 | +#include "gdalalg_vector_info.h" |
32 | 34 | #include "gdalalg_vector_rasterize.h" |
33 | 35 |
|
34 | 36 | #include <algorithm> |
@@ -219,9 +221,19 @@ bool GDALPipelineStepAlgorithm::RunImpl(GDALProgressFunc pfnProgress, |
219 | 221 |
|
220 | 222 | std::unique_ptr<GDALPipelineStepAlgorithm> writeAlg; |
221 | 223 | if (GetOutputType() == GDAL_OF_RASTER) |
222 | | - writeAlg = std::make_unique<GDALRasterWriteAlgorithm>(); |
| 224 | + { |
| 225 | + if (GetName() == GDALRasterInfoAlgorithm::NAME) |
| 226 | + writeAlg = std::make_unique<GDALRasterInfoAlgorithm>(); |
| 227 | + else |
| 228 | + writeAlg = std::make_unique<GDALRasterWriteAlgorithm>(); |
| 229 | + } |
223 | 230 | else |
224 | | - writeAlg = std::make_unique<GDALVectorWriteAlgorithm>(); |
| 231 | + { |
| 232 | + if (GetName() == GDALVectorInfoAlgorithm::NAME) |
| 233 | + writeAlg = std::make_unique<GDALVectorInfoAlgorithm>(); |
| 234 | + else |
| 235 | + writeAlg = std::make_unique<GDALVectorWriteAlgorithm>(); |
| 236 | + } |
225 | 237 | for (auto &arg : writeAlg->GetArgs()) |
226 | 238 | { |
227 | 239 | auto stepArg = GetArg(arg->GetName()); |
@@ -252,8 +264,9 @@ bool GDALPipelineStepAlgorithm::RunImpl(GDALProgressFunc pfnProgress, |
252 | 264 | } |
253 | 265 | else if (readAlg->Run()) |
254 | 266 | { |
| 267 | + auto outputArg = GetArg(GDAL_ARG_NAME_OUTPUT); |
255 | 268 | const bool bOutputSpecified = |
256 | | - GetArg(GDAL_ARG_NAME_OUTPUT)->IsExplicitlySet(); |
| 269 | + outputArg && outputArg->IsExplicitlySet(); |
257 | 270 |
|
258 | 271 | m_inputDataset.clear(); |
259 | 272 | m_inputDataset.resize(1); |
@@ -402,6 +415,14 @@ class GDALPipelineAlgorithm final |
402 | 415 | .SetHiddenForCLI() |
403 | 416 | .SetPositional(); |
404 | 417 |
|
| 418 | + AddOutputStringArg(&m_output).SetHiddenForCLI(); |
| 419 | + AddArg( |
| 420 | + "stdout", 0, |
| 421 | + _("Directly output on stdout (format=text mode only). If enabled, " |
| 422 | + "output-string will be empty"), |
| 423 | + &m_stdout) |
| 424 | + .SetHidden(); |
| 425 | + |
405 | 426 | GDALRasterPipelineAlgorithm::RegisterAlgorithms(m_stepRegistry, true); |
406 | 427 | GDALVectorPipelineAlgorithm::RegisterAlgorithms(m_stepRegistry, true); |
407 | 428 | m_stepRegistry.Register<GDALRasterContourAlgorithm>(); |
@@ -618,24 +639,28 @@ bool GDALPipelineAlgorithm::ParseCommandLineArguments( |
618 | 639 | if (!CheckFirstStep(stepAlgs)) |
619 | 640 | return false; // CheckFirstStep emits an error |
620 | 641 |
|
621 | | - if (steps.back().alg->GetName() != GDALRasterWriteAlgorithm::NAME) |
| 642 | + if (steps.back().alg->GetName() != GDALRasterWriteAlgorithm::NAME && |
| 643 | + steps.back().alg->GetName() != GDALRasterInfoAlgorithm::NAME) |
622 | 644 | { |
623 | 645 | if (helpRequested) |
624 | 646 | { |
625 | 647 | steps.back().alg->ParseCommandLineArguments(steps.back().args); |
626 | 648 | return false; |
627 | 649 | } |
628 | | - ReportError(CE_Failure, CPLE_AppDefined, "Last step should be '%s'", |
629 | | - GDALRasterWriteAlgorithm::NAME); |
| 650 | + ReportError( |
| 651 | + CE_Failure, CPLE_AppDefined, "Last step should be '%s' or '%s'", |
| 652 | + GDALRasterWriteAlgorithm::NAME, GDALRasterInfoAlgorithm::NAME); |
630 | 653 | return false; |
631 | 654 | } |
632 | 655 | for (size_t i = 0; i < steps.size() - 1; ++i) |
633 | 656 | { |
634 | | - if (steps[i].alg->GetName() == GDALRasterWriteAlgorithm::NAME) |
| 657 | + if (steps[i].alg->GetName() == GDALRasterWriteAlgorithm::NAME || |
| 658 | + steps[i].alg->GetName() == GDALRasterInfoAlgorithm::NAME) |
635 | 659 | { |
636 | 660 | ReportError(CE_Failure, CPLE_AppDefined, |
637 | | - "Only last step can be '%s'", |
638 | | - GDALRasterWriteAlgorithm::NAME); |
| 661 | + "Only last step can be '%s' or '%s'", |
| 662 | + GDALRasterWriteAlgorithm::NAME, |
| 663 | + GDALRasterInfoAlgorithm::NAME); |
639 | 664 | return false; |
640 | 665 | } |
641 | 666 | } |
@@ -764,6 +789,8 @@ bool GDALPipelineAlgorithm::ParseCommandLineArguments( |
764 | 789 | steps[i].alg->SetCallPath({steps[i].alg->GetName()}); |
765 | 790 | steps[i].alg->SetReferencePathForRelativePaths( |
766 | 791 | GetReferencePathForRelativePaths()); |
| 792 | + if (IsCalledFromCommandLine()) |
| 793 | + steps[i].alg->SetCalledFromCommandLine(); |
767 | 794 | steps[i].alreadyChangedType = true; |
768 | 795 | } |
769 | 796 | else if (steps[i].alg->GetInputType() != nLastStepOutputType) |
@@ -896,17 +923,18 @@ GDALPipelineAlgorithm::GetUsageForCLI(bool shortUsage, |
896 | 923 | ret += alg->GetUsageForCLI(shortUsage, stepUsageOptions); |
897 | 924 | } |
898 | 925 | } |
| 926 | + for (const std::string &name : |
| 927 | + {std::string(GDALRasterInfoAlgorithm::NAME) + RASTER_SUFFIX, |
| 928 | + std::string(GDALRasterWriteAlgorithm::NAME) + RASTER_SUFFIX, |
| 929 | + std::string(GDALVectorInfoAlgorithm::NAME) + VECTOR_SUFFIX, |
| 930 | + std::string(GDALVectorWriteAlgorithm::NAME) + VECTOR_SUFFIX}) |
899 | 931 | { |
900 | 932 | ret += '\n'; |
901 | | - auto alg = std::make_unique<GDALRasterWriteAlgorithm>(); |
902 | | - alg->SetCallPath({alg->GetName()}); |
903 | | - ret += alg->GetUsageForCLI(shortUsage, stepUsageOptions); |
904 | | - } |
905 | | - { |
906 | | - ret += '\n'; |
907 | | - auto alg = std::make_unique<GDALVectorWriteAlgorithm>(); |
| 933 | + auto alg = GetStepAlg(name); |
908 | 934 | assert(alg); |
909 | | - alg->SetCallPath({alg->GetName()}); |
| 935 | + alg->SetCallPath({CPLString(alg->GetName()) |
| 936 | + .replaceAll(RASTER_SUFFIX, "") |
| 937 | + .replaceAll(VECTOR_SUFFIX, "")}); |
910 | 938 | ret += alg->GetUsageForCLI(shortUsage, stepUsageOptions); |
911 | 939 | } |
912 | 940 |
|
|
0 commit comments