-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsgeometrycollection.h
235 lines (190 loc) · 8.78 KB
/
qgsgeometrycollection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/***************************************************************************
qgsgeometrycollection.h
-------------------------------------------------------------------
Date : 28 Oct 2014
Copyright : (C) 2014 by Marco Hugentobler
email : marco.hugentobler at sourcepole dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGEOMETRYCOLLECTIONV2_H
#define QGSGEOMETRYCOLLECTIONV2_H
#include <QVector>
#include "qgis_core.h"
#include "qgis.h"
#include "qgsabstractgeometry.h"
class QgsPoint;
/**
* \ingroup core
* \class QgsGeometryCollection
* \brief Geometry collection
* \since QGIS 2.10
*/
class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
{
public:
QgsGeometryCollection();
QgsGeometryCollection( const QgsGeometryCollection &c );
QgsGeometryCollection &operator=( const QgsGeometryCollection &c );
~QgsGeometryCollection() override;
bool operator==( const QgsAbstractGeometry &other ) const override;
bool operator!=( const QgsAbstractGeometry &other ) const override;
QgsGeometryCollection *clone() const override SIP_FACTORY;
/**
* Returns the number of geometries within the collection.
*/
int numGeometries() const
{
return mGeometries.size();
}
#ifdef SIP_RUN
/**
* Returns the number of geometries within the collection.
*/
int __len__() const;
% MethodCode
sipRes = sipCpp->numGeometries();
% End
//! Ensures that bool(obj) returns true (otherwise __len__() would be used)
int __bool__() const;
% MethodCode
sipRes = true;
% End
#endif
/**
* Returns a const reference to a geometry from within the collection.
* \param n index of geometry to return
* \note not available in Python bindings
*/
const QgsAbstractGeometry *geometryN( int n ) const SIP_SKIP
{
return mGeometries.value( n );
}
/**
* Returns a geometry from within the collection.
* \param n index of geometry to return
*/
#ifndef SIP_RUN
QgsAbstractGeometry *geometryN( int n );
#else
SIP_PYOBJECT geometryN( int n ) const;
% MethodCode
if ( a0 < 0 || a0 >= sipCpp->numGeometries() )
{
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
sipIsErr = 1;
}
else
{
return sipConvertFromType( sipCpp->geometryN( a0 ), sipType_QgsAbstractGeometry, NULL );
}
% End
#endif
//methods inherited from QgsAbstractGeometry
bool isEmpty() const override;
int dimension() const override;
QString geometryType() const override;
void clear() override;
QgsGeometryCollection *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
QgsAbstractGeometry *boundary() const override SIP_FACTORY;
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
int vertexNumberFromVertexId( QgsVertexId id ) const override;
//! Adds a geometry and takes ownership. Returns true in case of success.
virtual bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER );
/**
* Inserts a geometry before a specified index and takes ownership. Returns true in case of success.
* \param g geometry to insert. Ownership is transferred to the collection.
* \param index position to insert geometry before
*/
virtual bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index );
/**
* Removes a geometry from the collection.
* \param nr index of geometry to remove
* \returns true if removal was successful.
*/
virtual bool removeGeometry( int nr );
void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) override SIP_THROW( QgsCsException );
void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
void draw( QPainter &p ) const override;
bool fromWkb( QgsConstWkbPtr &wkb ) override;
bool fromWkt( const QString &wkt ) override;
QByteArray asWkb() const override;
QString asWkt( int precision = 17 ) const override;
QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QString asJson( int precision = 17 ) const override;
QgsRectangle boundingBox() const override;
QgsCoordinateSequence coordinateSequence() const override;
int nCoordinates() const override;
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;
bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
//low-level editing
bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
bool deleteVertex( QgsVertexId position ) override;
double length() const override;
double area() const override;
double perimeter() const override;
bool hasCurvedSegments() const override;
/**
* Returns a geometry without curves. Caller takes ownership
* \param tolerance segmentation tolerance
* \param toleranceType maximum segmentation angle or maximum difference between approximation and curve*/
QgsAbstractGeometry *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
double vertexAngle( QgsVertexId vertex ) const override;
double segmentLength( QgsVertexId startVertex ) const override;
int vertexCount( int part = 0, int ring = 0 ) const override;
int ringCount( int part = 0 ) const override;
int partCount() const override;
QgsPoint vertexAt( QgsVertexId id ) const override;
bool addZValue( double zValue = 0 ) override;
bool addMValue( double mValue = 0 ) override;
bool dropZValue() override;
bool dropMValue() override;
void swapXy() override;
QgsGeometryCollection *toCurveType() const override SIP_FACTORY;
#ifndef SIP_RUN
void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
/**
* Cast the \a geom to a QgsGeometryCollection.
* Should be used by qgsgeometry_cast<QgsGeometryCollection *>( geometry ).
*
* \note Not available in Python. Objects will be automatically be converted to the appropriate target type.
* \since QGIS 3.0
*/
inline const QgsGeometryCollection *cast( const QgsAbstractGeometry *geom ) const
{
if ( geom && QgsWkbTypes::isMultiType( geom->wkbType() ) )
return static_cast<const QgsGeometryCollection *>( geom );
return nullptr;
}
#endif
QgsGeometryCollection *createEmptyWithSameType() const override SIP_FACTORY;
protected:
int childCount() const override;
QgsAbstractGeometry *childGeometry( int index ) const override;
protected:
QVector< QgsAbstractGeometry * > mGeometries;
/**
* Returns whether child type names are omitted from Wkt representations of the collection
* \since QGIS 2.12
*/
virtual bool wktOmitChildType() const;
/**
* Reads a collection from a WKT string.
*/
bool fromCollectionWkt( const QString &wkt, const QVector<QgsAbstractGeometry *> &subtypes, const QString &defaultChildWkbType = QString() );
QgsRectangle calculateBoundingBox() const override;
void clearCache() const override;
private:
mutable QgsRectangle mBoundingBox;
};
// clazy:excludeall=qstring-allocations
#endif // QGSGEOMETRYCOLLECTIONV2_H