Coverage Report

Created: 2026-07-25 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrmulticurve.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  OpenGIS Simple Features Reference Implementation
4
 * Purpose:  The OGRMultiCurve class.
5
 * Author:   Even Rouault <even dot rouault at spatialys dot com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2014, Even Rouault <even dot rouault at spatialys dot com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#include "cpl_port.h"
14
#include "ogr_geometry.h"
15
16
#include <cstddef>
17
18
#include "cpl_error.h"
19
#include "ogr_api.h"
20
#include "ogr_core.h"
21
#include "ogr_p.h"
22
23
/************************************************************************/
24
/*                OGRMultiCurve( const OGRMultiCurve& )                 */
25
/************************************************************************/
26
27
/**
28
 * \brief Copy constructor.
29
 */
30
31
0
OGRMultiCurve::OGRMultiCurve(const OGRMultiCurve &) = default;
32
33
/************************************************************************/
34
/*                   operator=( const OGRMultiCurve&)                   */
35
/************************************************************************/
36
37
/**
38
 * \brief Assignment operator.
39
 */
40
41
OGRMultiCurve &OGRMultiCurve::operator=(const OGRMultiCurve &other)
42
0
{
43
0
    if (this != &other)
44
0
    {
45
0
        OGRGeometryCollection::operator=(other);
46
0
    }
47
0
    return *this;
48
0
}
49
50
/************************************************************************/
51
/*                               clone()                                */
52
/************************************************************************/
53
54
OGRMultiCurve *OGRMultiCurve::clone() const
55
56
0
{
57
0
    auto ret = new (std::nothrow) OGRMultiCurve(*this);
58
0
    if (ret)
59
0
    {
60
0
        if (ret->WkbSize() != WkbSize())
61
0
        {
62
0
            delete ret;
63
0
            ret = nullptr;
64
0
        }
65
0
    }
66
0
    return ret;
67
0
}
68
69
/************************************************************************/
70
/*                          getGeometryType()                           */
71
/************************************************************************/
72
73
OGRwkbGeometryType OGRMultiCurve::getGeometryType() const
74
75
0
{
76
0
    if ((flags & OGR_G_3D) && (flags & OGR_G_MEASURED))
77
0
        return wkbMultiCurveZM;
78
0
    else if (flags & OGR_G_MEASURED)
79
0
        return wkbMultiCurveM;
80
0
    else if (flags & OGR_G_3D)
81
0
        return wkbMultiCurveZ;
82
0
    else
83
0
        return wkbMultiCurve;
84
0
}
85
86
/************************************************************************/
87
/*                            getDimension()                            */
88
/************************************************************************/
89
90
int OGRMultiCurve::getDimension() const
91
92
0
{
93
0
    return 1;
94
0
}
95
96
/************************************************************************/
97
/*                          getGeometryName()                           */
98
/************************************************************************/
99
100
const char *OGRMultiCurve::getGeometryName() const
101
102
0
{
103
0
    return "MULTICURVE";
104
0
}
105
106
/************************************************************************/
107
/*                        isCompatibleSubType()                         */
108
/************************************************************************/
109
110
bool OGRMultiCurve::isCompatibleSubType(OGRwkbGeometryType eGeomType) const
111
0
{
112
0
    return CPL_TO_BOOL(OGR_GT_IsCurve(eGeomType));
113
0
}
114
115
/*! @cond Doxygen_Suppress */
116
/************************************************************************/
117
/*                      addCurveDirectlyFromWkt()                       */
118
/************************************************************************/
119
120
OGRErr OGRMultiCurve::addCurveDirectlyFromWkt(OGRGeometry *poSelf,
121
                                              OGRCurve *poCurve)
122
0
{
123
0
    return poSelf->toMultiCurve()->addGeometryDirectly(poCurve);
124
0
}
125
126
/*! @endcond */
127
128
/************************************************************************/
129
/*                           importFromWkt()                            */
130
/*                                                                      */
131
/*      Instantiate from well known text format.                        */
132
/************************************************************************/
133
134
OGRErr OGRMultiCurve::importFromWkt(const char **ppszInput)
135
136
0
{
137
0
    const bool bIsMultiCurve = wkbFlatten(getGeometryType()) == wkbMultiCurve;
138
0
    return importCurveCollectionFromWkt(ppszInput,
139
0
                                        TRUE,           // bAllowEmptyComponent.
140
0
                                        bIsMultiCurve,  // bAllowLineString.
141
0
                                        bIsMultiCurve,  // bAllowCurve.
142
0
                                        bIsMultiCurve,  // bAllowCompoundCurve.
143
0
                                        addCurveDirectlyFromWkt);
144
0
}
145
146
/************************************************************************/
147
/*                            exportToWkt()                             */
148
/************************************************************************/
149
150
std::string OGRMultiCurve::exportToWkt(const OGRWktOptions &opts,
151
                                       OGRErr *err) const
152
0
{
153
0
    OGRWktOptions optsModified(opts);
154
0
    optsModified.variant = wkbVariantIso;
155
0
    return exportToWktInternal(optsModified, err, "LINESTRING");
156
0
}
157
158
/************************************************************************/
159
/*                          hasCurveGeometry()                          */
160
/************************************************************************/
161
162
bool OGRMultiCurve::hasCurveGeometry(int bLookForNonLinear) const
163
0
{
164
0
    if (bLookForNonLinear)
165
0
        return OGRGeometryCollection::hasCurveGeometry(TRUE);
166
0
    return true;
167
0
}
168
169
/************************************************************************/
170
/*                       CastToMultiLineString()                        */
171
/************************************************************************/
172
173
/**
174
 * \brief Cast to multi line string.
175
 *
176
 * This method should only be called if the multicurve actually only contains
177
 * instances of OGRLineString. This can be verified if hasCurveGeometry(TRUE)
178
 * returns FALSE. It is not intended to approximate circular curves. For that
179
 * use getLinearGeometry().
180
 *
181
 * The passed in geometry is consumed and a new one returned (or NULL in case
182
 * of failure).
183
 *
184
 * @param poMC the input geometry - ownership is passed to the method.
185
 * @return new geometry.
186
 */
187
188
OGRMultiLineString *OGRMultiCurve::CastToMultiLineString(OGRMultiCurve *poMC)
189
0
{
190
0
    for (auto &&poSubGeom : *poMC)
191
0
    {
192
0
        poSubGeom = OGRCurve::CastToLineString(poSubGeom);
193
0
        if (poSubGeom == nullptr)
194
0
        {
195
0
            delete poMC;
196
0
            return nullptr;
197
0
        }
198
0
    }
199
0
    OGRMultiLineString *poMLS = new OGRMultiLineString();
200
0
    TransferMembersAndDestroy(poMC, poMLS);
201
0
    return poMLS;
202
0
}