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-03-31 11:17:27 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          74 : GDALVectorGeomAlgorithm::GDALVectorGeomAlgorithm(bool standaloneStep)
      33             :     : GDALVectorPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
      34          74 :                                       /* standaloneStep = */ false)
      35             : {
      36          74 :     RegisterSubAlgorithm<GDALVectorGeomSetTypeAlgorithm>(standaloneStep);
      37          74 :     RegisterSubAlgorithm<GDALVectorGeomExplodeCollectionsAlgorithm>(
      38             :         standaloneStep);
      39          74 :     RegisterSubAlgorithm<GDALVectorGeomMakeValidAlgorithm>(standaloneStep);
      40          74 :     RegisterSubAlgorithm<GDALVectorGeomSegmentizeAlgorithm>(standaloneStep);
      41          74 :     RegisterSubAlgorithm<GDALVectorGeomSimplifyAlgorithm>(standaloneStep);
      42          74 :     RegisterSubAlgorithm<GDALVectorGeomBufferAlgorithm>(standaloneStep);
      43          74 :     RegisterSubAlgorithm<GDALVectorGeomSwapXYAlgorithm>(standaloneStep);
      44          74 : }
      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          99 : GDALVectorGeomAbstractAlgorithm::GDALVectorGeomAbstractAlgorithm(
      63             :     const std::string &name, const std::string &description,
      64          99 :     const std::string &helpURL, bool standaloneStep, OptionsBase &opts)
      65             :     : GDALVectorPipelineStepAlgorithm(name, description, helpURL,
      66             :                                       standaloneStep),
      67          99 :       m_activeLayer(opts.m_activeLayer)
      68             : {
      69          99 :     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          99 :            &opts.m_geomField);
      74          99 : }
      75             : 
      76             : /************************************************************************/
      77             : /*               GDALVectorGeomAbstractAlgorithm::RunStep()             */
      78             : /************************************************************************/
      79             : 
      80          47 : bool GDALVectorGeomAbstractAlgorithm::RunStep(GDALProgressFunc, void *)
      81             : {
      82          47 :     auto poSrcDS = m_inputDataset.GetDatasetRef();
      83          47 :     CPLAssert(poSrcDS);
      84          47 :     CPLAssert(m_outputDataset.GetName().empty());
      85          47 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      86             : 
      87          47 :     auto outDS = std::make_unique<GDALVectorPipelineOutputDataset>(*poSrcDS);
      88             : 
      89          97 :     for (auto &&poSrcLayer : poSrcDS->GetLayers())
      90             :     {
      91          56 :         if (m_activeLayer.empty() ||
      92           6 :             m_activeLayer == poSrcLayer->GetDescription())
      93             :         {
      94          47 :             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          47 :     m_outputDataset.Set(std::move(outDS));
     106             : 
     107          94 :     return true;
     108             : }
     109             : 
     110             : //! @endcond

Generated by: LCOV version 1.14