/src/gdal/ogr/ogrmultilinestring.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | * Note: before GDAL 2.1, only the default implementation of the constructor |
31 | | * existed, which could be unsafe to use. |
32 | | * |
33 | | * @since GDAL 2.1 |
34 | | */ |
35 | | |
36 | 0 | OGRMultiLineString::OGRMultiLineString(const OGRMultiLineString &) = default; |
37 | | |
38 | | /************************************************************************/ |
39 | | /* operator=( const OGRMultiCurve&) */ |
40 | | /************************************************************************/ |
41 | | |
42 | | /** |
43 | | * \brief Assignment operator. |
44 | | * |
45 | | * Note: before GDAL 2.1, only the default implementation of the operator |
46 | | * existed, which could be unsafe to use. |
47 | | * |
48 | | * @since GDAL 2.1 |
49 | | */ |
50 | | |
51 | | OGRMultiLineString & |
52 | | OGRMultiLineString::operator=(const OGRMultiLineString &other) |
53 | 0 | { |
54 | 0 | if (this != &other) |
55 | 0 | { |
56 | 0 | OGRMultiCurve::operator=(other); |
57 | 0 | } |
58 | 0 | return *this; |
59 | 0 | } |
60 | | |
61 | | /************************************************************************/ |
62 | | /* clone() */ |
63 | | /************************************************************************/ |
64 | | |
65 | | OGRMultiLineString *OGRMultiLineString::clone() const |
66 | | |
67 | 0 | { |
68 | 0 | auto ret = new (std::nothrow) OGRMultiLineString(*this); |
69 | 0 | if (ret) |
70 | 0 | { |
71 | 0 | if (ret->WkbSize() != WkbSize()) |
72 | 0 | { |
73 | 0 | delete ret; |
74 | 0 | ret = nullptr; |
75 | 0 | } |
76 | 0 | } |
77 | 0 | return ret; |
78 | 0 | } |
79 | | |
80 | | /************************************************************************/ |
81 | | /* getGeometryType() */ |
82 | | /************************************************************************/ |
83 | | |
84 | | OGRwkbGeometryType OGRMultiLineString::getGeometryType() const |
85 | | |
86 | 0 | { |
87 | 0 | if ((flags & OGR_G_3D) && (flags & OGR_G_MEASURED)) |
88 | 0 | return wkbMultiLineStringZM; |
89 | 0 | else if (flags & OGR_G_MEASURED) |
90 | 0 | return wkbMultiLineStringM; |
91 | 0 | else if (flags & OGR_G_3D) |
92 | 0 | return wkbMultiLineString25D; |
93 | 0 | else |
94 | 0 | return wkbMultiLineString; |
95 | 0 | } |
96 | | |
97 | | /************************************************************************/ |
98 | | /* getGeometryName() */ |
99 | | /************************************************************************/ |
100 | | |
101 | | const char *OGRMultiLineString::getGeometryName() const |
102 | | |
103 | 0 | { |
104 | 0 | return "MULTILINESTRING"; |
105 | 0 | } |
106 | | |
107 | | /************************************************************************/ |
108 | | /* isCompatibleSubType() */ |
109 | | /************************************************************************/ |
110 | | |
111 | | OGRBoolean |
112 | | OGRMultiLineString::isCompatibleSubType(OGRwkbGeometryType eGeomType) const |
113 | 0 | { |
114 | 0 | return wkbFlatten(eGeomType) == wkbLineString; |
115 | 0 | } |
116 | | |
117 | | /************************************************************************/ |
118 | | /* importFromWkb() */ |
119 | | /************************************************************************/ |
120 | | |
121 | | OGRErr OGRMultiLineString::importFromWkb(const unsigned char *pabyData, |
122 | | size_t nSize, |
123 | | OGRwkbVariant eWkbVariant, |
124 | | size_t &nBytesConsumedOut) |
125 | | |
126 | 0 | { |
127 | 0 | if (nGeomCount == 1 && nSize >= 9 && flags == 0 && pabyData[0] == wkbNDR && |
128 | 0 | memcmp(pabyData + 1, "\x05\x00\x00\x00\x01\x00\x00\x00", 8) == 0) |
129 | 0 | { |
130 | | // Optimization to import a Intel-ordered 1-part multilinestring on |
131 | | // top of an existing 1-part multilinestring, to save dynamic memory |
132 | | // allocations. |
133 | 0 | const size_t nDataOffset = 9; |
134 | 0 | size_t nBytesConsumedLineString = 0; |
135 | | // cppcheck-suppress knownConditionTrueFalse |
136 | 0 | if (nSize != static_cast<size_t>(-1)) |
137 | 0 | nSize -= nDataOffset; |
138 | 0 | OGRErr eErr = cpl::down_cast<OGRLineString *>(papoGeoms[0]) |
139 | 0 | ->OGRLineString::importFromWkb( |
140 | 0 | pabyData + nDataOffset, nSize, eWkbVariant, |
141 | 0 | nBytesConsumedLineString); |
142 | 0 | if (eErr == OGRERR_NONE) |
143 | 0 | { |
144 | 0 | nBytesConsumedOut = nDataOffset + nBytesConsumedLineString; |
145 | 0 | } |
146 | 0 | else |
147 | 0 | { |
148 | 0 | empty(); |
149 | 0 | } |
150 | 0 | return eErr; |
151 | 0 | } |
152 | | |
153 | 0 | return OGRGeometryCollection::importFromWkbInternal( |
154 | 0 | pabyData, nSize, /*nRecLevel=*/0, eWkbVariant, nBytesConsumedOut); |
155 | 0 | } |
156 | | |
157 | | /************************************************************************/ |
158 | | /* exportToWkt() */ |
159 | | /************************************************************************/ |
160 | | |
161 | | std::string OGRMultiLineString::exportToWkt(const OGRWktOptions &opts, |
162 | | OGRErr *err) const |
163 | | |
164 | 0 | { |
165 | 0 | return exportToWktInternal(opts, err, "LINESTRING"); |
166 | 0 | } |
167 | | |
168 | | /************************************************************************/ |
169 | | /* hasCurveGeometry() */ |
170 | | /************************************************************************/ |
171 | | |
172 | | OGRBoolean |
173 | | OGRMultiLineString::hasCurveGeometry(int /* bLookForNonLinear */) const |
174 | 0 | { |
175 | 0 | return false; |
176 | 0 | } |
177 | | |
178 | | /************************************************************************/ |
179 | | /* CastToMultiCurve() */ |
180 | | /************************************************************************/ |
181 | | |
182 | | /** |
183 | | * \brief Cast to multicurve. |
184 | | * |
185 | | * The passed in geometry is consumed and a new one returned. |
186 | | * |
187 | | * @param poMLS the input geometry - ownership is passed to the method. |
188 | | * @return new geometry. |
189 | | */ |
190 | | |
191 | | OGRMultiCurve *OGRMultiLineString::CastToMultiCurve(OGRMultiLineString *poMLS) |
192 | 0 | { |
193 | 0 | OGRMultiCurve *poMLC = new OGRMultiCurve(); |
194 | 0 | TransferMembersAndDestroy(poMLS, poMLC); |
195 | 0 | return poMLC; |
196 | 0 | } |