QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgscompoundcurve.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscompoundcurve.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 QGSCOMPOUNDCURVE_H
19 #define QGSCOMPOUNDCURVE_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include "qgscurve.h"
24 
31 class CORE_EXPORT QgsCompoundCurve: public QgsCurve
32 {
33  public:
35  QgsCompoundCurve( const QgsCompoundCurve &curve );
37  ~QgsCompoundCurve() override;
38 
39  bool equals( const QgsCurve &other ) const override;
40 
41  QString geometryType() const override;
42  int dimension() const override;
43  QgsCompoundCurve *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( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
50  QString asWkt( int precision = 17 ) const override;
51  QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
52  QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
53  json asJsonObject( int precision = 17 ) const override SIP_SKIP;
54 
55  //curve interface
56  double length() const override;
57  QgsPoint startPoint() const override;
58  QgsPoint endPoint() const override;
59  void points( QgsPointSequence &pts SIP_OUT ) const override;
60  int numPoints() const override;
61  bool isEmpty() const override;
62 
68  QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
69 
70  QgsCompoundCurve *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
71  bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
72 
76  int nCurves() const { return mCurves.size(); }
77 
81  const QgsCurve *curveAt( int i ) const;
82 
86  void addCurve( QgsCurve *c SIP_TRANSFER );
87 
92  void removeCurve( int i );
93 
97  void addVertex( const QgsPoint &pt );
98 
99  void draw( QPainter &p ) const override;
101  void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
102  void addToPainterPath( QPainterPath &path ) const override;
103  void drawAsPolygon( QPainter &p ) const override;
104  bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
105  bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
106  bool deleteVertex( QgsVertexId position ) override;
107  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;
108  bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;
109  void sumUpArea( double &sum SIP_OUT ) const override;
110 
112  void close();
113 
114  bool hasCurvedSegments() const override;
115  double vertexAngle( QgsVertexId vertex ) const override;
116  double segmentLength( QgsVertexId startVertex ) const override;
117  QgsCompoundCurve *reversed() const override SIP_FACTORY;
118  QgsPoint *interpolatePoint( double distance ) const override SIP_FACTORY;
119  QgsCompoundCurve *curveSubstring( double startDistance, double endDistance ) const override SIP_FACTORY;
120 
121  bool addZValue( double zValue = 0 ) override;
122  bool addMValue( double mValue = 0 ) override;
123 
124  bool dropZValue() override;
125  bool dropMValue() override;
126  void swapXy() override;
127 
128  double xAt( int index ) const override;
129  double yAt( int index ) const override;
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 QgsCompoundCurve *cast( const QgsAbstractGeometry *geom ) const
143  {
144  if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::CompoundCurve )
145  return static_cast<const QgsCompoundCurve *>( 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( "<QgsCompoundCurve: %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< QgsCurve * > mCurves;
169 
173  QVector< QPair<int, QgsVertexId> > curveVertexId( QgsVertexId id ) const;
174 
175 };
176 
177 // clazy:excludeall=qstring-allocations
178 
179 #endif // QGSCOMPOUNDCURVE_H
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
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::fromWkt
virtual bool fromWkt(const QString &wkt)=0
Sets the geometry from a WKT string.
QgsAbstractGeometry::wkbType
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Definition: qgsabstractgeometry.h:189
QgsCurve::startPoint
virtual QgsPoint startPoint() const =0
Returns the starting point of the curve.
QgsAbstractGeometry::asWkb
virtual QByteArray asWkb(WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const =0
Returns a WKB representation of the geometry.
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
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.
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
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:58
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:112
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:43
closestSegment
double closestSegment(const QgsPolylineXY &pl, const QgsPointXY &pt, int &vertexAfter, double epsilon)
Definition: qgstracer.cpp:68
QgsRectangle
Definition: qgsrectangle.h:41
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsCompoundCurve::nCurves
int nCurves() const
Returns the number of curves in the geometry.
Definition: qgscompoundcurve.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
precision
int precision
Definition: qgswfsgetfeature.cpp:103
QgsAbstractGeometry::dimension
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
QgsCsException
Definition: qgsexception.h:65
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
SIP_THROW
#define SIP_THROW(name)
Definition: qgis_sip.h:184
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:128
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:127
QgsCurve::equals
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
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.
QgsCompoundCurve::cast
const QgsCompoundCurve * cast(const QgsAbstractGeometry *geom) const
Cast the geom to a QgsCompoundCurve.
Definition: qgscompoundcurve.h:142
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:71
QgsCoordinateTransform::ForwardTransform
@ ForwardTransform
Transform from source to destination CRS.
Definition: qgscoordinatetransform.h:60
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.
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.
QgsAbstractGeometry::operator=
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
Definition: qgsabstractgeometry.cpp:33
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:44
qgscurve.h
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsAbstractGeometry::draw
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition: qgsabstractgeometry.h:1033
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
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
Definition: qgscoordinatetransform.h:52
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.
QgsWkbTypes::flatType
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:701
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.
QgsCompoundCurve
Compound curve geometry type.
Definition: qgscompoundcurve.h:31
QgsWkbTypes::CompoundCurve
@ CompoundCurve
Definition: qgswkbtypes.h:80
QgsAbstractGeometry::calculateBoundingBox
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
Definition: qgsabstractgeometry.cpp:85