/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 | 467k | 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 | 467k | { |
58 | 467k | auto ret = new (std::nothrow) OGRMultiLineString(*this); |
59 | 467k | if (ret) |
60 | 467k | { |
61 | 467k | if (ret->WkbSize() != WkbSize()) |
62 | 0 | { |
63 | 0 | delete ret; |
64 | 0 | ret = nullptr; |
65 | 0 | } |
66 | 467k | } |
67 | 467k | return ret; |
68 | 467k | } |
69 | | |
70 | | /************************************************************************/ |
71 | | /* getGeometryType() */ |
72 | | /************************************************************************/ |
73 | | |
74 | | OGRwkbGeometryType OGRMultiLineString::getGeometryType() const |
75 | | |
76 | 761k | { |
77 | 761k | if ((flags & OGR_G_3D) && (flags & OGR_G_MEASURED)) |
78 | 61.9k | return wkbMultiLineStringZM; |
79 | 699k | else if (flags & OGR_G_MEASURED) |
80 | 140k | return wkbMultiLineStringM; |
81 | 559k | else if (flags & OGR_G_3D) |
82 | 100k | return wkbMultiLineString25D; |
83 | 459k | else |
84 | 459k | return wkbMultiLineString; |
85 | 761k | } |
86 | | |
87 | | /************************************************************************/ |
88 | | /* getGeometryName() */ |
89 | | /************************************************************************/ |
90 | | |
91 | | const char *OGRMultiLineString::getGeometryName() const |
92 | | |
93 | 57.4k | { |
94 | 57.4k | return "MULTILINESTRING"; |
95 | 57.4k | } |
96 | | |
97 | | /************************************************************************/ |
98 | | /* isCompatibleSubType() */ |
99 | | /************************************************************************/ |
100 | | |
101 | | OGRBoolean |
102 | | OGRMultiLineString::isCompatibleSubType(OGRwkbGeometryType eGeomType) const |
103 | 597k | { |
104 | 597k | return wkbFlatten(eGeomType) == wkbLineString; |
105 | 597k | } |
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 | 30.3k | { |
117 | 30.3k | 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 | 30.3k | return OGRGeometryCollection::importFromWkbInternal( |
144 | 30.3k | pabyData, nSize, /*nRecLevel=*/0, eWkbVariant, nBytesConsumedOut); |
145 | 30.3k | } |
146 | | |
147 | | /************************************************************************/ |
148 | | /* exportToWkt() */ |
149 | | /************************************************************************/ |
150 | | |
151 | | std::string OGRMultiLineString::exportToWkt(const OGRWktOptions &opts, |
152 | | OGRErr *err) const |
153 | | |
154 | 43.4k | { |
155 | 43.4k | return exportToWktInternal(opts, err, "LINESTRING"); |
156 | 43.4k | } |
157 | | |
158 | | /************************************************************************/ |
159 | | /* hasCurveGeometry() */ |
160 | | /************************************************************************/ |
161 | | |
162 | | OGRBoolean |
163 | | OGRMultiLineString::hasCurveGeometry(int /* bLookForNonLinear */) const |
164 | 329k | { |
165 | 329k | return false; |
166 | 329k | } |
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 | } |