• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OSGeo / gdal / 14132676652

28 Mar 2025 03:43PM UTC coverage: 70.519% (+0.01%) from 70.507%
14132676652

Pull #12043

github

web-flow
Merge eed987467 into 51803af31
Pull Request #12043: Add gdal geom vector make-valid, segmentize, simplify, buffer

258 of 260 new or added lines in 13 files covered. (99.23%)

62 existing lines in 31 files now uncovered.

555975 of 788410 relevant lines covered (70.52%)

221414.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.08
/apps/gdalalg_vector_geom.h
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
#ifndef GDALALG_VECTOR_GEOM_INCLUDED
14
#define GDALALG_VECTOR_GEOM_INCLUDED
15

16
#include "gdalalg_vector_pipeline.h"
17

18
//! @cond Doxygen_Suppress
19

20
/************************************************************************/
21
/*                       GDALVectorGeomAlgorithm                        */
22
/************************************************************************/
23

24
class GDALVectorGeomAlgorithm /* non final */
25
    : public GDALVectorPipelineStepAlgorithm
26
{
27
  public:
28
    static constexpr const char *NAME = "geom";
29
    static constexpr const char *DESCRIPTION =
30
        "Geometry operations on a vector dataset.";
31
    static constexpr const char *HELP_URL = "/programs/gdal_vector_geom.html";
32

33
    static std::vector<std::string> GetAliases()
336✔
34
    {
35
        return {};
336✔
36
    }
37

38
    explicit GDALVectorGeomAlgorithm(bool standaloneStep = false);
39

40
  private:
41
    bool RunStep(GDALProgressFunc pfnProgress, void *pProgressData) override;
42

43
    /** Register the sub-algorithm of type MyAlgorithm.
44
     */
45
    template <class MyAlgorithm> bool RegisterSubAlgorithm(bool standalone)
420✔
46
    {
47
        GDALAlgorithmRegistry::AlgInfo info;
840✔
48
        info.m_name = MyAlgorithm::NAME;
420✔
49
        info.m_aliases = MyAlgorithm::GetAliases();
420✔
50
        info.m_creationFunc = [standalone]() -> std::unique_ptr<GDALAlgorithm>
510✔
51
        { return std::make_unique<MyAlgorithm>(standalone); };
90✔
52
        return GDALAlgorithm::RegisterSubAlgorithm(info);
840✔
53
    }
54
};
55

56
/************************************************************************/
57
/*                    GDALVectorGeomAlgorithmStandalone                 */
58
/************************************************************************/
59

60
class GDALVectorGeomAlgorithmStandalone final : public GDALVectorGeomAlgorithm
61
{
62
  public:
63
    GDALVectorGeomAlgorithmStandalone()
60✔
64
        : GDALVectorGeomAlgorithm(/* standaloneStep = */ true)
60✔
65
    {
66
    }
60✔
67
};
68

69
/************************************************************************/
70
/*                    GDALVectorGeomAbstractAlgorithm                   */
71
/************************************************************************/
72

73
class GDALVectorGeomAbstractAlgorithm /* non final */
74
    : public GDALVectorPipelineStepAlgorithm
75
{
76
  protected:
77
    struct OptionsBase
78
    {
79
        std::string m_activeLayer{};
80
        std::string m_geomField{};
81
    };
82

83
    virtual std::unique_ptr<OGRLayerWithTranslateFeature>
84
    CreateAlgLayer(OGRLayer &srcLayer) = 0;
85

86
    GDALVectorGeomAbstractAlgorithm(const std::string &name,
87
                                    const std::string &description,
88
                                    const std::string &helpURL,
89
                                    bool standaloneStep, OptionsBase &opts);
90

91
    bool RunStep(GDALProgressFunc, void *) override;
92

93
  private:
94
    std::string &m_activeLayer;
95
};
96

97
/************************************************************************/
98
/*                  GDALVectorGeomMakeValidAlgorithmLayer               */
99
/************************************************************************/
100

101
template <class T>
102
class GDALVectorGeomOneToOneAlgorithmLayer /* non final */
103
    : public GDALVectorPipelineOutputLayer
104
{
105
  public:
106
    OGRFeatureDefn *GetLayerDefn() override
220✔
107
    {
108
        return m_srcLayer.GetLayerDefn();
220✔
109
    }
110

111
    GIntBig GetFeatureCount(int bForce) override
19✔
112
    {
113
        if (!m_poAttrQuery && !m_poFilterGeom)
19✔
114
            return m_srcLayer.GetFeatureCount(bForce);
10✔
115
        return OGRLayer::GetFeatureCount(bForce);
9✔
116
    }
117

118
    OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent,
12✔
119
                      bool bForce) override
120
    {
121
        return m_srcLayer.GetExtent(iGeomField, psExtent, bForce);
12✔
122
    }
123

124
    OGRFeature *GetFeature(GIntBig nFID) override
24✔
125
    {
126
        auto poSrcFeature =
48✔
127
            std::unique_ptr<OGRFeature>(m_srcLayer.GetFeature(nFID));
24✔
128
        if (!poSrcFeature)
24✔
129
            return nullptr;
10✔
130
        return TranslateFeature(std::move(poSrcFeature)).release();
14✔
131
    }
132

133
    int TestCapability(const char *pszCap) override
44✔
134
    {
135
        if (EQUAL(pszCap, OLCRandomRead) || EQUAL(pszCap, OLCCurveGeometries) ||
44✔
136
            EQUAL(pszCap, OLCMeasuredGeometries) ||
40✔
137
            EQUAL(pszCap, OLCZGeometries) || EQUAL(pszCap, OLCFastGetExtent) ||
36✔
138
            (EQUAL(pszCap, OLCFastFeatureCount) && !m_poAttrQuery &&
31✔
139
             !m_poFilterGeom) ||
3✔
140
            EQUAL(pszCap, OLCStringsAsUTF8))
28✔
141
        {
142
            return m_srcLayer.TestCapability(pszCap);
31✔
143
        }
144
        return false;
13✔
145
    }
146

147
  protected:
148
    const typename T::Options m_opts;
149

150
    GDALVectorGeomOneToOneAlgorithmLayer(OGRLayer &oSrcLayer,
36✔
151
                                         const typename T::Options &opts)
152
        : GDALVectorPipelineOutputLayer(oSrcLayer), m_opts(opts)
36✔
153
    {
154
        SetDescription(oSrcLayer.GetDescription());
36✔
155
        SetMetadata(oSrcLayer.GetMetadata());
36✔
156
        if (!m_opts.m_geomField.empty())
36✔
157
        {
158
            const int nIdx = oSrcLayer.GetLayerDefn()->GetGeomFieldIndex(
2✔
159
                m_opts.m_geomField.c_str());
160
            if (nIdx >= 0)
2✔
161
                m_iGeomIdx = nIdx;
2✔
162
            else
NEW
163
                m_iGeomIdx = INT_MAX;
×
164
        }
165
    }
36✔
166

167
    bool IsSelectedGeomField(int idx) const
647✔
168
    {
169
        return m_iGeomIdx < 0 || idx == m_iGeomIdx;
647✔
170
    }
171

172
    virtual std::unique_ptr<OGRFeature>
173
    TranslateFeature(std::unique_ptr<OGRFeature> poSrcFeature) const = 0;
174

175
    void TranslateFeature(
611✔
176
        std::unique_ptr<OGRFeature> poSrcFeature,
177
        std::vector<std::unique_ptr<OGRFeature>> &apoOutFeatures) override
178
    {
179
        auto poDstFeature = TranslateFeature(std::move(poSrcFeature));
1,222✔
180
        if (poDstFeature)
611✔
181
            apoOutFeatures.push_back(std::move(poDstFeature));
609✔
182
    }
611✔
183

184
  private:
185
    int m_iGeomIdx = -1;
186
};
187

188
//! @endcond
189

190
#endif /* GDALALG_VECTOR_GEOM_INCLUDED */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc