QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
26 class QgsLineString;
27 class QPainterPath;
28 
35 class CORE_EXPORT QgsCurve: public QgsAbstractGeometry
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;
71 
75  virtual bool isRing() const;
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 
97  virtual void drawAsPolygon( QPainter &p ) const = 0;
98 
102  virtual void points( QgsPointSequence &pt SIP_OUT ) const = 0;
103 
107  virtual int numPoints() const = 0;
108 
109 #ifdef SIP_RUN
110  int __len__() const;
111  % Docstring
112  Returns the number of points in the curve.
113  % End
114  % MethodCode
115  sipRes = sipCpp->numPoints();
116  % End
117 
119  int __bool__() const;
120  % MethodCode
121  sipRes = true;
122  % End
123 #endif
124 
128  virtual void sumUpArea( double &sum SIP_OUT ) const = 0;
129 
130  QgsCoordinateSequence coordinateSequence() const override;
131  bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
132  void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
133  int vertexNumberFromVertexId( QgsVertexId id ) const override;
134 
142  virtual bool pointAt( int node, QgsPoint &point SIP_OUT, QgsVertexId::VertexType &type SIP_OUT ) const = 0;
143 
148  virtual QgsCurve *reversed() const = 0 SIP_FACTORY;
149 
150  QgsAbstractGeometry *boundary() const override SIP_FACTORY;
151 
152  QString asKml( int precision = 17 ) const override;
153 
158  QgsCurve *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
159 
160  int vertexCount( int part = 0, int ring = 0 ) const override;
161  int ringCount( int part = 0 ) const override;
162  int partCount() const override;
163  QgsPoint vertexAt( QgsVertexId id ) const override;
164  QgsCurve *toCurveType() const override SIP_FACTORY;
165 
166  QgsRectangle boundingBox() const override;
167  bool isValid( QString &error SIP_OUT, int flags = 0 ) const override;
168 
174  virtual double xAt( int index ) const = 0;
175 
181  virtual double yAt( int index ) const = 0;
182 
186  virtual QPolygonF asQPolygonF() const;
187 
199  virtual QgsPoint *interpolatePoint( double distance ) const = 0 SIP_FACTORY;
200 
213  virtual QgsCurve *curveSubstring( double startDistance, double endDistance ) const = 0 SIP_FACTORY;
214 
222  double straightDistance2d() const;
223 
233  double sinuosity() const;
234 
237  {
240  };
241 
249  Orientation orientation() const;
250 
251 #ifndef SIP_RUN
252 
260  inline const QgsCurve *cast( const QgsAbstractGeometry *geom ) const
261  {
262  if ( !geom )
263  return nullptr;
264 
265  QgsWkbTypes::Type type = geom->wkbType();
267  {
268  return static_cast<const QgsCurve *>( geom );
269  }
270  return nullptr;
271  }
272 #endif
273 
274 
275  protected:
276 
277  void clearCache() const override;
278 
279  int childCount() const override;
280  QgsPoint childPoint( int index ) const override;
281 
282 #ifndef SIP_RUN
283 
288  bool snapToGridPrivate( double hSpacing, double vSpacing, double dSpacing, double mSpacing,
289  const QVector<double> &srcX, const QVector<double> &srcY, const QVector<double> &srcZ, const QVector<double> &srcM,
290  QVector<double> &outX, QVector<double> &outY, QVector<double> &outZ, QVector<double> &outM ) const;
291 #endif
292 
293  private:
294 
295  mutable QgsRectangle mBoundingBox;
296 
297  mutable bool mHasCachedValidity = false;
298  mutable QString mValidityFailureReason;
299 };
300 
301 #endif // QGSCURVE_H
int precision
A rectangle specified with double values.
Definition: qgsrectangle.h:41
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 bool isValid(QString &error, int flags=0) const =0
Checks validity of the geometry, and returns true if the geometry is valid.
virtual QgsAbstractGeometry * toCurveType() const =0
Returns the geometry converted to the more generic curve type.
virtual QgsPoint childPoint(int index) const
Returns point at index (for geometries without child geometries - i.e.
QVector< QgsRingSequence > QgsCoordinateSequence
virtual bool operator==(const QgsAbstractGeometry &other) const =0
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 bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
virtual QgsRectangle boundingBox() const =0
Returns the minimal bounding box for the geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
virtual bool operator!=(const QgsAbstractGeometry &other) const =0
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
Utility class for identifying a unique vertex within a geometry.
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:812
virtual QString asKml(int precision=17) const =0
Returns a KML representation of the geometry.
virtual int ringCount(int part=0) const =0
Returns the number of rings of which this geometry is built.
Orientation
Curve orientation.
Definition: qgscurve.h:236
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
#define SIP_FACTORY
Definition: qgis_sip.h:76
Abstract base class for all geometries.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Counter-clockwise orientation.
Definition: qgscurve.h:239
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
Clockwise orientation.
Definition: qgscurve.h:238
static bool isSingleType(Type type)
Returns true if the WKB type is a single type.
Definition: qgswkbtypes.h:696
QVector< QgsPoint > QgsPointSequence
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
virtual void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const =0
Returns the vertices adjacent to a specified vertex within a geometry.
#define SIP_OUT
Definition: qgis_sip.h:58
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:43
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
const QgsCurve * cast(const QgsAbstractGeometry *geom) const
Cast the geom to a QgsCurve.
Definition: qgscurve.h:260
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
virtual int partCount() const =0
Returns count of parts contained in the geometry.