QGIS API Documentation 3.99.0-Master (d270888f95f)
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
38using namespace Qt::StringLiterals;
39
40#ifndef SIP_RUN
41#include <nlohmann/json_fwd.hpp>
42using namespace nlohmann;
43#endif
44
46class QgsVectorLayer;
47class QgsMapToPixel;
48class QPainter;
49class QgsPolygon;
50class QgsLineString;
52class QgsCurve;
53class QgsFeedback;
54
63typedef QVector<QgsPointXY> QgsPolylineXY;
64
71#ifndef SIP_RUN
73#else
74typedef QVector<QgsPoint> QgsPolyline;
75#endif
76
84#ifndef SIP_RUN
85typedef QVector<QgsPolyline> QgsMultiPolyline;
86#else
87typedef QVector<QVector< QgsPoint >> QgsMultiPolyline;
88#endif
89
91#ifndef SIP_RUN
92typedef QVector<QgsPolylineXY> QgsPolygonXY;
93#else
94typedef QVector<QVector<QgsPointXY>> QgsPolygonXY;
95#endif
96
98typedef QVector<QgsPointXY> QgsMultiPointXY;
99
101#ifndef SIP_RUN
102typedef QVector<QgsPolylineXY> QgsMultiPolylineXY;
103#else
104typedef QVector<QVector<QgsPointXY>> QgsMultiPolylineXY;
105#endif
106
108#ifndef SIP_RUN
109typedef QVector<QgsPolygonXY> QgsMultiPolygonXY;
110#else
111typedef QVector<QVector<QVector<QgsPointXY>>> QgsMultiPolygonXY;
112#endif
113
114class QgsRectangle;
115
116class QgsConstWkbPtr;
117
118struct QgsGeometryPrivate;
119
126class CORE_EXPORT QgsGeometryParameters
127{
128 public:
139 double gridSize() const { return mGridSize; }
140
151 void setGridSize( double size ) { mGridSize = size; }
152
153 private:
154 double mGridSize = -1;
155};
156
177class CORE_EXPORT QgsGeometry
178{
179 Q_GADGET
180 Q_PROPERTY( bool isNull READ isNull )
181 Q_PROPERTY( Qgis::GeometryType type READ type )
182
183 public:
185
187 QgsGeometry( const QgsGeometry & );
188
193 QgsGeometry &operator=( QgsGeometry const &rhs ) SIP_SKIP;
194
200
206 explicit QgsGeometry( std::unique_ptr< QgsAbstractGeometry > geom ) SIP_SKIP;
207
208 virtual ~QgsGeometry();
209
221
234
247
255 bool isNull() const SIP_HOLDGIL;
256
258 Q_INVOKABLE static QgsGeometry fromWkt( const QString &wkt );
260 static QgsGeometry fromPointXY( const QgsPointXY &point ) SIP_HOLDGIL;
261
267 static QgsGeometry fromPoint( const QgsPoint &point ) SIP_HOLDGIL;
268
270 static QgsGeometry fromMultiPointXY( const QgsMultiPointXY &multipoint );
271
282 static QgsGeometry fromPolylineXY( const QgsPolylineXY &polyline );
283
292 static QgsGeometry fromPolyline( const QgsPolyline &polyline );
293
297 static QgsGeometry fromMultiPolylineXY( const QgsMultiPolylineXY &multiline );
298
299#ifndef SIP_RUN
300
304#else
305
323#endif
324 static QgsGeometry fromPolygonXY( const QgsPolygonXY &polygon );
325
329 static QgsGeometry fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly );
330
332 static QgsGeometry fromRect( const QgsRectangle &rect ) SIP_HOLDGIL;
333
341 static QgsGeometry fromBox3D( const QgsBox3D &box ) SIP_HOLDGIL;
342
343
345 static QgsGeometry collectGeometry( const QVector<QgsGeometry> &geometries );
346
362 static QgsGeometry collectTinPatches( const QVector<QgsGeometry> &geometries );
363
379 static QgsGeometry createWedgeBuffer( const QgsPoint &center, double azimuth, double angularWidth, double outerRadius, double innerRadius = 0 );
380
394 static QgsGeometry createWedgeBufferFromAngles( const QgsPoint &center, double startAngle, double endAngle, double outerRadius, double innerRadius = 0 );
395
401 void fromWkb( unsigned char *wkb, int length ) SIP_SKIP;
402
406 void fromWkb( const QByteArray &wkb );
407
413
418 Qgis::GeometryType type() const SIP_HOLDGIL;
419
426 bool isEmpty() const SIP_HOLDGIL;
427
429 bool isMultipart() const SIP_HOLDGIL;
430
444 bool equals( const QgsGeometry &geometry ) const;
445
461 bool isGeosEqual( const QgsGeometry & ) const;
462
469 bool isGeosValid( Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const;
470
478 bool isSimple() const;
479
493 bool isAxisParallelRectangle( double maximumDeviation, bool simpleRectanglesOnly = false ) const;
494
507 double area() const;
508
523
537 double length() const;
538
546 double distance( const QgsGeometry &geom ) const;
547
548#ifndef SIP_RUN
549
550 // TODO QGIS 5: consider renaming vertices_begin, vertices_end, parts_begin, parts_end, etc
551 // to camelCase
552
557
562#endif
563
587
588#ifndef SIP_RUN
589
599
609
619
629#endif
630
669
703
720 double hausdorffDistance( const QgsGeometry &geom ) const;
721
739 double hausdorffDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const;
740
755 double frechetDistance( const QgsGeometry &geom ) const SIP_THROW( QgsNotSupportedException );
756
779 double frechetDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const SIP_THROW( QgsNotSupportedException );
780
793 QgsPointXY closestVertex( const QgsPointXY &point, int &closestVertexIndex SIP_OUT, int &previousVertexIndex SIP_OUT, int &nextVertexIndex SIP_OUT, double &sqrDist SIP_OUT ) const;
794
802 double distanceToVertex( int vertex ) const;
803
810 double angleAtVertex( int vertex ) const;
811
824 void adjacentVertices( int atVertex, int &beforeVertex SIP_OUT, int &afterVertex SIP_OUT ) const;
825
838 bool insertVertex( double x, double y, int beforeVertex );
839
852 bool insertVertex( const QgsPoint &point, int beforeVertex );
853
861 bool addTopologicalPoint( const QgsPoint &point, double snappingTolerance = 1e-8, double segmentSearchEpsilon = 1e-12 );
862
870 bool moveVertex( double x, double y, int atVertex );
871
879 bool moveVertex( const QgsPoint &p, int atVertex );
880
893 bool deleteVertex( int atVertex );
894
902 bool toggleCircularAtVertex( int atVertex );
903
909 QgsPoint vertexAt( int atVertex ) const;
910
916 double sqrDistToVertexAt( QgsPointXY &point SIP_IN, int atVertex ) const;
917
922 QgsGeometry nearestPoint( const QgsGeometry &other ) const;
923
933 QgsGeometry shortestLine( const QgsGeometry &other ) const;
934
941 double closestVertexWithContext( const QgsPointXY &point, int &atVertex SIP_OUT ) const;
942
954 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;
955
961 Qgis::GeometryOperationResult addRing( const QVector<QgsPointXY> &ring );
962
969
977 Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) SIP_PYNAME( addPointsXY ) SIP_DEPRECATED;
978
986 Qgis::GeometryOperationResult addPartV2( const QVector<QgsPointXY> &points, Qgis::WkbType wkbType = Qgis::WkbType::Unknown ) SIP_PYNAME( addPointsXYV2 );
987
996
1005
1014
1023
1029 Qgis::GeometryOperationResult addPart( const QgsGeometry &newPart ) SIP_PYNAME( addPartGeometry );
1030
1036 QgsGeometry removeInteriorRings( double minimumAllowedArea = -1 ) const;
1037
1042 Qgis::GeometryOperationResult translate( double dx, double dy, double dz = 0.0, double dm = 0.0 );
1043
1059
1068 Qgis::GeometryOperationResult transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 );
1069
1076 Qgis::GeometryOperationResult rotate( double rotation, const QgsPointXY &center );
1077
1088 Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitGeometry( const QVector<QgsPointXY> &splitLine, QVector<QgsGeometry> &newGeometries, bool topological, QVector<QgsPointXY> &topologyTestPoints, bool splitFeature = true ) SIP_SKIP;
1089
1111 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;
1112
1113
1114 /*
1115 This SIP code is to support overloaded methods of splitGeometry.
1116 When the deprecated method is removed in QGIS 5.0 this code can be dropped
1117 TODO QGIS 5 remove MethodCode
1118 */
1119#ifdef SIP_RUN
1120
1139 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]]] );
1140 % MethodCode
1141 {
1142 int sipIsErr = 0;
1143 int state;
1144
1145 if ( PyList_Check( a0 ) && PyList_GET_SIZE( a0 ) )
1146 {
1147 PyObject *p0 = PyList_GetItem( a0, 0 );
1148 if ( sipCanConvertToType( p0, sipType_QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1149 {
1150 QVector<QgsGeometry> newGeometries;
1151 QVector<QgsPointXY> topologyTestPoints;
1152
1153 QVector<QgsPointXY> *splitLine = reinterpret_cast<QVector<QgsPointXY> *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1154 if ( !sipIsErr )
1155 {
1156 Qgis::GeometryOperationResult result = sipCpp->splitGeometry( *splitLine, newGeometries, a1, topologyTestPoints, a2 );
1157
1158 PyObject *o0 = sipConvertFromEnum( static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1159 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1160 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPointXY, Py_None );
1161
1162 sipRes = PyTuple_New( 3 );
1163 PyTuple_SET_ITEM( sipRes, 0, o0 );
1164 PyTuple_SET_ITEM( sipRes, 1, o1 );
1165 PyTuple_SET_ITEM( sipRes, 2, o2 );
1166 }
1167 sipReleaseType( splitLine, sipType_QVector_0100QgsPointXY, state );
1168 }
1169
1170 else if ( sipCanConvertToType( p0, sipType_QgsPoint, SIP_NOT_NONE ) && sipCanConvertToType( a0, sipType_QVector_0100QgsPoint, SIP_NOT_NONE ) )
1171 {
1172 QVector<QgsGeometry> newGeometries;
1173 QVector<QgsPoint> topologyTestPoints;
1174
1175 QVector<QgsPoint> *splitLine = reinterpret_cast<QVector<QgsPoint> *>( sipConvertToType( a0, sipType_QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1176 if ( !sipIsErr )
1177 {
1178 Qgis::GeometryOperationResult result = sipCpp->splitGeometry( *splitLine, newGeometries, a1, topologyTestPoints, a2 );
1179
1180 PyObject *o0 = sipConvertFromEnum( static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1181 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1182 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPoint, Py_None );
1183
1184 sipRes = PyTuple_New( 3 );
1185 PyTuple_SET_ITEM( sipRes, 0, o0 );
1186 PyTuple_SET_ITEM( sipRes, 1, o1 );
1187 PyTuple_SET_ITEM( sipRes, 2, o2 );
1188 }
1189 sipReleaseType( splitLine, sipType_QVector_0100QgsPoint, state );
1190 }
1191 else
1192 {
1193 sipIsErr = 1;
1194 PyErr_SetString( PyExc_TypeError, u"Could not convert first argument to a list of QgsPoint or QgsPointXY."_s.toUtf8().constData() );
1195 }
1196 }
1197 else
1198 {
1199 sipIsErr = 1;
1200 PyErr_SetString( PyExc_TypeError, u"First argument is not a list of points or is empty."_s.toUtf8().constData() );
1201 }
1202 }
1203 % End
1204#endif
1205
1217 Qgis::GeometryOperationResult splitGeometry( const QgsCurve *curve, QVector<QgsGeometry> &newGeometries SIP_OUT, bool preserveCircular, bool topological, QgsPointSequence &topologyTestPoints SIP_OUT, bool splitFeature = true );
1218
1223 Qgis::GeometryOperationResult reshapeGeometry( const QgsLineString &reshapeLineString );
1224
1230 int makeDifferenceInPlace( const QgsGeometry &other ) SIP_SKIP;
1231
1238 QgsGeometry makeDifference( const QgsGeometry &other ) const;
1239
1244 QgsRectangle boundingBox() const;
1245
1251 QgsBox3D boundingBox3D() const;
1252
1265 QgsGeometry orientedMinimumBoundingBox( double &area SIP_OUT, double &angle SIP_OUT, double &width SIP_OUT, double &height SIP_OUT ) const;
1266
1276 QgsGeometry orientedMinimumBoundingBox() const SIP_SKIP;
1277
1285 QgsGeometry minimalEnclosingCircle( QgsPointXY &center SIP_OUT, double &radius SIP_OUT, unsigned int segments = 36 ) const;
1286
1291 QgsGeometry minimalEnclosingCircle( unsigned int segments = 36 ) const SIP_SKIP;
1292
1300 QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
1301
1314 QgsGeometry triangularWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1315
1334 QgsGeometry triangularWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1335
1348 QgsGeometry squareWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1349
1368 QgsGeometry squareWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1369
1382 QgsGeometry roundWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1383
1402 QgsGeometry roundWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1403
1417 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;
1418
1430 QgsGeometry snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const;
1431
1451 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false );
1452
1462 bool intersects( const QgsRectangle &rectangle ) const;
1463
1478 bool intersects( const QgsGeometry &geometry ) const;
1479
1488 bool boundingBoxIntersects( const QgsRectangle &rectangle ) const;
1489
1498 bool boundingBoxIntersects( const QgsGeometry &geometry ) const;
1499
1503 bool contains( const QgsPointXY *p ) const;
1504
1510 bool contains( double x, double y ) const;
1511
1521 bool contains( const QgsGeometry &geometry ) const;
1522
1532 bool disjoint( const QgsGeometry &geometry ) const;
1533
1543 bool touches( const QgsGeometry &geometry ) const;
1544
1554 bool overlaps( const QgsGeometry &geometry ) const;
1555
1565 bool within( const QgsGeometry &geometry ) const;
1566
1576 bool crosses( const QgsGeometry &geometry ) const;
1577
1585 QgsGeometry buffer( double distance, int segments ) const;
1586
1598 QgsGeometry buffer( double distance, int segments, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit ) const;
1599
1607 QgsGeometry offsetCurve( double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit ) const;
1608
1623 QgsGeometry singleSidedBuffer( double distance, int segments, Qgis::BufferSide side, Qgis::JoinStyle joinStyle = Qgis::JoinStyle::Round, double miterLimit = 2.0 ) const;
1624
1642 QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const;
1643
1658 QgsGeometry variableWidthBufferByM( int segments ) const;
1659
1665 QgsGeometry extendLine( double startDistance, double endDistance ) const;
1666
1668 QgsGeometry simplify( double tolerance ) const;
1669
1678 QgsGeometry densifyByCount( int extraNodesPerSegment ) const;
1679
1693 QgsGeometry densifyByDistance( double distance ) const;
1694
1710 QgsGeometry convertToCurves( double distanceTolerance = 1e-8, double angleTolerance = 1e-8 ) const;
1711
1725 QgsGeometry centroid() const;
1726
1740 QgsGeometry pointOnSurface() const;
1741
1753 QgsGeometry poleOfInaccessibility( double precision, double *distanceToBoundary SIP_OUT = nullptr ) const;
1754
1778 QgsGeometry largestEmptyCircle( double tolerance, const QgsGeometry &boundary = QgsGeometry() ) const SIP_THROW( QgsNotSupportedException );
1779
1794 QgsGeometry minimumWidth() const SIP_THROW( QgsNotSupportedException );
1795
1817 double minimumClearance() const SIP_THROW( QgsNotSupportedException );
1818
1830 QgsGeometry minimumClearanceLine() const SIP_THROW( QgsNotSupportedException );
1831
1840 QgsGeometry convexHull() const;
1841
1855 QgsGeometry concaveHull( double targetPercent, bool allowHoles = false ) const SIP_THROW( QgsNotSupportedException );
1856
1871 QgsGeometry voronoiDiagram( const QgsGeometry &extent = QgsGeometry(), double tolerance = 0.0, bool edgesOnly = false ) const;
1872
1883 QgsGeometry delaunayTriangulation( double tolerance = 0.0, bool edgesOnly = false ) const;
1884
1897 QgsGeometry constrainedDelaunayTriangulation() const SIP_THROW( QgsNotSupportedException );
1898
1916 Qgis::CoverageValidityResult validateCoverage( double gapWidth, QgsGeometry *invalidEdges SIP_OUT = nullptr ) const SIP_THROW( QgsNotSupportedException );
1917
1938 QgsGeometry simplifyCoverageVW( double tolerance, bool preserveBoundary ) const SIP_THROW( QgsNotSupportedException );
1939
1951 QgsGeometry unionCoverage() const;
1952
1963 QgsGeometry node() const;
1964
1979 QgsGeometry sharedPaths( const QgsGeometry &other ) const;
1980
2002 QgsGeometry subdivide( int maxNodes = 256, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2003
2018 QgsGeometry interpolate( double distance ) const;
2019
2030 double lineLocatePoint( const QgsGeometry &point ) const;
2031
2040 double interpolateAngle( double distance ) const;
2041
2053 QgsGeometry intersection( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2054
2061 QgsGeometry clipped( const QgsRectangle &rectangle );
2062
2077 QgsGeometry combine( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2078
2089 QgsGeometry mergeLines( const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2090
2102 QgsGeometry difference( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2103
2115 QgsGeometry symDifference( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2116
2118 QgsGeometry extrude( double x, double y );
2119
2120#ifndef SIP_RUN
2121
2143 QVector< QgsPointXY > randomPointsInPolygon( int count, const std::function< bool( const QgsPointXY & ) > &acceptPoint, unsigned long seed = 0, QgsFeedback *feedback = nullptr, int maxTriesPerPoint = 0 ) const;
2144
2158 QVector< QgsPointXY > randomPointsInPolygon( int count, unsigned long seed = 0, QgsFeedback *feedback = nullptr ) const;
2160#else
2161
2175 SIP_PYOBJECT randomPointsInPolygon( int count, unsigned long seed = 0 ) const SIP_TYPEHINT( QgsPolylineXY );
2176 % MethodCode
2177 const Qgis::GeometryType type = sipCpp->type();
2178 if ( sipCpp->isNull() )
2179 {
2180 PyErr_SetString( PyExc_ValueError, u"Cannot generate points inside a null geometry."_s.toUtf8().constData() );
2181 sipIsErr = 1;
2182 }
2183 else if ( type != Qgis::GeometryType::Polygon )
2184 {
2185 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() );
2186 sipIsErr = 1;
2187 }
2188 else
2189 {
2190 const sipTypeDef *qvector_type = sipFindType( "QVector<QgsPointXY>" );
2191 sipRes = sipConvertFromNewType( new QVector< QgsPointXY >( sipCpp->randomPointsInPolygon( a0, a1 ) ), qvector_type, Py_None );
2192 }
2193 % End
2194
2195
2196#endif
2198
2206 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const;
2207
2214 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const;
2215
2221 Q_INVOKABLE QString asWkt( int precision = 17 ) const;
2222
2223#ifdef SIP_RUN
2224 SIP_PYOBJECT __repr__();
2225 % MethodCode
2226 QString str;
2227 if ( sipCpp->isNull() )
2228 str = u"<QgsGeometry: null>"_s;
2229 else
2230 {
2231 QString wkt = sipCpp->asWkt();
2232 if ( wkt.length() > 1000 )
2233 wkt = wkt.left( 1000 ) + u"..."_s;
2234 str = u"<QgsGeometry: %1>"_s.arg( wkt );
2235 }
2236 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
2237 % End
2238#endif
2239
2243 QString asJson( int precision = 17 ) const;
2244
2250 virtual json asJsonObject( int precision = 17 ) const SIP_SKIP;
2251
2288 QVector< QgsGeometry > coerceToType( Qgis::WkbType type, double defaultZ = 0, double defaultM = 0, bool avoidDuplicates = true ) const;
2289
2301 QgsGeometry convertToType( Qgis::GeometryType destType, bool destMultipart = false ) const;
2302
2303 /* Accessor functions for getting geometry data */
2304
2305#ifndef SIP_RUN
2306
2315 QgsPointXY asPoint() const;
2316#else
2317
2328 SIP_PYOBJECT asPoint() const SIP_TYPEHINT( QgsPointXY );
2329 % MethodCode
2330 if ( sipCpp->isNull() )
2331 {
2332 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a point."_s.toUtf8().constData() );
2333 sipIsErr = 1;
2334 }
2335 else
2336 {
2337 const QgsAbstractGeometry *geom = sipCpp->constGet();
2339 {
2340 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() );
2341 sipIsErr = 1;
2342 }
2343 else
2344 {
2345 sipRes = sipConvertFromNewType( new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
2346 }
2347 }
2348 % End
2349#endif
2350
2351#ifndef SIP_RUN
2352
2361 QgsPolylineXY asPolyline() const;
2362#else
2363
2375 SIP_PYOBJECT asPolyline() const SIP_TYPEHINT( QgsPolylineXY );
2376 % MethodCode
2377 const Qgis::WkbType type = sipCpp->wkbType();
2378 if ( sipCpp->isNull() )
2379 {
2380 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a polyline."_s.toUtf8().constData() );
2381 sipIsErr = 1;
2382 }
2384 {
2385 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() );
2386 sipIsErr = 1;
2387 }
2388 else
2389 {
2390 const sipTypeDef *qvector_type = sipFindType( "QVector< QgsPointXY >" );
2391 sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
2392 }
2393 % End
2394#endif
2395
2396#ifndef SIP_RUN
2397
2406 QgsPolygonXY asPolygon() const;
2407#else
2408
2420 SIP_PYOBJECT asPolygon() const SIP_TYPEHINT( QgsPolygonXY );
2421 % MethodCode
2422 const Qgis::WkbType type = sipCpp->wkbType();
2423 if ( sipCpp->isNull() )
2424 {
2425 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a polygon."_s.toUtf8().constData() );
2426 sipIsErr = 1;
2427 }
2429 {
2430 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() );
2431 sipIsErr = 1;
2432 }
2433 else
2434 {
2435 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QgsPointXY>>" );
2436 sipRes = sipConvertFromNewType( new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
2437 }
2438 % End
2439#endif
2440
2441#ifndef SIP_RUN
2442
2450 QgsMultiPointXY asMultiPoint() const;
2451#else
2452
2463 SIP_PYOBJECT asMultiPoint() const SIP_TYPEHINT( QgsMultiPointXY );
2464 % MethodCode
2465 const Qgis::WkbType type = sipCpp->wkbType();
2466 if ( sipCpp->isNull() )
2467 {
2468 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a multipoint."_s.toUtf8().constData() );
2469 sipIsErr = 1;
2470 }
2472 {
2473 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() );
2474 sipIsErr = 1;
2475 }
2476 else
2477 {
2478 const sipTypeDef *qvector_type = sipFindType( "QVector< QgsPointXY >" );
2479 sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
2480 }
2481 % End
2482#endif
2483
2484#ifndef SIP_RUN
2485
2494 QgsMultiPolylineXY asMultiPolyline() const;
2495#else
2496
2508 SIP_PYOBJECT asMultiPolyline() const SIP_TYPEHINT( QgsMultiPolylineXY );
2509 % MethodCode
2510 const Qgis::WkbType type = sipCpp->wkbType();
2511 if ( sipCpp->isNull() )
2512 {
2513 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a multilinestring."_s.toUtf8().constData() );
2514 sipIsErr = 1;
2515 }
2517 {
2518 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() );
2519 sipIsErr = 1;
2520 }
2521 else
2522 {
2523 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QgsPointXY>>" );
2524 sipRes = sipConvertFromNewType( new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
2525 }
2526 % End
2527#endif
2528
2529#ifndef SIP_RUN
2530
2539 QgsMultiPolygonXY asMultiPolygon() const;
2540#else
2541
2553 SIP_PYOBJECT asMultiPolygon() const SIP_TYPEHINT( QgsMultiPolygonXY );
2554 % MethodCode
2555 const Qgis::WkbType type = sipCpp->wkbType();
2556 if ( sipCpp->isNull() )
2557 {
2558 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a multipolygon."_s.toUtf8().constData() );
2559 sipIsErr = 1;
2560 }
2562 {
2563 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() );
2564 sipIsErr = 1;
2565 }
2566 else
2567 {
2568 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QVector<QgsPointXY>>>" );
2569 sipRes = sipConvertFromNewType( new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
2570 }
2571 % End
2572#endif
2573
2577 QVector<QgsGeometry> asGeometryCollection() const;
2578
2583 QPointF asQPointF() const SIP_HOLDGIL;
2584
2596 QPolygonF asQPolygonF() const SIP_HOLDGIL;
2597
2603 bool deleteRing( int ringNum, int partNum = 0 );
2604
2609 bool deletePart( int partNum );
2610
2619 bool convertToMultiType();
2620
2636 bool convertToCurvedMultiType();
2637
2647 bool convertToSingleType();
2648
2658 bool convertGeometryCollectionToSubclass( Qgis::GeometryType geomType );
2659
2671 Q_DECL_DEPRECATED int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers, const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) ) SIP_DEPRECATED;
2672
2684 Qgis::GeometryOperationResult avoidIntersectionsV2( const QList<QgsVectorLayer *> &avoidIntersectionsLayers, const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
2685
2706 QgsGeometry makeValid( Qgis::MakeValidMethod method = Qgis::MakeValidMethod::Linework, bool keepCollapsed = false ) const SIP_THROW( QgsNotSupportedException );
2707
2717 Qgis::AngularDirection polygonOrientation() const;
2718
2733
2748
2749
2764 QgsGeometry forceRHR() const;
2765
2776 QgsGeometry forcePolygonClockwise() const;
2777
2788 QgsGeometry forcePolygonCounterClockwise() const;
2789
2794 class CORE_EXPORT Error
2795 {
2796 public:
2798 : mMessage( u"none"_s )
2799 {}
2800
2801 explicit Error( const QString &m )
2802 : mMessage( m )
2803 {}
2804
2805 Error( const QString &m, const QgsPointXY &p )
2806 : mMessage( m )
2807 , mLocation( p )
2808 , mHasLocation( true ) {}
2809
2813 QString what() const;
2814
2818 QgsPointXY where() const;
2819
2823 bool hasWhere() const;
2824
2825#ifdef SIP_RUN
2826 SIP_PYOBJECT __repr__();
2827 % MethodCode
2828 QString str = u"<QgsGeometry.Error: %1>"_s.arg( sipCpp->what() );
2829 sipRes = PyUnicode_FromString( str.toUtf8().data() );
2830 % End
2831#endif
2832
2833 // TODO c++20 - replace with = default
2834 bool operator==( const QgsGeometry::Error &other ) const
2835 {
2836 return other.mMessage == mMessage && other.mHasLocation == mHasLocation && other.mLocation == mLocation;
2837 }
2838
2839 private:
2840 QString mMessage;
2841 QgsPointXY mLocation;
2842 bool mHasLocation = false;
2843 };
2844
2852 void validateGeometry( QVector<QgsGeometry::Error> &errors SIP_OUT, Qgis::GeometryValidationEngine method = Qgis::GeometryValidationEngine::QgisInternal, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const;
2853
2863 void normalize();
2864
2873 static QgsGeometry unaryUnion( const QVector<QgsGeometry> &geometries, const QgsGeometryParameters &parameters = QgsGeometryParameters() );
2874
2882 static QgsGeometry polygonize( const QVector<QgsGeometry> &geometries );
2883
2890 void convertToStraightSegment( double tolerance = M_PI / 180., QgsAbstractGeometry::SegmentationToleranceType toleranceType = QgsAbstractGeometry::MaximumAngle );
2891
2897 bool requiresConversionToStraightSegments() const;
2898
2903 void mapToPixel( const QgsMapToPixel &mtp );
2904
2909 void draw( QPainter &p ) const;
2910
2920 bool vertexIdFromVertexNr( int number, QgsVertexId &id SIP_OUT ) const;
2921
2932 int vertexNrFromVertexId( QgsVertexId id ) const;
2933
2940 QString lastError() const SIP_HOLDGIL;
2941
2951 void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) SIP_SKIP;
2952
2967 void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) SIP_SKIP;
2968
2973 static QgsGeometry fromQPointF( QPointF point ) SIP_HOLDGIL;
2974
2981 static QgsGeometry fromQPolygonF( const QPolygonF &polygon );
2982
2990 Q_DECL_DEPRECATED static QgsPolylineXY createPolylineFromQPolygonF( const QPolygonF &polygon ) SIP_DEPRECATED;
2991
2999 Q_DECL_DEPRECATED static QgsPolygonXY createPolygonFromQPolygonF( const QPolygonF &polygon ) SIP_DEPRECATED;
3000
3001#ifndef SIP_RUN
3002
3011 static bool compare( const QgsPolylineXY &p1, const QgsPolylineXY &p2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3012
3021 static bool compare( const QgsPolygonXY &p1, const QgsPolygonXY &p2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3022
3032 static bool compare( const QgsMultiPolygonXY &p1, const QgsMultiPolygonXY &p2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3033#else
3034
3053 static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3054 % MethodCode
3055 {
3056 sipRes = false;
3057 int state0;
3058 int state1;
3059 int sipIsErr = 0;
3060
3061 if ( PyList_Check( a0 ) && PyList_Check( a1 ) && PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
3062 {
3063 PyObject *o0 = PyList_GetItem( a0, 0 );
3064 PyObject *o1 = PyList_GetItem( a1, 0 );
3065 if ( o0 && o1 )
3066 {
3067 // compare polyline - polyline
3068 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 ) )
3069 {
3070 QgsPolylineXY *p0;
3071 QgsPolylineXY *p1;
3072 p0 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3073 p1 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3074 if ( !sipIsErr )
3075 {
3076 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3077 }
3078 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
3079 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
3080 }
3081 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) && PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
3082 {
3083 PyObject *oo0 = PyList_GetItem( o0, 0 );
3084 PyObject *oo1 = PyList_GetItem( o1, 0 );
3085 if ( oo0 && oo1 )
3086 {
3087 // compare polygon - polygon
3088 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 ) )
3089 {
3090 QgsPolygonXY *p0;
3091 QgsPolygonXY *p1;
3092 p0 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3093 p1 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3094 if ( !sipIsErr )
3095 {
3096 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3097 }
3098 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
3099 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
3100 }
3101 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) && PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
3102 {
3103 PyObject *ooo0 = PyList_GetItem( oo0, 0 );
3104 PyObject *ooo1 = PyList_GetItem( oo1, 0 );
3105 if ( ooo0 && ooo1 )
3106 {
3107 // compare multipolygon - multipolygon
3108 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 ) )
3109 {
3112 p0 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3113 p1 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3114 if ( !sipIsErr )
3115 {
3116 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3117 }
3118 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
3119 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
3120 }
3121 }
3122 }
3123 }
3124 }
3125 }
3126 }
3127 }
3128 % End
3129#endif
3130
3146 QgsGeometry smooth( unsigned int iterations = 1, double offset = 0.25, double minimumDistance = -1.0, double maxAngle = 180.0 ) const;
3147
3187 static QgsGeometryEngine *createGeometryEngine( const QgsAbstractGeometry *geometry, double precision = 0.0, Qgis::GeosCreationFlags flags = Qgis::GeosCreationFlag::SkipEmptyInteriorRings ) SIP_FACTORY;
3188
3194 static void convertPointList( const QVector<QgsPointXY> &input, QgsPointSequence &output );
3195
3201 static void convertPointList( const QgsPointSequence &input, QVector<QgsPointXY> &output );
3202
3204 operator QVariant() const
3205 {
3206 return QVariant::fromValue( *this );
3207 }
3208
3214 {
3215 Chamfer = 1,
3216 Fillet,
3217 };
3218#ifndef SIP_RUN
3219 Q_ENUM( ChamferFilletOperationType )
3220#endif
3221
3238 QgsGeometry fillet( int vertexIndex, double radius, int segments = 8 ) const;
3239
3258 static QgsGeometry fillet( const QgsPoint &segment1Start, const QgsPoint &segment1End, const QgsPoint &segment2Start, const QgsPoint &segment2End, double radius, int segments = 8 ) SIP_THROW( QgsInvalidArgumentException );
3259
3273 QgsGeometry chamfer( int vertexIndex, double distance1, double distance2 = -1.0 ) const;
3274
3293 static QgsGeometry chamfer( const QgsPoint &segment1Start, const QgsPoint &segment1End, const QgsPoint &segment2Start, const QgsPoint &segment2End, double distance1, double distance2 = -1.0 ) SIP_THROW( QgsInvalidArgumentException );
3294
3295
3296 private:
3297 QgsGeometryPrivate *d; //implicitly shared data pointer
3298
3300 mutable QString mLastError;
3301
3306 void detach();
3307
3312 void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
3313
3314 static void convertPolygon( const QgsPolygon &input, QgsPolygonXY &output );
3315
3317 QgsGeometry convertToPoint( bool destMultipart ) const;
3319 QgsGeometry convertToLine( bool destMultipart ) const;
3321 QgsGeometry convertToPolygon( bool destMultipart ) const;
3322
3334 std::unique_ptr< QgsLineString > smoothLine( const QgsLineString &line, unsigned int iterations = 1, double offset = 0.25, double minimumDistance = -1, double maxAngle = 180.0 ) const;
3335
3347 std::unique_ptr< QgsPolygon > smoothPolygon( const QgsPolygon &polygon, unsigned int iterations = 1, double offset = 0.25, double minimumDistance = -1, double maxAngle = 180.0 ) const;
3348
3349 QgsGeometry doChamferFillet( ChamferFilletOperationType op, int vertexIndex, double distance1, double distance2, int segments ) const;
3350
3352
3353}; // class QgsGeometry
3354
3356
3358CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsGeometry &geometry );
3360CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry );
3361
3362#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
@ CounterClockwise
Counter-clockwise direction.
Definition qgis.h:3493
@ Clockwise
Clockwise direction.
Definition qgis.h:3492
GeometryOperationResult
Success or failure of a geometry operation.
Definition qgis.h:2100
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
Definition qgis.h:2133
GeometryValidationEngine
Available engines for validating geometries.
Definition qgis.h:2142
@ QgisInternal
Use internal QgsGeometryValidator method.
Definition qgis.h:2143
@ SkipEmptyInteriorRings
Skip any empty polygon interior ring.
Definition qgis.h:2207
QFlags< GeosCreationFlag > GeosCreationFlags
Geos geometry creation behavior flags.
Definition qgis.h:2216
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:6523
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:2729
@ Forward
Forward transform (from source to destination).
Definition qgis.h:2730
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:45
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:62
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
Polygon geometry type.
Definition qgspolygon.h:37
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:92
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:98
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition qgsgeometry.h:63
QVector< QgsPolyline > QgsMultiPolyline
Multi polyline represented as a vector of polylines.
Definition qgsgeometry.h:85
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:72
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:34