QGIS API Documentation 4.1.0-Master (31622b25bb0)
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:
184 // clang-format off
186 // clang-format on
187
189 QgsGeometry( const QgsGeometry & );
190
195 QgsGeometry &operator=( QgsGeometry const &rhs ) SIP_SKIP;
196
202
208 explicit QgsGeometry( std::unique_ptr< QgsAbstractGeometry > geom ) SIP_SKIP;
209
210 virtual ~QgsGeometry();
211
223
236
249
257 bool isNull() const SIP_HOLDGIL;
258
260 Q_INVOKABLE static QgsGeometry fromWkt( const QString &wkt );
262 static QgsGeometry fromPointXY( const QgsPointXY &point ) SIP_HOLDGIL;
263
269 static QgsGeometry fromPoint( const QgsPoint &point ) SIP_HOLDGIL;
270
272 static QgsGeometry fromMultiPointXY( const QgsMultiPointXY &multipoint );
273
284 static QgsGeometry fromPolylineXY( const QgsPolylineXY &polyline );
285
294 static QgsGeometry fromPolyline( const QgsPolyline &polyline );
295
299 static QgsGeometry fromMultiPolylineXY( const QgsMultiPolylineXY &multiline );
300
301#ifndef SIP_RUN
302
306#else
307
325#endif
326 static QgsGeometry fromPolygonXY( const QgsPolygonXY &polygon );
327
331 static QgsGeometry fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly );
332
334 static QgsGeometry fromRect( const QgsRectangle &rect ) SIP_HOLDGIL;
335
343 static QgsGeometry fromBox3D( const QgsBox3D &box ) SIP_HOLDGIL;
344
345
347 static QgsGeometry collectGeometry( const QVector<QgsGeometry> &geometries );
348
364 static QgsGeometry collectTinPatches( const QVector<QgsGeometry> &geometries );
365
381 static QgsGeometry createWedgeBuffer( const QgsPoint &center, double azimuth, double angularWidth, double outerRadius, double innerRadius = 0 );
382
396 static QgsGeometry createWedgeBufferFromAngles( const QgsPoint &center, double startAngle, double endAngle, double outerRadius, double innerRadius = 0 );
397
403 void fromWkb( unsigned char *wkb, int length ) SIP_SKIP;
404
408 void fromWkb( const QByteArray &wkb );
409
415
420 Qgis::GeometryType type() const SIP_HOLDGIL;
421
428 bool isEmpty() const SIP_HOLDGIL;
429
431 bool isMultipart() const SIP_HOLDGIL;
432
446 Q_DECL_DEPRECATED bool equals( const QgsGeometry &geometry ) const SIP_DEPRECATED;
447
463 Q_DECL_DEPRECATED bool isGeosEqual( const QgsGeometry & ) const SIP_DEPRECATED;
464
483 bool isExactlyEqual( const QgsGeometry &geometry, Qgis::GeometryBackend backend = Qgis::GeometryBackend::QGIS ) const SIP_THROW( QgsNotSupportedException );
484
502 bool isTopologicallyEqual( const QgsGeometry &geometry, Qgis::GeometryBackend backend = Qgis::GeometryBackend::GEOS ) const SIP_THROW( QgsNotSupportedException );
503
521 bool isFuzzyEqual( const QgsGeometry &geometry, double epsilon = 1e-4, Qgis::GeometryBackend backend = Qgis::GeometryBackend::QGIS ) const SIP_THROW( QgsNotSupportedException );
522
529 bool isGeosValid( Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const;
530
538 bool isSimple() const;
539
553 bool isAxisParallelRectangle( double maximumDeviation, bool simpleRectanglesOnly = false ) const;
554
567 double area() const;
568
583
597 double length() const;
598
606 double distance( const QgsGeometry &geom ) const;
607
608#ifndef SIP_RUN
609
610 // TODO QGIS 5: consider renaming vertices_begin, vertices_end, parts_begin, parts_end, etc
611 // to camelCase
612
617
622#endif
623
647
648#ifndef SIP_RUN
649
659
669
679
689#endif
690
729
763
780 double hausdorffDistance( const QgsGeometry &geom ) const;
781
799 double hausdorffDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const;
800
815 double frechetDistance( const QgsGeometry &geom ) const SIP_THROW( QgsNotSupportedException );
816
839 double frechetDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const SIP_THROW( QgsNotSupportedException );
840
853 QgsPointXY closestVertex( const QgsPointXY &point, int &closestVertexIndex SIP_OUT, int &previousVertexIndex SIP_OUT, int &nextVertexIndex SIP_OUT, double &sqrDist SIP_OUT ) const;
854
862 double distanceToVertex( int vertex ) const;
863
870 double angleAtVertex( int vertex ) const;
871
884 void adjacentVertices( int atVertex, int &beforeVertex SIP_OUT, int &afterVertex SIP_OUT ) const;
885
898 bool insertVertex( double x, double y, int beforeVertex );
899
912 bool insertVertex( const QgsPoint &point, int beforeVertex );
913
921 bool addTopologicalPoint( const QgsPoint &point, double snappingTolerance = 1e-8, double segmentSearchEpsilon = 1e-12 );
922
930 bool moveVertex( double x, double y, int atVertex );
931
939 bool moveVertex( const QgsPoint &p, int atVertex );
940
953 bool deleteVertex( int atVertex );
954
968 bool deleteVertices( const QSet<int> &atVertices );
969
977 bool toggleCircularAtVertex( int atVertex );
978
984 QgsPoint vertexAt( int atVertex ) const;
985
991 double sqrDistToVertexAt( QgsPointXY &point SIP_IN, int atVertex ) const;
992
997 QgsGeometry nearestPoint( const QgsGeometry &other ) const;
998
1008 QgsGeometry shortestLine( const QgsGeometry &other ) const;
1009
1016 double closestVertexWithContext( const QgsPointXY &point, int &atVertex SIP_OUT ) const;
1017
1029 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;
1030
1036 Qgis::GeometryOperationResult addRing( const QVector<QgsPointXY> &ring );
1037
1044
1052 Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) SIP_PYNAME( addPointsXY ) SIP_DEPRECATED;
1053
1061 Qgis::GeometryOperationResult addPartV2( const QVector<QgsPointXY> &points, Qgis::WkbType wkbType = Qgis::WkbType::Unknown ) SIP_PYNAME( addPointsXYV2 );
1062
1071
1080
1089
1098
1104 Qgis::GeometryOperationResult addPart( const QgsGeometry &newPart ) SIP_PYNAME( addPartGeometry );
1105
1111 QgsGeometry removeInteriorRings( double minimumAllowedArea = -1 ) const;
1112
1117 Qgis::GeometryOperationResult translate( double dx, double dy, double dz = 0.0, double dm = 0.0 );
1118
1134
1143 Qgis::GeometryOperationResult transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 );
1144
1151 Qgis::GeometryOperationResult rotate( double rotation, const QgsPointXY &center );
1152
1163 Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitGeometry( const QVector<QgsPointXY> &splitLine, QVector<QgsGeometry> &newGeometries, bool topological, QVector<QgsPointXY> &topologyTestPoints, bool splitFeature = true ) SIP_SKIP;
1164
1186 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;
1187
1188
1189 /*
1190 This SIP code is to support overloaded methods of splitGeometry.
1191 When the deprecated method is removed in QGIS 5.0 this code can be dropped
1192 TODO QGIS 5 remove MethodCode
1193 */
1194#ifdef SIP_RUN
1195// clang-format off
1196
1215 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]]] );
1216 % MethodCode
1217 {
1218 int sipIsErr = 0;
1219 int state;
1220
1221 if ( PyList_Check( a0 ) && PyList_GET_SIZE( a0 ) )
1222 {
1223 PyObject *p0 = PyList_GetItem( a0, 0 );
1224 if ( sipCanConvertToType( p0, sipType_QgsPointXY, SIP_NOT_NONE ) && sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1225 {
1226 QVector<QgsGeometry> newGeometries;
1227 QVector<QgsPointXY> topologyTestPoints;
1228
1229 QVector<QgsPointXY> *splitLine = reinterpret_cast<QVector<QgsPointXY> *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1230 if ( !sipIsErr )
1231 {
1232 Qgis::GeometryOperationResult result = sipCpp->splitGeometry( *splitLine, newGeometries, a1, topologyTestPoints, a2 );
1233
1234 PyObject *o0 = sipConvertFromEnum( static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1235 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1236 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPointXY, Py_None );
1237
1238 sipRes = PyTuple_New( 3 );
1239 PyTuple_SET_ITEM( sipRes, 0, o0 );
1240 PyTuple_SET_ITEM( sipRes, 1, o1 );
1241 PyTuple_SET_ITEM( sipRes, 2, o2 );
1242 }
1243 sipReleaseType( splitLine, sipType_QVector_0100QgsPointXY, state );
1244 }
1245
1246 else if ( sipCanConvertToType( p0, sipType_QgsPoint, SIP_NOT_NONE ) && sipCanConvertToType( a0, sipType_QVector_0100QgsPoint, SIP_NOT_NONE ) )
1247 {
1248 QVector<QgsGeometry> newGeometries;
1249 QVector<QgsPoint> topologyTestPoints;
1250
1251 QVector<QgsPoint> *splitLine = reinterpret_cast<QVector<QgsPoint> *>( sipConvertToType( a0, sipType_QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1252 if ( !sipIsErr )
1253 {
1254 Qgis::GeometryOperationResult result = sipCpp->splitGeometry( *splitLine, newGeometries, a1, topologyTestPoints, a2 );
1255
1256 PyObject *o0 = sipConvertFromEnum( static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1257 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1258 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPoint, Py_None );
1259
1260 sipRes = PyTuple_New( 3 );
1261 PyTuple_SET_ITEM( sipRes, 0, o0 );
1262 PyTuple_SET_ITEM( sipRes, 1, o1 );
1263 PyTuple_SET_ITEM( sipRes, 2, o2 );
1264 }
1265 sipReleaseType( splitLine, sipType_QVector_0100QgsPoint, state );
1266 }
1267 else
1268 {
1269 sipIsErr = 1;
1270 PyErr_SetString( PyExc_TypeError, u"Could not convert first argument to a list of QgsPoint or QgsPointXY."_s.toUtf8().constData() );
1271 }
1272 }
1273 else
1274 {
1275 sipIsErr = 1;
1276 PyErr_SetString( PyExc_TypeError, u"First argument is not a list of points or is empty."_s.toUtf8().constData() );
1277 }
1278 }
1279 % End
1280// clang-format on
1281#endif
1282
1294 Qgis::GeometryOperationResult splitGeometry( const QgsCurve *curve, QVector<QgsGeometry> &newGeometries SIP_OUT, bool preserveCircular, bool topological, QgsPointSequence &topologyTestPoints SIP_OUT, bool splitFeature = true );
1295
1300 Qgis::GeometryOperationResult reshapeGeometry( const QgsLineString &reshapeLineString );
1301
1308 int makeDifferenceInPlace( const QgsGeometry &other, QgsFeedback* feedback = nullptr ) SIP_SKIP;
1309
1317 QgsGeometry makeDifference( const QgsGeometry &other, QgsFeedback* feedback = nullptr ) const;
1318
1323 QgsRectangle boundingBox() const;
1324
1330 QgsBox3D boundingBox3D() const;
1331
1344 QgsGeometry orientedMinimumBoundingBox( double &area SIP_OUT, double &angle SIP_OUT, double &width SIP_OUT, double &height SIP_OUT ) const;
1345
1355 QgsGeometry orientedMinimumBoundingBox() const SIP_SKIP;
1356
1364 QgsGeometry minimalEnclosingCircle( QgsPointXY &center SIP_OUT, double &radius SIP_OUT, unsigned int segments = 36 ) const;
1365
1370 QgsGeometry minimalEnclosingCircle( unsigned int segments = 36 ) const SIP_SKIP;
1371
1379 QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
1380
1393 QgsGeometry triangularWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1394
1413 QgsGeometry triangularWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1414
1427 QgsGeometry squareWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1428
1447 QgsGeometry squareWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1448
1461 QgsGeometry roundWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1462
1481 QgsGeometry roundWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1482
1496 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;
1497
1509 QgsGeometry snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const;
1510
1530 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false );
1531
1541 Q_INVOKABLE bool intersects( const QgsRectangle &rectangle ) const;
1542
1557 Q_INVOKABLE bool intersects( const QgsGeometry &geometry ) const;
1558
1567 Q_INVOKABLE bool boundingBoxIntersects( const QgsRectangle &rectangle ) const;
1568
1577 Q_INVOKABLE bool boundingBoxIntersects( const QgsGeometry &geometry ) const;
1578
1582 bool contains( const QgsPointXY *p ) const;
1583
1589 Q_INVOKABLE bool contains( double x, double y ) const;
1590
1600 Q_INVOKABLE bool contains( const QgsGeometry &geometry ) const;
1601
1611 Q_INVOKABLE bool disjoint( const QgsGeometry &geometry ) const;
1612
1622 Q_INVOKABLE bool touches( const QgsGeometry &geometry ) const;
1623
1633 Q_INVOKABLE bool overlaps( const QgsGeometry &geometry ) const;
1634
1644 Q_INVOKABLE bool within( const QgsGeometry &geometry ) const;
1645
1655 Q_INVOKABLE bool crosses( const QgsGeometry &geometry ) const;
1656
1666 QgsGeometry buffer( double distance, int segments, QgsFeedback* feedback = nullptr ) const;
1667
1680 QgsGeometry buffer( double distance, int segments, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit, QgsFeedback* feedback = nullptr ) const;
1681
1689 QgsGeometry offsetCurve( double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit ) const;
1690
1705 QgsGeometry singleSidedBuffer( double distance, int segments, Qgis::BufferSide side, Qgis::JoinStyle joinStyle = Qgis::JoinStyle::Round, double miterLimit = 2.0 ) const;
1706
1724 QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const;
1725
1740 QgsGeometry variableWidthBufferByM( int segments ) const;
1741
1747 QgsGeometry extendLine( double startDistance, double endDistance ) const;
1748
1754 QgsGeometry simplify( double tolerance, QgsFeedback* feedback = nullptr ) const;
1755
1764 QgsGeometry densifyByCount( int extraNodesPerSegment ) const;
1765
1779 QgsGeometry densifyByDistance( double distance ) const;
1780
1796 QgsGeometry convertToCurves( double distanceTolerance = 1e-8, double angleTolerance = 1e-8 ) const;
1797
1811 QgsGeometry centroid() const;
1812
1826 QgsGeometry pointOnSurface() const;
1827
1839 QgsGeometry poleOfInaccessibility( double precision, double *distanceToBoundary SIP_OUT = nullptr ) const;
1840
1864 QgsGeometry largestEmptyCircle( double tolerance, const QgsGeometry &boundary = QgsGeometry() ) const SIP_THROW( QgsNotSupportedException );
1865
1880 QgsGeometry minimumWidth() const SIP_THROW( QgsNotSupportedException );
1881
1903 double minimumClearance() const SIP_THROW( QgsNotSupportedException );
1904
1916 QgsGeometry minimumClearanceLine() const SIP_THROW( QgsNotSupportedException );
1917
1926 QgsGeometry convexHull() const;
1927
1943 QgsGeometry concaveHull( double targetPercent, bool allowHoles = false, QgsFeedback * feedback = nullptr ) const SIP_THROW( QgsNotSupportedException );
1944
1980 QgsGeometry concaveHullOfPolygons( double lengthRatio, bool allowHoles = false, bool isTight = false, QgsFeedback *feedback = nullptr ) const SIP_THROW( QgsNotSupportedException );
1981
1996 QgsGeometry voronoiDiagram( const QgsGeometry &extent = QgsGeometry(), double tolerance = 0.0, bool edgesOnly = false ) const;
1997
2008 QgsGeometry delaunayTriangulation( double tolerance = 0.0, bool edgesOnly = false ) const;
2009
2022 QgsGeometry constrainedDelaunayTriangulation() const SIP_THROW( QgsNotSupportedException );
2023
2041 Qgis::CoverageValidityResult validateCoverage( double gapWidth, QgsGeometry *invalidEdges SIP_OUT = nullptr ) const SIP_THROW( QgsNotSupportedException );
2042
2063 QgsGeometry simplifyCoverageVW( double tolerance, bool preserveBoundary ) const SIP_THROW( QgsNotSupportedException );
2064
2076 QgsGeometry unionCoverage() const;
2077
2088 QgsGeometry node() const;
2089
2104 QgsGeometry sharedPaths( const QgsGeometry &other ) const;
2105
2128 QgsGeometry subdivide( int maxNodes = 256, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback* feedback = nullptr ) const;
2129
2144 QgsGeometry interpolate( double distance ) const;
2145
2156 double lineLocatePoint( const QgsGeometry &point ) const;
2157
2166 double interpolateAngle( double distance ) const;
2167
2181 QgsGeometry intersection( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback* feedback = nullptr ) const;
2182
2191 QgsGeometry clipped( const QgsRectangle &rectangle, QgsFeedback* feedback = nullptr );
2192
2209 QgsGeometry combine( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback* feedback = nullptr ) const;
2210
2221 QgsGeometry mergeLines( const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2222
2236 QgsGeometry difference( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback* feedback = nullptr ) const;
2237
2251 QgsGeometry symDifference( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback* feedback = nullptr ) const;
2252
2254 QgsGeometry extrude( double x, double y );
2255
2256#ifndef SIP_RUN
2257
2279 QVector< QgsPointXY > randomPointsInPolygon( int count, const std::function< bool( const QgsPointXY & ) > &acceptPoint, unsigned long seed = 0, QgsFeedback *feedback = nullptr, int maxTriesPerPoint = 0 ) const;
2280
2294 QVector< QgsPointXY > randomPointsInPolygon( int count, unsigned long seed = 0, QgsFeedback *feedback = nullptr ) const;
2296#else
2297// clang-format off
2298
2312 SIP_PYOBJECT randomPointsInPolygon( int count, unsigned long seed = 0 ) const SIP_TYPEHINT( QgsPolylineXY );
2313 % MethodCode
2314 const Qgis::GeometryType type = sipCpp->type();
2315 if ( sipCpp->isNull() )
2316 {
2317 PyErr_SetString( PyExc_ValueError, u"Cannot generate points inside a null geometry."_s.toUtf8().constData() );
2318 sipIsErr = 1;
2319 }
2320 else if ( type != Qgis::GeometryType::Polygon )
2321 {
2322 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() );
2323 sipIsErr = 1;
2324 }
2325 else
2326 {
2327 const sipTypeDef *qvector_type = sipFindType( "QVector<QgsPointXY>" );
2328 sipRes = sipConvertFromNewType( new QVector< QgsPointXY >( sipCpp->randomPointsInPolygon( a0, a1 ) ), qvector_type, Py_None );
2329 }
2330 % End
2331
2332
2333// clang-format on
2334#endif
2336
2344 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const;
2345
2352 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const;
2353
2359 Q_INVOKABLE QString asWkt( int precision = 17 ) const;
2360
2361#ifdef SIP_RUN
2362// clang-format off
2363 SIP_PYOBJECT __repr__();
2364 % MethodCode
2365 QString str;
2366 if ( sipCpp->isNull() )
2367 str = u"<QgsGeometry: null>"_s;
2368 else
2369 {
2370 QString wkt = sipCpp->asWkt();
2371 if ( wkt.length() > 1000 )
2372 wkt = wkt.left( 1000 ) + u"..."_s;
2373 str = u"<QgsGeometry: %1>"_s.arg( wkt );
2374 }
2375 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
2376 % End
2377// clang-format on
2378#endif
2379
2383 QString asJson( int precision = 17 ) const;
2384
2390 virtual json asJsonObject( int precision = 17 ) const SIP_SKIP;
2391
2428 QVector< QgsGeometry > coerceToType( Qgis::WkbType type, double defaultZ = 0, double defaultM = 0, bool avoidDuplicates = true ) const;
2429
2441 QgsGeometry convertToType( Qgis::GeometryType destType, bool destMultipart = false ) const;
2442
2443 /* Accessor functions for getting geometry data */
2444
2445#ifndef SIP_RUN
2446
2455 QgsPointXY asPoint() const;
2456#else
2457// clang-format off
2458
2469 SIP_PYOBJECT asPoint() const SIP_TYPEHINT( QgsPointXY );
2470 % MethodCode
2471 if ( sipCpp->isNull() )
2472 {
2473 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a point."_s.toUtf8().constData() );
2474 sipIsErr = 1;
2475 }
2476 else
2477 {
2478 const QgsAbstractGeometry *geom = sipCpp->constGet();
2480 {
2481 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() );
2482 sipIsErr = 1;
2483 }
2484 else
2485 {
2486 sipRes = sipConvertFromNewType( new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
2487 }
2488 }
2489 % End
2490// clang-format on
2491#endif
2492
2493#ifndef SIP_RUN
2494
2503 QgsPolylineXY asPolyline() const;
2504#else
2505// clang-format off
2506
2518 SIP_PYOBJECT asPolyline() const SIP_TYPEHINT( QgsPolylineXY );
2519 % MethodCode
2520 const Qgis::WkbType type = sipCpp->wkbType();
2521 if ( sipCpp->isNull() )
2522 {
2523 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a polyline."_s.toUtf8().constData() );
2524 sipIsErr = 1;
2525 }
2527 {
2528 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() );
2529 sipIsErr = 1;
2530 }
2531 else
2532 {
2533 const sipTypeDef *qvector_type = sipFindType( "QVector< QgsPointXY >" );
2534 sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
2535 }
2536 % End
2537// clang-format on
2538#endif
2539
2540#ifndef SIP_RUN
2541
2550 QgsPolygonXY asPolygon() const;
2551#else
2552// clang-format off
2553
2565 SIP_PYOBJECT asPolygon() const SIP_TYPEHINT( QgsPolygonXY );
2566 % MethodCode
2567 const Qgis::WkbType type = sipCpp->wkbType();
2568 if ( sipCpp->isNull() )
2569 {
2570 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a polygon."_s.toUtf8().constData() );
2571 sipIsErr = 1;
2572 }
2574 {
2575 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() );
2576 sipIsErr = 1;
2577 }
2578 else
2579 {
2580 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QgsPointXY>>" );
2581 sipRes = sipConvertFromNewType( new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
2582 }
2583 % End
2584// clang-format on
2585#endif
2586
2587#ifndef SIP_RUN
2588
2596 QgsMultiPointXY asMultiPoint() const;
2597#else
2598// clang-format off
2599
2610 SIP_PYOBJECT asMultiPoint() const SIP_TYPEHINT( QgsMultiPointXY );
2611 % MethodCode
2612 const Qgis::WkbType type = sipCpp->wkbType();
2613 if ( sipCpp->isNull() )
2614 {
2615 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a multipoint."_s.toUtf8().constData() );
2616 sipIsErr = 1;
2617 }
2619 {
2620 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() );
2621 sipIsErr = 1;
2622 }
2623 else
2624 {
2625 const sipTypeDef *qvector_type = sipFindType( "QVector< QgsPointXY >" );
2626 sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
2627 }
2628 % End
2629// clang-format on
2630#endif
2631
2632#ifndef SIP_RUN
2633
2642 QgsMultiPolylineXY asMultiPolyline() const;
2643#else
2644// clang-format off
2645
2657 SIP_PYOBJECT asMultiPolyline() const SIP_TYPEHINT( QgsMultiPolylineXY );
2658 % MethodCode
2659 const Qgis::WkbType type = sipCpp->wkbType();
2660 if ( sipCpp->isNull() )
2661 {
2662 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a multilinestring."_s.toUtf8().constData() );
2663 sipIsErr = 1;
2664 }
2666 {
2667 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() );
2668 sipIsErr = 1;
2669 }
2670 else
2671 {
2672 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QgsPointXY>>" );
2673 sipRes = sipConvertFromNewType( new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
2674 }
2675 % End
2676// clang-format on
2677#endif
2678
2679#ifndef SIP_RUN
2680
2689 QgsMultiPolygonXY asMultiPolygon() const;
2690#else
2691// clang-format off
2692
2704 SIP_PYOBJECT asMultiPolygon() const SIP_TYPEHINT( QgsMultiPolygonXY );
2705 % MethodCode
2706 const Qgis::WkbType type = sipCpp->wkbType();
2707 if ( sipCpp->isNull() )
2708 {
2709 PyErr_SetString( PyExc_ValueError, u"Null geometry cannot be converted to a multipolygon."_s.toUtf8().constData() );
2710 sipIsErr = 1;
2711 }
2713 {
2714 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() );
2715 sipIsErr = 1;
2716 }
2717 else
2718 {
2719 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QVector<QgsPointXY>>>" );
2720 sipRes = sipConvertFromNewType( new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
2721 }
2722 % End
2723// clang-format on
2724#endif
2725
2729 QVector<QgsGeometry> asGeometryCollection() const;
2730
2735 QPointF asQPointF() const SIP_HOLDGIL;
2736
2748 QPolygonF asQPolygonF() const SIP_HOLDGIL;
2749
2755 bool deleteRing( int ringNum, int partNum = 0 );
2756
2761 bool deletePart( int partNum );
2762
2771 bool convertToMultiType();
2772
2788 bool convertToCurvedMultiType();
2789
2799 bool convertToSingleType();
2800
2810 bool convertGeometryCollectionToSubclass( Qgis::GeometryType geomType );
2811
2823 Q_DECL_DEPRECATED int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers, const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) ) SIP_DEPRECATED;
2824
2836 Qgis::GeometryOperationResult avoidIntersectionsV2( const QList<QgsVectorLayer *> &avoidIntersectionsLayers, const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
2837
2859 QgsGeometry makeValid( Qgis::MakeValidMethod method = Qgis::MakeValidMethod::Linework, bool keepCollapsed = false, QgsFeedback* feedback = nullptr ) const SIP_THROW( QgsNotSupportedException );
2860
2870 Qgis::AngularDirection polygonOrientation() const;
2871
2886
2901
2902
2917 QgsGeometry forceRHR() const;
2918
2929 QgsGeometry forcePolygonClockwise() const;
2930
2941 QgsGeometry forcePolygonCounterClockwise() const;
2942
2947 class CORE_EXPORT Error
2948 {
2949 public:
2951 : mMessage( u"none"_s )
2952 {}
2953
2954 explicit Error( const QString &m )
2955 : mMessage( m )
2956 {}
2957
2958 Error( const QString &m, const QgsPointXY &p )
2959 : mMessage( m )
2960 , mLocation( p )
2961 , mHasLocation( true ) {}
2962
2966 QString what() const;
2967
2971 QgsPointXY where() const;
2972
2976 bool hasWhere() const;
2977
2978#ifdef SIP_RUN
2979// clang-format off
2980 SIP_PYOBJECT __repr__();
2981 % MethodCode
2982 QString str = u"<QgsGeometry.Error: %1>"_s.arg( sipCpp->what() );
2983 sipRes = PyUnicode_FromString( str.toUtf8().data() );
2984 % End
2985// clang-format on
2986#endif
2987
2988 // TODO c++20 - replace with = default
2989 bool operator==( const QgsGeometry::Error &other ) const
2990 {
2991 return other.mMessage == mMessage && other.mHasLocation == mHasLocation && other.mLocation == mLocation;
2992 }
2993
2994 private:
2995 QString mMessage;
2996 QgsPointXY mLocation;
2997 bool mHasLocation = false;
2998 };
2999
3007 void validateGeometry( QVector<QgsGeometry::Error> &errors SIP_OUT, Qgis::GeometryValidationEngine method = Qgis::GeometryValidationEngine::QgisInternal, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const;
3008
3018 void normalize();
3019
3030 static QgsGeometry unaryUnion( const QVector<QgsGeometry> &geometries, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback* feedback = nullptr );
3031
3039 static QgsGeometry polygonize( const QVector<QgsGeometry> &geometries );
3040
3047 void convertToStraightSegment( double tolerance = M_PI / 180., QgsAbstractGeometry::SegmentationToleranceType toleranceType = QgsAbstractGeometry::MaximumAngle );
3048
3054 bool requiresConversionToStraightSegments() const;
3055
3060 void mapToPixel( const QgsMapToPixel &mtp );
3061
3066 void draw( QPainter &p ) const;
3067
3077 bool vertexIdFromVertexNr( int number, QgsVertexId &id SIP_OUT ) const;
3078
3089 int vertexNrFromVertexId( QgsVertexId id ) const;
3090
3097 QString lastError() const SIP_HOLDGIL;
3098
3108 void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) SIP_SKIP;
3109
3124 void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) SIP_SKIP;
3125
3130 static QgsGeometry fromQPointF( QPointF point ) SIP_HOLDGIL;
3131
3138 static QgsGeometry fromQPolygonF( const QPolygonF &polygon );
3139
3147 Q_DECL_DEPRECATED static QgsPolylineXY createPolylineFromQPolygonF( const QPolygonF &polygon ) SIP_DEPRECATED;
3148
3156 Q_DECL_DEPRECATED static QgsPolygonXY createPolygonFromQPolygonF( const QPolygonF &polygon ) SIP_DEPRECATED;
3157
3158#ifndef SIP_RUN
3159
3168 static bool compare( const QgsPolylineXY &p1, const QgsPolylineXY &p2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3169
3178 static bool compare( const QgsPolygonXY &p1, const QgsPolygonXY &p2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3179
3189 static bool compare( const QgsMultiPolygonXY &p1, const QgsMultiPolygonXY &p2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3190#else
3191// clang-format off
3192
3211 static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3212 % MethodCode
3213 {
3214 sipRes = false;
3215 int state0;
3216 int state1;
3217 int sipIsErr = 0;
3218
3219 if ( PyList_Check( a0 ) && PyList_Check( a1 ) && PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
3220 {
3221 PyObject *o0 = PyList_GetItem( a0, 0 );
3222 PyObject *o1 = PyList_GetItem( a1, 0 );
3223 if ( o0 && o1 )
3224 {
3225 // compare polyline - polyline
3226 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 ) )
3227 {
3228 QgsPolylineXY *p0;
3229 QgsPolylineXY *p1;
3230 p0 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3231 p1 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3232 if ( !sipIsErr )
3233 {
3234 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3235 }
3236 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
3237 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
3238 }
3239 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) && PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
3240 {
3241 PyObject *oo0 = PyList_GetItem( o0, 0 );
3242 PyObject *oo1 = PyList_GetItem( o1, 0 );
3243 if ( oo0 && oo1 )
3244 {
3245 // compare polygon - polygon
3246 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 ) )
3247 {
3248 QgsPolygonXY *p0;
3249 QgsPolygonXY *p1;
3250 p0 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3251 p1 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3252 if ( !sipIsErr )
3253 {
3254 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3255 }
3256 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
3257 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
3258 }
3259 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) && PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
3260 {
3261 PyObject *ooo0 = PyList_GetItem( oo0, 0 );
3262 PyObject *ooo1 = PyList_GetItem( oo1, 0 );
3263 if ( ooo0 && ooo1 )
3264 {
3265 // compare multipolygon - multipolygon
3266 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 ) )
3267 {
3270 p0 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3271 p1 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3272 if ( !sipIsErr )
3273 {
3274 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3275 }
3276 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
3277 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
3278 }
3279 }
3280 }
3281 }
3282 }
3283 }
3284 }
3285 }
3286 % End
3287// clang-format on
3288#endif
3289
3305 QgsGeometry smooth( unsigned int iterations = 1, double offset = 0.25, double minimumDistance = -1.0, double maxAngle = 180.0 ) const;
3306
3346 static QgsGeometryEngine *createGeometryEngine( const QgsAbstractGeometry *geometry, double precision = 0.0, Qgis::GeosCreationFlags flags = Qgis::GeosCreationFlag::SkipEmptyInteriorRings ) SIP_FACTORY;
3347
3353 static void convertPointList( const QVector<QgsPointXY> &input, QgsPointSequence &output );
3354
3360 static void convertPointList( const QgsPointSequence &input, QVector<QgsPointXY> &output );
3361
3363 operator QVariant() const
3364 {
3365 return QVariant::fromValue( *this );
3366 }
3367
3373 {
3374 Chamfer = 1,
3375 Fillet,
3376 };
3377#ifndef SIP_RUN
3378 Q_ENUM( ChamferFilletOperationType )
3379#endif
3380
3397 QgsGeometry fillet( int vertexIndex, double radius, int segments = 8 ) const;
3398
3417 static QgsGeometry fillet( const QgsPoint &segment1Start, const QgsPoint &segment1End, const QgsPoint &segment2Start, const QgsPoint &segment2End, double radius, int segments = 8 ) SIP_THROW( QgsInvalidArgumentException );
3418
3432 QgsGeometry chamfer( int vertexIndex, double distance1, double distance2 = -1.0 ) const;
3433
3452 static QgsGeometry chamfer( const QgsPoint &segment1Start, const QgsPoint &segment1End, const QgsPoint &segment2Start, const QgsPoint &segment2End, double distance1, double distance2 = -1.0 ) SIP_THROW( QgsInvalidArgumentException );
3453
3454
3455 private:
3456 QgsGeometryPrivate *d; //implicitly shared data pointer
3457
3459 mutable QString mLastError;
3460
3465 void detach();
3466
3471 void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
3472
3473 static void convertPolygon( const QgsPolygon &input, QgsPolygonXY &output );
3474
3476 QgsGeometry convertToPoint( bool destMultipart ) const;
3478 QgsGeometry convertToLine( bool destMultipart ) const;
3480 QgsGeometry convertToPolygon( bool destMultipart ) const;
3481
3493 std::unique_ptr< QgsLineString > smoothLine( const QgsLineString &line, unsigned int iterations = 1, double offset = 0.25, double minimumDistance = -1, double maxAngle = 180.0 ) const;
3494
3506 std::unique_ptr< QgsPolygon > smoothPolygon( const QgsPolygon &polygon, unsigned int iterations = 1, double offset = 0.25, double minimumDistance = -1, double maxAngle = 180.0 ) const;
3507
3508 QgsGeometry doChamferFillet( ChamferFilletOperationType op, int vertexIndex, double distance1, double distance2, int segments ) const;
3509
3511
3512}; // class QgsGeometry
3513
3515
3517CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsGeometry &geometry );
3519CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry );
3520
3521#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
@ CounterClockwise
Counter-clockwise direction.
Definition qgis.h:3615
@ Clockwise
Clockwise direction.
Definition qgis.h:3614
GeometryOperationResult
Success or failure of a geometry operation.
Definition qgis.h:2162
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
Definition qgis.h:2196
GeometryValidationEngine
Available engines for validating geometries.
Definition qgis.h:2205
@ QgisInternal
Use internal QgsGeometryValidator method.
Definition qgis.h:2206
@ SkipEmptyInteriorRings
Skip any empty polygon interior ring.
Definition qgis.h:2282
QFlags< GeosCreationFlag > GeosCreationFlags
Geos geometry creation behavior flags.
Definition qgis.h:2291
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:379
@ Point
Points.
Definition qgis.h:380
@ Line
Lines.
Definition qgis.h:381
@ Polygon
Polygons.
Definition qgis.h:382
@ Unknown
Unknown types.
Definition qgis.h:383
static const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
Definition qgis.h:6858
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ Point
Point.
Definition qgis.h:296
@ Unknown
Unknown.
Definition qgis.h:295
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition qgis.h:2831
@ Forward
Forward transform (from source to destination).
Definition qgis.h:2832
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:211
Handles coordinate transforms between two coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
Definition qgscurve.h:36
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Java-style iterator for const traversal of parts of a geometry.
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.
bool isExactlyEqual(const QgsGeometry &geometry, Qgis::GeometryBackend backend=Qgis::GeometryBackend::QGIS) const
Compares the geometry with another geometry using the specified backend.
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.
Q_DECL_DEPRECATED 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.
bool deleteVertices(const QSet< int > &atVertices)
Deletes vertices at the given positions (first number is index 0).
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.
bool isFuzzyEqual(const QgsGeometry &geometry, double epsilon=1e-4, Qgis::GeometryBackend backend=Qgis::GeometryBackend::QGIS) const
Compares the geometry with another geometry within the tolerance epsilon using the specified backend.
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...
bool isTopologicallyEqual(const QgsGeometry &geometry, Qgis::GeometryBackend backend=Qgis::GeometryBackend::GEOS) const
Compares the geometry with another geometry using the specified backend.
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...
Q_DECL_DEPRECATED 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.
As part of the API refactoring and improvements which landed in QGIS
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:237
#define SIP_IN
Definition qgis_sip.h:70
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_PYNAME(name)
Definition qgis_sip.h:88
#define SIP_PYARGREMOVE
Definition qgis_sip.h:158
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_HOLDGIL
Definition qgis_sip.h:178
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_THROW(name,...)
Definition qgis_sip.h:210
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:35