QGIS API Documentation  3.37.0-Master (a5b4d9743e8)
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 
30 class CORE_EXPORT QgsCompoundCurve: public QgsCurve
31 {
32  public:
34  QgsCompoundCurve( const QgsCompoundCurve &curve );
36  ~QgsCompoundCurve() override;
37 
38 #ifndef SIP_RUN
39  private:
40  bool fuzzyHelper( const QgsAbstractGeometry &other, double epsilon, bool useDistance ) const
41  {
42  const QgsCompoundCurve *otherCurve = qgsgeometry_cast< const QgsCompoundCurve * >( &other );
43  if ( !otherCurve )
44  return false;
45 
46  if ( mWkbType != otherCurve->mWkbType )
47  return false;
48 
49  if ( mCurves.size() != otherCurve->mCurves.size() )
50  return false;
51 
52  for ( int i = 0; i < mCurves.size(); ++i )
53  {
54  if ( useDistance )
55  {
56  if ( !( *mCurves.at( i ) ).fuzzyDistanceEqual( *otherCurve->mCurves.at( i ), epsilon ) )
57  {
58  return false;
59  }
60 
61  }
62  else
63  {
64  if ( !( *mCurves.at( i ) ).fuzzyEqual( *otherCurve->mCurves.at( i ), epsilon ) )
65  {
66  return false;
67  }
68 
69  }
70  }
71 
72  return true;
73  }
74 #endif
75  public:
76  bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
77  {
78  return fuzzyHelper( other, epsilon, false );
79  }
80  bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
81  {
82  return fuzzyHelper( other, epsilon, true );
83  }
84 
85  bool equals( const QgsCurve &other ) const override
86  {
87  return fuzzyEqual( other, 1e-8 );
88  }
89 
90 
91  QString geometryType() const override SIP_HOLDGIL;
92  int dimension() const override SIP_HOLDGIL;
93  QgsCompoundCurve *clone() const override SIP_FACTORY;
94  void clear() override;
95 
96  bool fromWkb( QgsConstWkbPtr &wkb ) override;
97  bool fromWkt( const QString &wkt ) override;
98 
99  int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
100  QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
101  QString asWkt( int precision = 17 ) const override;
102  QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
103  QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
104  json asJsonObject( int precision = 17 ) const override SIP_SKIP;
105 
106  //curve interface
107  double length() const override SIP_HOLDGIL;
108  QgsPoint startPoint() const override SIP_HOLDGIL;
109  QgsPoint endPoint() const override SIP_HOLDGIL;
110  void points( QgsPointSequence &pts SIP_OUT ) const override;
111  int numPoints() const override SIP_HOLDGIL;
112  bool isEmpty() const override SIP_HOLDGIL;
113  bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
114  int indexOf( const QgsPoint &point ) const final;
115 
122  QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
123 
124  QgsCompoundCurve *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
125  bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
126  bool boundingBoxIntersects( const QgsBox3D &box3d ) const override SIP_HOLDGIL;
127  const QgsAbstractGeometry *simplifiedTypeRef() const override SIP_HOLDGIL;
128 
132  int nCurves() const SIP_HOLDGIL { return mCurves.size(); }
133 
137  const QgsCurve *curveAt( int i ) const SIP_HOLDGIL;
138 
148  void addCurve( QgsCurve *c SIP_TRANSFER, bool extendPrevious = false );
149 
154  void removeCurve( int i );
155 
159  void addVertex( const QgsPoint &pt );
160 
167  void condenseCurves();
168 
177  bool toggleCircularAtVertex( QgsVertexId position );
178 
179  void draw( QPainter &p ) const override;
181  void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
182  void addToPainterPath( QPainterPath &path ) const override;
183  void drawAsPolygon( QPainter &p ) const override;
184  bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
185  bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
186  bool deleteVertex( QgsVertexId position ) override;
187  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;
188  bool pointAt( int node, QgsPoint &point, Qgis::VertexType &type ) const override;
189  void sumUpArea( double &sum SIP_OUT ) const override;
190 
192  void close();
193 
194  bool hasCurvedSegments() const override;
195  double vertexAngle( QgsVertexId vertex ) const override;
196  double segmentLength( QgsVertexId startVertex ) const override;
197  QgsCompoundCurve *reversed() const override SIP_FACTORY;
198  QgsPoint *interpolatePoint( double distance ) const override SIP_FACTORY;
199  QgsCompoundCurve *curveSubstring( double startDistance, double endDistance ) const override SIP_FACTORY;
200 
201  bool addZValue( double zValue = 0 ) override;
202  bool addMValue( double mValue = 0 ) override;
203 
204  bool dropZValue() override;
205  bool dropMValue() override;
206  void swapXy() override;
207 
208  double xAt( int index ) const override SIP_HOLDGIL;
209  double yAt( int index ) const override SIP_HOLDGIL;
210  double zAt( int index ) const override SIP_HOLDGIL;
211  double mAt( int index ) const override SIP_HOLDGIL;
212 
213  bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = nullptr ) override;
214  void scroll( int firstVertexIndex ) final;
215 
216 #ifndef SIP_RUN
217  void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
218  void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
219  std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex( int index ) const final;
220 
227  inline static const QgsCompoundCurve *cast( const QgsAbstractGeometry *geom )
228  {
229  if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == Qgis::WkbType::CompoundCurve )
230  return static_cast<const QgsCompoundCurve *>( geom );
231  return nullptr;
232  }
233 #endif
234 
236 
237 #ifdef SIP_RUN
238  SIP_PYOBJECT __repr__();
239  % MethodCode
240  QString wkt = sipCpp->asWkt();
241  if ( wkt.length() > 1000 )
242  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
243  QString str = QStringLiteral( "<QgsCompoundCurve: %1>" ).arg( wkt );
244  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
245  % End
246 #endif
247 
248  protected:
249 
250  int compareToSameClass( const QgsAbstractGeometry *other ) const final;
251  QgsBox3D calculateBoundingBox3D() const override;
252 
253  private:
254  QVector< QgsCurve * > mCurves;
255 
260  QVector< QPair<int, QgsVertexId> > curveVertexId( QgsVertexId id ) const;
261 
262 };
263 
264 // clazy:excludeall=qstring-allocations
265 
266 #endif // QGSCOMPOUNDCURVE_H
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:54
@ CompoundCurve
CompoundCurve.
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition: qgis.h:2171
@ Forward
Forward transform (from source to destination)
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...
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
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.
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 QgsCompoundCurve * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsCompoundCurve.
bool equals(const QgsCurve &other) const override
Checks whether this curve exactly equals another curve.
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.
Definition: qgsexception.h:67
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
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:45
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:628
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negative values mean left ...
Definition: MathUtils.cpp:222
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 str(x)
Definition: qgis.cpp:38
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#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
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