Marble

GeoDataLineString.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2008-2009 Torsten Rahn <tackat@kde.org>
4// SPDX-FileCopyrightText: 2009 Patrick Spendrin <ps_ml@gmx.de>
5//
6
7#ifndef MARBLE_GEODATALINESTRING_H
8#define MARBLE_GEODATALINESTRING_H
9
10#include <QList>
11#include <QMetaType>
12
13#include "MarbleGlobal.h"
14
15#include "GeoDataGeometry.h"
16#include "geodata_export.h"
17
18namespace Marble
19{
20class GeoDataCoordinates;
21class GeoDataLineStringPrivate;
22
23/*!
24 \class GeoDataLineString
25 \brief A LineString that allows to store a contiguous set of line segments.
26
27 GeoDataLineString is a tool class that implements the LineString tag/class
28 of the Open Geospatial Consortium standard KML 2.2.
29
30 GeoDataLineString extends GeoDataGeometry to store and edit
31 LineStrings.
32
33 In the QPainter API "pure" LineStrings are also referred to as "polylines".
34 As such they are similar to the outline of a non-closed QPolygon.
35
36 Whenever a LineString is painted GeoDataLineStyle should be used to assign a
37 color and line width.
38
39 A GeoDataLineString consists of several (geodetic) nodes which are each
40 connected through line segments. The nodes are stored as GeoDataCoordinates
41 objects.
42
43 The API which provides access to the nodes is similar to the API of
44 QList.
45
46 GeoDataLineString allows LineStrings to be tessellated in order to make them
47 follow the terrain and the curvature of the earth. The tessellation options
48 allow for different ways of visualization:
49
50 \li Not tessellated: A LineString that connects each two nodes directly and
51 straight in screen coordinate space.
52 \li A tessellated line: Each line segment is bent so that the LineString
53 follows the curvature of the earth and its terrain. A tessellated
54 line segment connects two nodes at the shortest possible distance
55 ("along great circles").
56 \li A tessellated line that follows latitude circles whenever possible:
57 In this case Latitude circles are followed as soon as two subsequent
58 nodes have exactly the same amount of latitude. In all other places the
59 line segments follow great circles.
60
61 Some convenience methods have been added that allow to calculate the
62 geodesic bounding box or the length of a LineString.
63*/
64
65class GEODATA_EXPORT GeoDataLineString : public GeoDataGeometry
66{
67public:
69 using ConstIterator = QList<GeoDataCoordinates>::ConstIterator;
71
72 /*!
73 \brief Creates a new LineString.
74 */
75 explicit GeoDataLineString(TessellationFlags f = NoTessellation);
76
77 /*!
78 \brief Creates a LineString from an existing geometry object.
79 */
80 explicit GeoDataLineString(const GeoDataGeometry &other);
81
82 /*!
83 \brief Destroys a LineString.
84 */
85 ~GeoDataLineString() override;
86
87 const char *nodeType() const override;
88
89 EnumGeometryId geometryId() const override;
90
91 GeoDataGeometry *copy() const override;
92
93 /*!
94 \brief Returns whether a LineString is a closed polygon.
95
96 \return <code>false</code> if the LineString is not a LinearRing.
97 */
98 virtual bool isClosed() const;
99
100 /*!
101 \brief Returns whether the LineString follows the earth's surface.
102
103 \return <code>true</code> if the LineString's line segments follow the
104 earth's surface and terrain along great circles.
105 */
106 bool tessellate() const;
107
108 /*!
109 \brief Sets the tessellation property for the LineString.
110
111 If \a tessellate is <code>true</code> then the LineString's line segments
112 are bent and follow the earth's surface and terrain along great circles.
113 If \a tessellate is <code>false</code> then the LineString's line segments
114 are rendered as straight lines in screen coordinate space.
115 */
116 void setTessellate(bool tessellate);
117
118 /*!
119 \brief Returns the tessellation flags for a LineString.
120 */
121 TessellationFlags tessellationFlags() const;
122
123 /*!
124 \brief Sets the given tessellation flags for a LineString.
125 */
126 void setTessellationFlags(TessellationFlags f);
127
128 /*!
129 \brief Reverses the LineString.
130 @since 0.26.0
131 */
132 void reverse();
133
134 /*!
135 \brief Returns the smallest latLonAltBox that contains the LineString.
136
137 \see GeoDataLatLonAltBox
138 */
139
140 const GeoDataLatLonAltBox &latLonAltBox() const override;
141
142 /**
143 * @brief Returns the length of LineString across a sphere starting from a coordinate in LineString
144 * This method can be used as an approximation for distances along LineStrings.
145 * The unit used for the resulting length matches the unit of the planet
146 * radius.
147 * @param planetRadius radius of the sphere
148 * @param offset position of coordinate within LineString
149 */
150 virtual qreal length(qreal planetRadius, int offset = 0) const;
151
152 /*!
153 \brief Provides a more generic representation of the LineString.
154
155 The LineString is normalized, and pole corrected.
156
157 Deprecation Warning: This method will likely be removed from the public API.
158 */
159 virtual GeoDataLineString toRangeCorrected() const;
160
161 /*!
162 \brief The line string with nodes that have proper longitude/latitude ranges.
163
164 \return A LineString that resembles the original linestring with nodes that
165 have longitude values between -180 and +180 deg and that
166 feature latitude values between -90 and +90 deg.
167
168 Deprecation Warning: This method will likely be removed from the public API.
169 */
170 virtual GeoDataLineString toNormalized() const;
171
172 /*!
173 \brief The line string with more generic pole values.
174
175 \return A LineString that resembles the original linestring. Nodes that
176 represent one of the poles are duplicated to allow for a better
177 visualization of flat projections.
178
179 Deprecation Warning: This method will likely be removed from the public API.
180 */
181 virtual GeoDataLineString toPoleCorrected() const;
182
183 /*!
184 \brief The line string corrected for date line crossing.
185
186 \return A set of LineStrings that don't cross the dateline and which
187 resemble the original linestring.
188
189 Deprecation Warning: This method will likely be removed from the public API.
190 */
191 virtual QList<GeoDataLineString *> toDateLineCorrected() const;
192
193 // "Reimplementation" of QList API
194 /*!
195 \brief Returns whether the LineString has no nodes at all.
196
197 \return <code>true</code> if there are no nodes inside the line string.
198 */
199 bool isEmpty() const;
200
201 /*!
202 \brief Returns the number of nodes in a LineString.
203 */
204 int size() const;
205
206 /*!
207 \brief Returns a reference to the coordinates of a node at a given position.
208 This method detaches the returned coordinate object from the line string.
209 */
210 GeoDataCoordinates &at(int pos);
211
212 /*!
213 \brief Returns a reference to the coordinates of a node at a given position.
214 This method does not detach the returned coordinate object from the line string.
215 */
216 const GeoDataCoordinates &at(int pos) const;
217
218 /*!
219 \brief Returns a reference to the coordinates of a node at a given position.
220 This method detaches the returned coordinate object from the line string.
221 */
222 GeoDataCoordinates &operator[](int pos);
223
224 /**
225 Returns a sub-string which contains elements from this vector, starting at position pos. If length is -1
226 (the default), all elements after pos are included; otherwise length elements (or all remaining elements if
227 there are less than length elements) are included.
228 */
229 GeoDataLineString mid(int pos, int length = -1) const;
230
231 /*!
232 \brief Returns a reference to the coordinates of a node at a given position.
233 This method does not detach the returned coordinate object from the line string.
234 */
235 const GeoDataCoordinates &operator[](int pos) const;
236
237 /*!
238 \brief Returns a reference to the first node in the LineString.
239 This method detaches the returned coordinate object from the line string.
240 */
241 GeoDataCoordinates &first();
242
243 /*!
244 \brief Returns a reference to the first node in the LineString.
245 This method does not detach the returned coordinate object from the line string.
246 */
247 const GeoDataCoordinates &first() const;
248
249 /*!
250 \brief Returns a reference to the last node in the LineString.
251 This method detaches the returned coordinate object from the line string.
252 */
253 GeoDataCoordinates &last();
254
255 /*!
256 \brief Returns a reference to the last node in the LineString.
257 This method does not detach the returned coordinate object from the line string.
258 */
259 const GeoDataCoordinates &last() const;
260
261 /*!
262 \brief Inserts a new node at the given index.
263 */
264 void insert(int index, const GeoDataCoordinates &value);
265
266 /*!
267 \brief Attempts to allocate memory for at least \a size coordinates.
268 */
269 void reserve(int size);
270
271 /*!
272 \brief Appends a given geodesic position as a new node to the LineString.
273 */
274 void append(const GeoDataCoordinates &value);
275
276 /*!
277 \brief Appends a given geodesic position as new nodes to the LineString.
278 */
279 void append(const QList<GeoDataCoordinates> &values);
280
281 /*!
282 \brief Appends a given geodesic position as a new node to the LineString.
283 */
284 GeoDataLineString &operator<<(const GeoDataCoordinates &value);
285
286 /*!
287 \brief Appends a given LineString to the end of the LineString.
288 */
289 GeoDataLineString &operator<<(const GeoDataLineString &lineString);
290
291 /*!
292 \brief Returns true/false depending on whether this and other are/are not equal.
293 */
294 bool operator==(const GeoDataLineString &other) const;
295 bool operator!=(const GeoDataLineString &other) const;
296
297 /*!
298 \brief Returns an iterator that points to the begin of the LineString.
299 */
302
303 /*!
304 \brief Returns an iterator that points to the end of the LineString.
305 */
308
309 /*!
310 \brief Returns a const iterator that points to the begin of the LineString.
311 */
313
314 /*!
315 \brief Returns a const iterator that points to the end of the LineString.
316 */
318
319 /*!
320 \brief Destroys all nodes in a LineString.
321 */
322 void clear();
323
324 /*!
325 \brief Removes the node at the given position and returns it.
326 */
328
329 /*!
330 \brief Removes the nodes within the given range and returns them.
331 */
333
334 /*!
335 \brief Removes the node at the given position and destroys it.
336 */
337 void remove(int i);
338
339 /*!
340 \brief Returns a linestring with detail values assigned to each node.
341 */
342 GeoDataLineString optimized() const;
343
344 /*!
345 \brief Returns a javascript-style list (that can be used e.g. with the QML GeoPolyline element).
346 */
347 QVariantList toVariantList() const;
348
349 // Serialization
350 /*!
351 \brief Serialize the LineString to a stream.
352 \param stream the stream.
353 */
354 void pack(QDataStream &stream) const override;
355
356 /*!
357 \brief Unserialize the LineString from a stream.
358 \param stream the stream.
359 */
360 void unpack(QDataStream &stream) override;
361
362protected:
363 explicit GeoDataLineString(GeoDataLineStringPrivate *priv);
364
365private:
366 Q_DECLARE_PRIVATE(GeoDataLineString)
367};
368
369}
370
371Q_DECLARE_METATYPE(Marble::GeoDataLineString)
372
373#endif
A 3d point representation.
A base class for all geodata features.
A class that defines a 3D bounding box for geographic data.
A LineString that allows to store a contiguous set of line segments.
Binds a QML item to a specific geodetic location in screen coordinates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:52:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.