Coverage Report

Created: 2026-07-25 06:50

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
0
{
77
0
    if ((flags & OGR_G_3D) && (flags & OGR_G_MEASURED))
78
0
        return wkbMultiLineStringZM;
79
0
    else if (flags & OGR_G_MEASURED)
80
0
        return wkbMultiLineStringM;
81
0
    else if (flags & OGR_G_3D)
82
0
        return wkbMultiLineString25D;
83
0
    else
84
0
        return wkbMultiLineString;
85
0
}
86
87
/************************************************************************/
88
/*                          getGeometryName()                           */
89
/************************************************************************/
90
91
const char *OGRMultiLineString::getGeometryName() const
92
93
0
{
94
0
    return "MULTILINESTRING";
95
0
}
96
97
/************************************************************************/
98
/*                        isCompatibleSubType()                         */
99
/************************************************************************/
100
101
bool OGRMultiLineString::isCompatibleSubType(OGRwkbGeometryType eGeomType) const
102
0
{
103
0
    return wkbFlatten(eGeomType) == wkbLineString;
104
0
}
105
106
/************************************************************************/
107
/*                           importFromWkb()                            */
108
/************************************************************************/
109
110
OGRErr OGRMultiLineString::importFromWkb(const unsigned char *pabyData,
111
                                         size_t nSize,
112
                                         OGRwkbVariant eWkbVariant,
113
                                         size_t &nBytesConsumedOut)
114
115
0
{
116
0
    if (nGeomCount == 1 && nSize >= 9 && flags == 0 && pabyData[0] == wkbNDR &&
117
0
        memcmp(pabyData + 1, "\x05\x00\x00\x00\x01\x00\x00\x00", 8) == 0)
118
0
    {
119
        // Optimization to import a Intel-ordered 1-part multilinestring on
120
        // top of an existing 1-part multilinestring, to save dynamic memory
121
        // allocations.
122
0
        const size_t nDataOffset = 9;
123
0
        size_t nBytesConsumedLineString = 0;
124
        // cppcheck-suppress knownConditionTrueFalse
125
0
        if (nSize != static_cast<size_t>(-1))
126
0
            nSize -= nDataOffset;
127
0
        OGRErr eErr = cpl::down_cast<OGRLineString *>(papoGeoms[0])
128
0
                          ->OGRLineString::importFromWkb(
129
0
                              pabyData + nDataOffset, nSize, eWkbVariant,
130
0
                              nBytesConsumedLineString);
131
0
        if (eErr == OGRERR_NONE)
132
0
        {
133
0
            nBytesConsumedOut = nDataOffset + nBytesConsumedLineString;
134
0
        }
135
0
        else
136
0
        {
137
0
            empty();
138
0
        }
139
0
        return eErr;
140
0
    }
141
142
0
    return OGRGeometryCollection::importFromWkbInternal(
143
0
        pabyData, nSize, /*nRecLevel=*/0, eWkbVariant, nBytesConsumedOut);
144
0
}
145
146
/************************************************************************/
147
/*                            exportToWkt()                             */
148
/************************************************************************/
149
150
std::string OGRMultiLineString::exportToWkt(const OGRWktOptions &opts,
151
                                            OGRErr *err) const
152
153
0
{
154
0
    return exportToWktInternal(opts, err, "LINESTRING");
155
0
}
156
157
/************************************************************************/
158
/*                          hasCurveGeometry()                          */
159
/************************************************************************/
160
161
bool OGRMultiLineString::hasCurveGeometry(int /* bLookForNonLinear */) const
162
0
{
163
0
    return false;
164
0
}
165
166
/************************************************************************/
167
/*                          CastToMultiCurve()                          */
168
/************************************************************************/
169
170
/**
171
 * \brief Cast to multicurve.
172
 *
173
 * The passed in geometry is consumed and a new one returned.
174
 *
175
 * @param poMLS the input geometry - ownership is passed to the method.
176
 * @return new geometry.
177
 */
178
179
OGRMultiCurve *OGRMultiLineString::CastToMultiCurve(OGRMultiLineString *poMLS)
180
0
{
181
0
    OGRMultiCurve *poMLC = new OGRMultiCurve();
182
0
    TransferMembersAndDestroy(poMLS, poMLC);
183
0
    return poMLC;
184
0
}