QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 <QVector>
22 
23 #include "qgis_core.h"
24 #include "qgis_sip.h"
25 #include "qgscurve.h"
26 
27 
34 class CORE_EXPORT QgsCircularString: public QgsCurve
35 {
36  public:
37 
42 
49  QgsCircularString( const QgsPoint &p1,
50  const QgsPoint &p2,
51  const QgsPoint &p3 ) SIP_HOLDGIL;
52 
63  static QgsCircularString fromTwoPointsAndCenter( const QgsPoint &p1,
64  const QgsPoint &p2,
65  const QgsPoint &center,
66  bool useShortestArc = true );
67 
68  bool equals( const QgsCurve &other ) const override;
69 
70  QString geometryType() const override SIP_HOLDGIL;
71  int dimension() const override SIP_HOLDGIL;
72  QgsCircularString *clone() const override SIP_FACTORY;
73  void clear() override;
74 
75  bool fromWkb( QgsConstWkbPtr &wkb ) override;
76  bool fromWkt( const QString &wkt ) override;
77 
78  int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
79  QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
80  QString asWkt( int precision = 17 ) const override;
81  QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
82  QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
83  json asJsonObject( int precision = 17 ) const override SIP_SKIP;
84  bool isEmpty() const override SIP_HOLDGIL;
85  int numPoints() const override SIP_HOLDGIL;
86 
90  QgsPoint pointN( int i ) const SIP_HOLDGIL;
91 
92  void points( QgsPointSequence &pts SIP_OUT ) const override;
93 
97  void setPoints( const QgsPointSequence &points );
98 
99  double length() const override;
100  QgsPoint startPoint() const override SIP_HOLDGIL;
101  QgsPoint endPoint() const override SIP_HOLDGIL;
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 ) const override SIP_FACTORY;
104  bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
105 
106  void draw( QPainter &p ) const override;
108  void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
109  void addToPainterPath( QPainterPath &path ) const override;
110  void drawAsPolygon( QPainter &p ) const override;
111  bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
112  bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
113  bool deleteVertex( QgsVertexId position ) override;
114  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;
115  bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;
116  void sumUpArea( 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  QgsCircularString *reversed() const override SIP_FACTORY;
121  QgsPoint *interpolatePoint( double distance ) const override SIP_FACTORY;
122  QgsCircularString *curveSubstring( double startDistance, double endDistance ) const override SIP_FACTORY;
123  bool addZValue( double zValue = 0 ) override;
124  bool addMValue( double mValue = 0 ) override;
125  bool dropZValue() override;
126  bool dropMValue() override;
127  void swapXy() override;
128  double xAt( int index ) const override SIP_HOLDGIL;
129  double yAt( int index ) const override SIP_HOLDGIL;
130 
131 #ifndef SIP_RUN
132  void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
133  void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
134 
142  inline const QgsCircularString *cast( const QgsAbstractGeometry *geom ) const
143  {
144  if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::CircularString )
145  return static_cast<const QgsCircularString *>( geom );
146  return nullptr;
147  }
148 #endif
149 
151 
152 #ifdef SIP_RUN
153  SIP_PYOBJECT __repr__();
154  % MethodCode
155  QString wkt = sipCpp->asWkt();
156  if ( wkt.length() > 1000 )
157  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
158  QString str = QStringLiteral( "<QgsCircularString: %1>" ).arg( wkt );
159  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
160  % End
161 #endif
162 
163  protected:
164 
165  QgsRectangle calculateBoundingBox() const override;
166 
167  private:
168  QVector<double> mX;
169  QVector<double> mY;
170  QVector<double> mZ;
171  QVector<double> mM;
172 
173 #if 0
174  static void arcTo( QPainterPath &path, QPointF pt1, QPointF pt2, QPointF pt3 );
175 #endif
176  //bounding box of a single segment
177  static QgsRectangle segmentBoundingBox( const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3 );
178  static QgsPointSequence compassPointsOnSegment( double p1Angle, double p2Angle, double p3Angle, double centerX, double centerY, double radius );
179  static double closestPointOnArc( double x1, double y1, double x2, double y2, double x3, double y3,
180  const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon );
181  void insertVertexBetween( int after, int before, int pointOnCircle );
182  void deleteVertex( int i );
183 
184 };
185 
186 // clazy:excludeall=qstring-allocations
187 
188 #endif // QGSCIRCULARSTRING_H
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
QgsCircularString::cast
const QgsCircularString * cast(const QgsAbstractGeometry *geom) const
Cast the geom to a QgsCircularString.
Definition: qgscircularstring.h:142
QgsCurve::pointAt
virtual bool pointAt(int node, QgsPoint &point, QgsVertexId::VertexType &type) const =0
Returns the point and vertex id of a point within the curve.
QgsAbstractGeometry::removeDuplicateNodes
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::dropMValue
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
QgsAbstractGeometry::fromWkt
virtual bool fromWkt(const QString &wkt)=0
Sets the geometry from a WKT string.
QgsAbstractGeometry::dropZValue
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
QgsCurve::drawAsPolygon
virtual void drawAsPolygon(QPainter &p) const =0
Draws the curve as a polygon on the specified QPainter.
QgsCurve::startPoint
virtual QgsPoint startPoint() const =0
Returns the starting point of the curve.
QgsCurve::interpolatePoint
virtual QgsPoint * interpolatePoint(double distance) const =0
Returns an interpolated point on the curve at the specified distance.
QgsAbstractGeometry::asWkb
virtual QByteArray asWkb(WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const =0
Returns a WKB representation of the geometry.
QgsAbstractGeometry::addZValue
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
QgsAbstractGeometry::snappedToGrid
virtual QgsAbstractGeometry * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const =0
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
QgsAbstractGeometry::moveVertex
virtual bool moveVertex(QgsVertexId position, const QgsPoint &newPos)=0
Moves a vertex within the geometry.
QgsAbstractGeometry::wkbSize
virtual int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const =0
Returns the length of the QByteArray returned by asWkb()
QgsCurve::reversed
virtual QgsCurve * reversed() const =0
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsAbstractGeometry::addMValue
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
QgsWkbTypes::flatType
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:702
QgsAbstractGeometry::filterVertices
virtual void filterVertices(const std::function< bool(const QgsPoint &) > &filter)
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
Definition: qgsabstractgeometry.cpp:250
QgsCoordinateTransform::TransformDirection
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
Definition: qgscoordinatetransform.h:59
QgsAbstractGeometry::asWkt
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
QgsAbstractGeometry::length
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
Definition: qgsabstractgeometry.cpp:132
QgsAbstractGeometry::SegmentationToleranceType
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
Definition: qgsabstractgeometry.h:115
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
QgsCurve::sumUpArea
virtual void sumUpArea(double &sum) const =0
Sums up the area of the curve by iterating over the vertices (shoelace formula).
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
MathUtils::leftOf
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negative values mean left ...
Definition: MathUtils.cpp:292
QgsAbstractGeometry::vertexAngle
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
precision
int precision
Definition: qgswfsgetfeature.cpp:49
QgsAbstractGeometry::dimension
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
QgsCsException
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
SIP_HOLDGIL
#define SIP_HOLDGIL
Definition: qgis_sip.h:157
SIP_THROW
#define SIP_THROW(name)
Definition: qgis_sip.h:189
QgsCircularString
Circular string geometry type.
Definition: qgscircularstring.h:35
QgsCurve::addToPainterPath
virtual void addToPainterPath(QPainterPath &path) const =0
Adds a curve to a painter path.
QgsAbstractGeometry::wkbType
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
Definition: qgsabstractgeometry.h:193
QgsAbstractGeometry::insertVertex
virtual bool insertVertex(QgsVertexId position, const QgsPoint &vertex)=0
Inserts a vertex into the geometry.
QgsCurve::endPoint
virtual QgsPoint endPoint() const =0
Returns the end point of the curve.
QgsAbstractGeometry::AxisOrder
AxisOrder
Axis order for GML generation.
Definition: qgsabstractgeometry.h:133
QgsAbstractGeometry::asJsonObject
virtual json asJsonObject(int precision=17) const
Returns a json object representation of the geometry.
Definition: qgsabstractgeometry.cpp:162
QgsConstWkbPtr
Definition: qgswkbptr.h:128
QgsAbstractGeometry::swapXy
virtual void swapXy()=0
Swaps the x and y coordinates from the geometry.
QgsCurve::equals
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
QgsCurve::curveSubstring
virtual QgsCurve * curveSubstring(double startDistance, double endDistance) const =0
Returns a new curve representing a substring of this curve.
qgis_sip.h
QgsAbstractGeometry::deleteVertex
virtual bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
QgsCurve::yAt
virtual double yAt(int index) const =0
Returns the y-coordinate of the specified node in the line string.
QgsAbstractGeometry::closestSegment
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.
QgsAbstractGeometry::hasCurvedSegments
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
Definition: qgsabstractgeometry.cpp:305
QgsAbstractGeometry::clear
virtual void clear()=0
Clears the geometry, ie reset it to a null geometry.
QgsAbstractGeometry::isEmpty
virtual bool isEmpty() const
Returns true if the geometry is empty.
Definition: qgsabstractgeometry.cpp:298
QgsAbstractGeometry::fromWkb
virtual bool fromWkb(QgsConstWkbPtr &wkb)=0
Sets the geometry from a WKB string.
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:74
QgsCoordinateTransform::ForwardTransform
@ ForwardTransform
Transform from source to destination CRS.
Definition: qgscoordinatetransform.h:60
QgsCurve::xAt
virtual double xAt(int index) const =0
Returns the x-coordinate of the specified node in the line string.
QgsAbstractGeometry::geometryType
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
QgsCurve::clone
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
QgsAbstractGeometry::createEmptyWithSameType
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
QgsWkbTypes::CircularString
@ CircularString
Definition: qgswkbtypes.h:80
QgsAbstractGeometry::asGml3
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.
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:46
qgscurve.h
QgsAbstractGeometry::draw
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
QgsAbstractGeometry::segmentLength
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition: qgsabstractgeometry.h:1059
QgsAbstractGeometry::transformVertices
virtual void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform)
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
Definition: qgsabstractgeometry.cpp:255
QgsVertexId::VertexType
VertexType
Type of vertex.
Definition: qgsabstractgeometry.h:1065
QgsCurve::points
virtual void points(QgsPointSequence &pt) const =0
Returns a list of points within the curve.
QgsCurve::numPoints
virtual int numPoints() const =0
Returns the number of points in the curve.
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:53
QgsAbstractGeometry::transform
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)=0
Transforms the geometry using a coordinate transform.
QgsCurve::curveToLine
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.
QgsAbstractGeometry::asGml2
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.
QgsAbstractGeometry::calculateBoundingBox
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
Definition: qgsabstractgeometry.cpp:85