QGIS API Documentation 4.1.0-Master (3fcefe620d1)
Loading...
Searching...
No Matches
qgscircularstring.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscircularstring.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 QGSCIRCULARSTRING_H
19#define QGSCIRCULARSTRING_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgscurve.h"
24#include "qgssimplecurve.h"
25
26#include <QString>
27#include <QVector>
28
29using namespace Qt::StringLiterals;
30
36class CORE_EXPORT QgsCircularString : public QgsSimpleCurve
37{
38 public:
39 // clang-format off
44 // clang-format on
45
52 QgsCircularString( const QgsPoint &p1,
53 const QgsPoint &p2,
54 const QgsPoint &p3 ) SIP_HOLDGIL;
55
71 QgsCircularString( const QVector<double> &x, const QVector<double> &y,
72 const QVector<double> &z = QVector<double>(),
73 const QVector<double> &m = QVector<double>() ) SIP_HOLDGIL;
74
75
87 const QgsPoint &p2,
88 const QgsPoint &center,
89 bool useShortestArc = true );
90
91 QString geometryType() const override SIP_HOLDGIL;
92 QgsCircularString *clone() const override SIP_FACTORY;
93 void clear() override;
94
95 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
96 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
97 json asJsonObject( int precision = 17 ) const override SIP_SKIP;
98 bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
99 int indexOf( const QgsPoint &point ) const final;
100
101 double length() const override;
102 QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
103 QgsCircularString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
104 QgsAbstractGeometry *simplifyByDistance( double tolerance ) const override SIP_FACTORY;
105 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
106
107 void draw( QPainter &p ) const override;
108 void addToPainterPath( QPainterPath &path ) const override;
109 void drawAsPolygon( QPainter &p ) const override;
110 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
111 bool deleteVertex( QgsVertexId position ) override;
112 bool deleteVertices( const QSet<QgsVertexId> &positions ) override;
113 double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
114 bool pointAt( int node, QgsPoint &point, Qgis::VertexType &type ) const override;
115 void sumUpArea( double &sum SIP_OUT ) const override;
116 void sumUpArea3D( double &sum SIP_OUT ) const override;
117 bool hasCurvedSegments() const override;
118 double vertexAngle( QgsVertexId vertex ) const override;
119 double segmentLength( QgsVertexId startVertex ) const override;
120 double distanceBetweenVertices( QgsVertexId fromVertex, QgsVertexId toVertex ) const override;
121 QgsCircularString *reversed() const override SIP_FACTORY;
122 QgsPoint *interpolatePoint( double distance ) const override SIP_FACTORY;
123 QgsCircularString *curveSubstring( double startDistance, double endDistance ) const override SIP_FACTORY;
124
125#ifndef SIP_RUN
126 std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex( int index ) const final;
127
136 inline static const QgsCircularString *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
137 {
139 return static_cast<const QgsCircularString *>( geom );
140 return nullptr;
141 }
142
151 inline static QgsCircularString *cast( QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
152 {
154 return static_cast<QgsCircularString *>( geom );
155 return nullptr;
156 }
157#endif
158
160
161#ifdef SIP_RUN
162// clang-format off
163 SIP_PYOBJECT __repr__();
164 % MethodCode
165 QString wkt = sipCpp->asWkt();
166 if ( wkt.length() > 1000 )
167 wkt = wkt.left( 1000 ) + u"..."_s;
168 QString str = u"<QgsCircularString: %1>"_s.arg( wkt );
169 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
170 % End
171// clang-format on
172#endif
173
174 protected:
175 QgsBox3D calculateBoundingBox3D() const override;
176
177 private:
178#if 0
179 static void arcTo( QPainterPath &path, QPointF pt1, QPointF pt2, QPointF pt3 );
180#endif
181 //bounding box of a single segment
182 static QgsRectangle segmentBoundingBox( const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3 );
183 static QgsPointSequence compassPointsOnSegment( double p1Angle, double p2Angle, double p3Angle, double centerX, double centerY, double radius );
184 static double closestPointOnArc( double x1, double y1, double x2, double y2, double x3, double y3,
185 const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon );
186 void insertVertexBetween( int after, int before, int pointOnCircle );
187 void deleteVertex( int i );
188
189};
190
191// clazy:excludeall=qstring-allocations
192
193#endif // QGSCIRCULARSTRING_H
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
Definition qgis.h:2197
VertexType
Types of vertex.
Definition qgis.h:3247
@ CircularString
CircularString.
Definition qgis.h:304
virtual QgsAbstractGeometry * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0, bool removeRedundantPoints=false) const =0
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
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 double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
virtual QgsBox3D calculateBoundingBox3D() const
Calculates the minimal 3D bounding box for the geometry.
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
virtual QgsAbstractGeometry * simplifyByDistance(double tolerance) const =0
Simplifies the geometry by applying the Douglas Peucker simplification by distance algorithm.
AxisOrder
Axis order for GML generation.
@ XY
X comes before Y (or lon before lat).
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
virtual bool deleteVertices(const QSet< QgsVertexId > &positions)=0
Deletes vertices within the geometry.
virtual QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const =0
Returns a GML2 representation of the geometry.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual bool insertVertex(QgsVertexId position, const QgsPoint &vertex)=0
Inserts a vertex into the geometry.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
virtual json asJsonObject(int precision=17) const
Returns a json object representation of the geometry.
virtual QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const =0
Returns a GML3 representation of the geometry.
virtual bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
virtual bool removeDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false)=0
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
QgsAbstractGeometry()=default
virtual double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const =0
Searches for the closest segment of the geometry to a given point.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
Circular string geometry type.
static QgsCircularString * cast(QgsAbstractGeometry *geom)
Cast the geom to a QgsCircularString.
static QgsCircularString fromTwoPointsAndCenter(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &center, bool useShortestArc=true)
Creates a circular string with a single arc representing the curve from p1 to p2 with the specified c...
static const QgsCircularString * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsCircularString.
QgsCircularString()
Constructs an empty circular string.
virtual bool pointAt(int node, QgsPoint &point, Qgis::VertexType &type) const =0
Returns the point and vertex type of a point within the curve.
virtual QgsCurve * curveSubstring(double startDistance, double endDistance) const =0
Returns a new curve representing a substring of this curve.
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 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...
virtual void sumUpArea(double &sum) const =0
Sums up the area of the curve by iterating over the vertices (shoelace formula).
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 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 void drawAsPolygon(QPainter &p) const =0
Draws the curve as a polygon on the specified QPainter.
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.
virtual void sumUpArea3D(double &sum) const =0
Sums up the 3d area of the curve by iterating over the vertices (shoelace formula).
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
A rectangle specified with double values.
QgsSimpleCurve()=default
void clear() override
Clears the geometry, ie reset it to a null geometry.
QgsSimpleCurve * reversed() const override
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_HOLDGIL
Definition qgis_sip.h:178
#define SIP_FACTORY
Definition qgis_sip.h:83
QVector< QgsPoint > QgsPointSequence
void arcTo(QPainterPath &path, QPointF pt1, QPointF pt2, QPointF pt3)
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:35