QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
72  virtual bool isClosed() const SIP_HOLDGIL;
73 
83  virtual bool isClosed2D() const SIP_HOLDGIL;
84 
88  virtual bool isRing() const SIP_HOLDGIL;
89 
99  virtual QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const = 0 SIP_FACTORY;
100 
104  virtual void addToPainterPath( QPainterPath &path ) const = 0;
105  QPainterPath asQPainterPath() const override;
106 
111  virtual void drawAsPolygon( QPainter &p ) const = 0;
112 
116  virtual void points( QgsPointSequence &pt SIP_OUT ) const = 0;
117 
121  virtual int numPoints() const = 0;
122 
123 #ifdef SIP_RUN
124  int __len__() const;
125  % Docstring
126  Returns the number of points in the curve.
127  % End
128  % MethodCode
129  sipRes = sipCpp->numPoints();
130  % End
131 
133  int __bool__() const;
134  % MethodCode
135  sipRes = true;
136  % End
137 #endif
138 
142  virtual void sumUpArea( double &sum SIP_OUT ) const = 0;
143 
144  QgsCoordinateSequence coordinateSequence() const override;
145  bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
146  void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
147  int vertexNumberFromVertexId( QgsVertexId id ) const override;
148 
156  virtual bool pointAt( int node, QgsPoint &point SIP_OUT, Qgis::VertexType &type SIP_OUT ) const = 0;
157 
168  virtual int indexOf( const QgsPoint &point ) const = 0;
169 
174  virtual QgsCurve *reversed() const = 0 SIP_FACTORY;
175 
176  QgsAbstractGeometry *boundary() const override SIP_FACTORY;
177 
178  QString asKml( int precision = 17 ) const override;
179 
185  QgsCurve *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
186 
187  int vertexCount( int part = 0, int ring = 0 ) const override;
188  int ringCount( int part = 0 ) const override;
189  int partCount() const override;
190  QgsPoint vertexAt( QgsVertexId id ) const override;
191  QgsCurve *toCurveType() const override SIP_FACTORY;
192  void normalize() final SIP_HOLDGIL;
193 
194  QgsRectangle boundingBox() const override;
195  bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
196 
202  virtual double xAt( int index ) const = 0;
203 
209  virtual double yAt( int index ) const = 0;
210 
214  virtual QPolygonF asQPolygonF() const;
215 
227  virtual QgsPoint *interpolatePoint( double distance ) const = 0 SIP_FACTORY;
228 
241  virtual QgsCurve *curveSubstring( double startDistance, double endDistance ) const = 0 SIP_FACTORY;
242 
250  double straightDistance2d() const;
251 
261  double sinuosity() const;
262 
270  Qgis::AngularDirection orientation() const;
271 
283  virtual void scroll( int firstVertexIndex ) = 0;
284 
285 #ifndef SIP_RUN
286 
294  inline static const QgsCurve *cast( const QgsAbstractGeometry *geom )
295  {
296  if ( !geom )
297  return nullptr;
298 
299  const QgsWkbTypes::Type type = geom->wkbType();
301  {
302  return static_cast<const QgsCurve *>( geom );
303  }
304  return nullptr;
305  }
306 
317  virtual std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex( int index ) const = 0;
318 
319 #endif
320 
321 
322  protected:
323 
324  void clearCache() const override;
325 
326  int childCount() const override;
327  QgsPoint childPoint( int index ) const override;
328 #ifndef SIP_RUN
329 
334  bool snapToGridPrivate( double hSpacing, double vSpacing, double dSpacing, double mSpacing,
335  const QVector<double> &srcX, const QVector<double> &srcY, const QVector<double> &srcZ, const QVector<double> &srcM,
336  QVector<double> &outX, QVector<double> &outY, QVector<double> &outZ, QVector<double> &outM ) const;
337 #endif
338 
343 
344  private:
345 
346  mutable bool mHasCachedValidity = false;
347  mutable QString mValidityFailureReason;
348 
349  friend class TestQgsGeometry;
350 };
351 
352 #endif // QGSCURVE_H
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
QgsAbstractGeometry::coordinateSequence
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
QgsCoordinateSequence
QVector< QgsRingSequence > QgsCoordinateSequence
Definition: qgsabstractgeometry.h:57
QgsWkbTypes::isSingleType
static bool isSingleType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a single type.
Definition: qgswkbtypes.h:852
QgsAbstractGeometry::adjacentVertices
virtual void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const =0
Returns the vertices adjacent to a specified vertex within a geometry.
QgsAbstractGeometry::clearCache
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
Definition: qgsabstractgeometry.cpp:146
QgsAbstractGeometry::isValid
virtual bool isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const =0
Checks validity of the geometry, and returns true if the geometry is valid.
QgsCurve::cast
static const QgsCurve * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsCurve.
Definition: qgscurve.h:294
QgsAbstractGeometry::asQPainterPath
virtual QPainterPath asQPainterPath() const =0
Returns the geometry represented as a QPainterPath.
qgsrectangle.h
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsAbstractGeometry::asKml
virtual QString asKml(int precision=17) const =0
Returns a KML representation of the geometry.
QgsAbstractGeometry::SegmentationToleranceType
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
Definition: qgsabstractgeometry.h:120
QgsAbstractGeometry::partCount
virtual int partCount() const =0
Returns count of parts contained in the geometry.
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsAbstractGeometry::vertexCount
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsAbstractGeometry::vertexAt
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
precision
int precision
Definition: qgswfsgetfeature.cpp:103
SIP_HOLDGIL
#define SIP_HOLDGIL
Definition: qgis_sip.h:166
QgsAbstractGeometry::wkbType
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
Definition: qgsabstractgeometry.h:206
QgsAbstractGeometry::childPoint
virtual QgsPoint childPoint(int index) const
Returns point at index (for geometries without child geometries - i.e.
Definition: qgsabstractgeometry.cpp:372
QgsAbstractGeometry::clone
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
qgis_sip.h
QgsAbstractGeometry::vertexNumberFromVertexId
virtual int vertexNumberFromVertexId(QgsVertexId id) const =0
Returns the vertex number corresponding to a vertex id.
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:79
QgsAbstractGeometry::segmentize
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
Definition: qgsabstractgeometry.cpp:395
QgsAbstractGeometry::normalize
virtual void normalize()=0
Reorganizes the geometry into a normalized form (or "canonical" form).
QgsAbstractGeometry::boundingBox
virtual QgsRectangle boundingBox() const =0
Returns the minimal bounding box for the geometry.
Qgis::VertexType
VertexType
Types of vertex.
Definition: qgis.h:1356
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:143
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:52
QgsAbstractGeometry::operator!=
virtual bool operator!=(const QgsAbstractGeometry &other) const =0
QgsAbstractGeometry::toCurveType
virtual QgsAbstractGeometry * toCurveType() const =0
Returns the geometry converted to the more generic curve type.
QgsAbstractGeometry::childCount
virtual int childCount() const
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
Definition: qgsabstractgeometry.h:1102
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition: qgsvertexid.h:30
QgsWkbTypes::geometryType
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:968
QgsAbstractGeometry::boundary
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
QgsAbstractGeometry::operator==
virtual bool operator==(const QgsAbstractGeometry &other) const =0
QgsCurve::mBoundingBox
QgsRectangle mBoundingBox
Cached bounding box.
Definition: qgscurve.h:342
QgsAbstractGeometry::ringCount
virtual int ringCount(int part=0) const =0
Returns the number of rings of which this geometry is built.
qgsabstractgeometry.h
QgsAbstractGeometry::nextVertex
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
Qgis::AngularDirection
AngularDirection
Angular directions.
Definition: qgis.h:1635
SIP_ABSTRACT
#define SIP_ABSTRACT
Definition: qgis_sip.h:208