QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 <QVector>
22
23#include "qgis_core.h"
24#include "qgis_sip.h"
25#include "qgscurve.h"
26
27
33class CORE_EXPORT QgsCircularString: public QgsCurve
34{
35 public:
36
41
48 QgsCircularString( const QgsPoint &p1,
49 const QgsPoint &p2,
50 const QgsPoint &p3 ) SIP_HOLDGIL;
51
67 QgsCircularString( const QVector<double> &x, const QVector<double> &y,
68 const QVector<double> &z = QVector<double>(),
69 const QVector<double> &m = QVector<double>() ) SIP_HOLDGIL;
70
71
82 static QgsCircularString fromTwoPointsAndCenter( const QgsPoint &p1,
83 const QgsPoint &p2,
84 const QgsPoint &center,
85 bool useShortestArc = true );
86
87#ifndef SIP_RUN
88 private:
89 bool fuzzyHelper( double epsilon,
90 const QgsAbstractGeometry &other,
91 bool is3DFlag,
92 bool isMeasureFlag,
93 std::function<bool( double, double, double, double, double, double, double, double, double )> comparator3DMeasure,
94 std::function<bool( double, double, double, double, double, double, double )> comparator3D,
95 std::function<bool( double, double, double, double, double, double, double )> comparatorMeasure,
96 std::function<bool( double, double, double, double, double )> comparator2D ) const
97 {
98 const QgsCircularString *otherLine = qgsgeometry_cast< const QgsCircularString * >( &other );
99 if ( !otherLine )
100 return false;
101
102 if ( mWkbType != otherLine->mWkbType )
103 return false;
104
105 const int size = mX.count();
106 if ( size != otherLine->mX.count() )
107 return false;
108
109 bool result = true;
110 const double *xData = mX.constData();
111 const double *yData = mY.constData();
112 const double *zData = is3DFlag ? mZ.constData() : nullptr;
113 const double *mData = isMeasureFlag ? mM.constData() : nullptr;
114 const double *otherXData = otherLine->mX.constData();
115 const double *otherYData = otherLine->mY.constData();
116 const double *otherZData = is3DFlag ? otherLine->mZ.constData() : nullptr;
117 const double *otherMData = isMeasureFlag ? otherLine->mM.constData() : nullptr;
118 for ( int i = 0; i < size; ++i )
119 {
120 if ( is3DFlag && isMeasureFlag )
121 {
122 result &= comparator3DMeasure( epsilon, *xData++, *yData++, *zData++, *mData++,
123 *otherXData++, *otherYData++, *otherZData++, *otherMData++ );
124 }
125 else if ( is3DFlag )
126 {
127 result &= comparator3D( epsilon, *xData++, *yData++, *zData++,
128 *otherXData++, *otherYData++, *otherZData++ );
129 }
130 else if ( isMeasureFlag )
131 {
132 result &= comparatorMeasure( epsilon, *xData++, *yData++, *mData++,
133 *otherXData++, *otherYData++, *otherMData++ );
134 }
135 else
136 {
137 result &= comparator2D( epsilon, *xData++, *yData++,
138 *otherXData++, *otherYData++ );
139 }
140 if ( ! result )
141 {
142 return false;
143 }
144 }
145
146 return result;
147 }
148#endif // !SIP_RUN
149
150 public:
151 bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
152 {
153 return fuzzyHelper(
154 epsilon,
155 other,
156 is3D(),
157 isMeasure(),
158 []( double epsilon, double x1, double y1, double z1, double m1,
159 double x2, double y2, double z2, double m2 )
160 {
161 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, z1, m1, x2, y2, z2, m2 );
162 },
163 []( double epsilon, double x1, double y1, double z1,
164 double x2, double y2, double z2 )
165 {
166 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, z1, x2, y2, z2 );
167 },
168 []( double epsilon, double x1, double y1, double m1,
169 double x2, double y2, double m2 )
170 {
171 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, m1, x2, y2, m2 );
172 },
173 []( double epsilon, double x1, double y1,
174 double x2, double y2 )
175 {
176 return QgsGeometryUtilsBase::fuzzyEqual( epsilon, x1, y1, x2, y2 );
177 } );
178 }
179
180 bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
181 {
182 return fuzzyHelper(
183 epsilon,
184 other,
185 is3D(),
186 isMeasure(),
187 []( double epsilon, double x1, double y1, double z1, double m1,
188 double x2, double y2, double z2, double m2 )
189 {
190 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, z1, m1, x2, y2, z2, m2 );
191 },
192 []( double epsilon, double x1, double y1, double z1,
193 double x2, double y2, double z2 )
194 {
195 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, z1, x2, y2, z2 );
196 },
197 []( double epsilon, double x1, double y1, double m1,
198 double x2, double y2, double m2 )
199 {
200 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, m1, x2, y2, m2 );
201 },
202 []( double epsilon, double x1, double y1,
203 double x2, double y2 )
204 {
205 return QgsGeometryUtilsBase::fuzzyDistanceEqual( epsilon, x1, y1, x2, y2 );
206 } );
207 }
208
209 bool equals( const QgsCurve &other ) const override
210 {
211 return fuzzyEqual( other, 1e-8 );
212 }
213
214
215 QString geometryType() const override SIP_HOLDGIL;
216 int dimension() const override SIP_HOLDGIL;
217 QgsCircularString *clone() const override SIP_FACTORY;
218 void clear() override;
219
220 bool fromWkb( QgsConstWkbPtr &wkb ) override;
221 bool fromWkt( const QString &wkt ) override;
222
223 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
224 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
225 QString asWkt( int precision = 17 ) const override;
226 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
227 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
228 json asJsonObject( int precision = 17 ) const override SIP_SKIP;
229 bool isEmpty() const override SIP_HOLDGIL;
230 bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
231 int numPoints() const override SIP_HOLDGIL;
232 int indexOf( const QgsPoint &point ) const final;
233
237 QgsPoint pointN( int i ) const SIP_HOLDGIL;
238
239 void points( QgsPointSequence &pts SIP_OUT ) const override;
240
244 void setPoints( const QgsPointSequence &points );
245
256 void append( const QgsCircularString *string );
257
258 double length() const override;
259 QgsPoint startPoint() const override SIP_HOLDGIL;
260 QgsPoint endPoint() const override SIP_HOLDGIL;
261 QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
262 QgsCircularString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
263 QgsAbstractGeometry *simplifyByDistance( double tolerance ) const override SIP_FACTORY;
264 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
265
266 void draw( QPainter &p ) const override;
267 void transform( const QgsCoordinateTransform &ct, Qgis::TransformDirection d = Qgis::TransformDirection::Forward, bool transformZ = false ) override SIP_THROW( QgsCsException );
268 void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
269 void addToPainterPath( QPainterPath &path ) const override;
270 void drawAsPolygon( QPainter &p ) const override;
271 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
272 bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
273 bool deleteVertex( QgsVertexId position ) override;
274 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;
275 bool pointAt( int node, QgsPoint &point, Qgis::VertexType &type ) const override;
276 void sumUpArea( double &sum SIP_OUT ) const override;
277 bool hasCurvedSegments() const override;
278 double vertexAngle( QgsVertexId vertex ) const override;
279 double segmentLength( QgsVertexId startVertex ) 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
307 inline static const QgsCircularString *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
308 {
310 return static_cast<const QgsCircularString *>( geom );
311 return nullptr;
312 }
313#endif
314
316
317#ifdef SIP_RUN
318 SIP_PYOBJECT __repr__();
319 % MethodCode
320 QString wkt = sipCpp->asWkt();
321 if ( wkt.length() > 1000 )
322 wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
323 QString str = QStringLiteral( "<QgsCircularString: %1>" ).arg( wkt );
324 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
325 % End
326#endif
327
328 protected:
329
330 int compareToSameClass( const QgsAbstractGeometry *other ) const final;
331 QgsBox3D calculateBoundingBox3D() const override;
332
333 private:
334 QVector<double> mX;
335 QVector<double> mY;
336 QVector<double> mZ;
337 QVector<double> mM;
338
339#if 0
340 static void arcTo( QPainterPath &path, QPointF pt1, QPointF pt2, QPointF pt3 );
341#endif
342 //bounding box of a single segment
343 static QgsRectangle segmentBoundingBox( const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3 );
344 static QgsPointSequence compassPointsOnSegment( double p1Angle, double p2Angle, double p3Angle, double centerX, double centerY, double radius );
345 static double closestPointOnArc( double x1, double y1, double x2, double y2, double x3, double y3,
346 const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon );
347 void insertVertexBetween( int after, int before, int pointOnCircle );
348 void deleteVertex( int i );
349
350};
351
352// clazy:excludeall=qstring-allocations
353
354#endif // QGSCIRCULARSTRING_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
@ CircularString
CircularString.
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...
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:43
Circular string geometry type.
bool equals(const QgsCurve &other) const override
Checks whether this curve exactly equals another curve.
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.
A const WKB pointer.
Definition qgswkbptr.h:138
Class for doing transforms between two map coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
Definition qgscurve.h:35
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...
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 str(x)
Definition qgis.cpp:38
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_HOLDGIL
Definition qgis_sip.h:171
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_THROW(name,...)
Definition qgis_sip.h:203
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:69
int precision
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30