QGIS API Documentation 4.1.0-Master (31622b25bb0)
Loading...
Searching...
No Matches
qgsabstractgeometry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsabstractgeometry.h
3 -------------------------------------------------------------------
4Date : 04 Sept 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 QGSABSTRACTGEOMETRYV2
17#define QGSABSTRACTGEOMETRYV2
18
19#include <array>
20#include <functional>
21#include <type_traits>
22
23#include "qgis.h"
24#include "qgis_core.h"
25#include "qgswkbptr.h"
26#include "qgswkbtypes.h"
27
28#include <QSet>
29#include <QString>
30
31#ifndef SIP_RUN
32#include <nlohmann/json_fwd.hpp>
33using namespace nlohmann;
34#endif
35
36class QgsMapToPixel;
37class QgsCurve;
38class QgsMultiCurve;
39class QgsMultiPoint;
40
41struct QgsVertexId;
43class QPainter;
44class QDomDocument;
45class QDomElement;
48class QgsConstWkbPtr;
49class QPainterPath;
51class QgsFeedback;
53class QgsPoint;
54class QgsRectangle;
55class QgsBox3D;
56
57typedef QVector< QgsPoint > QgsPointSequence;
58#ifndef SIP_RUN
59typedef QVector< QgsPointSequence > QgsRingSequence;
60typedef QVector< QgsRingSequence > QgsCoordinateSequence;
61#else
62typedef QVector< QVector< QgsPoint > > QgsRingSequence;
63typedef QVector< QVector< QVector< QgsPoint > > > QgsCoordinateSequence;
64#endif
65
66
81class CORE_EXPORT QgsAbstractGeometry
82{
83 // clang-format off
84
85#ifdef SIP_RUN
87 if ( qgsgeometry_cast<QgsPoint *>( sipCpp ) != nullptr )
88 sipType = sipType_QgsPoint;
89 else if ( qgsgeometry_cast<QgsLineString *>( sipCpp ) != nullptr )
90 sipType = sipType_QgsLineString;
91 else if ( qgsgeometry_cast<QgsCircularString *>( sipCpp ) != nullptr )
92 sipType = sipType_QgsCircularString;
93 else if ( qgsgeometry_cast<QgsCompoundCurve *>( sipCpp ) != nullptr )
94 sipType = sipType_QgsCompoundCurve;
95 else if ( qgsgeometry_cast<QgsNurbsCurve *>( sipCpp ) != nullptr )
96 sipType = sipType_QgsNurbsCurve;
97 else if ( qgsgeometry_cast<QgsTriangle *>( sipCpp ) != nullptr )
98 sipType = sipType_QgsTriangle;
99 else if ( qgsgeometry_cast<QgsPolygon *>( sipCpp ) != nullptr )
100 sipType = sipType_QgsPolygon;
101 else if ( qgsgeometry_cast<QgsCurvePolygon *>( sipCpp ) != nullptr )
102 sipType = sipType_QgsCurvePolygon;
103 else if ( qgsgeometry_cast<QgsTriangulatedSurface *>( sipCpp ) != nullptr )
104 sipType = sipType_QgsTriangulatedSurface;
105 else if ( qgsgeometry_cast<QgsPolyhedralSurface *>( sipCpp ) != nullptr )
106 sipType = sipType_QgsPolyhedralSurface;
107 else if ( qgsgeometry_cast<QgsSurface *>( sipCpp ) != nullptr )
108 sipType = sipType_QgsSurface;
109 else if ( qgsgeometry_cast<QgsMultiPoint *>( sipCpp ) != nullptr )
110 sipType = sipType_QgsMultiPoint;
111 else if ( qgsgeometry_cast<QgsMultiLineString *>( sipCpp ) != nullptr )
112 sipType = sipType_QgsMultiLineString;
113 else if ( qgsgeometry_cast<QgsMultiPolygon *>( sipCpp ) != nullptr )
114 sipType = sipType_QgsMultiPolygon;
115 else if ( qgsgeometry_cast<QgsMultiSurface *>( sipCpp ) != nullptr )
116 sipType = sipType_QgsMultiSurface;
117 else if ( qgsgeometry_cast<QgsMultiCurve *>( sipCpp ) != nullptr )
118 sipType = sipType_QgsMultiCurve;
119 else if ( qgsgeometry_cast<QgsGeometryCollection *>( sipCpp ) != nullptr )
120 sipType = sipType_QgsGeometryCollection;
121 else
122 sipType = 0;
123 SIP_END
124#endif
125
126 Q_GADGET
127
128 public:
129
146 Q_ENUM( SegmentationToleranceType )
147
148
150 {
151
155 XY = 0,
156
161 };
163
164 // clang-format on
165
167 virtual ~QgsAbstractGeometry() = default;
169 QgsAbstractGeometry &operator=( const QgsAbstractGeometry &geom );
170
171 // === WARNING ===
172 // implementation of `QgsAbstractGeometry::operator==` are mainly delegated to `fuzzyEquals` functions if the default tolerance/epsilon value is changed, documentation must be updaded accordingly and also changed in expression helper files (resources/function_help/json)
173 virtual bool operator==( const QgsAbstractGeometry &other ) const = 0;
174 virtual bool operator!=( const QgsAbstractGeometry &other ) const = 0;
175
186 virtual bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const = 0;
187
201 virtual bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const = 0;
202
207
213 virtual int compareTo( const QgsAbstractGeometry *other ) const;
214
218 virtual void clear() = 0;
219
223 virtual QgsRectangle boundingBox() const;
224
230 virtual QgsBox3D boundingBox3D() const = 0;
231
232 //mm-sql interface
233
238 virtual int dimension() const = 0;
239
245 virtual QString geometryType() const = 0;
246
247 // clang-format off
253 inline Qgis::WkbType wkbType() const SIP_HOLDGIL { return mWkbType; }
254 // clang-format on
255
261 QString wktTypeStr() const;
262
267 bool is3D() const SIP_HOLDGIL
268 {
269 return QgsWkbTypes::hasZ( mWkbType );
270 }
271
277 {
278 return QgsWkbTypes::hasM( mWkbType );
279 }
280
287
297 virtual void normalize() = 0;
298
299 //import
300
306 virtual bool fromWkb( QgsConstWkbPtr &wkb ) = 0;
307
312 virtual bool fromWkt( const QString &wkt ) = 0;
313
314 //export
315
325 Q_DECLARE_FLAGS( WkbFlags, WkbFlag )
326
327
335
346 virtual QByteArray asWkb( WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const = 0;
347
356 virtual QString asWkt( int precision = 17 ) const = 0;
357
369 virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const = 0;
370
382 virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const = 0;
383
393 QString asJson( int precision = 17 );
394
405 virtual json asJsonObject( int precision = 17 ) SIP_SKIP const;
406
411 virtual QString asKml( int precision = 17 ) const = 0;
412
413
414 //render pipeline
415
426 virtual void transform( const QgsCoordinateTransform &ct, Qgis::TransformDirection d = Qgis::TransformDirection::Forward, bool transformZ = false ) SIP_THROW( QgsCsException ) = 0;
427
434 virtual void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0,
435 double mTranslate = 0.0, double mScale = 1.0 ) = 0;
436
441 virtual void draw( QPainter &p ) const = 0;
442
451 virtual QPainterPath asQPainterPath() const = 0;
452
462 virtual int vertexNumberFromVertexId( QgsVertexId id ) const = 0;
463
471 virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const = 0;
472
476 virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const = 0;
477
483
487 virtual int nCoordinates() const;
488
492 virtual QgsPoint vertexAt( QgsVertexId id ) const = 0;
493
506 virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT,
507 QgsVertexId &vertexAfter SIP_OUT,
508 int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const = 0;
509
510 //low-level editing
511
520 virtual bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) = 0;
521
530 virtual bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) = 0;
531
539 virtual bool deleteVertex( QgsVertexId position ) = 0;
540
550 virtual bool deleteVertices( const QSet<QgsVertexId> &positions ) = 0;
551
556 virtual bool hasVertex( QgsVertexId position ) const = 0;
557
570 virtual double length() const;
571
584 virtual double perimeter() const;
585
599 virtual double area() const;
600
611 virtual double area3D() const;
612
620 virtual double segmentLength( QgsVertexId startVertex ) const = 0;
621
623 virtual QgsPoint centroid() const;
624
628 virtual bool isEmpty() const;
629
633 virtual bool hasCurvedSegments() const;
634
643 virtual bool boundingBoxIntersects( const QgsRectangle &rectangle ) const SIP_HOLDGIL;
644
653 virtual bool boundingBoxIntersects( const QgsBox3D &box3d ) const SIP_HOLDGIL;
654
661 virtual QgsAbstractGeometry *segmentize( double tolerance = M_PI / 180., SegmentationToleranceType toleranceType = MaximumAngle ) const SIP_FACTORY;
662
670
693 virtual QgsAbstractGeometry *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const = 0 SIP_FACTORY;
694
707 virtual QgsAbstractGeometry *simplifyByDistance( double tolerance ) const = 0 SIP_FACTORY;
708
728 virtual bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) = 0;
729
737 virtual double vertexAngle( QgsVertexId vertex ) const = 0;
738
742 virtual int vertexCount( int part = 0, int ring = 0 ) const = 0;
743
747 virtual int ringCount( int part = 0 ) const = 0;
748
754 virtual int partCount() const = 0;
755
763 virtual bool addZValue( double zValue = 0 ) = 0;
764
772 virtual bool addMValue( double mValue = 0 ) = 0;
773
780 virtual bool dropZValue() = 0;
781
788 virtual bool dropMValue() = 0;
789
796 virtual void swapXy() = 0;
797
802 virtual bool convertTo( Qgis::WkbType type );
803
823
835 virtual bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const = 0;
836
850 virtual bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = nullptr ) = 0;
851
852#ifndef SIP_RUN
853
863 virtual void filterVertices( const std::function< bool( const QgsPoint & ) > &filter );
864
879 virtual void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform );
880
886 class CORE_EXPORT part_iterator
887 {
888 private:
889
890 int mIndex = 0;
891 QgsAbstractGeometry *mGeometry = nullptr;
892
893 public:
895 part_iterator() = default;
896
898 part_iterator( QgsAbstractGeometry *g, int index );
899
905
908
911
913 int partNumber() const;
914
915 bool operator==( part_iterator other ) const;
916 bool operator!=( part_iterator other ) const { return !( *this == other ); }
917 };
918
928 {
929 return part_iterator( this, 0 );
930 }
931
940 part_iterator parts_end();
941
949 QgsGeometryConstPartIterator parts() const;
950
956 class CORE_EXPORT const_part_iterator
957 {
958 private:
959
960 int mIndex = 0;
961 const QgsAbstractGeometry *mGeometry = nullptr;
962
963 public:
966
968 const_part_iterator( const QgsAbstractGeometry *g, int index );
969
975
978
980 const QgsAbstractGeometry *operator*() const;
981
983 int partNumber() const;
984
985 bool operator==( const_part_iterator other ) const;
986 bool operator!=( const_part_iterator other ) const { return !( *this == other ); }
987 };
988
997 {
998 return const_part_iterator( this, 0 );
999 }
1000
1008 const_part_iterator const_parts_end() const;
1009
1010
1015 class CORE_EXPORT vertex_iterator
1016 {
1017 private:
1018
1024 struct Level
1025 {
1026 const QgsAbstractGeometry *g = nullptr;
1027 int index = 0;
1028
1029 bool operator==( const Level &other ) const;
1030 };
1031
1032 std::array<Level, 3> levels;
1033 int depth = -1;
1034
1035 void digDown();
1036
1037 public:
1039 vertex_iterator() = default;
1040
1042 vertex_iterator( const QgsAbstractGeometry *g, int index );
1043
1049
1052
1054 QgsPoint operator*() const;
1055
1057 QgsVertexId vertexId() const;
1058
1059 bool operator==( const vertex_iterator &other ) const;
1060 bool operator!=( const vertex_iterator &other ) const { return !( *this == other ); }
1061 };
1062
1071 {
1072 return vertex_iterator( this, 0 );
1073 }
1074
1083 {
1084 return vertex_iterator( this, childCount() );
1085 }
1086#endif
1087
1122
1123
1146 QgsVertexIterator vertices() const;
1147
1154
1155 protected:
1156
1163 int sortIndex() const;
1164
1175 virtual int compareToSameClass( const QgsAbstractGeometry *other ) const = 0;
1176
1181 virtual bool hasChildGeometries() const;
1182
1187 virtual int childCount() const { return 0; }
1188
1193 virtual QgsAbstractGeometry *childGeometry( int index ) const { Q_UNUSED( index ) return nullptr; }
1194
1199 virtual QgsPoint childPoint( int index ) const;
1200
1201 protected:
1203
1207 void setZMTypeFromSubGeometry( const QgsAbstractGeometry *subggeom, Qgis::WkbType baseGeomType );
1208
1213 virtual QgsRectangle calculateBoundingBox() const;
1214
1221 virtual QgsBox3D calculateBoundingBox3D() const;
1222
1226 virtual void clearCache() const;
1227
1228 friend class TestQgsGeometry;
1229};
1230
1231
1232#ifndef SIP_RUN
1233
1234template <class T>
1236{
1237 return std::remove_pointer<T>::type::cast( geom );
1238}
1239
1240template <class T>
1242{
1243 return std::remove_pointer<T>::type::cast( geom );
1244}
1245
1246#endif
1247
1248// clazy:excludeall=qstring-allocations
1249
1254class CORE_EXPORT QgsVertexIterator
1255{
1256 public:
1257
1259
1262 : g( geometry )
1263 , i( g->vertices_begin() )
1264 , n( g->vertices_end() )
1265 {
1266 }
1267
1269 bool hasNext() const
1270 {
1271 return g && g->vertices_end() != i;
1272 }
1273
1275 QgsPoint next();
1276
1277#ifdef SIP_RUN
1278// clang-format off
1279 QgsVertexIterator *__iter__();
1280 % MethodCode
1281 sipRes = sipCpp;
1282 % End
1283
1284 SIP_PYOBJECT __next__() SIP_TYPEHINT( QgsPoint );
1285 % MethodCode
1286 if ( sipCpp->hasNext() )
1287 sipRes = sipConvertFromType( new QgsPoint( sipCpp->next() ), sipType_QgsPoint, Py_None );
1288 else
1289 PyErr_SetString( PyExc_StopIteration, "" );
1290 % End
1291// clang-format on
1292#endif
1293
1294 private:
1295 const QgsAbstractGeometry *g = nullptr;
1297
1298};
1299
1306{
1307 public:
1308
1310
1313 : g( geometry )
1314 , i( g->parts_begin() )
1315 , n( g->parts_end() )
1316 {
1317 }
1318
1321 {
1322 return g && g->parts_end() != i;
1323 }
1324
1326 QgsAbstractGeometry *next();
1327
1328#ifdef SIP_RUN
1329// clang-format off
1330 QgsGeometryPartIterator *__iter__();
1331 % MethodCode
1332 sipRes = sipCpp;
1333 % End
1334
1335 SIP_PYOBJECT __next__() SIP_TYPEHINT( QgsAbstractGeometry );
1336 % MethodCode
1337 if ( sipCpp->hasNext() )
1338 sipRes = sipConvertFromType( sipCpp->next(), sipType_QgsAbstractGeometry, NULL );
1339 else
1340 PyErr_SetString( PyExc_StopIteration, "" );
1341 % End
1342// clang-format on
1343#endif
1344
1345 private:
1346 QgsAbstractGeometry *g = nullptr;
1348
1349};
1350
1351
1358{
1359 public:
1360
1362
1365 : g( geometry )
1366 , i( g->const_parts_begin() )
1367 , n( g->const_parts_end() )
1368 {
1369 }
1370
1373 {
1374 return g && g->const_parts_end() != i;
1375 }
1376
1378 const QgsAbstractGeometry *next();
1379
1380#ifdef SIP_RUN
1381// clang-format off
1382 QgsGeometryConstPartIterator *__iter__();
1383 % MethodCode
1384 sipRes = sipCpp;
1385 % End
1386
1387 SIP_PYOBJECT __next__() SIP_TYPEHINT( QgsAbstractGeometry );
1388 % MethodCode
1389 if ( sipCpp->hasNext() )
1390 sipRes = sipConvertFromType( const_cast< QgsAbstractGeometry * >( sipCpp->next() ), sipType_QgsAbstractGeometry, NULL );
1391 else
1392 PyErr_SetString( PyExc_StopIteration, "" );
1393 % End
1394// clang-format on
1395#endif
1396
1397 private:
1398 const QgsAbstractGeometry *g = nullptr;
1400
1401};
1402
1404
1405#endif //QGSABSTRACTGEOMETRYV2
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ Unknown
Unknown.
Definition qgis.h:295
An abstract base class for classes which transform geometries by transforming input points to output ...
The part_iterator class provides an STL-style iterator for const references to geometry parts.
const_part_iterator & operator++()
The prefix ++ operator (++it) advances the iterator to the next part and returns an iterator to the n...
bool operator!=(const_part_iterator other) const
const_part_iterator()=default
Create invalid iterator.
int partNumber() const
Returns the part number of the current item.
The part_iterator class provides an STL-style iterator for geometry parts.
part_iterator & operator++()
The prefix ++ operator (++it) advances the iterator to the next part and returns an iterator to the n...
part_iterator()=default
Create invalid iterator.
bool operator!=(part_iterator other) const
int partNumber() const
Returns the part number of the current item.
The vertex_iterator class provides an STL-style iterator for vertices.
vertex_iterator()=default
Create invalid iterator.
bool operator!=(const vertex_iterator &other) const
vertex_iterator & operator++()
The prefix ++ operator (++it) advances the iterator to the next vertex and returns an iterator to the...
QgsVertexId vertexId() const
Returns vertex ID of the current item.
Abstract base class for all geometries.
virtual int ringCount(int part=0) const =0
Returns the number of rings of which this geometry is built.
virtual QgsAbstractGeometry * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0, bool removeRedundantPoints=false) const =0
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
virtual bool fromWkb(QgsConstWkbPtr &wkb)=0
Sets the geometry from a WKB string.
virtual bool moveVertex(QgsVertexId position, const QgsPoint &newPos)=0
Moves a vertex within the geometry.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
@ MaximumDifference
Maximum distance between an arbitrary point on the original curve and closest point on its approximat...
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices).
virtual int vertexNumberFromVertexId(QgsVertexId id) const =0
Returns the vertex number corresponding to a vertex id.
virtual bool convertTo(Qgis::WkbType type)
Converts the geometry to a specified type.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
virtual QgsBox3D calculateBoundingBox3D() const
Calculates the minimal 3D bounding box for the geometry.
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
virtual const QgsAbstractGeometry * simplifiedTypeRef() const
Returns a reference to the simplest lossless representation of this geometry, e.g.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
bool isMeasure() const
Returns true if the geometry contains m values.
QFlags< WkbFlag > WkbFlags
virtual QgsAbstractGeometry * simplifyByDistance(double tolerance) const =0
Simplifies the geometry by applying the Douglas Peucker simplification by distance algorithm.
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
virtual int childCount() const
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
virtual QgsRectangle boundingBox() const
Returns 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 isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const =0
Checks validity of the geometry, and returns true if the geometry is valid.
virtual bool hasVertex(QgsVertexId position) const =0
Returns true if the geometry contains a vertex matching the given position.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
AxisOrder
Axis order for GML generation.
@ XY
X comes before Y (or lon before lat).
@ YX
Y comes before X (or lat before lon).
virtual QgsBox3D boundingBox3D() const =0
Returns the 3D bounding box for the geometry.
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
int sortIndex() const
Returns the sort index for the geometry, used in the compareTo() method to compare geometries of diff...
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
virtual double perimeter() const
Returns the planar, 2-dimensional perimeter of the geometry.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual QByteArray asWkb(WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const =0
Returns a WKB representation of the geometry.
virtual double area3D() const
Returns the 3-dimensional surface area of the geometry.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual QgsAbstractGeometry * toCurveType() const =0
Returns the geometry converted to the more generic curve type.
virtual bool deleteVertices(const QSet< QgsVertexId > &positions)=0
Deletes vertices within the geometry.
virtual void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const =0
Returns the vertices adjacent to a specified vertex within a 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.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual bool insertVertex(QgsVertexId position, const QgsPoint &vertex)=0
Inserts a vertex into the geometry.
virtual void swapXy()=0
Swaps the x and y coordinates from the geometry.
QString asJson(int precision=17)
Returns a GeoJSON representation of the geometry as a QString.
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, Qgis::WkbType baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
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 fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const =0
Performs fuzzy comparison between this geometry and other using an epsilon.
virtual bool isEmpty() const
Returns true if the geometry is empty.
virtual bool fuzzyDistanceEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const =0
Performs fuzzy distance comparison between this geometry and other using an epsilon.
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 QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
virtual bool fromWkt(const QString &wkt)=0
Sets the geometry from a WKT string.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
virtual bool hasChildGeometries() const
Returns whether the geometry has any child geometries (false for point / curve, true otherwise).
virtual QPainterPath asQPainterPath() const =0
Returns the geometry represented as a QPainterPath.
virtual void transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection d=Qgis::TransformDirection::Forward, bool transformZ=false)=0
Transforms the geometry using a coordinate transform.
virtual bool boundingBoxIntersects(const QgsRectangle &rectangle) const
Returns true if the bounding box of this geometry intersects with a rectangle.
virtual void normalize()=0
Reorganizes the geometry into a normalized form (or "canonical" form).
vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
virtual bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
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...
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
@ FlagExportTrianglesAsPolygons
Triangles should be exported as polygon geometries.
@ FlagExportNanAsDoubleMin
Use -DOUBLE_MAX to represent NaN.
virtual QgsPoint centroid() const
Returns the centroid of the geometry.
virtual QgsAbstractGeometry * childGeometry(int index) const
Returns pointer to child geometry (for geometries with child geometries - i.e.
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
virtual int compareTo(const QgsAbstractGeometry *other) const
Comparator for sorting of geometry.
virtual QString asKml(int precision=17) const =0
Returns a KML representation 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().
const_part_iterator const_parts_begin() const
Returns STL-style iterator pointing to the const first part of the geometry.
QgsAbstractGeometry()=default
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
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...
part_iterator parts_begin()
Returns STL-style iterator pointing to the first part of the geometry.
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
virtual double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const =0
Searches for the closest segment of the geometry to a given point.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
A const WKB pointer.
Definition qgswkbptr.h:211
Handles coordinate transforms between two coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
Definition qgscurve.h:36
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Java-style iterator for const traversal of parts of a geometry.
QgsGeometryConstPartIterator(const QgsAbstractGeometry *geometry)
Constructs iterator for the given geometry.
bool hasNext() const
Find out whether there are more parts.
Java-style iterator for traversal of parts of a geometry.
QgsGeometryPartIterator()=default
bool hasNext() const
Find out whether there are more parts.
QgsGeometryPartIterator(QgsAbstractGeometry *geometry)
Constructs iterator for the given geometry.
Perform transforms between map coordinates and device coordinates.
Multi curve geometry collection.
Multi point geometry collection.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
A rectangle specified with double values.
Java-style iterator for traversal of vertices of a geometry.
bool hasNext() const
Find out whether there are more vertices.
QgsVertexIterator()=default
QgsVertexIterator(const QgsAbstractGeometry *geometry)
Constructs iterator for the given geometry.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:237
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:198
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:272
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_HOLDGIL
Definition qgis_sip.h:178
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_THROW(name,...)
Definition qgis_sip.h:210
#define SIP_END
Definition qgis_sip.h:215
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QVector< QgsRingSequence > QgsCoordinateSequence
QVector< QgsPointSequence > QgsRingSequence
QVector< QgsPoint > QgsPointSequence
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QgsMargins operator*(const QgsMargins &margins, double factor)
Returns a QgsMargins object that is formed by multiplying each component of the given margins by fact...
Definition qgsmargins.h:245
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:35