QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsgeometrycollection.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometrycollection.h
3 -------------------------------------------------------------------
4Date : 28 Oct 2014
5Copyright : (C) 2014 by Marco Hugentobler
6email : 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 QGSGEOMETRYCOLLECTION_H
17#define QGSGEOMETRYCOLLECTION_H
18
19#include <QVector>
20
21
22#include "qgis_core.h"
23#include "qgis_sip.h"
24#include "qgsabstractgeometry.h"
25#include "qgsrectangle.h"
26#include "qgsbox3d.h"
27
28class QgsPoint;
29
30
38{
39 public:
40
41
46
49 ~QgsGeometryCollection() override;
50
51 bool operator==( const QgsAbstractGeometry &other ) const override;
52 bool operator!=( const QgsAbstractGeometry &other ) const override;
53
54 QgsGeometryCollection *clone() const override SIP_FACTORY;
55
60 {
61 return mGeometries.size();
62 }
63
64#ifdef SIP_RUN
65
69 int __len__() const;
70 % MethodCode
71 sipRes = sipCpp->numGeometries();
72 % End
73
75 int __bool__() const;
76 % MethodCode
77 sipRes = true;
78 % End
79#endif
80
81
88 {
89 return mGeometries.value( n );
90 }
91
92#ifndef SIP_RUN
93
98 QgsAbstractGeometry *geometryN( int n ) SIP_HOLDGIL;
99#else
100
106 SIP_PYOBJECT geometryN( int n ) SIP_TYPEHINT( QgsAbstractGeometry );
107 % MethodCode
108 if ( a0 < 0 || a0 >= sipCpp->numGeometries() )
109 {
110 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
111 sipIsErr = 1;
112 }
113 else
114 {
115 return sipConvertFromType( sipCpp->geometryN( a0 ), sipType_QgsAbstractGeometry, NULL );
116 }
117 % End
118#endif
119
120
121 //methods inherited from QgsAbstractGeometry
122 bool isEmpty() const override SIP_HOLDGIL;
123 int dimension() const override SIP_HOLDGIL;
124 QString geometryType() const override SIP_HOLDGIL;
125 void clear() override;
126 QgsGeometryCollection *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
127 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
128 QgsAbstractGeometry *boundary() const override SIP_FACTORY;
129 void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
130 int vertexNumberFromVertexId( QgsVertexId id ) const override;
131 bool boundingBoxIntersects( const QgsBox3D &box3d ) const override SIP_HOLDGIL;
132
141 void reserve( int size ) SIP_HOLDGIL;
142
144 virtual bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER );
145
151 virtual bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index );
152
153#ifndef SIP_RUN
154
160 virtual bool removeGeometry( int nr );
161#else
162
169 virtual bool removeGeometry( int nr );
170 % MethodCode
171 const int count = sipCpp->numGeometries();
172 if ( a0 < 0 || a0 >= count )
173 {
174 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
175 sipIsErr = 1;
176 }
177 else
178 {
179 return PyBool_FromLong( sipCpp->removeGeometry( a0 ) );
180 }
181 % End
182#endif
183
184 void normalize() final SIP_HOLDGIL;
185 void transform( const QgsCoordinateTransform &ct, Qgis::TransformDirection d = Qgis::TransformDirection::Forward, bool transformZ = false ) override SIP_THROW( QgsCsException );
186 void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
187
188 void draw( QPainter &p ) const override;
189 QPainterPath asQPainterPath() const override;
190
191 bool fromWkb( QgsConstWkbPtr &wkb ) override;
192 bool fromWkt( const QString &wkt ) override;
193
194 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
195 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
196 QString asWkt( int precision = 17 ) const override;
197 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
198 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
199 json asJsonObject( int precision = 17 ) const override SIP_SKIP;
200 QString asKml( int precision = 17 ) const override;
201
202 QgsBox3D boundingBox3D() const override;
203
204 QgsCoordinateSequence coordinateSequence() const override;
205 int nCoordinates() const override;
206
207 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;
208 bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
209
210 //low-level editing
211 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
212 bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
213 bool deleteVertex( QgsVertexId position ) override;
214
215 double length() const override SIP_HOLDGIL;
216 double area() const override SIP_HOLDGIL;
217 double perimeter() const override SIP_HOLDGIL;
218
219 bool hasCurvedSegments() const override SIP_HOLDGIL;
220
226 QgsAbstractGeometry *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
227
228 double vertexAngle( QgsVertexId vertex ) const override;
229 double segmentLength( QgsVertexId startVertex ) const override;
230 int vertexCount( int part = 0, int ring = 0 ) const override;
231 int ringCount( int part = 0 ) const override;
232 int partCount() const override;
233 QgsPoint vertexAt( QgsVertexId id ) const override;
234 bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
235
236 bool addZValue( double zValue = 0 ) override;
237 bool addMValue( double mValue = 0 ) override;
238 bool dropZValue() override;
239 bool dropMValue() override;
240 void swapXy() override;
241 QgsGeometryCollection *toCurveType() const override SIP_FACTORY;
242 const QgsAbstractGeometry *simplifiedTypeRef() const override SIP_HOLDGIL;
243
244 bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = nullptr ) override;
245
246#ifndef SIP_RUN
247 void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
248 void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
249
257 inline static const QgsGeometryCollection *cast( const QgsAbstractGeometry *geom )
258 {
259 if ( geom && QgsWkbTypes::isMultiType( geom->wkbType() ) )
260 return static_cast<const QgsGeometryCollection *>( geom );
261 return nullptr;
262 }
263#endif
264
265
266#ifdef SIP_RUN
267
278 SIP_PYOBJECT __getitem__( int index ) SIP_TYPEHINT( QgsAbstractGeometry );
279 % MethodCode
280 const int count = sipCpp->numGeometries();
281 if ( a0 < -count || a0 >= count )
282 {
283 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
284 sipIsErr = 1;
285 }
286 else if ( a0 >= 0 )
287 {
288 return sipConvertFromType( sipCpp->geometryN( a0 ), sipType_QgsAbstractGeometry, NULL );
289 }
290 else
291 {
292 return sipConvertFromType( sipCpp->geometryN( count + a0 ), sipType_QgsAbstractGeometry, NULL );
293 }
294 % End
295
306 void __delitem__( int index );
307 % MethodCode
308 const int count = sipCpp->numGeometries();
309 if ( a0 >= 0 && a0 < count )
310 sipCpp->removeGeometry( a0 );
311 else if ( a0 < 0 && a0 >= -count )
312 sipCpp->removeGeometry( count + a0 );
313 else
314 {
315 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
316 sipIsErr = 1;
317 }
318 % End
319
325 SIP_PYOBJECT __iter__() SIP_TYPEHINT( QgsGeometryPartIterator );
326 % MethodCode
327 sipRes = sipConvertFromNewType( new QgsGeometryPartIterator( sipCpp ), sipType_QgsGeometryPartIterator, Py_None );
328 % End
329#endif
330
332
333 protected:
334 int childCount() const override;
335 QgsAbstractGeometry *childGeometry( int index ) const override;
336 int compareToSameClass( const QgsAbstractGeometry *other ) const final;
337
338 protected:
339 QVector< QgsAbstractGeometry * > mGeometries;
340
345 virtual bool wktOmitChildType() const;
346
350 bool fromCollectionWkt( const QString &wkt, const QVector<QgsAbstractGeometry *> &subtypes, const QString &defaultChildWkbType = QString() );
351
352 QgsBox3D calculateBoundingBox3D() const override;
353 void clearCache() const override;
354
355 private:
356
357 mutable QgsBox3D mBoundingBox;
358 mutable bool mHasCachedValidity = false;
359 mutable QString mValidityFailureReason;
360};
361
362// clazy:excludeall=qstring-allocations
363
364#endif // QGSGEOMETRYCOLLECTION_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
An abstract base class for classes which transform geometries by transforming input points to output ...
Abstract base class for all geometries.
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 QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual bool operator!=(const QgsAbstractGeometry &other) const =0
virtual bool isEmpty() const
Returns true if the geometry is empty.
virtual void normalize()=0
Reorganizes the geometry into a normalized form (or "canonical" form).
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...
virtual bool operator==(const QgsAbstractGeometry &other) const =0
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:44
A const WKB pointer.
Definition qgswkbptr.h:138
Class for doing transforms between two map coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:45
static const QgsGeometryCollection * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsGeometryCollection.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
Java-style iterator for traversal of parts of a geometry.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
static bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
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 SIP_TYPEHINT(type)
Definition qgis_sip.h:227
#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:166
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_THROW(name,...)
Definition qgis_sip.h:198
QVector< QgsRingSequence > QgsCoordinateSequence
double closestSegment(const QgsPolylineXY &pl, const QgsPointXY &pt, int &vertexAfter, double epsilon)
Definition qgstracer.cpp:69
int precision
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:31