/src/gdal/apps/gdalalg_vector_segmentize.cpp
Line | Count | Source |
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 | 0 | #define _(x) (x) |
22 | | #endif |
23 | | |
24 | | /************************************************************************/ |
25 | | /* GDALVectorSegmentizeAlgorithm() */ |
26 | | /************************************************************************/ |
27 | | |
28 | | GDALVectorSegmentizeAlgorithm::GDALVectorSegmentizeAlgorithm( |
29 | | bool standaloneStep) |
30 | 0 | : GDALVectorGeomAbstractAlgorithm(NAME, DESCRIPTION, HELP_URL, |
31 | 0 | standaloneStep, m_opts) |
32 | 0 | { |
33 | 0 | AddArg("max-length", 0, _("Maximum length of a segment"), |
34 | 0 | &m_opts.m_maxLength) |
35 | 0 | .SetPositional() |
36 | 0 | .SetRequired() |
37 | 0 | .SetMinValueExcluded(0); |
38 | 0 | } |
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 | | GDALVectorSegmentizeAlgorithmLayer( |
58 | | OGRLayer &oSrcLayer, const GDALVectorSegmentizeAlgorithm::Options &opts) |
59 | 0 | : GDALVectorGeomOneToOneAlgorithmLayer<GDALVectorSegmentizeAlgorithm>( |
60 | 0 | oSrcLayer, opts) |
61 | 0 | { |
62 | 0 | } |
63 | | }; |
64 | | |
65 | | /************************************************************************/ |
66 | | /* TranslateFeature() */ |
67 | | /************************************************************************/ |
68 | | |
69 | | std::unique_ptr<OGRFeature> |
70 | | GDALVectorSegmentizeAlgorithmLayer::TranslateFeature( |
71 | | std::unique_ptr<OGRFeature> poSrcFeature) const |
72 | 0 | { |
73 | 0 | const int nGeomFieldCount = poSrcFeature->GetGeomFieldCount(); |
74 | 0 | for (int i = 0; i < nGeomFieldCount; ++i) |
75 | 0 | { |
76 | 0 | if (IsSelectedGeomField(i)) |
77 | 0 | { |
78 | 0 | if (auto poGeom = poSrcFeature->GetGeomFieldRef(i)) |
79 | 0 | { |
80 | 0 | poGeom->segmentize(m_opts.m_maxLength); |
81 | 0 | } |
82 | 0 | } |
83 | 0 | } |
84 | |
|
85 | 0 | return poSrcFeature; |
86 | 0 | } |
87 | | |
88 | | } // namespace |
89 | | |
90 | | /************************************************************************/ |
91 | | /* GDALVectorSegmentizeAlgorithm::CreateAlgLayer() */ |
92 | | /************************************************************************/ |
93 | | |
94 | | std::unique_ptr<OGRLayerWithTranslateFeature> |
95 | | GDALVectorSegmentizeAlgorithm::CreateAlgLayer(OGRLayer &srcLayer) |
96 | 0 | { |
97 | 0 | return std::make_unique<GDALVectorSegmentizeAlgorithmLayer>(srcLayer, |
98 | 0 | m_opts); |
99 | 0 | } |
100 | | |
101 | | GDALVectorSegmentizeAlgorithmStandalone:: |
102 | 0 | ~GDALVectorSegmentizeAlgorithmStandalone() = default; |
103 | | |
104 | | //! @endcond |