Coverage Report

Created: 2025-11-16 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrmultilinestring.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  OpenGIS Simple Features Reference Implementation
4
 * Purpose:  The OGRMultiLineString class.
5
 * Author:   Frank Warmerdam, warmerdam@pobox.com
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 1999, Frank Warmerdam
9
 * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com>
10
 *
11
 * SPDX-License-Identifier: MIT
12
 ****************************************************************************/
13
14
#include "cpl_port.h"
15
#include "ogr_geometry.h"
16
17
#include <cstddef>
18
19
#include "cpl_error.h"
20
#include "ogr_core.h"
21
#include "ogr_p.h"
22
23
/************************************************************************/
24
/*           OGRMultiLineString( const OGRMultiLineString& )            */
25
/************************************************************************/
26
27
/**
28
 * \brief Copy constructor.
29
 */
30
31
0
OGRMultiLineString::OGRMultiLineString(const OGRMultiLineString &) = default;
32
33
/************************************************************************/
34
/*                  operator=( const OGRMultiCurve&)                    */
35
/************************************************************************/
36
37
/**
38
 * \brief Assignment operator.
39
 */
40
41
OGRMultiLineString &
42
OGRMultiLineString::operator=(const OGRMultiLineString &other)
43
0
{
44
0
    if (this != &other)
45
0
    {
46
0
        OGRMultiCurve::operator=(other);
47
0
    }
48
0
    return *this;
49
0
}
50
51
/************************************************************************/
52
/*                               clone()                                */
53
/************************************************************************/
54
55
OGRMultiLineString *OGRMultiLineString::clone() const
56
57
0
{
58
0
    auto ret = new (std::nothrow) OGRMultiLineString(*this);
59
0
    if (ret)
60
0
    {
61
0
        if (ret->WkbSize() != WkbSize())
62
0
        {
63
0
            delete ret;
64
0
            ret = nullptr;
65
0
        }
66
0
    }
67
0
    return ret;
68
0
}
69
70
/************************************************************************/
71
/*                          getGeometryType()                           */
72
/************************************************************************/
73
74
OGRwkbGeometryType OGRMultiLineString::getGeometryType() const
75
76
517
{
77
517
    if ((flags & OGR_G_3D) && (flags & OGR_G_MEASURED))
78
234
        return wkbMultiLineStringZM;
79
283
    else if (flags & OGR_G_MEASURED)
80
72
        return wkbMultiLineStringM;
81
211
    else if (flags & OGR_G_3D)
82
102
        return wkbMultiLineString25D;
83
109
    else
84
109
        return wkbMultiLineString;
85
517
}
86
87
/************************************************************************/
88
/*                          getGeometryName()                           */
89
/************************************************************************/
90
91
const char *OGRMultiLineString::getGeometryName() const
92
93
98
{
94
98
    return "MULTILINESTRING";
95
98
}
96
97
/************************************************************************/
98
/*                          isCompatibleSubType()                       */
99
/************************************************************************/
100
101
OGRBoolean
102
OGRMultiLineString::isCompatibleSubType(OGRwkbGeometryType eGeomType) const
103
106
{
104
106
    return wkbFlatten(eGeomType) == wkbLineString;
105
106
}
106
107
/************************************************************************/
108
/*                           importFromWkb()                            */
109
/************************************************************************/
110
111
OGRErr OGRMultiLineString::importFromWkb(const unsigned char *pabyData,
112
                                         size_t nSize,
113
                                         OGRwkbVariant eWkbVariant,
114
                                         size_t &nBytesConsumedOut)
115
116
0
{
117
0
    if (nGeomCount == 1 && nSize >= 9 && flags == 0 && pabyData[0] == wkbNDR &&
118
0
        memcmp(pabyData + 1, "\x05\x00\x00\x00\x01\x00\x00\x00", 8) == 0)
119
0
    {
120
        // Optimization to import a Intel-ordered 1-part multilinestring on
121
        // top of an existing 1-part multilinestring, to save dynamic memory
122
        // allocations.
123
0
        const size_t nDataOffset = 9;
124
0
        size_t nBytesConsumedLineString = 0;
125
        // cppcheck-suppress knownConditionTrueFalse
126
0
        if (nSize != static_cast<size_t>(-1))
127
0
            nSize -= nDataOffset;
128
0
        OGRErr eErr = cpl::down_cast<OGRLineString *>(papoGeoms[0])
129
0
                          ->OGRLineString::importFromWkb(
130
0
                              pabyData + nDataOffset, nSize, eWkbVariant,
131
0
                              nBytesConsumedLineString);
132
0
        if (eErr == OGRERR_NONE)
133
0
        {
134
0
            nBytesConsumedOut = nDataOffset + nBytesConsumedLineString;
135
0
        }
136
0
        else
137
0
        {
138
0
            empty();
139
0
        }
140
0
        return eErr;
141
0
    }
142
143
0
    return OGRGeometryCollection::importFromWkbInternal(
144
0
        pabyData, nSize, /*nRecLevel=*/0, eWkbVariant, nBytesConsumedOut);
145
0
}
146
147
/************************************************************************/
148
/*                            exportToWkt()                             */
149
/************************************************************************/
150
151
std::string OGRMultiLineString::exportToWkt(const OGRWktOptions &opts,
152
                                            OGRErr *err) const
153
154
0
{
155
0
    return exportToWktInternal(opts, err, "LINESTRING");
156
0
}
157
158
/************************************************************************/
159
/*                         hasCurveGeometry()                           */
160
/************************************************************************/
161
162
OGRBoolean
163
OGRMultiLineString::hasCurveGeometry(int /* bLookForNonLinear */) const
164
87
{
165
87
    return false;
166
87
}
167
168
/************************************************************************/
169
/*                          CastToMultiCurve()                          */
170
/************************************************************************/
171
172
/**
173
 * \brief Cast to multicurve.
174
 *
175
 * The passed in geometry is consumed and a new one returned.
176
 *
177
 * @param poMLS the input geometry - ownership is passed to the method.
178
 * @return new geometry.
179
 */
180
181
OGRMultiCurve *OGRMultiLineString::CastToMultiCurve(OGRMultiLineString *poMLS)
182
0
{
183
0
    OGRMultiCurve *poMLC = new OGRMultiCurve();
184
0
    TransferMembersAndDestroy(poMLS, poMLC);
185
0
    return poMLC;
186
0
}