QGIS API Documentation  3.19.0-Master (f616be29d3)
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 SIP_HOLDGIL;
42  int dimension() const override SIP_HOLDGIL;
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  int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
50  QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
51  QString asWkt( int precision = 17 ) const override;
52  QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
53  QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
54  json asJsonObject( int precision = 17 ) const override SIP_SKIP;
55 
56  //curve interface
57  double length() const override SIP_HOLDGIL;
58  QgsPoint startPoint() const override SIP_HOLDGIL;
59  QgsPoint endPoint() const override SIP_HOLDGIL;
60  void points( QgsPointSequence &pts SIP_OUT ) const override;
61  int numPoints() const override SIP_HOLDGIL;
62  bool isEmpty() const override SIP_HOLDGIL;
63  bool isValid( QString &error SIP_OUT, int flags = 0 ) const override;
64  int indexOf( const QgsPoint &point ) const final;
65 
72  QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
73 
74  QgsCompoundCurve *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
75  bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
76  bool boundingBoxIntersects( const QgsRectangle &rectangle ) const override SIP_HOLDGIL;
77 
81  int nCurves() const SIP_HOLDGIL { return mCurves.size(); }
82 
86  const QgsCurve *curveAt( int i ) const SIP_HOLDGIL;
87 
97  void addCurve( QgsCurve *c SIP_TRANSFER, bool extendPrevious = false );
98 
103  void removeCurve( int i );
104 
108  void addVertex( const QgsPoint &pt );
109 
116  void condenseCurves();
117 
118  void draw( QPainter &p ) const override;
120  void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
121  void addToPainterPath( QPainterPath &path ) const override;
122  void drawAsPolygon( QPainter &p ) const override;
123  bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
124  bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
125  bool deleteVertex( QgsVertexId position ) override;
126  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;
127  bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;
128  void sumUpArea( double &sum SIP_OUT ) const override;
129 
131  void close();
132 
133  bool hasCurvedSegments() const override;
134  double vertexAngle( QgsVertexId vertex ) const override;
135  double segmentLength( QgsVertexId startVertex ) const override;
136  QgsCompoundCurve *reversed() const override SIP_FACTORY;
137  QgsPoint *interpolatePoint( double distance ) const override SIP_FACTORY;
138  QgsCompoundCurve *curveSubstring( double startDistance, double endDistance ) const override SIP_FACTORY;
139 
140  bool addZValue( double zValue = 0 ) override;
141  bool addMValue( double mValue = 0 ) override;
142 
143  bool dropZValue() override;
144  bool dropMValue() override;
145  void swapXy() override;
146 
147  double xAt( int index ) const override SIP_HOLDGIL;
148  double yAt( int index ) const override SIP_HOLDGIL;
149 
150  bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = nullptr ) override;
151  void scroll( int firstVertexIndex ) final;
152 
153 #ifndef SIP_RUN
154  void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
155  void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
156  std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex( int index ) const final;
157 
165  inline static const QgsCompoundCurve *cast( const QgsAbstractGeometry *geom )
166  {
167  if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::CompoundCurve )
168  return static_cast<const QgsCompoundCurve *>( geom );
169  return nullptr;
170  }
171 #endif
172 
174 
175 #ifdef SIP_RUN
176  SIP_PYOBJECT __repr__();
177  % MethodCode
178  QString wkt = sipCpp->asWkt();
179  if ( wkt.length() > 1000 )
180  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
181  QString str = QStringLiteral( "<QgsCompoundCurve: %1>" ).arg( wkt );
182  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
183  % End
184 #endif
185 
186  protected:
187 
188  int compareToSameClass( const QgsAbstractGeometry *other ) const final;
189  QgsRectangle calculateBoundingBox() const override;
190 
191  private:
192  QVector< QgsCurve * > mCurves;
193 
198  QVector< QPair<int, QgsVertexId> > curveVertexId( QgsVertexId id ) const;
199 
200 };
201 
202 // clazy:excludeall=qstring-allocations
203 
204 #endif // QGSCOMPOUNDCURVE_H
An abstract base class for classes which transform geometries by transforming input points to output ...
Abstract base class for all geometries.
virtual bool fromWkb(QgsConstWkbPtr &wkb)=0
Sets the geometry from a WKB string.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
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.
virtual bool boundingBoxIntersects(const QgsRectangle &rectangle) const SIP_HOLDGIL
Returns true if the bounding box of this geometry intersects with a rectangle.
AxisOrder
Axis order for GML generation.
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 QByteArray asWkb(WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const =0
Returns a WKB representation of 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.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
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 void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)=0
Transforms the geometry using a coordinate transform.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
virtual bool isEmpty() const
Returns true if the geometry is empty.
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 fromWkt(const QString &wkt)=0
Sets the geometry from a WKT string.
virtual void clear()=0
Clears the geometry, ie reset it to a null geometry.
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...
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
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...
virtual int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const =0
Returns the length of the QByteArray returned by asWkb()
virtual int compareToSameClass(const QgsAbstractGeometry *other) const =0
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
Compound curve geometry type.
static const QgsCompoundCurve * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsCompoundCurve.
int nCurves() const SIP_HOLDGIL
Returns the number of curves in the geometry.
A const WKB pointer.
Definition: qgswkbptr.h:138
Class for doing transforms between two map coordinate systems.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
@ ForwardTransform
Transform from source to destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
virtual int numPoints() const =0
Returns the number of points in the curve.
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.
bool isValid(QString &error, int flags=0) const override
Checks validity of the geometry, and returns true if the geometry is valid.
Definition: qgscurve.cpp:238
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...
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 QgsPoint endPoint() const =0
Returns the end point of the curve.
virtual void points(QgsPointSequence &pt) const =0
Returns a list of points within the curve.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
A rectangle specified with double values.
Definition: qgsrectangle.h:42
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:702
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
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
#define str(x)
Definition: qgis.cpp:37
#define SIP_THROW(name)
Definition: qgis_sip.h:189
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_HOLDGIL
Definition: qgis_sip.h:157
#define SIP_FACTORY
Definition: qgis_sip.h:76
QVector< QgsPoint > QgsPointSequence
double closestSegment(const QgsPolylineXY &pl, const QgsPointXY &pt, int &vertexAfter, double epsilon)
Definition: qgstracer.cpp:68
int precision
Utility class for identifying a unique vertex within a geometry.