QGIS API Documentation  3.0.2-Girona (307d082)
qgsgeometrycollection.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometrycollection.h
3  -------------------------------------------------------------------
4 Date : 28 Oct 2014
5 Copyright : (C) 2014 by Marco Hugentobler
6 email : marco.hugentobler at sourcepole dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSGEOMETRYCOLLECTIONV2_H
17 #define QGSGEOMETRYCOLLECTIONV2_H
18 
19 #include <QVector>
20 
21 
22 #include "qgis_core.h"
23 #include "qgis.h"
24 #include "qgsabstractgeometry.h"
25 #include "qgspoint.h"
26 
27 
34 class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
35 {
36  public:
40  ~QgsGeometryCollection() override;
41 
42  bool operator==( const QgsAbstractGeometry &other ) const override;
43  bool operator!=( const QgsAbstractGeometry &other ) const override;
44 
45  QgsGeometryCollection *clone() const override SIP_FACTORY;
46 
50  int numGeometries() const;
51 
57  const QgsAbstractGeometry *geometryN( int n ) const SIP_SKIP;
58 
63  QgsAbstractGeometry *geometryN( int n );
64 
65  //methods inherited from QgsAbstractGeometry
66  bool isEmpty() const override;
67  int dimension() const override;
68  QString geometryType() const override;
69  void clear() override;
70  QgsGeometryCollection *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
71  bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override;
72  QgsAbstractGeometry *boundary() const override SIP_FACTORY;
73  void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
74  int vertexNumberFromVertexId( QgsVertexId id ) const override;
75 
77  virtual bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER );
78 
84  virtual bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index );
85 
91  virtual bool removeGeometry( int nr );
92 
94  bool transformZ = false ) override;
95  void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
96 
97  void draw( QPainter &p ) const override;
98 
99  bool fromWkb( QgsConstWkbPtr &wkb ) override;
100  bool fromWkt( const QString &wkt ) override;
101  QByteArray asWkb() const override;
102  QString asWkt( int precision = 17 ) const override;
103  QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override;
104  QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml" ) const override;
105  QString asJson( int precision = 17 ) const override;
106 
107  QgsRectangle boundingBox() const override;
108 
109  QgsCoordinateSequence coordinateSequence() const override;
110  int nCoordinates() const override;
111 
112  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;
113  bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
114 
115  //low-level editing
116  bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
117  bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
118  bool deleteVertex( QgsVertexId position ) override;
119 
120  double length() const override;
121  double area() const override;
122  double perimeter() const override;
123 
124  bool hasCurvedSegments() const override;
125 
130  QgsAbstractGeometry *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
131 
132  double vertexAngle( QgsVertexId vertex ) const override;
133  double segmentLength( QgsVertexId startVertex ) const override;
134  int vertexCount( int part = 0, int ring = 0 ) const override;
135  int ringCount( int part = 0 ) const override;
136  int partCount() const override;
137  QgsPoint vertexAt( QgsVertexId id ) const override;
138 
139  bool addZValue( double zValue = 0 ) override;
140  bool addMValue( double mValue = 0 ) override;
141  bool dropZValue() override;
142  bool dropMValue() override;
144 
145 #ifndef SIP_RUN
146 
154  inline const QgsGeometryCollection *cast( const QgsAbstractGeometry *geom ) const
155  {
156  if ( geom && QgsWkbTypes::isMultiType( geom->wkbType() ) )
157  return static_cast<const QgsGeometryCollection *>( geom );
158  return nullptr;
159  }
160 #endif
161 
163 
164  protected:
165  int childCount() const override;
166  QgsAbstractGeometry *childGeometry( int index ) const override;
167 
168  protected:
169  QVector< QgsAbstractGeometry * > mGeometries;
170 
175  virtual bool wktOmitChildType() const;
176 
180  bool fromCollectionWkt( const QString &wkt, const QVector<QgsAbstractGeometry *> &subtypes, const QString &defaultChildWkbType = QString() );
181 
182  QgsRectangle calculateBoundingBox() const override;
183  void clearCache() const override;
184 
185  private:
186 
187  mutable QgsRectangle mBoundingBox;
188 };
189 
190 // clazy:excludeall=qstring-allocations
191 
192 #endif // QGSGEOMETRYCOLLECTIONV2_H
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 int vertexNumberFromVertexId(QgsVertexId id) const =0
Returns the vertex number corresponding to a vertex id.
virtual int childCount() const
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
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 QgsAbstractGeometry * toCurveType() const =0
Returns the geometry converted to the more generic curve type.
virtual QByteArray asWkb() const =0
Returns a WKB representation of the geometry.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
Definition: qgswkbtypes.h:557
virtual bool insertVertex(QgsVertexId position, const QgsPoint &vertex)=0
Inserts a vertex into the geometry.
QVector< QgsRingSequence > QgsCoordinateSequence
virtual bool operator==(const QgsAbstractGeometry &other) const =0
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 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 QgsAbstractGeometry * childGeometry(int index) const
Returns pointer to child geometry (for geometries with child geometries - i.e.
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.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
virtual QgsRectangle boundingBox() const =0
Returns the minimal bounding box for the geometry.
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false)=0
Transforms the geometry using a coordinate transform.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
virtual double length() const
Returns the length of the geometry.
virtual bool operator!=(const QgsAbstractGeometry &other) const =0
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
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.
Geometry collection.
#define SIP_SKIP
Definition: qgis_sip.h:119
#define SIP_TRANSFER
Definition: qgis_sip.h:36
const QgsGeometryCollection * cast(const QgsAbstractGeometry *geom) const
Cast the geom to a QgsGeometryCollection.
virtual double area() const
Returns the area of the geometry.
virtual int ringCount(int part=0) const =0
Returns the number of rings of which this geometry is built.
#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
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
virtual void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const =0
Returns the vertices adjacent to a specified vertex within a geometry.
QVector< QgsAbstractGeometry *> mGeometries
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.
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.
virtual double perimeter() const
Returns the perimeter of the geometry.
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
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.
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 vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
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 int partCount() const =0
Returns count of parts contained in the geometry.
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.