LCOV - code coverage report
Current view: top level - apps - gdalalg_vector_segmentize.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 22 22 100.0 %
Date: 2025-06-19 12:30:01 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  "gdal vector segmentize"
       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_segmentize.h"
      14             : 
      15             : #include "gdal_priv.h"
      16             : #include "ogrsf_frmts.h"
      17             : 
      18             : //! @cond Doxygen_Suppress
      19             : 
      20             : #ifndef _
      21             : #define _(x) (x)
      22             : #endif
      23             : 
      24             : /************************************************************************/
      25             : /*                   GDALVectorSegmentizeAlgorithm()                    */
      26             : /************************************************************************/
      27             : 
      28          22 : GDALVectorSegmentizeAlgorithm::GDALVectorSegmentizeAlgorithm(
      29          22 :     bool standaloneStep)
      30             :     : GDALVectorGeomAbstractAlgorithm(NAME, DESCRIPTION, HELP_URL,
      31          22 :                                       standaloneStep, m_opts)
      32             : {
      33             :     AddArg("max-length", 0, _("Maximum length of a segment"),
      34          44 :            &m_opts.m_maxLength)
      35          22 :         .SetPositional()
      36          22 :         .SetRequired()
      37          22 :         .SetMinValueExcluded(0);
      38          22 : }
      39             : 
      40             : namespace
      41             : {
      42             : 
      43             : /************************************************************************/
      44             : /*                   GDALVectorSegmentizeAlgorithmLayer                 */
      45             : /************************************************************************/
      46             : 
      47             : class GDALVectorSegmentizeAlgorithmLayer final
      48             :     : public GDALVectorGeomOneToOneAlgorithmLayer<GDALVectorSegmentizeAlgorithm>
      49             : {
      50             :   protected:
      51             :     using GDALVectorGeomOneToOneAlgorithmLayer::TranslateFeature;
      52             : 
      53             :     std::unique_ptr<OGRFeature>
      54             :     TranslateFeature(std::unique_ptr<OGRFeature> poSrcFeature) const override;
      55             : 
      56             :   public:
      57           1 :     GDALVectorSegmentizeAlgorithmLayer(
      58             :         OGRLayer &oSrcLayer, const GDALVectorSegmentizeAlgorithm::Options &opts)
      59           1 :         : GDALVectorGeomOneToOneAlgorithmLayer<GDALVectorSegmentizeAlgorithm>(
      60           1 :               oSrcLayer, opts)
      61             :     {
      62           1 :     }
      63             : };
      64             : 
      65             : /************************************************************************/
      66             : /*                          TranslateFeature()                          */
      67             : /************************************************************************/
      68             : 
      69             : std::unique_ptr<OGRFeature>
      70           5 : GDALVectorSegmentizeAlgorithmLayer::TranslateFeature(
      71             :     std::unique_ptr<OGRFeature> poSrcFeature) const
      72             : {
      73           5 :     const int nGeomFieldCount = poSrcFeature->GetGeomFieldCount();
      74          10 :     for (int i = 0; i < nGeomFieldCount; ++i)
      75             :     {
      76           5 :         if (IsSelectedGeomField(i))
      77             :         {
      78           5 :             if (auto poGeom = poSrcFeature->GetGeomFieldRef(i))
      79             :             {
      80           3 :                 poGeom->segmentize(m_opts.m_maxLength);
      81             :             }
      82             :         }
      83             :     }
      84             : 
      85           5 :     return poSrcFeature;
      86             : }
      87             : 
      88             : }  // namespace
      89             : 
      90             : /************************************************************************/
      91             : /*             GDALVectorSegmentizeAlgorithm::CreateAlgLayer()          */
      92             : /************************************************************************/
      93             : 
      94             : std::unique_ptr<OGRLayerWithTranslateFeature>
      95           1 : GDALVectorSegmentizeAlgorithm::CreateAlgLayer(OGRLayer &srcLayer)
      96             : {
      97           1 :     return std::make_unique<GDALVectorSegmentizeAlgorithmLayer>(srcLayer,
      98           1 :                                                                 m_opts);
      99             : }
     100             : 
     101             : GDALVectorSegmentizeAlgorithmStandalone::
     102             :     ~GDALVectorSegmentizeAlgorithmStandalone() = default;
     103             : 
     104             : //! @endcond

Generated by: LCOV version 1.14