Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: gdal "raster polygonize" subcommand 5 : * Author: Even Rouault <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef GDALALG_RASTER_POLYGONIZE_INCLUDED 14 : #define GDALALG_RASTER_POLYGONIZE_INCLUDED 15 : 16 : #include "gdalalg_abstract_pipeline.h" 17 : 18 : //! @cond Doxygen_Suppress 19 : 20 : /************************************************************************/ 21 : /* GDALRasterPolygonizeAlgorithm */ 22 : /************************************************************************/ 23 : 24 : class GDALRasterPolygonizeAlgorithm /* non final */ 25 : : public GDALPipelineStepAlgorithm 26 : { 27 : public: 28 : static constexpr const char *NAME = "polygonize"; 29 : static constexpr const char *DESCRIPTION = 30 : "Create a polygon feature dataset from a raster band."; 31 : static constexpr const char *HELP_URL = 32 : "/programs/gdal_raster_polygonize.html"; 33 : 34 : explicit GDALRasterPolygonizeAlgorithm(bool standaloneStep = false); 35 : 36 6 : bool IsNativelyStreamingCompatible() const override 37 : { 38 6 : return false; 39 : } 40 : 41 5 : int GetInputType() const override 42 : { 43 5 : return GDAL_OF_RASTER; 44 : } 45 : 46 3 : int GetOutputType() const override 47 : { 48 3 : return GDAL_OF_VECTOR; 49 : } 50 : 51 : bool 52 : CanHandleNextStep(GDALPipelineStepAlgorithm *poNextStep) const override; 53 : 54 : private: 55 : bool RunStep(GDALPipelineStepRunContext &ctxt) override; 56 : bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override; 57 : 58 : // polygonize specific arguments 59 : int m_band = 1; 60 : std::string m_attributeName = "DN"; 61 : bool m_connectDiagonalPixels = false; 62 : 63 : // hidden 64 : int m_commitInterval = 0; 65 : }; 66 : 67 : /************************************************************************/ 68 : /* GDALRasterPolygonizeAlgorithmStandalone */ 69 : /************************************************************************/ 70 : 71 46 : class GDALRasterPolygonizeAlgorithmStandalone final 72 : : public GDALRasterPolygonizeAlgorithm 73 : { 74 : public: 75 23 : GDALRasterPolygonizeAlgorithmStandalone() 76 23 : : GDALRasterPolygonizeAlgorithm(/* standaloneStep = */ true) 77 : { 78 23 : } 79 : 80 : ~GDALRasterPolygonizeAlgorithmStandalone() override; 81 : }; 82 : 83 : //! @endcond 84 : 85 : #endif