QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgscircularstring.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscircularstring.h
3 ---------------------
4 begin : September 2014
5 copyright : (C) 2014 by Marco Hugentobler
6 email : marco at sourcepole dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSCIRCULARSTRING_H
19#define QGSCIRCULARSTRING_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgscurve.h"
24
25#include <QString>
26#include <QVector>
27
28using namespace Qt::StringLiterals;
29
35class CORE_EXPORT QgsCircularString : public QgsCurve
36{
37 public:
38 // clang-format off
43 // clang-format on
44
51 QgsCircularString( const QgsPoint &p1,
52 const QgsPoint &p2,
53 const QgsPoint &p3 ) SIP_HOLDGIL;
54
70 QgsCircularString( const QVector<double> &x, const QVector<double> &y,
71 const QVector<double> &z = QVector<double>(),
72 const QVector<double> &m = QVector<double>() ) SIP_HOLDGIL;
73
74
86 const QgsPoint &p2,
87 const QgsPoint &center,
88 bool useShortestArc = true );
89
90#ifndef SIP_RUN
91 private:
92 bool fuzzyHelper( double epsilon,
93 const QgsAbstractGeometry &other,
94 bool is3DFlag,
95 bool isMeasureFlag,
96 std::function<bool( double, double, double, double, double, double, double, double, double )> comparator3DMeasure,
97 std::function<bool( double, double, double, double, double, double, double )> comparator3D,
98 std::function<bool( double, double, double, double, double, double, double )> comparatorMeasure,
99 std::function<bool( double, double, double, double, double )> comparator2D ) const
100 {
102 if ( !otherLine )
103 return false;
104
105 if ( mWkbType != otherLine->mWkbType )
106 return false;
107
108 const int size = mX.count();
109 if ( size != otherLine->mX.count() )
110 return false;
111
112 bool result = true;
113 const double *xData = mX.constData();
114 const double *yData = mY.constData();
115 const double *zData = is3DFlag ? mZ.constData() : nullptr;
116 const double *mData = isMeasureFlag ? mM.constData() : nullptr;
117 const double *otherXData = otherLine->mX.constData();
118 const double *otherYData = otherLine->mY.constData();
119 const double *otherZData = is3DFlag ? otherLine->mZ.constData() : nullptr;
120 const double *otherMData = isMeasureFlag ? otherLine->mM.constData() : nullptr;
121 for ( int i = 0; i < size; ++i )
122 {
123 if ( is3DFlag && isMeasureFlag )
124 {
125 result &= comparator3DMeasure( epsilon, *xData++, *yData++, *zData++, *mData++,
126 *otherXData++, *otherYData++, *otherZData++, *otherMData++ );
127 }
128 else if ( is3DFlag )
129 {
130 result &= comparator3D( epsilon, *xData++, *yData++, *zData++,
131 *otherXData++, *otherYData++, *otherZData++ );
132 }
133 else if ( isMeasureFlag )
134 {
135 result &= comparatorMeasure( epsilon, *xData++, *yData++, *mData++,
136 *otherXData++, *otherYData++, *otherMData++ );
137 }
138 else
139 {
140 result &= comparator2D( epsilon, *xData++, *yData++,
141 *otherXData++, *otherYData++ );
142 }
143 if ( ! result )
144 {
145 return false;
146 }
147 }
148
149 return result;
150 }
151#endif // !SIP_RUN
152
153 public:
154 bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
155 {
156 return fuzzyHelper(
157 epsilon,
158 other,
159 is3D(),
160 isMeasure(),
161 []( double epsilon, double x1, double y1, double z1, double m1,
162 double x2, double y2, double z2, double m2 )
163 {
164 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, z1, m1, x2, y2, z2, m2 );
165 },
166 []( double epsilon, double x1, double y1, double z1,
167 double x2, double y2, double z2 )
168 {
169 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, z1, x2, y2, z2 );
170 },
171 []( double epsilon, double x1, double y1, double m1,
172 double x2, double y2, double m2 )
173 {
174 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, m1, x2, y2, m2 );
175 },
176 []( double epsilon, double x1, double y1,
177 double x2, double y2 )
178 {
179 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, x2, y2 );
180 } );
181 }
182
183 bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
184 {
185 return fuzzyHelper(
186 epsilon,
187 other,
188 is3D(),
189 isMeasure(),
190 []( double epsilon, double x1, double y1, double z1, double m1,
191 double x2, double y2, double z2, double m2 )
192 {
193 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, z1, m1, x2, y2, z2, m2 );
194 },
195 []( double epsilon, double x1, double y1, double z1,
196 double x2, double y2, double z2 )
197 {
198 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, z1, x2, y2, z2 );
199 },
200 []( double epsilon, double x1, double y1, double m1,
201 double x2, double y2, double m2 )
202 {
203 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, m1, x2, y2, m2 );
204 },
205 []( double epsilon, double x1, double y1,
206 double x2, double y2 )
207 {
208 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, x2, y2 );
209 } );
210 }
211
212 bool equals( const QgsCurve &other ) const override
213 {
214 return fuzzyEqual( other, 1e-8 );
215 }
216
217
218 QString geometryType() const override SIP_HOLDGIL;
219 int dimension() const override SIP_HOLDGIL;
220 QgsCircularString *clone() const override SIP_FACTORY;
221 void clear() override;
222
223 bool fromWkb( QgsConstWkbPtr &wkb ) override;
224 bool fromWkt( const QString &wkt ) override;
225
226 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
227 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
228 QString asWkt( int precision = 17 ) const override;
229 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
230 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
231 json asJsonObject( int precision = 17 ) const override SIP_SKIP;
232 bool isEmpty() const override SIP_HOLDGIL;
233 bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
234 int numPoints() const override SIP_HOLDGIL;
235 int indexOf( const QgsPoint &point ) const final;
236
240 QgsPoint pointN( int i ) const SIP_HOLDGIL;
241
242 void points( QgsPointSequence &pts SIP_OUT ) const override;
243
247 void setPoints( const QgsPointSequence &points );
248
259 void append( const QgsCircularString *string );
260
261 double length() const override;
262 QgsPoint startPoint() const override SIP_HOLDGIL;
263 QgsPoint endPoint() const override SIP_HOLDGIL;
264 QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
265 QgsCircularString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
266 QgsAbstractGeometry *simplifyByDistance( double tolerance ) const override SIP_FACTORY;
267 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
268
269 void draw( QPainter &p ) const override;
270 void transform( const QgsCoordinateTransform &ct, Qgis::TransformDirection d = Qgis::TransformDirection::Forward, bool transformZ = false ) override SIP_THROW( QgsCsException );
271 void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
272 void addToPainterPath( QPainterPath &path ) const override;
273 void drawAsPolygon( QPainter &p ) const override;
274 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
275 bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
276 bool deleteVertex( QgsVertexId position ) override;
277 double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
278 bool pointAt( int node, QgsPoint &point, Qgis::VertexType &type ) const override;
279 void sumUpArea( double &sum SIP_OUT ) const override;
280 void sumUpArea3D( double &sum SIP_OUT ) const override;
281 bool hasCurvedSegments() const override;
282 double vertexAngle( QgsVertexId vertex ) const override;
283 double segmentLength( QgsVertexId startVertex ) const override;
284 double distanceBetweenVertices( QgsVertexId fromVertex, QgsVertexId toVertex ) const override;
285 QgsCircularString *reversed() const override SIP_FACTORY;
286 QgsPoint *interpolatePoint( double distance ) const override SIP_FACTORY;
287 QgsCircularString *curveSubstring( double startDistance, double endDistance ) const override SIP_FACTORY;
288 bool addZValue( double zValue = 0 ) override;
289 bool addMValue( double mValue = 0 ) override;
290 bool dropZValue() override;
291 bool dropMValue() override;
292 void swapXy() override;
293 double xAt( int index ) const override SIP_HOLDGIL;
294 double yAt( int index ) const override SIP_HOLDGIL;
295 double zAt( int index ) const override SIP_HOLDGIL;
296 double mAt( int index ) const override SIP_HOLDGIL;
297
298 bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = nullptr ) override;
299 void scroll( int firstVertexIndex ) final;
300
301#ifndef SIP_RUN
302 void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
303 void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
304 std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex( int index ) const final;
305
314 inline static const QgsCircularString *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
315 {
317 return static_cast<const QgsCircularString *>( geom );
318 return nullptr;
319 }
320
329 inline static QgsCircularString *cast( QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
330 {
332 return static_cast<QgsCircularString *>( geom );
333 return nullptr;
334 }
335#endif
336
338
339#ifdef SIP_RUN
340// clang-format off
341 SIP_PYOBJECT __repr__();
342 % MethodCode
343 QString wkt = sipCpp->asWkt();
344 if ( wkt.length() > 1000 )
345 wkt = wkt.left( 1000 ) + u"..."_s;
346 QString str = u"<QgsCircularString: %1>"_s.arg( wkt );
347 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
348 % End
349// clang-format on
350#endif
351
352 protected:
353
354 int compareToSameClass( const QgsAbstractGeometry *other ) const final;
355 QgsBox3D calculateBoundingBox3D() const override;
356
357 private:
358 QVector<double> mX;
359 QVector<double> mY;
360 QVector<double> mZ;
361 QVector<double> mM;
362
363#if 0
364 static void arcTo( QPainterPath &path, QPointF pt1, QPointF pt2, QPointF pt3 );
365#endif
366 //bounding box of a single segment
367 static QgsRectangle segmentBoundingBox( const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3 );
368 static QgsPointSequence compassPointsOnSegment( double p1Angle, double p2Angle, double p3Angle, double centerX, double centerY, double radius );
369 static double closestPointOnArc( double x1, double y1, double x2, double y2, double x3, double y3,
370 const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon );
371 void insertVertexBetween( int after, int before, int pointOnCircle );
372 void deleteVertex( int i );
373
374};
375
376// clazy:excludeall=qstring-allocations
377
378#endif // QGSCIRCULARSTRING_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
@ CircularString
CircularString.
Definition qgis.h:304
An abstract base class for classes which transform geometries by transforming input points to output ...
Abstract base class for all geometries.
virtual QgsBox3D calculateBoundingBox3D() const
Calculates the minimal 3D bounding box for the geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
virtual void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform)
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual bool fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const =0
Performs fuzzy comparison between this geometry and other using an epsilon.
virtual bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
virtual void filterVertices(const std::function< bool(const QgsPoint &) > &filter)
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
QgsAbstractGeometry()=default
virtual int compareToSameClass(const QgsAbstractGeometry *other) const =0
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
Circular string geometry type.
bool equals(const QgsCurve &other) const override
Checks whether this curve exactly equals another curve.
static QgsCircularString * cast(QgsAbstractGeometry *geom)
Cast the geom to a QgsCircularString.
static QgsCircularString fromTwoPointsAndCenter(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &center, bool useShortestArc=true)
Creates a circular string with a single arc representing the curve from p1 to p2 with the specified c...
bool fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy comparison between this geometry and other using an epsilon.
bool fuzzyDistanceEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy distance comparison between this geometry and other using an epsilon.
static const QgsCircularString * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsCircularString.
QgsCircularString()
Constructs an empty circular string.
A const WKB pointer.
Definition qgswkbptr.h:211
Handles coordinate transforms between two coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
virtual std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex(int index) const =0
Splits the curve at the specified vertex index, returning two curves which represent the portion of t...
QgsCurve()=default
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
static bool fuzzyEqual(T epsilon, const Args &... args) noexcept
Performs fuzzy comparison between pairs of values within a specified epsilon.
static bool fuzzyDistanceEqual(T epsilon, const Args &... args) noexcept
Compare equality between multiple pairs of values with a specified epsilon.
Line string geometry type, with support for z-dimension and m-values.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
A rectangle specified with double values.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_HOLDGIL
Definition qgis_sip.h:178
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_THROW(name,...)
Definition qgis_sip.h:210
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QVector< QgsPoint > QgsPointSequence
void arcTo(QPainterPath &path, QPointF pt1, QPointF pt2, QPointF pt3)
double closestSegment(const QgsPolylineXY &pl, const QgsPointXY &pt, int &vertexAfter, double epsilon)
Definition qgstracer.cpp:72
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:34