QGIS API Documentation  3.19.0-Master (f616be29d3)
qgscurve.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscurve.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 QGSCURVE_H
19 #define QGSCURVE_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include "qgsabstractgeometry.h"
24 #include "qgsrectangle.h"
25 #include <QPainterPath>
26 
27 class QgsLineString;
28 
35 class CORE_EXPORT QgsCurve: public QgsAbstractGeometry SIP_ABSTRACT
36 {
37  public:
38 
42  QgsCurve() = default;
43 
48  virtual bool equals( const QgsCurve &other ) const = 0;
49 
50  bool operator==( const QgsAbstractGeometry &other ) const override;
51  bool operator!=( const QgsAbstractGeometry &other ) const override;
52 
53  QgsCurve *clone() const override = 0 SIP_FACTORY;
54 
59  virtual QgsPoint startPoint() const = 0;
60 
65  virtual QgsPoint endPoint() const = 0;
66 
70  virtual bool isClosed() const SIP_HOLDGIL;
71 
75  virtual bool isRing() const SIP_HOLDGIL;
76 
86  virtual QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const = 0 SIP_FACTORY;
87 
91  virtual void addToPainterPath( QPainterPath &path ) const = 0;
92  QPainterPath asQPainterPath() const override;
93 
98  virtual void drawAsPolygon( QPainter &p ) const = 0;
99 
103  virtual void points( QgsPointSequence &pt SIP_OUT ) const = 0;
104 
108  virtual int numPoints() const = 0;
109 
110 #ifdef SIP_RUN
111  int __len__() const;
112  % Docstring
113  Returns the number of points in the curve.
114  % End
115  % MethodCode
116  sipRes = sipCpp->numPoints();
117  % End
118 
120  int __bool__() const;
121  % MethodCode
122  sipRes = true;
123  % End
124 #endif
125 
129  virtual void sumUpArea( double &sum SIP_OUT ) const = 0;
130 
131  QgsCoordinateSequence coordinateSequence() const override;
132  bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
133  void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
134  int vertexNumberFromVertexId( QgsVertexId id ) const override;
135 
143  virtual bool pointAt( int node, QgsPoint &point SIP_OUT, QgsVertexId::VertexType &type SIP_OUT ) const = 0;
144 
155  virtual int indexOf( const QgsPoint &point ) const = 0;
156 
161  virtual QgsCurve *reversed() const = 0 SIP_FACTORY;
162 
163  QgsAbstractGeometry *boundary() const override SIP_FACTORY;
164 
165  QString asKml( int precision = 17 ) const override;
166 
172  QgsCurve *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
173 
174  int vertexCount( int part = 0, int ring = 0 ) const override;
175  int ringCount( int part = 0 ) const override;
176  int partCount() const override;
177  QgsPoint vertexAt( QgsVertexId id ) const override;
178  QgsCurve *toCurveType() const override SIP_FACTORY;
179  void normalize() final SIP_HOLDGIL;
180 
181  QgsRectangle boundingBox() const override;
182  bool isValid( QString &error SIP_OUT, int flags = 0 ) const override;
183 
189  virtual double xAt( int index ) const = 0;
190 
196  virtual double yAt( int index ) const = 0;
197 
201  virtual QPolygonF asQPolygonF() const;
202 
214  virtual QgsPoint *interpolatePoint( double distance ) const = 0 SIP_FACTORY;
215 
228  virtual QgsCurve *curveSubstring( double startDistance, double endDistance ) const = 0 SIP_FACTORY;
229 
237  double straightDistance2d() const;
238 
248  double sinuosity() const;
249 
252  {
255  };
256 
264  Orientation orientation() const;
265 
277  virtual void scroll( int firstVertexIndex ) = 0;
278 
279 #ifndef SIP_RUN
280 
288  inline static const QgsCurve *cast( const QgsAbstractGeometry *geom )
289  {
290  if ( !geom )
291  return nullptr;
292 
293  QgsWkbTypes::Type type = geom->wkbType();
295  {
296  return static_cast<const QgsCurve *>( geom );
297  }
298  return nullptr;
299  }
300 
311  virtual std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex( int index ) const = 0;
312 
313 #endif
314 
315 
316  protected:
317 
318  void clearCache() const override;
319 
320  int childCount() const override;
321  QgsPoint childPoint( int index ) const override;
322 #ifndef SIP_RUN
323 
328  bool snapToGridPrivate( double hSpacing, double vSpacing, double dSpacing, double mSpacing,
329  const QVector<double> &srcX, const QVector<double> &srcY, const QVector<double> &srcZ, const QVector<double> &srcM,
330  QVector<double> &outX, QVector<double> &outY, QVector<double> &outZ, QVector<double> &outM ) const;
331 #endif
332 
337 
338  private:
339 
340  mutable bool mHasCachedValidity = false;
341  mutable QString mValidityFailureReason;
342 
343  friend class TestQgsGeometry;
344 };
345 
346 #endif // QGSCURVE_H
Abstract base class for all geometries.
virtual QgsPoint childPoint(int index) const
Returns point at index (for geometries without child geometries - i.e.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
virtual int vertexNumberFromVertexId(QgsVertexId id) const =0
Returns the vertex number corresponding to a vertex id.
virtual int childCount() const
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
virtual void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const =0
Returns the vertices adjacent to a specified vertex within a geometry.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
virtual bool operator!=(const QgsAbstractGeometry &other) const =0
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
virtual bool operator==(const QgsAbstractGeometry &other) const =0
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
virtual void scroll(int firstVertexIndex)=0
Scrolls the curve vertices so that they start with the vertex at the given index.
virtual int indexOf(const QgsPoint &point) const =0
Returns the index of the first vertex matching the given point, or -1 if a matching vertex is not fou...
virtual void sumUpArea(double &sum) const =0
Sums up the area of the curve by iterating over the vertices (shoelace formula).
static const QgsCurve * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsCurve.
Definition: qgscurve.h:288
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
Orientation
Curve orientation.
Definition: qgscurve.h:252
@ Clockwise
Clockwise orientation.
Definition: qgscurve.h:253
@ CounterClockwise
Counter-clockwise orientation.
Definition: qgscurve.h:254
virtual QgsPoint startPoint() const =0
Returns the starting point of the curve.
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...
QgsRectangle mBoundingBox
Cached bounding box.
Definition: qgscurve.h:336
virtual bool pointAt(int node, QgsPoint &point, QgsVertexId::VertexType &type) const =0
Returns the point and vertex id of a point within the curve.
virtual QgsPoint endPoint() const =0
Returns the end point of the curve.
virtual QgsCurve * reversed() const =0
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
QgsCurve()=default
Constructor for QgsCurve.
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
A rectangle specified with double values.
Definition: qgsrectangle.h:42
static bool isSingleType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a single type.
Definition: qgswkbtypes.h:822
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:938
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_ABSTRACT
Definition: qgis_sip.h:199
#define SIP_HOLDGIL
Definition: qgis_sip.h:157
#define SIP_FACTORY
Definition: qgis_sip.h:76
QVector< QgsRingSequence > QgsCoordinateSequence
QVector< QgsPoint > QgsPointSequence
int precision
Utility class for identifying a unique vertex within a geometry.
VertexType
Type of vertex.