QGIS API Documentation  3.0.2-Girona (307d082)
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.h"
25 #include "qgscurve.h"
26 
27 
34 class CORE_EXPORT QgsCircularString: public QgsCurve
35 {
36  public:
38 
39  bool equals( const QgsCurve &other ) const override;
40 
41  QString geometryType() const override;
42  int dimension() const override;
43  QgsCircularString *clone() const override SIP_FACTORY;
44  void clear() override;
45 
46  bool fromWkb( QgsConstWkbPtr &wkb ) override;
47  bool fromWkt( const QString &wkt ) override;
48 
49  QByteArray asWkb() const override;
50  QString asWkt( int precision = 17 ) const override;
51  QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override;
52  QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override;
53  QString asJson( int precision = 17 ) const override;
54 
55  bool isEmpty() const override;
56  int numPoints() const override;
57 
61  QgsPoint pointN( int i ) const;
62 
63  void points( QgsPointSequence &pts SIP_OUT ) const override;
64 
68  void setPoints( const QgsPointSequence &points );
69 
70  double length() const override;
71  QgsPoint startPoint() const override;
72  QgsPoint endPoint() const override;
73  QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
74  QgsCircularString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
75  bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override;
76 
77  void draw( QPainter &p ) const override;
79  bool transformZ = false ) override;
80  void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
81  void addToPainterPath( QPainterPath &path ) const override;
82  void drawAsPolygon( QPainter &p ) const override;
83  bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
84  bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
85  bool deleteVertex( QgsVertexId position ) override;
86  double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override;
87  bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;
88  void sumUpArea( double &sum SIP_OUT ) const override;
89  bool hasCurvedSegments() const override;
90  double vertexAngle( QgsVertexId vertex ) const override;
91  double segmentLength( QgsVertexId startVertex ) const override;
92  QgsCircularString *reversed() const override SIP_FACTORY;
93  bool addZValue( double zValue = 0 ) override;
94  bool addMValue( double mValue = 0 ) override;
95  bool dropZValue() override;
96  bool dropMValue() override;
97  double xAt( int index ) const override;
98  double yAt( int index ) const override;
99 #ifndef SIP_RUN
100 
108  inline const QgsCircularString *cast( const QgsAbstractGeometry *geom ) const
109  {
110  if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::CircularString )
111  return static_cast<const QgsCircularString *>( geom );
112  return nullptr;
113  }
114 #endif
115 
117 
118  protected:
119 
120  QgsRectangle calculateBoundingBox() const override;
121 
122  private:
123  QVector<double> mX;
124  QVector<double> mY;
125  QVector<double> mZ;
126  QVector<double> mM;
127 
128 #if 0
129  static void arcTo( QPainterPath &path, QPointF pt1, QPointF pt2, QPointF pt3 );
130 #endif
131  //bounding box of a single segment
132  static QgsRectangle segmentBoundingBox( const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3 );
133  static QgsPointSequence compassPointsOnSegment( double p1Angle, double p2Angle, double p3Angle, double centerX, double centerY, double radius );
134  static double closestPointOnArc( double x1, double y1, double x2, double y2, double x3, double y3,
135  const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon );
136  void insertVertexBetween( int after, int before, int pointOnCircle );
137  void deleteVertex( int i );
138 
139 };
140 
141 // clazy:excludeall=qstring-allocations
142 
143 #endif // QGSCIRCULARSTRING_H
virtual QgsCurve * reversed() const =0
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
A rectangle specified with double values.
Definition: qgsrectangle.h:39
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...
virtual bool isEmpty() const
Returns true if the geometry is empty.
virtual bool removeDuplicateNodes(double epsilon=4 *DBL_EPSILON, bool useZValues=false)=0
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
virtual bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
virtual QByteArray asWkb() const =0
Returns a WKB representation of the geometry.
virtual bool insertVertex(QgsVertexId position, const QgsPoint &vertex)=0
Inserts a vertex into the geometry.
const QgsCircularString * cast(const QgsAbstractGeometry *geom) const
Cast the geom to a QgsCircularString.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
virtual void sumUpArea(double &sum) const =0
Sums up the area of the curve by iterating over the vertices (shoelace formula).
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership...
virtual QString asJson(int precision=17) const =0
Returns a GeoJSON representation of the geometry.
virtual double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *DBL_EPSILON) const =0
Searches for the closest segment of the geometry to a given point.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
virtual bool pointAt(int node, QgsPoint &point, QgsVertexId::VertexType &type) const =0
Returns the point and vertex id of a point within the curve.
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false)=0
Transforms the geometry using a coordinate transform.
virtual QgsPoint endPoint() const =0
Returns the end point of the curve.
virtual double length() const
Returns the length of the geometry.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
Utility class for identifying a unique vertex within a geometry.
virtual double xAt(int index) const =0
Returns the x-coordinate of the specified node in the line string.
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
#define SIP_FACTORY
Definition: qgis_sip.h:69
Abstract base class for all geometries.
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
QVector< QgsPoint > QgsPointSequence
virtual void addToPainterPath(QPainterPath &path) const =0
Adds a curve to a painter path.
virtual void clear()=0
Clears the geometry, ie reset it to a null geometry.
virtual QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml") const =0
Returns a GML2 representation of the geometry.
virtual bool moveVertex(QgsVertexId position, const QgsPoint &newPos)=0
Moves a vertex within the geometry.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
#define SIP_OUT
Definition: qgis_sip.h:51
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:41
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 QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
virtual double yAt(int index) const =0
Returns the y-coordinate of the specified node in the line string.
Class for doing transforms between two map coordinate systems.
virtual QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml") const =0
Returns a GML3 representation of the geometry.
Transform from source to destination CRS.
Circular string geometry type.
virtual void drawAsPolygon(QPainter &p) const =0
Draws the curve as a polygon on the specified QPainter.
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
virtual bool fromWkt(const QString &wkt)=0
Sets the geometry from a WKT string.
virtual QgsPoint startPoint() const =0
Returns the starting point of the curve.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:427
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
virtual int numPoints() const =0
Returns the number of points in the curve.
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether &#39;thepoint&#39; is left or right of the line from &#39;p1&#39; to &#39;p2&#39;. Negativ values mean left a...
Definition: MathUtils.cpp:292
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
virtual void points(QgsPointSequence &pt) const =0
Returns a list of points within the curve.
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
virtual bool fromWkb(QgsConstWkbPtr &wkb)=0
Sets the geometry from a WKB string.