QGIS API Documentation 3.99.0-Master (a8882ad4560)
Loading...
Searching...
No Matches
qgsgeometry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometry.h - Geometry (stored as Open Geospatial Consortium WKB)
3 -------------------------------------------------------------------
4Date : 02 May 2005
5Copyright : (C) 2005 by Brendan Morley
6email : morb at ozemail dot com dot au
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 QGSGEOMETRY_H
17#define QGSGEOMETRY_H
18
19#include <climits>
20#include <functional>
21#include <limits>
22#include <memory>
23
24#include "qgis_core.h"
25#include "qgis_sip.h"
26#include "qgsabstractgeometry.h"
27#include "qgsfeatureid.h"
28#include "qgspoint.h"
29#include "qgspointxy.h"
30#include "qgsvertexid.h"
31
32#include <QDomDocument>
33#include <QJsonObject>
34#include <QSet>
35#include <QString>
36#include <QVector>
37
38#ifndef SIP_RUN
39#include <nlohmann/json_fwd.hpp>
40using namespace nlohmann;
41#endif
42
44class QgsVectorLayer;
45class QgsMapToPixel;
46class QPainter;
47class QgsPolygon;
48class QgsLineString;
50class QgsCurve;
51class QgsFeedback;
52
61typedef QVector<QgsPointXY> QgsPolylineXY;
62
69#ifndef SIP_RUN
71#else
72typedef QVector<QgsPoint> QgsPolyline;
73#endif
74
82#ifndef SIP_RUN
83typedef QVector<QgsPolyline> QgsMultiPolyline;
84#else
85typedef QVector<QVector< QgsPoint >> QgsMultiPolyline;
86#endif
87
89#ifndef SIP_RUN
90typedef QVector<QgsPolylineXY> QgsPolygonXY;
91#else
92typedef QVector<QVector<QgsPointXY>> QgsPolygonXY;
93#endif
94
96typedef QVector<QgsPointXY> QgsMultiPointXY;
97
99#ifndef SIP_RUN
100typedef QVector<QgsPolylineXY> QgsMultiPolylineXY;
101#else
102typedef QVector<QVector<QgsPointXY>> QgsMultiPolylineXY;
103#endif
104
106#ifndef SIP_RUN
107typedef QVector<QgsPolygonXY> QgsMultiPolygonXY;
108#else
109typedef QVector<QVector<QVector<QgsPointXY>>> QgsMultiPolygonXY;
110#endif
111
112class QgsRectangle;
113
114class QgsConstWkbPtr;
115
116struct QgsGeometryPrivate;
117
124class CORE_EXPORT QgsGeometryParameters
125{
126 public:
137 double gridSize() const { return mGridSize; }
138
149 void setGridSize( double size ) { mGridSize = size; }
150
151 private:
152 double mGridSize = -1;
153};
154
175class CORE_EXPORT QgsGeometry
176{
177 Q_GADGET
178 Q_PROPERTY( bool isNull READ isNull )
179 Q_PROPERTY( Qgis::GeometryType type READ type )
180
181 public:
183
185 QgsGeometry( const QgsGeometry & );
186
191 QgsGeometry &operator=( QgsGeometry const &rhs ) SIP_SKIP;
192
198
204 explicit QgsGeometry( std::unique_ptr< QgsAbstractGeometry > geom ) SIP_SKIP;
205
206 virtual ~QgsGeometry();
207
219
232
245
253 bool isNull() const SIP_HOLDGIL;
254
256 Q_INVOKABLE static QgsGeometry fromWkt( const QString &wkt );
258 static QgsGeometry fromPointXY( const QgsPointXY &point ) SIP_HOLDGIL;
259
265 static QgsGeometry fromPoint( const QgsPoint &point ) SIP_HOLDGIL;
266
268 static QgsGeometry fromMultiPointXY( const QgsMultiPointXY &multipoint );
269
280 static QgsGeometry fromPolylineXY( const QgsPolylineXY &polyline );
281
290 static QgsGeometry fromPolyline( const QgsPolyline &polyline );
291
295 static QgsGeometry fromMultiPolylineXY( const QgsMultiPolylineXY &multiline );
296
297#ifndef SIP_RUN
298
302#else
303
321#endif
322 static QgsGeometry fromPolygonXY( const QgsPolygonXY &polygon );
323
327 static QgsGeometry fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly );
328
330 static QgsGeometry fromRect( const QgsRectangle &rect ) SIP_HOLDGIL;
331
339 static QgsGeometry fromBox3D( const QgsBox3D &box ) SIP_HOLDGIL;
340
341
343 static QgsGeometry collectGeometry( const QVector<QgsGeometry> &geometries );
344
360 static QgsGeometry collectTinPatches( const QVector<QgsGeometry> &geometries );
361
377 static QgsGeometry createWedgeBuffer( const QgsPoint &center, double azimuth, double angularWidth, double outerRadius, double innerRadius = 0 );
378
392 static QgsGeometry createWedgeBufferFromAngles( const QgsPoint &center, double startAngle, double endAngle, double outerRadius, double innerRadius = 0 );
393
399 void fromWkb( unsigned char *wkb, int length ) SIP_SKIP;
400
404 void fromWkb( const QByteArray &wkb );
405
411
416 Qgis::GeometryType type() const SIP_HOLDGIL;
417
424 bool isEmpty() const SIP_HOLDGIL;
425
427 bool isMultipart() const SIP_HOLDGIL;
428
442 bool equals( const QgsGeometry &geometry ) const;
443
459 bool isGeosEqual( const QgsGeometry & ) const;
460
467 bool isGeosValid( Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const;
468
476 bool isSimple() const;
477
491 bool isAxisParallelRectangle( double maximumDeviation, bool simpleRectanglesOnly = false ) const;
492
505 double area() const;
506
521
535 double length() const;
536
544 double distance( const QgsGeometry &geom ) const;
545
546#ifndef SIP_RUN
547
548 // TODO QGIS 5: consider renaming vertices_begin, vertices_end, parts_begin, parts_end, etc
549 // to camelCase
550
555
560#endif
561
585
586#ifndef SIP_RUN
587
597
607
617
627#endif
628
667
701
718 double hausdorffDistance( const QgsGeometry &geom ) const;
719
737 double hausdorffDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const;
738
753 double frechetDistance( const QgsGeometry &geom ) const SIP_THROW( QgsNotSupportedException );
754
777 double frechetDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const SIP_THROW( QgsNotSupportedException );
778
791 QgsPointXY closestVertex( const QgsPointXY &point, int &closestVertexIndex SIP_OUT, int &previousVertexIndex SIP_OUT, int &nextVertexIndex SIP_OUT, double &sqrDist SIP_OUT ) const;
792
800 double distanceToVertex( int vertex ) const;
801
808 double angleAtVertex( int vertex ) const;
809
822 void adjacentVertices( int atVertex, int &beforeVertex SIP_OUT, int &afterVertex SIP_OUT ) const;
823
836 bool insertVertex( double x, double y, int beforeVertex );
837
850 bool insertVertex( const QgsPoint &point, int beforeVertex );
851
859 bool addTopologicalPoint( const QgsPoint &point, double snappingTolerance = 1e-8, double segmentSearchEpsilon = 1e-12 );
860
868 bool moveVertex( double x, double y, int atVertex );
869
877 bool moveVertex( const QgsPoint &p, int atVertex );
878
891 bool deleteVertex( int atVertex );
892
900 bool toggleCircularAtVertex( int atVertex );
901
907 QgsPoint vertexAt( int atVertex ) const;
908
914 double sqrDistToVertexAt( QgsPointXY &point SIP_IN, int atVertex ) const;
915
920 QgsGeometry nearestPoint( const QgsGeometry &other ) const;
921
931 QgsGeometry shortestLine( const QgsGeometry &other ) const;
932
939 double closestVertexWithContext( const QgsPointXY &point, int &atVertex SIP_OUT ) const;
940
952 double closestSegmentWithContext( const QgsPointXY &point, QgsPointXY &minDistPoint SIP_OUT, int &nextVertexIndex SIP_OUT, int *leftOrRightOfSegment SIP_OUT = nullptr, double epsilon = Qgis::DEFAULT_SEGMENT_EPSILON ) const;
953
959 Qgis::GeometryOperationResult addRing( const QVector<QgsPointXY> &ring );
960
967
975 Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) SIP_PYNAME( addPointsXY ) SIP_DEPRECATED;
976
984 Qgis::GeometryOperationResult addPartV2( const QVector<QgsPointXY> &points, Qgis::WkbType wkbType = Qgis::WkbType::Unknown ) SIP_PYNAME( addPointsXYV2 );
985
994
1003
1012
1021
1027 Qgis::GeometryOperationResult addPart( const QgsGeometry &newPart ) SIP_PYNAME( addPartGeometry );
1028
1034 QgsGeometry removeInteriorRings( double minimumAllowedArea = -1 ) const;
1035
1040 Qgis::GeometryOperationResult translate( double dx, double dy, double dz = 0.0, double dm = 0.0 );
1041
1057
1066 Qgis::GeometryOperationResult transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 );
1067
1074 Qgis::GeometryOperationResult rotate( double rotation, const QgsPointXY &center );
1075
1086 Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitGeometry( const QVector<QgsPointXY> &splitLine, QVector<QgsGeometry> &newGeometries, bool topological, QVector<QgsPointXY> &topologyTestPoints, bool splitFeature = true ) SIP_SKIP;
1087
1109 Qgis::GeometryOperationResult splitGeometry( const QgsPointSequence &splitLine, QVector<QgsGeometry> &newGeometries SIP_OUT, bool topological, QgsPointSequence &topologyTestPoints SIP_OUT, bool splitFeature = true, bool skipIntersectionTest SIP_PYARGREMOVE = false ) SIP_SKIP;
1110
1111
1112 /*
1113 This SIP code is to support overloaded methods of splitGeometry.
1114 When the deprecated method is removed in QGIS 5.0 this code can be dropped
1115 TODO QGIS 5 remove MethodCode
1116 */
1117#ifdef SIP_RUN
1118
1137 SIP_PYOBJECT splitGeometry( SIP_PYOBJECT splitLine SIP_TYPEHINT( List[Union[QgsPoint, QgsPointXY]] ), bool topological, bool splitFeature = true ) SIP_TYPEHINT( Tuple[Qgis.GeometryOperationResult, Union[List[QgsPoint], List[QgsPointXY]], Union[List[QgsPoint], List[QgsPointXY]]] );
1138 % MethodCode
1139 {
1140 int sipIsErr = 0;
1141 int state;
1142
1143 if ( PyList_Check( a0 ) && PyList_GET_SIZE( a0 ) )
1144 {
1145 PyObject *p0 = PyList_GetItem( a0, 0 );
1146 if ( sipCanConvertToType( p0, sipType_QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1147 {
1148 QVector<QgsGeometry> newGeometries;
1149 QVector<QgsPointXY> topologyTestPoints;
1150
1151 QVector<QgsPointXY> *splitLine = reinterpret_cast<QVector<QgsPointXY> *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1152 if ( !sipIsErr )
1153 {
1154 Qgis::GeometryOperationResult result = sipCpp->splitGeometry( *splitLine, newGeometries, a1, topologyTestPoints, a2 );
1155
1156 PyObject *o0 = sipConvertFromEnum( static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1157 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1158 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPointXY, Py_None );
1159
1160 sipRes = PyTuple_New( 3 );
1161 PyTuple_SET_ITEM( sipRes, 0, o0 );
1162 PyTuple_SET_ITEM( sipRes, 1, o1 );
1163 PyTuple_SET_ITEM( sipRes, 2, o2 );
1164 }
1165 sipReleaseType( splitLine, sipType_QVector_0100QgsPointXY, state );
1166 }
1167
1168 else if ( sipCanConvertToType( p0, sipType_QgsPoint, SIP_NOT_NONE ) && sipCanConvertToType( a0, sipType_QVector_0100QgsPoint, SIP_NOT_NONE ) )
1169 {
1170 QVector<QgsGeometry> newGeometries;
1171 QVector<QgsPoint> topologyTestPoints;
1172
1173 QVector<QgsPoint> *splitLine = reinterpret_cast<QVector<QgsPoint> *>( sipConvertToType( a0, sipType_QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1174 if ( !sipIsErr )
1175 {
1176 Qgis::GeometryOperationResult result = sipCpp->splitGeometry( *splitLine, newGeometries, a1, topologyTestPoints, a2 );
1177
1178 PyObject *o0 = sipConvertFromEnum( static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1179 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1180 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPoint, Py_None );
1181
1182 sipRes = PyTuple_New( 3 );
1183 PyTuple_SET_ITEM( sipRes, 0, o0 );
1184 PyTuple_SET_ITEM( sipRes, 1, o1 );
1185 PyTuple_SET_ITEM( sipRes, 2, o2 );
1186 }
1187 sipReleaseType( splitLine, sipType_QVector_0100QgsPoint, state );
1188 }
1189 else
1190 {
1191 sipIsErr = 1;
1192 PyErr_SetString( PyExc_TypeError, u"Could not convert first argument to a list of QgsPoint or QgsPointXY."_s.toUtf8().constData() );
1193 }
1194 }
1195 else
1196 {
1197 sipIsErr = 1;
1198 PyErr_SetString( PyExc_TypeError, u"First argument is not a list of points or is empty."_s.toUtf8().constData() );
1199 }
1200 }
1201 % End
1202#endif
1203
1215 Qgis::GeometryOperationResult splitGeometry( const QgsCurve *curve, QVector<QgsGeometry> &newGeometries SIP_OUT, bool preserveCircular, bool topological, QgsPointSequence &topologyTestPoints SIP_OUT, bool splitFeature = true );
1216
1221 Qgis::GeometryOperationResult reshapeGeometry( const QgsLineString &reshapeLineString );
1222
1228 int makeDifferenceInPlace( const QgsGeometry &other ) SIP_SKIP;
1229
1236 QgsGeometry makeDifference( const QgsGeometry &other ) const;
1237
1242 QgsRectangle boundingBox() const;
1243
1249 QgsBox3D boundingBox3D() const;
1250
1263 QgsGeometry orientedMinimumBoundingBox( double &area SIP_OUT, double &angle SIP_OUT, double &width SIP_OUT, double &height SIP_OUT ) const;
1264
1274 QgsGeometry orientedMinimumBoundingBox() const SIP_SKIP;
1275
1283 QgsGeometry minimalEnclosingCircle( QgsPointXY &center SIP_OUT, double &radius SIP_OUT, unsigned int segments = 36 ) const;
1284
1289 QgsGeometry minimalEnclosingCircle( unsigned int segments = 36 ) const SIP_SKIP;
1290
1298 QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
1299
1312 QgsGeometry triangularWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1313
1332 QgsGeometry triangularWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1333
1346 QgsGeometry squareWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1347
1366 QgsGeometry squareWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1367
1380 QgsGeometry roundWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1381
1400 QgsGeometry roundWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1401
1415 QgsGeometry applyDashPattern( const QVector< double > &pattern, Qgis::DashPatternLineEndingRule startRule = Qgis::DashPatternLineEndingRule::NoRule, Qgis::DashPatternLineEndingRule endRule = Qgis::DashPatternLineEndingRule::NoRule, Qgis::DashPatternSizeAdjustment adjustment = Qgis::DashPatternSizeAdjustment::ScaleBothDashAndGap, double patternOffset = 0 ) const;
1416
1428 QgsGeometry snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const;
1429
1449 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false );
1450
1460 bool intersects( const QgsRectangle &rectangle ) const;
1461
1476 bool intersects( const QgsGeometry &geometry ) const;
1477
1486 bool boundingBoxIntersects( const QgsRectangle &rectangle ) const;
1487
1496 bool boundingBoxIntersects( const QgsGeometry &geometry ) const;
1497
1501 bool contains( const QgsPointXY *p ) const;
1502
1508 bool contains( double x, double y ) const;
1509
1519 bool contains( const QgsGeometry &geometry ) const;
1520
1530 bool disjoint( const QgsGeometry &geometry ) const;
1531
1541 bool touches( const QgsGeometry &geometry ) const;
1542
1552 bool overlaps( const QgsGeometry &geometry ) const;
1553
1563 bool within( const QgsGeometry &geometry ) const;
1564
1574 bool crosses( const QgsGeometry &geometry ) const;
1575
1583 QgsGeometry buffer( double distance, int segments ) const;
1584
1596 QgsGeometry buffer( double distance, int segments, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit ) const;
1597
1605 QgsGeometry offsetCurve( double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit ) const;
1606
1621 QgsGeometry singleSidedBuffer( double distance, int segments, Qgis::BufferSide side, Qgis::JoinStyle joinStyle = Qgis::JoinStyle::Round, double miterLimit = 2.0 ) const;
1622
1640 QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const;
1641
1656 QgsGeometry variableWidthBufferByM( int segments ) const;
1657
1663 QgsGeometry extendLine( double startDistance, double endDistance ) const;
1664
1666 QgsGeometry simplify( double tolerance ) const;
1667
1676 QgsGeometry densifyByCount( int extraNodesPerSegment ) const;
1677
1691 QgsGeometry densifyByDistance( double distance ) const;
1692
1708 QgsGeometry convertToCurves( double distanceTolerance = 1e-8, double angleTolerance = 1e-8 ) const;
1709
1723 QgsGeometry centroid() const;
1724
1738 QgsGeometry pointOnSurface() const;
1739
1751 QgsGeometry poleOfInaccessibility( double precision, double *distanceToBoundary SIP_OUT = nullptr ) const;
1752
1776 QgsGeometry largestEmptyCircle( double tolerance, const QgsGeometry &boundary = QgsGeometry() ) const SIP_THROW( QgsNotSupportedException );
1777
1792 QgsGeometry minimumWidth() const SIP_THROW( QgsNotSupportedException );
1793
1815 double minimumClearance() const SIP_THROW( QgsNotSupportedException );
1816
1828 QgsGeometry minimumClearanceLine() const SIP_THROW( QgsNotSupportedException );
1829
1838 QgsGeometry convexHull() const;
1839
1853 QgsGeometry concaveHull( double targetPercent, bool allowHoles = false ) const SIP_THROW( QgsNotSupportedException );
1854
1869 QgsGeometry voronoiDiagram( const QgsGeometry &extent = QgsGeometry(), double tolerance = 0.0, bool edgesOnly = false ) const;
1870
1881 QgsGeometry delaunayTriangulation( double tolerance = 0.0, bool edgesOnly = false ) const;
1882
1895 QgsGeometry constrainedDelaunayTriangulation() const SIP_THROW( QgsNotSupportedException );
1896
1914 Qgis::CoverageValidityResult validateCoverage( double gapWidth, QgsGeometry *invalidEdges SIP_OUT = nullptr ) const SIP_THROW( QgsNotSupportedException );
1915
1936 QgsGeometry simplifyCoverageVW( double tolerance, bool preserveBoundary ) const SIP_THROW( QgsNotSupportedException );
1937
1949 QgsGeometry unionCoverage() const;
1950
1961 QgsGeometry node() const;
1962
1977 QgsGeometry sharedPaths( const QgsGeometry &other ) const;
1978
2000 QgsGeometry subdivide( int maxNodes = 256, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2001
2016 QgsGeometry interpolate( double distance ) const;
2017
2028 double lineLocatePoint( const QgsGeometry &point ) const;
2029
2038 double interpolateAngle( double distance ) const;
2039
2051 QgsGeometry intersection( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2052
2059 QgsGeometry clipped( const QgsRectangle &rectangle );
2060
2075 QgsGeometry combine( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2076
2087 QgsGeometry mergeLines( const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2088
2100 QgsGeometry difference( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2101
2113 QgsGeometry symDifference( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2114
2116 QgsGeometry extrude( double x, double y );
2117
2118#ifndef SIP_RUN
2119
2141 QVector< QgsPointXY > randomPointsInPolygon( int count, const std::function< bool( const QgsPointXY & ) > &acceptPoint, unsigned long seed = 0, QgsFeedback *feedback = nullptr, int maxTriesPerPoint = 0 ) const;
2142
2156 QVector< QgsPointXY > randomPointsInPolygon( int count, unsigned long seed = 0, QgsFeedback *feedback = nullptr ) const;
2158#else
2159
2173 SIP_PYOBJECT randomPointsInPolygon( int count, unsigned long seed = 0 ) const SIP_TYPEHINT( QgsPolylineXY );
2174 % MethodCode
2175 const Qgis::GeometryType type = sipCpp->type();
2176 if ( sipCpp->isNull() )
2177 {
2178 PyErr_SetString( PyExc_ValueError, u"Cannot generate points inside a null geometry."_s.toUtf8().constData() );
2179 sipIsErr = 1;
2180 }
2181 else if ( type != Qgis::GeometryType::Polygon )
2182 {
2183 PyErr_SetString( PyExc_TypeError, u"Cannot generate points inside a %1 geometry. Only Polygon types are permitted."_s.arg( QgsWkbTypes::displayString( sipCpp->wkbType() ) ).toUtf8().constData() );
2184 sipIsErr = 1;
2185 }
2186 else
2187 {
2188 const sipTypeDef *qvector_type = sipFindType( "QVector<QgsPointXY>" );
2189 sipRes = sipConvertFromNewType( new QVector< QgsPointXY >( sipCpp->randomPointsInPolygon( a0, a1 ) ), qvector_type, Py_None );
2190 }
2191 % End
2192
2193
2194#endif
2196
2204 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const;
2205
2212 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const;
2213
2219 Q_INVOKABLE QString asWkt( int precision = 17 ) const;
2220
2221#ifdef SIP_RUN
2222 SIP_PYOBJECT __repr__();
2223 % MethodCode
2224 QString str;
2225 if ( sipCpp->isNull() )
2226 str = u"<QgsGeometry: null>"_s;
2227 else
2228 {
2229 QString wkt = sipCpp->asWkt();
2230 if ( wkt.length() > 1000 )
2231 wkt = wkt.left( 1000 ) + u"..."_s;
2232 str = u"<QgsGeometry: %1>"_s.arg( wkt );
2233 }
2234 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
2235 % End
2236#endif
2237
2241 QString asJson( int precision = 17 ) const;
2242
2248 virtual json asJsonObject( int precision = 17 ) const SIP_SKIP;
2249
2286 QVector< QgsGeometry > coerceToType( Qgis::WkbType type, double defaultZ = 0, double defaultM = 0, bool avoidDuplicates = true ) const;
2287
2299 QgsGeometry convertToType( Qgis::GeometryType destType, bool destMultipart = false ) const;
2300
2301 /* Accessor functions for getting geometry data */
2302
2303#ifndef SIP_RUN
2304
2313 QgsPointXY asPoint() const;
2314#else
2315
2326 SIP_PYOBJECT asPoint() const SIP_TYPEHINT( QgsPointXY );
2327 % MethodCode
2328 if ( sipCpp->isNull() )
2329 {
2330 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a point."_s.toUtf8().constData() );
2331 sipIsErr = 1;
2332 }
2333 else
2334 {
2335 const QgsAbstractGeometry *geom = sipCpp->constGet();
2337 {
2338 PyErr_SetString( PyExc_TypeError, u"%1 geometry cannot be converted to a point. Only Point types are permitted."_s.arg( QgsWkbTypes::displayString( geom->wkbType() ) ).toUtf8().constData() );
2339 sipIsErr = 1;
2340 }
2341 else
2342 {
2343 sipRes = sipConvertFromNewType( new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
2344 }
2345 }
2346 % End
2347#endif
2348
2349#ifndef SIP_RUN
2350
2359 QgsPolylineXY asPolyline() const;
2360#else
2361
2373 SIP_PYOBJECT asPolyline() const SIP_TYPEHINT( QgsPolylineXY );
2374 % MethodCode
2375 const Qgis::WkbType type = sipCpp->wkbType();
2376 if ( sipCpp->isNull() )
2377 {
2378 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a polyline."_s.toUtf8().constData() );
2379 sipIsErr = 1;
2380 }
2382 {
2383 PyErr_SetString( PyExc_TypeError, u"%1 geometry cannot be converted to a polyline. Only single line or curve types are permitted."_s.arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2384 sipIsErr = 1;
2385 }
2386 else
2387 {
2388 const sipTypeDef *qvector_type = sipFindType( "QVector< QgsPointXY >" );
2389 sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
2390 }
2391 % End
2392#endif
2393
2394#ifndef SIP_RUN
2395
2404 QgsPolygonXY asPolygon() const;
2405#else
2406
2418 SIP_PYOBJECT asPolygon() const SIP_TYPEHINT( QgsPolygonXY );
2419 % MethodCode
2420 const Qgis::WkbType type = sipCpp->wkbType();
2421 if ( sipCpp->isNull() )
2422 {
2423 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a polygon."_s.toUtf8().constData() );
2424 sipIsErr = 1;
2425 }
2427 {
2428 PyErr_SetString( PyExc_TypeError, u"%1 geometry cannot be converted to a polygon. Only single polygon or curve polygon types are permitted."_s.arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2429 sipIsErr = 1;
2430 }
2431 else
2432 {
2433 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QgsPointXY>>" );
2434 sipRes = sipConvertFromNewType( new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
2435 }
2436 % End
2437#endif
2438
2439#ifndef SIP_RUN
2440
2448 QgsMultiPointXY asMultiPoint() const;
2449#else
2450
2461 SIP_PYOBJECT asMultiPoint() const SIP_TYPEHINT( QgsMultiPointXY );
2462 % MethodCode
2463 const Qgis::WkbType type = sipCpp->wkbType();
2464 if ( sipCpp->isNull() )
2465 {
2466 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a multipoint."_s.toUtf8().constData() );
2467 sipIsErr = 1;
2468 }
2470 {
2471 PyErr_SetString( PyExc_TypeError, u"%1 geometry cannot be converted to a multipoint. Only multipoint types are permitted."_s.arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2472 sipIsErr = 1;
2473 }
2474 else
2475 {
2476 const sipTypeDef *qvector_type = sipFindType( "QVector< QgsPointXY >" );
2477 sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
2478 }
2479 % End
2480#endif
2481
2482#ifndef SIP_RUN
2483
2492 QgsMultiPolylineXY asMultiPolyline() const;
2493#else
2494
2506 SIP_PYOBJECT asMultiPolyline() const SIP_TYPEHINT( QgsMultiPolylineXY );
2507 % MethodCode
2508 const Qgis::WkbType type = sipCpp->wkbType();
2509 if ( sipCpp->isNull() )
2510 {
2511 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a multilinestring."_s.toUtf8().constData() );
2512 sipIsErr = 1;
2513 }
2515 {
2516 PyErr_SetString( PyExc_TypeError, u"%1 geometry cannot be converted to a multilinestring. Only multi linestring or curves are permitted."_s.arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2517 sipIsErr = 1;
2518 }
2519 else
2520 {
2521 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QgsPointXY>>" );
2522 sipRes = sipConvertFromNewType( new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
2523 }
2524 % End
2525#endif
2526
2527#ifndef SIP_RUN
2528
2537 QgsMultiPolygonXY asMultiPolygon() const;
2538#else
2539
2551 SIP_PYOBJECT asMultiPolygon() const SIP_TYPEHINT( QgsMultiPolygonXY );
2552 % MethodCode
2553 const Qgis::WkbType type = sipCpp->wkbType();
2554 if ( sipCpp->isNull() )
2555 {
2556 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a multipolygon."_s.toUtf8().constData() );
2557 sipIsErr = 1;
2558 }
2560 {
2561 PyErr_SetString( PyExc_TypeError, u"%1 geometry cannot be converted to a multipolygon. Only multi polygon or curves are permitted."_s.arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2562 sipIsErr = 1;
2563 }
2564 else
2565 {
2566 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QVector<QgsPointXY>>>" );
2567 sipRes = sipConvertFromNewType( new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
2568 }
2569 % End
2570#endif
2571
2575 QVector<QgsGeometry> asGeometryCollection() const;
2576
2581 QPointF asQPointF() const SIP_HOLDGIL;
2582
2594 QPolygonF asQPolygonF() const SIP_HOLDGIL;
2595
2601 bool deleteRing( int ringNum, int partNum = 0 );
2602
2607 bool deletePart( int partNum );
2608
2617 bool convertToMultiType();
2618
2634 bool convertToCurvedMultiType();
2635
2645 bool convertToSingleType();
2646
2656 bool convertGeometryCollectionToSubclass( Qgis::GeometryType geomType );
2657
2669 Q_DECL_DEPRECATED int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers, const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) ) SIP_DEPRECATED;
2670
2682 Qgis::GeometryOperationResult avoidIntersectionsV2( const QList<QgsVectorLayer *> &avoidIntersectionsLayers, const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
2683
2704 QgsGeometry makeValid( Qgis::MakeValidMethod method = Qgis::MakeValidMethod::Linework, bool keepCollapsed = false ) const SIP_THROW( QgsNotSupportedException );
2705
2715 Qgis::AngularDirection polygonOrientation() const;
2716
2731
2746
2747
2762 QgsGeometry forceRHR() const;
2763
2774 QgsGeometry forcePolygonClockwise() const;
2775
2786 QgsGeometry forcePolygonCounterClockwise() const;
2787
2792 class CORE_EXPORT Error
2793 {
2794 public:
2796 : mMessage( u"none"_s )
2797 {}
2798
2799 explicit Error( const QString &m )
2800 : mMessage( m )
2801 {}
2802
2803 Error( const QString &m, const QgsPointXY &p )
2804 : mMessage( m )
2805 , mLocation( p )
2806 , mHasLocation( true ) {}
2807
2811 QString what() const;
2812
2816 QgsPointXY where() const;
2817
2821 bool hasWhere() const;
2822
2823#ifdef SIP_RUN
2824 SIP_PYOBJECT __repr__();
2825 % MethodCode
2826 QString str = u"<QgsGeometry.Error: %1>"_s.arg( sipCpp->what() );
2827 sipRes = PyUnicode_FromString( str.toUtf8().data() );
2828 % End
2829#endif
2830
2831 // TODO c++20 - replace with = default
2832 bool operator==( const QgsGeometry::Error &other ) const
2833 {
2834 return other.mMessage == mMessage && other.mHasLocation == mHasLocation && other.mLocation == mLocation;
2835 }
2836
2837 private:
2838 QString mMessage;
2839 QgsPointXY mLocation;
2840 bool mHasLocation = false;
2841 };
2842
2850 void validateGeometry( QVector<QgsGeometry::Error> &errors SIP_OUT, Qgis::GeometryValidationEngine method = Qgis::GeometryValidationEngine::QgisInternal, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const;
2851
2861 void normalize();
2862
2871 static QgsGeometry unaryUnion( const QVector<QgsGeometry> &geometries, const QgsGeometryParameters &parameters = QgsGeometryParameters() );
2872
2880 static QgsGeometry polygonize( const QVector<QgsGeometry> &geometries );
2881
2888 void convertToStraightSegment( double tolerance = M_PI / 180., QgsAbstractGeometry::SegmentationToleranceType toleranceType = QgsAbstractGeometry::MaximumAngle );
2889
2895 bool requiresConversionToStraightSegments() const;
2896
2901 void mapToPixel( const QgsMapToPixel &mtp );
2902
2907 void draw( QPainter &p ) const;
2908
2918 bool vertexIdFromVertexNr( int number, QgsVertexId &id SIP_OUT ) const;
2919
2930 int vertexNrFromVertexId( QgsVertexId id ) const;
2931
2938 QString lastError() const SIP_HOLDGIL;
2939
2949 void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) SIP_SKIP;
2950
2965 void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) SIP_SKIP;
2966
2971 static QgsGeometry fromQPointF( QPointF point ) SIP_HOLDGIL;
2972
2979 static QgsGeometry fromQPolygonF( const QPolygonF &polygon );
2980
2988 Q_DECL_DEPRECATED static QgsPolylineXY createPolylineFromQPolygonF( const QPolygonF &polygon ) SIP_DEPRECATED;
2989
2997 Q_DECL_DEPRECATED static QgsPolygonXY createPolygonFromQPolygonF( const QPolygonF &polygon ) SIP_DEPRECATED;
2998
2999#ifndef SIP_RUN
3000
3009 static bool compare( const QgsPolylineXY &p1, const QgsPolylineXY &p2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3010
3019 static bool compare( const QgsPolygonXY &p1, const QgsPolygonXY &p2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3020
3030 static bool compare( const QgsMultiPolygonXY &p1, const QgsMultiPolygonXY &p2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3031#else
3032
3051 static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3052 % MethodCode
3053 {
3054 sipRes = false;
3055 int state0;
3056 int state1;
3057 int sipIsErr = 0;
3058
3059 if ( PyList_Check( a0 ) && PyList_Check( a1 ) && PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
3060 {
3061 PyObject *o0 = PyList_GetItem( a0, 0 );
3062 PyObject *o1 = PyList_GetItem( a1, 0 );
3063 if ( o0 && o1 )
3064 {
3065 // compare polyline - polyline
3066 if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3067 {
3068 QgsPolylineXY *p0;
3069 QgsPolylineXY *p1;
3070 p0 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3071 p1 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3072 if ( !sipIsErr )
3073 {
3074 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3075 }
3076 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
3077 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
3078 }
3079 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) && PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
3080 {
3081 PyObject *oo0 = PyList_GetItem( o0, 0 );
3082 PyObject *oo1 = PyList_GetItem( o1, 0 );
3083 if ( oo0 && oo1 )
3084 {
3085 // compare polygon - polygon
3086 if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3087 {
3088 QgsPolygonXY *p0;
3089 QgsPolygonXY *p1;
3090 p0 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3091 p1 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3092 if ( !sipIsErr )
3093 {
3094 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3095 }
3096 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
3097 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
3098 }
3099 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) && PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
3100 {
3101 PyObject *ooo0 = PyList_GetItem( oo0, 0 );
3102 PyObject *ooo1 = PyList_GetItem( oo1, 0 );
3103 if ( ooo0 && ooo1 )
3104 {
3105 // compare multipolygon - multipolygon
3106 if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3107 {
3110 p0 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3111 p1 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3112 if ( !sipIsErr )
3113 {
3114 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3115 }
3116 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
3117 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
3118 }
3119 }
3120 }
3121 }
3122 }
3123 }
3124 }
3125 }
3126 % End
3127#endif
3128
3144 QgsGeometry smooth( unsigned int iterations = 1, double offset = 0.25, double minimumDistance = -1.0, double maxAngle = 180.0 ) const;
3145
3185 static QgsGeometryEngine *createGeometryEngine( const QgsAbstractGeometry *geometry, double precision = 0.0, Qgis::GeosCreationFlags flags = Qgis::GeosCreationFlag::SkipEmptyInteriorRings ) SIP_FACTORY;
3186
3192 static void convertPointList( const QVector<QgsPointXY> &input, QgsPointSequence &output );
3193
3199 static void convertPointList( const QgsPointSequence &input, QVector<QgsPointXY> &output );
3200
3202 operator QVariant() const
3203 {
3204 return QVariant::fromValue( *this );
3205 }
3206
3212 {
3213 Chamfer = 1,
3214 Fillet,
3215 };
3216#ifndef SIP_RUN
3217 Q_ENUM( ChamferFilletOperationType )
3218#endif
3219
3236 QgsGeometry fillet( int vertexIndex, double radius, int segments = 8 ) const;
3237
3256 static QgsGeometry fillet( const QgsPoint &segment1Start, const QgsPoint &segment1End, const QgsPoint &segment2Start, const QgsPoint &segment2End, double radius, int segments = 8 ) SIP_THROW( QgsInvalidArgumentException );
3257
3271 QgsGeometry chamfer( int vertexIndex, double distance1, double distance2 = -1.0 ) const;
3272
3291 static QgsGeometry chamfer( const QgsPoint &segment1Start, const QgsPoint &segment1End, const QgsPoint &segment2Start, const QgsPoint &segment2End, double distance1, double distance2 = -1.0 ) SIP_THROW( QgsInvalidArgumentException );
3292
3293
3294 private:
3295 QgsGeometryPrivate *d; //implicitly shared data pointer
3296
3298 mutable QString mLastError;
3299
3304 void detach();
3305
3310 void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
3311
3312 static void convertPolygon( const QgsPolygon &input, QgsPolygonXY &output );
3313
3315 QgsGeometry convertToPoint( bool destMultipart ) const;
3317 QgsGeometry convertToLine( bool destMultipart ) const;
3319 QgsGeometry convertToPolygon( bool destMultipart ) const;
3320
3332 std::unique_ptr< QgsLineString > smoothLine( const QgsLineString &line, unsigned int iterations = 1, double offset = 0.25, double minimumDistance = -1, double maxAngle = 180.0 ) const;
3333
3345 std::unique_ptr< QgsPolygon > smoothPolygon( const QgsPolygon &polygon, unsigned int iterations = 1, double offset = 0.25, double minimumDistance = -1, double maxAngle = 180.0 ) const;
3346
3347 QgsGeometry doChamferFillet( ChamferFilletOperationType op, int vertexIndex, double distance1, double distance2, int segments ) const;
3348
3350
3351}; // class QgsGeometry
3352
3354
3356CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsGeometry &geometry );
3358CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry );
3359
3360#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
@ CounterClockwise
Counter-clockwise direction.
Definition qgis.h:3481
@ Clockwise
Clockwise direction.
Definition qgis.h:3480
GeometryOperationResult
Success or failure of a geometry operation.
Definition qgis.h:2088
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
Definition qgis.h:2121
GeometryValidationEngine
Available engines for validating geometries.
Definition qgis.h:2130
@ QgisInternal
Use internal QgsGeometryValidator method.
Definition qgis.h:2131
@ SkipEmptyInteriorRings
Skip any empty polygon interior ring.
Definition qgis.h:2195
QFlags< GeosCreationFlag > GeosCreationFlags
Geos geometry creation behavior flags.
Definition qgis.h:2204
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:365
@ Point
Points.
Definition qgis.h:366
@ Line
Lines.
Definition qgis.h:367
@ Polygon
Polygons.
Definition qgis.h:368
@ Unknown
Unknown types.
Definition qgis.h:369
static const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
Definition qgis.h:6511
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
@ Point
Point.
Definition qgis.h:282
@ Unknown
Unknown.
Definition qgis.h:281
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition qgis.h:2717
@ Forward
Forward transform (from source to destination).
Definition qgis.h:2718
The part_iterator class provides an STL-style iterator for const references to geometry parts.
The part_iterator class provides an STL-style iterator for geometry parts.
The vertex_iterator class provides an STL-style iterator for vertices.
Abstract base class for all geometries.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices).
virtual const QgsAbstractGeometry * simplifiedTypeRef() const
Returns a reference to the simplest lossless representation of this geometry, e.g.
QFlags< WkbFlag > WkbFlags
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:42
Compound curve geometry type.
A const WKB pointer.
Definition qgswkbptr.h:139
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.
A geometry engine is a low-level representation of a QgsAbstractGeometry object, optimised for use wi...
Encapsulates parameters under which a geometry operation is performed.
double gridSize() const
Returns the grid size which will be used to snap vertices of a geometry.
void setGridSize(double size)
Sets the grid size which will be used to snap vertices of a geometry.
Java-style iterator for traversal of parts of a geometry.
A geometry error.
Error(const QString &m)
Error(const QString &m, const QgsPointXY &p)
bool operator==(const QgsGeometry::Error &other) const
A geometry is the spatial representation of a feature.
double closestSegmentWithContext(const QgsPointXY &point, QgsPointXY &minDistPoint, int &nextVertexIndex, int *leftOrRightOfSegment=nullptr, double epsilon=Qgis::DEFAULT_SEGMENT_EPSILON) const
Searches for the closest segment of geometry to the given point.
QVector< QgsPointXY > randomPointsInPolygon(int count, const std::function< bool(const QgsPointXY &) > &acceptPoint, unsigned long seed=0, QgsFeedback *feedback=nullptr, int maxTriesPerPoint=0) const
Returns a list of count random points generated inside a (multi)polygon geometry (if acceptPoint is s...
double hausdorffDistanceDensify(const QgsGeometry &geom, double densifyFraction) const
Returns the Hausdorff distance between this geometry and geom.
double area3D() const
Returns the 3-dimensional surface area of the geometry.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
void adjacentVertices(int atVertex, int &beforeVertex, int &afterVertex) const
Returns the indexes of the vertices before and after the given vertex index.
QVector< QgsPointXY > randomPointsInPolygon(int count, unsigned long seed=0, QgsFeedback *feedback=nullptr) const
Returns a list of count random points generated inside a (multi)polygon geometry.
bool deleteVertex(int atVertex)
Deletes the vertex at the given position number and item (first number is index 0).
double length() const
Returns the planar, 2-dimensional length of geometry.
static bool compare(const QgsPolylineXY &p1, const QgsPolylineXY &p2, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compares two polylines for equality within a specified tolerance.
QgsVertexIterator vertices() const
Returns a read-only, Java-style iterator for traversal of vertices of all the geometry,...
ChamferFilletOperationType
Privatly used in chamfer/fillet functions.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
static QgsGeometry collectTinPatches(const QVector< QgsGeometry > &geometries)
Collects all patches from a list of TIN or Triangle geometries into a single TIN geometry.
bool addTopologicalPoint(const QgsPoint &point, double snappingTolerance=1e-8, double segmentSearchEpsilon=1e-12)
Adds a vertex to the segment which intersect point but don't already have a vertex there.
QgsGeometry nearestPoint(const QgsGeometry &other) const
Returns the nearest (closest) point on this geometry to another geometry.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
static QgsGeometry fromMultiPolylineXY(const QgsMultiPolylineXY &multiline)
Creates a new geometry from a QgsMultiPolylineXY object.
double frechetDistance(const QgsGeometry &geom) const
Returns the Fréchet distance between this geometry and geom, restricted to discrete points for both g...
bool isAxisParallelRectangle(double maximumDeviation, bool simpleRectanglesOnly=false) const
Returns true if the geometry is a polygon that is almost an axis-parallel rectangle.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static QgsGeometry fromPolylineXY(const QgsPolylineXY &polyline)
Creates a new LineString geometry from a list of QgsPointXY points.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
QgsPointXY closestVertex(const QgsPointXY &point, int &closestVertexIndex, int &previousVertexIndex, int &nextVertexIndex, double &sqrDist) const
Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap ...
double distance(const QgsGeometry &geom) const
Returns the minimum distance between this geometry and another geometry.
static QgsGeometry fromMultiPointXY(const QgsMultiPointXY &multipoint)
Creates a new geometry from a QgsMultiPointXY object.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
friend class QgsInternalGeometryEngine
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsAbstractGeometry::part_iterator parts_begin()
Returns STL-style iterator pointing to the first part of the geometry.
bool equals(const QgsGeometry &geometry) const
Test if this geometry is exactly equal to another geometry.
bool isGeosValid(Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const
Checks validity of the geometry using GEOS.
bool insertVertex(double x, double y, int beforeVertex)
Insert a new vertex before the given vertex index, ring and item (first number is index 0) If the req...
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Qgis::GeometryOperationResult addRing(const QVector< QgsPointXY > &ring)
Adds a new ring to this geometry.
Qgis::GeometryType type
bool isSimple() const
Determines whether the geometry is simple (according to OGC definition), i.e.
static QgsGeometry fromPolyline(const QgsPolyline &polyline)
Creates a new LineString geometry from a list of QgsPoint points.
double area() const
Returns the planar, 2-dimensional area of the geometry.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
Qgis::AngularDirection polygonOrientation() const
Returns the orientation of the polygon.
double hausdorffDistance(const QgsGeometry &geom) const
Returns the Hausdorff distance between this geometry and geom.
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart(const QVector< QgsPointXY > &points, Qgis::GeometryType geomType=Qgis::GeometryType::Unknown)
Adds a new part to a the geometry.
QgsGeometryPartIterator parts()
Returns Java-style iterator for traversal of parts of the geometry.
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygonXY.
double sqrDistToVertexAt(QgsPointXY &point, int atVertex) const
Returns the squared Cartesian distance between the given point to the given vertex index (vertex at t...
void fromWkb(unsigned char *wkb, int length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
static QgsGeometry fromMultiPolygonXY(const QgsMultiPolygonXY &multipoly)
Creates a new geometry from a QgsMultiPolygonXY.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
bool isPolygonClockwise() const
Returns True if the Polygon is clockwise.
double distanceToVertex(int vertex) const
Returns the distance along this geometry from its first vertex to the specified vertex.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
QgsAbstractGeometry::part_iterator parts_end()
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
static QgsGeometry createWedgeBuffer(const QgsPoint &center, double azimuth, double angularWidth, double outerRadius, double innerRadius=0)
Creates a wedge shaped buffer from a center point.
double frechetDistanceDensify(const QgsGeometry &geom, double densifyFraction) const
Returns the Fréchet distance between this geometry and geom, restricted to discrete points for both g...
QgsGeometryConstPartIterator constParts() const
Returns Java-style iterator for traversal of parts of the geometry.
bool isPolygonCounterClockwise() const
Returns True if the Polygon is counter-clockwise.
Qgis::GeometryOperationResult addPartV2(const QVector< QgsPointXY > &points, Qgis::WkbType wkbType=Qgis::WkbType::Unknown)
Adds a new part to a the geometry.
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY &center)
Rotate this geometry around the Z axis.
Qgis::GeometryOperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
double angleAtVertex(int vertex) const
Returns the bisector angle for this geometry at the specified vertex.
double closestVertexWithContext(const QgsPointXY &point, int &atVertex) const
Searches for the closest vertex in this geometry to the given point.
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitGeometry(const QVector< QgsPointXY > &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QVector< QgsPointXY > &topologyTestPoints, bool splitFeature=true)
Splits this geometry according to a given line.
bool toggleCircularAtVertex(int atVertex)
Converts the vertex at the given position from/to circular.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.).
bool moveVertex(double x, double y, int atVertex)
Moves the vertex at the given position number and item (first number is index 0) to the given coordin...
bool isGeosEqual(const QgsGeometry &) const
Compares the geometry with another geometry using GEOS.
static QgsGeometry fromBox3D(const QgsBox3D &box)
Creates a new geometry from a QgsBox3D object Returns a 2D polygon geometry if the box is purely 2d,...
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
static QgsGeometry createWedgeBufferFromAngles(const QgsPoint &center, double startAngle, double endAngle, double outerRadius, double innerRadius=0)
Creates a wedge shaped buffer from a center point.
QgsGeometry removeInteriorRings(double minimumAllowedArea=-1) const
Removes the interior rings from a (multi)polygon geometry.
static QgsGeometry fromPoint(const QgsPoint &point)
Creates a new geometry from a QgsPoint object.
QgsGeometry shortestLine(const QgsGeometry &other) const
Returns the shortest line joining this geometry to another geometry.
Custom exception class when argument are invalid.
Line string geometry type, with support for z-dimension and m-values.
Perform transforms between map coordinates and device coordinates.
Custom exception class which is raised when an operation is not supported.
Represents a 2D point.
Definition qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Polygon geometry type.
Definition qgspolygon.h:33
A rectangle specified with double values.
Represents a vector layer which manages a vector based dataset.
Java-style iterator for traversal of vertices of a geometry.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static Q_INVOKABLE QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
static Q_INVOKABLE bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:240
#define SIP_IN
Definition qgis_sip.h:71
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_PYNAME(name)
Definition qgis_sip.h:89
#define SIP_PYARGREMOVE
Definition qgis_sip.h:159
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_HOLDGIL
Definition qgis_sip.h:179
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_THROW(name,...)
Definition qgis_sip.h:211
QVector< QgsPoint > QgsPointSequence
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition qgsgeometry.h:90
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
Definition qgsgeometry.h:96
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition qgsgeometry.h:61
QVector< QgsPolyline > QgsMultiPolyline
Multi polyline represented as a vector of polylines.
Definition qgsgeometry.h:83
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
Definition qgsgeometry.h:70
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30