QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <QVector>
26
32class CORE_EXPORT QgsCircularString: public QgsCurve
33{
34 public:
35
40
47 QgsCircularString( const QgsPoint &p1,
48 const QgsPoint &p2,
49 const QgsPoint &p3 ) SIP_HOLDGIL;
50
66 QgsCircularString( const QVector<double> &x, const QVector<double> &y,
67 const QVector<double> &z = QVector<double>(),
68 const QVector<double> &m = QVector<double>() ) SIP_HOLDGIL;
69
70
82 const QgsPoint &p2,
83 const QgsPoint &center,
84 bool useShortestArc = true );
85
86#ifndef SIP_RUN
87 private:
88 bool fuzzyHelper( double epsilon,
89 const QgsAbstractGeometry &other,
90 bool is3DFlag,
91 bool isMeasureFlag,
92 std::function<bool( double, double, double, double, double, double, double, double, double )> comparator3DMeasure,
93 std::function<bool( double, double, double, double, double, double, double )> comparator3D,
94 std::function<bool( double, double, double, double, double, double, double )> comparatorMeasure,
95 std::function<bool( double, double, double, double, double )> comparator2D ) const
96 {
98 if ( !otherLine )
99 return false;
100
101 if ( mWkbType != otherLine->mWkbType )
102 return false;
103
104 const int size = mX.count();
105 if ( size != otherLine->mX.count() )
106 return false;
107
108 bool result = true;
109 const double *xData = mX.constData();
110 const double *yData = mY.constData();
111 const double *zData = is3DFlag ? mZ.constData() : nullptr;
112 const double *mData = isMeasureFlag ? mM.constData() : nullptr;
113 const double *otherXData = otherLine->mX.constData();
114 const double *otherYData = otherLine->mY.constData();
115 const double *otherZData = is3DFlag ? otherLine->mZ.constData() : nullptr;
116 const double *otherMData = isMeasureFlag ? otherLine->mM.constData() : nullptr;
117 for ( int i = 0; i < size; ++i )
118 {
119 if ( is3DFlag && isMeasureFlag )
120 {
121 result &= comparator3DMeasure( epsilon, *xData++, *yData++, *zData++, *mData++,
122 *otherXData++, *otherYData++, *otherZData++, *otherMData++ );
123 }
124 else if ( is3DFlag )
125 {
126 result &= comparator3D( epsilon, *xData++, *yData++, *zData++,
127 *otherXData++, *otherYData++, *otherZData++ );
128 }
129 else if ( isMeasureFlag )
130 {
131 result &= comparatorMeasure( epsilon, *xData++, *yData++, *mData++,
132 *otherXData++, *otherYData++, *otherMData++ );
133 }
134 else
135 {
136 result &= comparator2D( epsilon, *xData++, *yData++,
137 *otherXData++, *otherYData++ );
138 }
139 if ( ! result )
140 {
141 return false;
142 }
143 }
144
145 return result;
146 }
147#endif // !SIP_RUN
148
149 public:
150 bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
151 {
152 return fuzzyHelper(
153 epsilon,
154 other,
155 is3D(),
156 isMeasure(),
157 []( double epsilon, double x1, double y1, double z1, double m1,
158 double x2, double y2, double z2, double m2 )
159 {
160 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, z1, m1, x2, y2, z2, m2 );
161 },
162 []( double epsilon, double x1, double y1, double z1,
163 double x2, double y2, double z2 )
164 {
165 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, z1, x2, y2, z2 );
166 },
167 []( double epsilon, double x1, double y1, double m1,
168 double x2, double y2, double m2 )
169 {
170 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, m1, x2, y2, m2 );
171 },
172 []( double epsilon, double x1, double y1,
173 double x2, double y2 )
174 {
175 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, x2, y2 );
176 } );
177 }
178
179 bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
180 {
181 return fuzzyHelper(
182 epsilon,
183 other,
184 is3D(),
185 isMeasure(),
186 []( double epsilon, double x1, double y1, double z1, double m1,
187 double x2, double y2, double z2, double m2 )
188 {
189 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, z1, m1, x2, y2, z2, m2 );
190 },
191 []( double epsilon, double x1, double y1, double z1,
192 double x2, double y2, double z2 )
193 {
194 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, z1, x2, y2, z2 );
195 },
196 []( double epsilon, double x1, double y1, double m1,
197 double x2, double y2, double m2 )
198 {
199 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, m1, x2, y2, m2 );
200 },
201 []( double epsilon, double x1, double y1,
202 double x2, double y2 )
203 {
204 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, x2, y2 );
205 } );
206 }
207
208 bool equals( const QgsCurve &other ) const override
209 {
210 return fuzzyEqual( other, 1e-8 );
211 }
212
213
214 QString geometryType() const override SIP_HOLDGIL;
215 int dimension() const override SIP_HOLDGIL;
216 QgsCircularString *clone() const override SIP_FACTORY;
217 void clear() override;
218
219 bool fromWkb( QgsConstWkbPtr &wkb ) override;
220 bool fromWkt( const QString &wkt ) override;
221
222 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
223 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
224 QString asWkt( int precision = 17 ) const override;
225 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
226 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
227 json asJsonObject( int precision = 17 ) const override SIP_SKIP;
228 bool isEmpty() const override SIP_HOLDGIL;
229 bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
230 int numPoints() const override SIP_HOLDGIL;
231 int indexOf( const QgsPoint &point ) const final;
232
236 QgsPoint pointN( int i ) const SIP_HOLDGIL;
237
238 void points( QgsPointSequence &pts SIP_OUT ) const override;
239
243 void setPoints( const QgsPointSequence &points );
244
255 void append( const QgsCircularString *string );
256
257 double length() const override;
258 QgsPoint startPoint() const override SIP_HOLDGIL;
259 QgsPoint endPoint() const override SIP_HOLDGIL;
260 QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
261 QgsCircularString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
262 QgsAbstractGeometry *simplifyByDistance( double tolerance ) const override SIP_FACTORY;
263 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
264
265 void draw( QPainter &p ) const override;
266 void transform( const QgsCoordinateTransform &ct, Qgis::TransformDirection d = Qgis::TransformDirection::Forward, bool transformZ = false ) override SIP_THROW( QgsCsException );
267 void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
268 void addToPainterPath( QPainterPath &path ) const override;
269 void drawAsPolygon( QPainter &p ) const override;
270 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
271 bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
272 bool deleteVertex( QgsVertexId position ) override;
273 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;
274 bool pointAt( int node, QgsPoint &point, Qgis::VertexType &type ) const override;
275 void sumUpArea( double &sum SIP_OUT ) const override;
276 bool hasCurvedSegments() const override;
277 double vertexAngle( QgsVertexId vertex ) const override;
278 double segmentLength( QgsVertexId startVertex ) const override;
279 double distanceBetweenVertices( QgsVertexId fromVertex, QgsVertexId toVertex ) const override;
280 QgsCircularString *reversed() const override SIP_FACTORY;
281 QgsPoint *interpolatePoint( double distance ) const override SIP_FACTORY;
282 QgsCircularString *curveSubstring( double startDistance, double endDistance ) const override SIP_FACTORY;
283 bool addZValue( double zValue = 0 ) override;
284 bool addMValue( double mValue = 0 ) override;
285 bool dropZValue() override;
286 bool dropMValue() override;
287 void swapXy() override;
288 double xAt( int index ) const override SIP_HOLDGIL;
289 double yAt( int index ) const override SIP_HOLDGIL;
290 double zAt( int index ) const override SIP_HOLDGIL;
291 double mAt( int index ) const override SIP_HOLDGIL;
292
293 bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = nullptr ) override;
294 void scroll( int firstVertexIndex ) final;
295
296#ifndef SIP_RUN
297 void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
298 void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
299 std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex( int index ) const final;
300
309 inline static const QgsCircularString *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
310 {
312 return static_cast<const QgsCircularString *>( geom );
313 return nullptr;
314 }
315
324 inline static QgsCircularString *cast( QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
325 {
327 return static_cast<QgsCircularString *>( geom );
328 return nullptr;
329 }
330#endif
331
333
334#ifdef SIP_RUN
335 SIP_PYOBJECT __repr__();
336 % MethodCode
337 QString wkt = sipCpp->asWkt();
338 if ( wkt.length() > 1000 )
339 wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
340 QString str = QStringLiteral( "<QgsCircularString: %1>" ).arg( wkt );
341 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
342 % End
343#endif
344
345 protected:
346
347 int compareToSameClass( const QgsAbstractGeometry *other ) const final;
348 QgsBox3D calculateBoundingBox3D() const override;
349
350 private:
351 QVector<double> mX;
352 QVector<double> mY;
353 QVector<double> mZ;
354 QVector<double> mM;
355
356#if 0
357 static void arcTo( QPainterPath &path, QPointF pt1, QPointF pt2, QPointF pt3 );
358#endif
359 //bounding box of a single segment
360 static QgsRectangle segmentBoundingBox( const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3 );
361 static QgsPointSequence compassPointsOnSegment( double p1Angle, double p2Angle, double p3Angle, double centerX, double centerY, double radius );
362 static double closestPointOnArc( double x1, double y1, double x2, double y2, double x3, double y3,
363 const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon );
364 void insertVertexBetween( int after, int before, int pointOnCircle );
365 void deleteVertex( int i );
366
367};
368
369// clazy:excludeall=qstring-allocations
370
371#endif // QGSCIRCULARSTRING_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
@ CircularString
CircularString.
Definition qgis.h:287
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:42
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:139
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:49
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:134
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_HOLDGIL
Definition qgis_sip.h:179
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_THROW(name,...)
Definition qgis_sip.h:211
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:30