Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: gdal "vector pipeline" subcommand 5 : * Author: Even Rouault <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2024, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef GDALALG_VECTOR_PIPELINE_INCLUDED 14 : #define GDALALG_VECTOR_PIPELINE_INCLUDED 15 : 16 : #include "gdalalgorithm.h" 17 : #include "gdalalg_abstract_pipeline.h" 18 : 19 : //! @cond Doxygen_Suppress 20 : 21 : /************************************************************************/ 22 : /* GDALVectorPipelineStepAlgorithm */ 23 : /************************************************************************/ 24 : 25 : class GDALVectorPipelineStepAlgorithm /* non final */ : public GDALAlgorithm 26 : { 27 : protected: 28 : GDALVectorPipelineStepAlgorithm(const std::string &name, 29 : const std::string &description, 30 : const std::string &helpURL, 31 : bool standaloneStep); 32 : 33 : friend class GDALVectorPipelineAlgorithm; 34 : friend class GDALAbstractPipelineAlgorithm<GDALVectorPipelineStepAlgorithm>; 35 : 36 : virtual bool RunStep(GDALProgressFunc pfnProgress, void *pProgressData) = 0; 37 : 38 : void AddInputArgs(bool hiddenForCLI); 39 : void AddOutputArgs(bool hiddenForCLI, bool shortNameOutputLayerAllowed); 40 : 41 : bool m_standaloneStep = false; 42 : 43 : // Input arguments 44 : GDALArgDatasetValue m_inputDataset{}; 45 : std::vector<std::string> m_openOptions{}; 46 : std::vector<std::string> m_inputFormats{}; 47 : std::vector<std::string> m_inputLayerNames{}; 48 : 49 : // Output arguments 50 : GDALArgDatasetValue m_outputDataset{}; 51 : std::string m_format{}; 52 : std::vector<std::string> m_creationOptions{}; 53 : std::vector<std::string> m_layerCreationOptions{}; 54 : bool m_overwrite = false; 55 : bool m_update = false; 56 : bool m_overwriteLayer = false; 57 : bool m_appendLayer = false; 58 : std::string m_outputLayerName{}; 59 : 60 : private: 61 : bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override; 62 : }; 63 : 64 : /************************************************************************/ 65 : /* GDALVectorPipelineAlgorithm */ 66 : /************************************************************************/ 67 : 68 : // This is an easter egg to pay tribute to PROJ pipeline syntax 69 : // We accept "gdal vector +gdal=pipeline +step +gdal=read +input=poly.gpkg +step +gdal=reproject +dst-crs=EPSG:32632 +step +gdal=write +output=out.gpkg +overwrite" 70 : // as an alternative to (recommended): 71 : // "gdal vector pipeline ! read poly.gpkg ! reproject--dst-crs=EPSG:32632 ! write out.gpkg --overwrite" 72 : #define GDAL_PIPELINE_PROJ_NOSTALGIA 73 : 74 : class GDALVectorPipelineAlgorithm final 75 : : public GDALAbstractPipelineAlgorithm<GDALVectorPipelineStepAlgorithm> 76 : { 77 : public: 78 : static constexpr const char *NAME = "pipeline"; 79 : static constexpr const char *DESCRIPTION = "Process a vector dataset."; 80 : static constexpr const char *HELP_URL = 81 : "/programs/gdal_vector_pipeline.html"; 82 : 83 85 : static std::vector<std::string> GetAliases() 84 : { 85 : return { 86 : #ifdef GDAL_PIPELINE_PROJ_NOSTALGIA 87 : GDALAlgorithmRegistry::HIDDEN_ALIAS_SEPARATOR, 88 : "+pipeline", 89 : "+gdal=pipeline", 90 : #endif 91 340 : }; 92 : } 93 : 94 : GDALVectorPipelineAlgorithm(); 95 : 96 : bool 97 : ParseCommandLineArguments(const std::vector<std::string> &args) override; 98 : 99 : std::string GetUsageForCLI(bool shortUsage, 100 : const UsageOptions &usageOptions) const override; 101 : 102 : protected: 103 46 : GDALArgDatasetValue &GetOutputDataset() override 104 : { 105 46 : return m_outputDataset; 106 : } 107 : }; 108 : 109 : //! @endcond 110 : 111 : #endif