/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 | 154 | { |
76 | 154 | if ((flags & OGR_G_3D) && (flags & OGR_G_MEASURED)) |
77 | 0 | return wkbMultiCurveZM; |
78 | 154 | else if (flags & OGR_G_MEASURED) |
79 | 0 | return wkbMultiCurveM; |
80 | 154 | else if (flags & OGR_G_3D) |
81 | 0 | return wkbMultiCurveZ; |
82 | 154 | else |
83 | 154 | return wkbMultiCurve; |
84 | 154 | } |
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 | 154 | { |
103 | 154 | return "MULTICURVE"; |
104 | 154 | } |
105 | | |
106 | | /************************************************************************/ |
107 | | /* isCompatibleSubType() */ |
108 | | /************************************************************************/ |
109 | | |
110 | | OGRBoolean |
111 | | OGRMultiCurve::isCompatibleSubType(OGRwkbGeometryType eGeomType) const |
112 | 128 | { |
113 | 128 | return OGR_GT_IsCurve(eGeomType); |
114 | 128 | } |
115 | | |
116 | | /*! @cond Doxygen_Suppress */ |
117 | | /************************************************************************/ |
118 | | /* addCurveDirectlyFromWkt() */ |
119 | | /************************************************************************/ |
120 | | |
121 | | OGRErr OGRMultiCurve::addCurveDirectlyFromWkt(OGRGeometry *poSelf, |
122 | | OGRCurve *poCurve) |
123 | 234 | { |
124 | 234 | return poSelf->toMultiCurve()->addGeometryDirectly(poCurve); |
125 | 234 | } |
126 | | |
127 | | /*! @endcond */ |
128 | | |
129 | | /************************************************************************/ |
130 | | /* importFromWkt() */ |
131 | | /* */ |
132 | | /* Instantiate from well known text format. */ |
133 | | /************************************************************************/ |
134 | | |
135 | | OGRErr OGRMultiCurve::importFromWkt(const char **ppszInput) |
136 | | |
137 | 252 | { |
138 | 252 | const bool bIsMultiCurve = wkbFlatten(getGeometryType()) == wkbMultiCurve; |
139 | 252 | return importCurveCollectionFromWkt(ppszInput, |
140 | 252 | TRUE, // bAllowEmptyComponent. |
141 | 252 | bIsMultiCurve, // bAllowLineString. |
142 | 252 | bIsMultiCurve, // bAllowCurve. |
143 | 252 | bIsMultiCurve, // bAllowCompoundCurve. |
144 | 252 | addCurveDirectlyFromWkt); |
145 | 252 | } |
146 | | |
147 | | /************************************************************************/ |
148 | | /* exportToWkt() */ |
149 | | /************************************************************************/ |
150 | | |
151 | | std::string OGRMultiCurve::exportToWkt(const OGRWktOptions &opts, |
152 | | OGRErr *err) const |
153 | 0 | { |
154 | 0 | OGRWktOptions optsModified(opts); |
155 | 0 | optsModified.variant = wkbVariantIso; |
156 | 0 | return exportToWktInternal(optsModified, err, "LINESTRING"); |
157 | 0 | } |
158 | | |
159 | | /************************************************************************/ |
160 | | /* hasCurveGeometry() */ |
161 | | /************************************************************************/ |
162 | | |
163 | | OGRBoolean OGRMultiCurve::hasCurveGeometry(int bLookForNonLinear) const |
164 | 0 | { |
165 | 0 | if (bLookForNonLinear) |
166 | 0 | return OGRGeometryCollection::hasCurveGeometry(TRUE); |
167 | 0 | return true; |
168 | 0 | } |
169 | | |
170 | | /************************************************************************/ |
171 | | /* CastToMultiLineString() */ |
172 | | /************************************************************************/ |
173 | | |
174 | | /** |
175 | | * \brief Cast to multi line string. |
176 | | * |
177 | | * This method should only be called if the multicurve actually only contains |
178 | | * instances of OGRLineString. This can be verified if hasCurveGeometry(TRUE) |
179 | | * returns FALSE. It is not intended to approximate circular curves. For that |
180 | | * use getLinearGeometry(). |
181 | | * |
182 | | * The passed in geometry is consumed and a new one returned (or NULL in case |
183 | | * of failure). |
184 | | * |
185 | | * @param poMC the input geometry - ownership is passed to the method. |
186 | | * @return new geometry. |
187 | | */ |
188 | | |
189 | | OGRMultiLineString *OGRMultiCurve::CastToMultiLineString(OGRMultiCurve *poMC) |
190 | 0 | { |
191 | 0 | for (auto &&poSubGeom : *poMC) |
192 | 0 | { |
193 | 0 | poSubGeom = OGRCurve::CastToLineString(poSubGeom); |
194 | 0 | if (poSubGeom == nullptr) |
195 | 0 | { |
196 | 0 | delete poMC; |
197 | 0 | return nullptr; |
198 | 0 | } |
199 | 0 | } |
200 | 0 | OGRMultiLineString *poMLS = new OGRMultiLineString(); |
201 | 0 | TransferMembersAndDestroy(poMC, poMLS); |
202 | 0 | return poMLS; |
203 | 0 | } |