LCOV - code coverage report
Current view: top level - apps - gdalalg_vector_geom.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 37 37 100.0 %
Date: 2025-06-19 12:30:01 Functions: 5 5 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_set_geom_type.h"
      15             : #include "gdalalg_vector_explode_collections.h"
      16             : #include "gdalalg_vector_make_valid.h"
      17             : #include "gdalalg_vector_segmentize.h"
      18             : #include "gdalalg_vector_simplify.h"
      19             : #include "gdalalg_vector_buffer.h"
      20             : #include "gdalalg_vector_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          26 : GDALVectorGeomAlgorithm::GDALVectorGeomAlgorithm(bool standaloneStep)
      33             :     : GDALVectorPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
      34          26 :                                       /* standaloneStep = */ false)
      35             : {
      36          26 :     m_hidden = true;
      37             : 
      38          26 :     RegisterSubAlgorithm<GDALVectorSetGeomTypeAlgorithm>(standaloneStep);
      39          26 :     RegisterSubAlgorithm<GDALVectorExplodeCollectionsAlgorithm>(standaloneStep);
      40          26 :     RegisterSubAlgorithm<GDALVectorMakeValidAlgorithm>(standaloneStep);
      41          26 :     RegisterSubAlgorithm<GDALVectorSegmentizeAlgorithm>(standaloneStep);
      42          26 :     RegisterSubAlgorithm<GDALVectorSimplifyAlgorithm>(standaloneStep);
      43          26 :     RegisterSubAlgorithm<GDALVectorBufferAlgorithm>(standaloneStep);
      44          26 :     RegisterSubAlgorithm<GDALVectorSwapXYAlgorithm>(standaloneStep);
      45          26 : }
      46             : 
      47             : /************************************************************************/
      48             : /*              GDALVectorGeomAlgorithm::WarnIfDeprecated()             */
      49             : /************************************************************************/
      50             : 
      51           1 : void GDALVectorGeomAlgorithm::WarnIfDeprecated()
      52             : {
      53           1 :     ReportError(CE_Warning, CPLE_AppDefined,
      54             :                 "'gdal vector geom' is deprecated in GDAL 3.12, and will be "
      55             :                 "removed in GDAL 3.13. Is subcommands are directly available "
      56             :                 "under 'gdal vector'");
      57           1 : }
      58             : 
      59             : /************************************************************************/
      60             : /*                GDALVectorGeomAlgorithm::RunStep()                    */
      61             : /************************************************************************/
      62             : 
      63           1 : bool GDALVectorGeomAlgorithm::RunStep(GDALPipelineStepRunContext &)
      64             : {
      65           1 :     CPLError(CE_Failure, CPLE_AppDefined,
      66             :              "The Run() method should not be called directly on the \"gdal "
      67             :              "vector geom\" program.");
      68           1 :     return false;
      69             : }
      70             : 
      71             : /************************************************************************/
      72             : /*                 GDALVectorGeomAbstractAlgorithm()                    */
      73             : /************************************************************************/
      74             : 
      75         209 : GDALVectorGeomAbstractAlgorithm::GDALVectorGeomAbstractAlgorithm(
      76             :     const std::string &name, const std::string &description,
      77         209 :     const std::string &helpURL, bool standaloneStep, OptionsBase &opts)
      78             :     : GDALVectorPipelineStepAlgorithm(name, description, helpURL,
      79             :                                       standaloneStep),
      80         209 :       m_activeLayer(opts.m_activeLayer)
      81             : {
      82         209 :     AddActiveLayerArg(&opts.m_activeLayer);
      83             :     AddArg("active-geometry", 0,
      84             :            _("Geometry field name to which to restrict the processing (if not "
      85             :              "specified, all)"),
      86         209 :            &opts.m_geomField);
      87         209 : }
      88             : 
      89             : /************************************************************************/
      90             : /*               GDALVectorGeomAbstractAlgorithm::RunStep()             */
      91             : /************************************************************************/
      92             : 
      93          50 : bool GDALVectorGeomAbstractAlgorithm::RunStep(GDALPipelineStepRunContext &)
      94             : {
      95          50 :     auto poSrcDS = m_inputDataset[0].GetDatasetRef();
      96          50 :     CPLAssert(poSrcDS);
      97          50 :     CPLAssert(m_outputDataset.GetName().empty());
      98          50 :     CPLAssert(!m_outputDataset.GetDatasetRef());
      99             : 
     100          50 :     auto outDS = std::make_unique<GDALVectorPipelineOutputDataset>(*poSrcDS);
     101             : 
     102         103 :     for (auto &&poSrcLayer : poSrcDS->GetLayers())
     103             :     {
     104          59 :         if (m_activeLayer.empty() ||
     105           6 :             m_activeLayer == poSrcLayer->GetDescription())
     106             :         {
     107          50 :             outDS->AddLayer(*poSrcLayer, CreateAlgLayer(*poSrcLayer));
     108             :         }
     109             :         else
     110             :         {
     111           6 :             outDS->AddLayer(
     112             :                 *poSrcLayer,
     113           6 :                 std::make_unique<GDALVectorPipelinePassthroughLayer>(
     114             :                     *poSrcLayer));
     115             :         }
     116             :     }
     117             : 
     118          50 :     m_outputDataset.Set(std::move(outDS));
     119             : 
     120         100 :     return true;
     121             : }
     122             : 
     123             : GDALVectorGeomAlgorithmStandalone::~GDALVectorGeomAlgorithmStandalone() =
     124             :     default;
     125             : 
     126             : //! @endcond

Generated by: LCOV version 1.14