LCOV - code coverage report
Current view: top level - apps - gdalalg_vector_geom.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 33 33 100.0 %
Date: 2025-05-15 18:21:54 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  "geom" step of "vector pipeline", or "gdal vector geom" standalone
       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             : #include "gdalalg_vector_geom.h"
      14             : #include "gdalalg_vector_geom_set_type.h"
      15             : #include "gdalalg_vector_geom_explode_collections.h"
      16             : #include "gdalalg_vector_geom_make_valid.h"
      17             : #include "gdalalg_vector_geom_segmentize.h"
      18             : #include "gdalalg_vector_geom_simplify.h"
      19             : #include "gdalalg_vector_geom_buffer.h"
      20             : #include "gdalalg_vector_geom_swap_xy.h"
      21             : 
      22             : //! @cond Doxygen_Suppress
      23             : 
      24             : #ifndef _
      25             : #define _(x) (x)
      26             : #endif
      27             : 
      28             : /************************************************************************/
      29             : /*           GDALVectorGeomAlgorithm::GDALVectorGeomAlgorithm()         */
      30             : /************************************************************************/
      31             : 
      32          76 : GDALVectorGeomAlgorithm::GDALVectorGeomAlgorithm(bool standaloneStep)
      33             :     : GDALVectorPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
      34          76 :                                       /* standaloneStep = */ false)
      35             : {
      36          76 :     RegisterSubAlgorithm<GDALVectorGeomSetTypeAlgorithm>(standaloneStep);
      37          76 :     RegisterSubAlgorithm<GDALVectorGeomExplodeCollectionsAlgorithm>(
      38             :         standaloneStep);
      39          76 :     RegisterSubAlgorithm<GDALVectorGeomMakeValidAlgorithm>(standaloneStep);
      40          76 :     RegisterSubAlgorithm<GDALVectorGeomSegmentizeAlgorithm>(standaloneStep);
      41          76 :     RegisterSubAlgorithm<GDALVectorGeomSimplifyAlgorithm>(standaloneStep);
      42          76 :     RegisterSubAlgorithm<GDALVectorGeomBufferAlgorithm>(standaloneStep);
      43          76 :     RegisterSubAlgorithm<GDALVectorGeomSwapXYAlgorithm>(standaloneStep);
      44          76 : }
      45             : 
      46             : /************************************************************************/
      47             : /*                GDALVectorGeomAlgorithm::RunStep()                    */
      48             : /************************************************************************/
      49             : 
      50           1 : bool GDALVectorGeomAlgorithm::RunStep(GDALProgressFunc, void *)
      51             : {
      52           1 :     CPLError(CE_Failure, CPLE_AppDefined,
      53             :              "The Run() method should not be called directly on the \"gdal "
      54             :              "vector geom\" program.");
      55           1 :     return false;
      56             : }
      57             : 
      58             : /************************************************************************/
      59             : /*                 GDALVectorGeomAbstractAlgorithm()                    */
      60             : /************************************************************************/
      61             : 
      62         101 : GDALVectorGeomAbstractAlgorithm::GDALVectorGeomAbstractAlgorithm(
      63             :     const std::string &name, const std::string &description,
      64         101 :     const std::string &helpURL, bool standaloneStep, OptionsBase &opts)
      65             :     : GDALVectorPipelineStepAlgorithm(name, description, helpURL,
      66             :                                       standaloneStep),
      67         101 :       m_activeLayer(opts.m_activeLayer)
      68             : {
      69         101 :     AddActiveLayerArg(&opts.m_activeLayer);
      70             :     AddArg("active-geometry", 0,
      71             :            _("Geometry field name to which to restrict the processing (if not "
      72             :              "specified, all)"),
      73         101 :            &opts.m_geomField);
      74         101 : }
      75             : 
      76             : /************************************************************************/
      77             : /*               GDALVectorGeomAbstractAlgorithm::RunStep()             */
      78             : /************************************************************************/
      79             : 
      80          50 : bool GDALVectorGeomAbstractAlgorithm::RunStep(GDALProgressFunc, void *)
      81             : {
      82          50 :     auto poSrcDS = m_inputDataset[0].GetDatasetRef();
      83          50 :     CPLAssert(poSrcDS);
      84          50 :     CPLAssert(m_outputDataset.GetName().empty());
      85          50 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      86             : 
      87          50 :     auto outDS = std::make_unique<GDALVectorPipelineOutputDataset>(*poSrcDS);
      88             : 
      89         103 :     for (auto &&poSrcLayer : poSrcDS->GetLayers())
      90             :     {
      91          59 :         if (m_activeLayer.empty() ||
      92           6 :             m_activeLayer == poSrcLayer->GetDescription())
      93             :         {
      94          50 :             outDS->AddLayer(*poSrcLayer, CreateAlgLayer(*poSrcLayer));
      95             :         }
      96             :         else
      97             :         {
      98           6 :             outDS->AddLayer(
      99             :                 *poSrcLayer,
     100           6 :                 std::make_unique<GDALVectorPipelinePassthroughLayer>(
     101             :                     *poSrcLayer));
     102             :         }
     103             :     }
     104             : 
     105          50 :     m_outputDataset.Set(std::move(outDS));
     106             : 
     107         100 :     return true;
     108             : }
     109             : 
     110             : //! @endcond

Generated by: LCOV version 1.14