QGIS API Documentation 4.3.0-Master (96c7fa699b4)
Loading...
Searching...
No Matches
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 "qgsbox3d.h"
25
26#include <QPainterPath>
27
28class QgsLineString;
29
35class CORE_EXPORT QgsCurve : public QgsAbstractGeometry SIP_ABSTRACT
36{
37 public:
38 QgsCurve() = default;
39
43 virtual bool equals( const QgsCurve &other ) const = 0;
44
45 bool operator==( const QgsAbstractGeometry &other ) const override;
46 bool operator!=( const QgsAbstractGeometry &other ) const override;
47
48 QgsCurve *clone() const override = 0 SIP_FACTORY;
49
54 virtual QgsPoint startPoint() const = 0;
55
60 virtual QgsPoint endPoint() const = 0;
61
67 virtual bool isSimpleCurve() const = 0;
68
69 // clang-format off
75 virtual bool isClosed() const SIP_HOLDGIL;
76 // clang-format on
77
87 virtual bool isClosed2D() const SIP_HOLDGIL;
88
92 virtual bool isRing() const SIP_HOLDGIL;
93
103 virtual QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const = 0 SIP_FACTORY;
104
108 virtual void addToPainterPath( QPainterPath &path ) const = 0;
109 QPainterPath asQPainterPath() const override;
110
115 virtual void drawAsPolygon( QPainter &p ) const = 0;
116
120 virtual void points( QgsPointSequence &pt SIP_OUT ) const = 0;
121
125 virtual int numPoints() const = 0;
126
127#ifdef SIP_RUN
128// clang-format off
129 int __len__() const;
130 % Docstring
131 Returns the number of points in the curve.
132 % End
133 % MethodCode
134 sipRes = sipCpp->numPoints();
135 % End
136
138 int __bool__() const;
139 % MethodCode
140 sipRes = true;
141 % End
142// clang-format on
143#endif
144
148 virtual void sumUpArea( double &sum SIP_OUT ) const = 0;
149
155 virtual void sumUpArea3D( double &sum SIP_OUT ) const = 0;
156
158 bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
159 void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
160 int vertexNumberFromVertexId( QgsVertexId id ) const override;
161
169 virtual bool pointAt( int node, QgsPoint &point SIP_OUT, Qgis::VertexType &type SIP_OUT ) const = 0;
170
181 virtual int indexOf( const QgsPoint &point ) const = 0;
182
186 virtual QgsCurve *reversed() const = 0 SIP_FACTORY;
187
188 QgsAbstractGeometry *boundary() const override SIP_FACTORY;
189
190 QString asKml( int precision = 17 ) const override;
191
197 QgsCurve *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
198
199 int vertexCount( int part = 0, int ring = 0 ) const override;
200 int ringCount( int part = 0 ) const override;
201 int partCount() const override;
202 QgsPoint vertexAt( QgsVertexId id ) const override;
203 bool hasVertex( QgsVertexId position ) const override;
204 QgsCurve *toCurveType() const override SIP_FACTORY;
205 void normalize() final SIP_HOLDGIL;
206
207 QgsBox3D boundingBox3D() const override;
208 bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
209
215 virtual double xAt( int index ) const = 0;
216
222 virtual double yAt( int index ) const = 0;
223
230 virtual double zAt( int index ) const = 0;
231
238 virtual double mAt( int index ) const = 0;
239
243 virtual QPolygonF asQPolygonF() const;
244
256 virtual QgsPoint *interpolatePoint( double distance ) const = 0 SIP_FACTORY;
257
270 virtual QgsCurve *curveSubstring( double startDistance, double endDistance ) const = 0 SIP_FACTORY;
271
279 double straightDistance2d() const;
280
290 double sinuosity() const;
291
299 Qgis::AngularDirection orientation() const;
300
312 virtual void scroll( int firstVertexIndex ) = 0;
313
328 virtual double distanceBetweenVertices( QgsVertexId fromVertex, QgsVertexId toVertex ) const = 0;
329
330#ifndef SIP_RUN
331
340 inline static const QgsCurve *cast( const QgsAbstractGeometry *geom )
341 {
342 if ( !geom )
343 return nullptr;
344
345 const Qgis::WkbType type = geom->wkbType();
347 {
348 return static_cast<const QgsCurve *>( geom );
349 }
350 return nullptr;
351 }
352
361 inline static QgsCurve *cast( QgsAbstractGeometry *geom )
362 {
363 if ( !geom )
364 return nullptr;
365
366 const Qgis::WkbType type = geom->wkbType();
368 {
369 return static_cast<QgsCurve *>( geom );
370 }
371 return nullptr;
372 }
373
384 virtual std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex( int index ) const = 0;
385
386#endif
387
388
389 protected:
390
391 void clearCache() const override;
392
393 int childCount() const override;
394 QgsPoint childPoint( int index ) const override;
395#ifndef SIP_RUN
396
401 bool snapToGridPrivate( double hSpacing, double vSpacing, double dSpacing, double mSpacing,
402 const QVector<double> &srcX, const QVector<double> &srcY, const QVector<double> &srcZ, const QVector<double> &srcM,
403 QVector<double> &outX, QVector<double> &outY, QVector<double> &outZ, QVector<double> &outM,
404 bool removeRedundantPoints ) const;
405#endif
406
411
412 mutable bool mHasCachedSummedUpArea = false;
413 mutable double mSummedUpArea = 0;
414 mutable bool mHasCachedSummedUpArea3D = false;
415 mutable double mSummedUpArea3D = 0;
416
417 private:
418
419 mutable bool mHasCachedValidity = false;
420 mutable QString mValidityFailureReason;
421
422 friend class TestQgsGeometry;
423};
424
425#endif // QGSCURVE_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
VertexType
Types of vertex.
Definition qgis.h:3303
@ Line
Lines.
Definition qgis.h:401
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:314
virtual QgsPoint childPoint(int index) const
Returns point at index (for geometries without child geometries - i.e.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices).
virtual int vertexNumberFromVertexId(QgsVertexId id) const =0
Returns the vertex number corresponding to a vertex id.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
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.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual bool operator!=(const QgsAbstractGeometry &other) const =0
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
virtual bool operator==(const QgsAbstractGeometry &other) const =0
QgsAbstractGeometry()=default
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
Qgis::AngularDirection orientation() const
Returns the curve's orientation, e.g.
Definition qgscurve.cpp:291
virtual int numPoints() const =0
Returns the number of points in the curve.
double mSummedUpArea3D
Definition qgscurve.h:415
double sinuosity() const
Returns the curve sinuosity, which is the ratio of the curve length() to curve straightDistance2d().
Definition qgscurve.cpp:282
bool mHasCachedSummedUpArea
Definition qgscurve.h:412
void normalize() final
Reorganizes the geometry into a normalized form (or "canonical" form).
Definition qgscurve.cpp:211
QPainterPath asQPainterPath() const override
Returns the geometry represented as a QPainterPath.
Definition qgscurve.cpp:70
virtual void scroll(int firstVertexIndex)=0
Scrolls the curve vertices so that they start with the vertex at the given index.
int partCount() const override
Returns count of parts contained in the geometry.
Definition qgscurve.cpp:193
QgsCurve * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
Definition qgscurve.cpp:175
virtual bool isRing() const
Returns true if the curve is a ring.
Definition qgscurve.cpp:65
virtual bool pointAt(int node, QgsPoint &point, Qgis::VertexType &type) const =0
Returns the point and vertex type of a point within the curve.
QgsBox3D boundingBox3D() const override
Returns the 3D bounding box for the geometry.
Definition qgscurve.cpp:238
virtual QgsCurve * curveSubstring(double startDistance, double endDistance) const =0
Returns a new curve representing a substring of this curve.
bool mHasCachedSummedUpArea3D
Definition qgscurve.h:414
virtual bool isClosed() const
Returns true if the curve is closed.
Definition qgscurve.cpp:53
static const QgsCurve * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsCurve.
Definition qgscurve.h:340
bool isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const override
Checks validity of the geometry, and returns true if the geometry is valid.
Definition qgscurve.cpp:247
virtual bool isClosed2D() const
Returns true if the curve is closed.
Definition qgscurve.cpp:42
int vertexCount(int part=0, int ring=0) const override
Returns the number of vertices of which this geometry is built.
Definition qgscurve.cpp:180
QgsPoint vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
Definition qgscurve.cpp:198
virtual QPolygonF asQPolygonF() const
Returns a QPolygonF representing the points.
Definition qgscurve.cpp:271
virtual void addToPainterPath(QPainterPath &path) const =0
Adds a curve to a painter path.
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...
friend class TestQgsGeometry
Definition qgscurve.h:422
QgsCurve * toCurveType() const override
Returns the geometry converted to the more generic curve type.
Definition qgscurve.cpp:206
virtual void sumUpArea(double &sum) const =0
Sums up the area of the curve by iterating over the vertices (shoelace formula).
bool snapToGridPrivate(double hSpacing, double vSpacing, double dSpacing, double mSpacing, const QVector< double > &srcX, const QVector< double > &srcY, const QVector< double > &srcZ, const QVector< double > &srcM, QVector< double > &outX, QVector< double > &outY, QVector< double > &outZ, QVector< double > &outM, bool removeRedundantPoints) const
Helper function for QgsCurve subclasses to snap to grids.
Definition qgscurve.cpp:323
QString asKml(int precision=17) const override
Returns a KML representation of the geometry.
Definition qgscurve.cpp:164
QgsBox3D mBoundingBox
Cached bounding box.
Definition qgscurve.h:410
virtual QgsPoint * interpolatePoint(double distance) const =0
Returns an interpolated point on the curve at the specified distance.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
virtual double distanceBetweenVertices(QgsVertexId fromVertex, QgsVertexId toVertex) const =0
Returns the distance along the curve between two vertices.
virtual double xAt(int index) const =0
Returns the x-coordinate of the specified node in the line string.
int ringCount(int part=0) const override
Returns the number of rings of which this geometry is built.
Definition qgscurve.cpp:187
virtual QgsPoint startPoint() const =0
Returns the starting point of the curve.
static QgsCurve * cast(QgsAbstractGeometry *geom)
Cast the geom to a QgsCurve.
Definition qgscurve.h:361
double straightDistance2d() const
Returns the straight distance of the curve, i.e.
Definition qgscurve.cpp:277
bool hasVertex(QgsVertexId position) const override
Returns true if the geometry contains a vertex matching the given position.
Definition qgscurve.cpp:266
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...
bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const override
Returns next vertex id and coordinates.
Definition qgscurve.cpp:87
virtual double zAt(int index) const =0
Returns the z-coordinate of the specified node in the line string.
virtual QgsCurve * reversed() const =0
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
virtual void drawAsPolygon(QPainter &p) const =0
Draws the curve as a polygon on the specified QPainter.
virtual double mAt(int index) const =0
Returns the m-coordinate of the specified node in the line string.
virtual QgsPoint endPoint() const =0
Returns the end point of the curve.
virtual double yAt(int index) const =0
Returns the y-coordinate of the specified node in the line string.
virtual bool isSimpleCurve() const =0
This method returns true for classes that can be cast to the QgsSimpleCurve class.
virtual void points(QgsPointSequence &pt) const =0
Returns a list of points within the curve.
virtual QgsLineString * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve.
double mSummedUpArea
Definition qgscurve.h:413
virtual void sumUpArea3D(double &sum) const =0
Sums up the 3d area of the curve by iterating over the vertices (shoelace formula).
QgsCurve()=default
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::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static Q_INVOKABLE bool isSingleType(Qgis::WkbType type)
Returns true if the WKB type is a single type.
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_ABSTRACT
Definition qgis_sip.h:225
#define SIP_HOLDGIL
Definition qgis_sip.h:183
#define SIP_FACTORY
Definition qgis_sip.h:83
QVector< QgsRingSequence > QgsCoordinateSequence
QVector< QgsPoint > QgsPointSequence
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:35