QGIS API Documentation 4.1.0-Master (31622b25bb0)
Loading...
Searching...
No Matches
qgscompoundcurve.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscompoundcurve.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 QGSCOMPOUNDCURVE_H
19#define QGSCOMPOUNDCURVE_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgscurve.h"
24
25#include <QString>
26
27using namespace Qt::StringLiterals;
28
34class CORE_EXPORT QgsCompoundCurve : public QgsCurve
35{
36 public:
38 QgsCompoundCurve( const QgsCompoundCurve &curve );
40 ~QgsCompoundCurve() override;
41
42#ifndef SIP_RUN
43 private:
44 bool fuzzyHelper( const QgsAbstractGeometry &other, double epsilon, bool useDistance ) const
45 {
47 if ( !otherCurve )
48 return false;
49
50 if ( mWkbType != otherCurve->mWkbType )
51 return false;
52
53 if ( mCurves.size() != otherCurve->mCurves.size() )
54 return false;
55
56 for ( int i = 0; i < mCurves.size(); ++i )
57 {
58 if ( useDistance )
59 {
60 if ( !( *mCurves.at( i ) ).fuzzyDistanceEqual( *otherCurve->mCurves.at( i ), epsilon ) )
61 {
62 return false;
63 }
64 }
65 else
66 {
67 if ( !( *mCurves.at( i ) ).fuzzyEqual( *otherCurve->mCurves.at( i ), epsilon ) )
68 {
69 return false;
70 }
71 }
72 }
73
74 return true;
75 }
76#endif
77 public:
78 // clang-format off
79 bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
80 // clang-format on
81 {
82 return fuzzyHelper( other, epsilon, false );
83 }
84 bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
85 {
86 return fuzzyHelper( other, epsilon, true );
87 }
88
89 bool equals( const QgsCurve &other ) const override
90 {
91 return fuzzyEqual( other, 1e-8 );
92 }
93
94
95 QString geometryType() const override SIP_HOLDGIL;
96 int dimension() const override SIP_HOLDGIL;
97 QgsCompoundCurve *clone() const override SIP_FACTORY;
98 void clear() override;
99
100 bool fromWkb( QgsConstWkbPtr &wkb ) override;
101 bool fromWkt( const QString &wkt ) override;
102
103 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
104 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
105 QString asWkt( int precision = 17 ) const override;
106 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
107 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
108 json asJsonObject( int precision = 17 ) const override SIP_SKIP;
109
110 //curve interface
111 double length() const override SIP_HOLDGIL;
112 QgsPoint startPoint() const override SIP_HOLDGIL;
113 QgsPoint endPoint() const override SIP_HOLDGIL;
114 void points( QgsPointSequence &pts SIP_OUT ) const override;
115 int numPoints() const override SIP_HOLDGIL;
116 bool isEmpty() const override SIP_HOLDGIL;
117 bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
118 int indexOf( const QgsPoint &point ) const final;
119
126 QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
127
128 QgsCompoundCurve *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
129 QgsAbstractGeometry *simplifyByDistance( double tolerance ) const override SIP_FACTORY;
130 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
131
132 using QgsCurve::boundingBoxIntersects;
133 bool boundingBoxIntersects( const QgsBox3D &box3d ) const override SIP_HOLDGIL;
134
135 const QgsAbstractGeometry *simplifiedTypeRef() const override SIP_HOLDGIL;
136
140 int nCurves() const SIP_HOLDGIL { return mCurves.size(); }
141
145 const QgsCurve *curveAt( int i ) const SIP_HOLDGIL;
146
156 void addCurve( QgsCurve *c SIP_TRANSFER, bool extendPrevious = false );
157
162 void removeCurve( int i );
163
167 void addVertex( const QgsPoint &pt );
168
175 void condenseCurves();
176
185 bool toggleCircularAtVertex( QgsVertexId position );
186
187 void draw( QPainter &p ) const override;
189 void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
190 void addToPainterPath( QPainterPath &path ) const override;
191 void drawAsPolygon( QPainter &p ) const override;
192 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
193 bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
194 bool deleteVertex( QgsVertexId position ) override;
195 bool deleteVertices( const QSet<QgsVertexId> &positions ) override;
196 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;
197 bool pointAt( int node, QgsPoint &point, Qgis::VertexType &type ) const override;
198 void sumUpArea( double &sum SIP_OUT ) const override;
199 void sumUpArea3D( double &sum SIP_OUT ) const override;
200
202 void close();
203
204 bool hasCurvedSegments() const override;
205 double vertexAngle( QgsVertexId vertex ) const override;
206 double segmentLength( QgsVertexId startVertex ) const override;
207 double distanceBetweenVertices( QgsVertexId fromVertex, QgsVertexId toVertex ) const override;
208 QgsCompoundCurve *reversed() const override SIP_FACTORY;
209 QgsPoint *interpolatePoint( double distance ) const override SIP_FACTORY;
210 QgsCompoundCurve *curveSubstring( double startDistance, double endDistance ) const override SIP_FACTORY;
211
212 bool addZValue( double zValue = 0 ) override;
213 bool addMValue( double mValue = 0 ) override;
214
215 bool dropZValue() override;
216 bool dropMValue() override;
217 void swapXy() override;
218
219 double xAt( int index ) const override SIP_HOLDGIL;
220 double yAt( int index ) const override SIP_HOLDGIL;
221 double zAt( int index ) const override SIP_HOLDGIL;
222 double mAt( int index ) const override SIP_HOLDGIL;
223
224 bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = nullptr ) override;
225 void scroll( int firstVertexIndex ) final;
226
227#ifndef SIP_RUN
228 void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
229 void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
230 std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex( int index ) const final;
231
240 inline static const QgsCompoundCurve *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
241 {
243 return static_cast<const QgsCompoundCurve *>( geom );
244 return nullptr;
245 }
246
255 inline static QgsCompoundCurve *cast( QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
256 {
258 return static_cast<QgsCompoundCurve *>( geom );
259 return nullptr;
260 }
261#endif
262
264
265#ifdef SIP_RUN
266// clang-format off
267 SIP_PYOBJECT __repr__();
268 % MethodCode
269 QString wkt = sipCpp->asWkt();
270 if ( wkt.length() > 1000 )
271 wkt = wkt.left( 1000 ) + u"..."_s;
272 QString str = u"<QgsCompoundCurve: %1>"_s.arg( wkt );
273 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
274 % End
275// clang-format on
276#endif
277
278 protected:
279
280 int compareToSameClass( const QgsAbstractGeometry *other ) const final;
281 QgsBox3D calculateBoundingBox3D() const override;
282
283 private:
284 QVector< QgsCurve * > mCurves;
285
290 QVector< QPair<int, QgsVertexId> > curveVertexId( QgsVertexId id ) const;
291
292};
293
294// clazy:excludeall=qstring-allocations
295
296#endif // QGSCOMPOUNDCURVE_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
@ CompoundCurve
CompoundCurve.
Definition qgis.h:305
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition qgis.h:2831
@ Forward
Forward transform (from source to destination).
Definition qgis.h:2832
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.
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
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.
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.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
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 void transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection d=Qgis::TransformDirection::Forward, bool transformZ=false)=0
Transforms the geometry using a coordinate transform.
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
Compound curve geometry type.
bool fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy comparison between this geometry and other using an epsilon.
int nCurves() const
Returns the number of curves in the geometry.
static QgsCompoundCurve * cast(QgsAbstractGeometry *geom)
Cast the geom to a QgsCompoundCurve.
bool fuzzyDistanceEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy distance comparison between this geometry and other using an epsilon.
bool equals(const QgsCurve &other) const override
Checks whether this curve exactly equals another curve.
static const QgsCompoundCurve * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsCompoundCurve.
A const WKB pointer.
Definition qgswkbptr.h:211
Handles coordinate transforms between two coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
Definition qgscurve.h:36
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
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
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#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
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:35