QGIS API Documentation 3.41.0-Master (3440c17df1d)
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#include <QPainterPath>
26
27class QgsLineString;
28
34class CORE_EXPORT QgsCurve: public QgsAbstractGeometry SIP_ABSTRACT
35{
36 public:
37
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 isClosed() const SIP_HOLDGIL;
68
78 virtual bool isClosed2D() const SIP_HOLDGIL;
79
83 virtual bool isRing() const SIP_HOLDGIL;
84
94 virtual QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const = 0 SIP_FACTORY;
95
99 virtual void addToPainterPath( QPainterPath &path ) const = 0;
100 QPainterPath asQPainterPath() const override;
101
106 virtual void drawAsPolygon( QPainter &p ) const = 0;
107
111 virtual void points( QgsPointSequence &pt SIP_OUT ) const = 0;
112
116 virtual int numPoints() const = 0;
117
118#ifdef SIP_RUN
119 int __len__() const;
120 % Docstring
121 Returns the number of points in the curve.
122 % End
123 % MethodCode
124 sipRes = sipCpp->numPoints();
125 % End
126
128 int __bool__() const;
129 % MethodCode
130 sipRes = true;
131 % End
132#endif
133
137 virtual void sumUpArea( double &sum SIP_OUT ) const = 0;
138
140 bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
141 void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
142 int vertexNumberFromVertexId( QgsVertexId id ) const override;
143
151 virtual bool pointAt( int node, QgsPoint &point SIP_OUT, Qgis::VertexType &type SIP_OUT ) const = 0;
152
163 virtual int indexOf( const QgsPoint &point ) const = 0;
164
168 virtual QgsCurve *reversed() const = 0 SIP_FACTORY;
169
170 QgsAbstractGeometry *boundary() const override SIP_FACTORY;
171
172 QString asKml( int precision = 17 ) const override;
173
179 QgsCurve *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
180
181 int vertexCount( int part = 0, int ring = 0 ) const override;
182 int ringCount( int part = 0 ) const override;
183 int partCount() const override;
184 QgsPoint vertexAt( QgsVertexId id ) const override;
185 QgsCurve *toCurveType() const override SIP_FACTORY;
186 void normalize() final SIP_HOLDGIL;
187
188 QgsBox3D boundingBox3D() const override;
189 bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
190
196 virtual double xAt( int index ) const = 0;
197
203 virtual double yAt( int index ) const = 0;
204
211 virtual double zAt( int index ) const = 0;
212
219 virtual double mAt( int index ) const = 0;
220
224 virtual QPolygonF asQPolygonF() const;
225
237 virtual QgsPoint *interpolatePoint( double distance ) const = 0 SIP_FACTORY;
238
251 virtual QgsCurve *curveSubstring( double startDistance, double endDistance ) const = 0 SIP_FACTORY;
252
260 double straightDistance2d() const;
261
271 double sinuosity() const;
272
280 Qgis::AngularDirection orientation() const;
281
293 virtual void scroll( int firstVertexIndex ) = 0;
294
295#ifndef SIP_RUN
296
303 inline static const QgsCurve *cast( const QgsAbstractGeometry *geom )
304 {
305 if ( !geom )
306 return nullptr;
307
308 const Qgis::WkbType type = geom->wkbType();
310 {
311 return static_cast<const QgsCurve *>( geom );
312 }
313 return nullptr;
314 }
315
326 virtual std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex( int index ) const = 0;
327
328#endif
329
330
331 protected:
332
333 void clearCache() const override;
334
335 int childCount() const override;
336 QgsPoint childPoint( int index ) const override;
337#ifndef SIP_RUN
338
343 bool snapToGridPrivate( double hSpacing, double vSpacing, double dSpacing, double mSpacing,
344 const QVector<double> &srcX, const QVector<double> &srcY, const QVector<double> &srcZ, const QVector<double> &srcM,
345 QVector<double> &outX, QVector<double> &outY, QVector<double> &outZ, QVector<double> &outM,
346 bool removeRedundantPoints ) const;
347#endif
348
353
354 mutable bool mHasCachedSummedUpArea = false;
355 mutable double mSummedUpArea = 0;
356
357 private:
358
359 mutable bool mHasCachedValidity = false;
360 mutable QString mValidityFailureReason;
361
362 friend class TestQgsGeometry;
363};
364
365#endif // QGSCURVE_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
VertexType
Types of vertex.
Definition qgis.h:2843
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
Abstract base class for all geometries.
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.
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
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:43
Abstract base class for curved geometry type.
Definition qgscurve.h:35
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
virtual bool pointAt(int node, QgsPoint &point, Qgis::VertexType &type) const =0
Returns the point and vertex id of a point within the curve.
static const QgsCurve * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsCurve.
Definition qgscurve.h:303
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).
QgsBox3D mBoundingBox
Cached bounding box.
Definition qgscurve.h:352
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
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...
virtual QgsCurve * reversed() const =0
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
virtual QgsPoint endPoint() const =0
Returns the end point of the curve.
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:49
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 bool isSingleType(Qgis::WkbType type)
Returns true if the WKB type is a single type.
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_ABSTRACT
Definition qgis_sip.h:213
#define SIP_HOLDGIL
Definition qgis_sip.h:171
#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.
Definition qgsvertexid.h:30