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