QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsgeometry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometry.h - Geometry (stored as Open Geospatial Consortium WKB)
3 -------------------------------------------------------------------
4Date : 02 May 2005
5Copyright : (C) 2005 by Brendan Morley
6email : morb at ozemail dot com dot au
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSGEOMETRY_H
17#define QGSGEOMETRY_H
18
19#include <climits>
20#include <functional>
21#include <limits>
22#include <memory>
23
24#include "qgis_core.h"
25#include "qgis_sip.h"
26#include "qgsabstractgeometry.h"
27#include "qgsfeatureid.h"
28#include "qgspoint.h"
29#include "qgspointxy.h"
30#include "qgsvertexid.h"
31
32#include <QDomDocument>
33#include <QJsonObject>
34#include <QSet>
35#include <QString>
36#include <QVector>
37
38#ifndef SIP_RUN
39#include <nlohmann/json_fwd.hpp>
40using namespace nlohmann;
41#endif
42
44class QgsVectorLayer;
45class QgsMapToPixel;
46class QPainter;
47class QgsPolygon;
48class QgsLineString;
50class QgsCurve;
51class QgsFeedback;
52
61typedef QVector<QgsPointXY> QgsPolylineXY;
62
69#ifndef SIP_RUN
71#else
72typedef QVector<QgsPoint> QgsPolyline;
73#endif
74
82#ifndef SIP_RUN
83typedef QVector<QgsPolyline> QgsMultiPolyline;
84#else
85typedef QVector<QVector< QgsPoint >> QgsMultiPolyline;
86#endif
87
89#ifndef SIP_RUN
90typedef QVector<QgsPolylineXY> QgsPolygonXY;
91#else
92typedef QVector<QVector<QgsPointXY>> QgsPolygonXY;
93#endif
94
96typedef QVector<QgsPointXY> QgsMultiPointXY;
97
99#ifndef SIP_RUN
100typedef QVector<QgsPolylineXY> QgsMultiPolylineXY;
101#else
102typedef QVector<QVector<QgsPointXY>> QgsMultiPolylineXY;
103#endif
104
106#ifndef SIP_RUN
107typedef QVector<QgsPolygonXY> QgsMultiPolygonXY;
108#else
109typedef QVector<QVector<QVector<QgsPointXY>>> QgsMultiPolygonXY;
110#endif
111
112class QgsRectangle;
113
114class QgsConstWkbPtr;
115
116struct QgsGeometryPrivate;
117
124class CORE_EXPORT QgsGeometryParameters
125{
126 public:
127
138 double gridSize() const { return mGridSize; }
139
150 void setGridSize( double size ) { mGridSize = size; }
151
152 private:
153
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
186
188 QgsGeometry( const QgsGeometry & );
189
194 QgsGeometry &operator=( QgsGeometry const &rhs ) SIP_SKIP;
195
201
207 explicit QgsGeometry( std::unique_ptr< QgsAbstractGeometry > geom ) SIP_SKIP;
208
209 virtual ~QgsGeometry();
210
222
235
248
256 bool isNull() const SIP_HOLDGIL;
257
259 Q_INVOKABLE static QgsGeometry fromWkt( const QString &wkt );
261 static QgsGeometry fromPointXY( const QgsPointXY &point ) SIP_HOLDGIL;
262
268 static QgsGeometry fromPoint( const QgsPoint &point ) SIP_HOLDGIL;
269
271 static QgsGeometry fromMultiPointXY( const QgsMultiPointXY &multipoint );
272
283 static QgsGeometry fromPolylineXY( const QgsPolylineXY &polyline );
284
293 static QgsGeometry fromPolyline( const QgsPolyline &polyline );
294
298 static QgsGeometry fromMultiPolylineXY( const QgsMultiPolylineXY &multiline );
299
300#ifndef SIP_RUN
301
305#else
306
324#endif
325 static QgsGeometry fromPolygonXY( const QgsPolygonXY &polygon );
326
330 static QgsGeometry fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly );
331
333 static QgsGeometry fromRect( const QgsRectangle &rect ) SIP_HOLDGIL;
334
342 static QgsGeometry fromBox3D( const QgsBox3D &box ) SIP_HOLDGIL;
343
344
346 static QgsGeometry collectGeometry( const QVector<QgsGeometry> &geometries );
347
363 static QgsGeometry createWedgeBuffer( const QgsPoint &center, double azimuth, double angularWidth,
364 double outerRadius, double innerRadius = 0 );
365
379 static QgsGeometry createWedgeBufferFromAngles( const QgsPoint &center, double startAngle, double endAngle,
380 double outerRadius, double innerRadius = 0 );
381
387 void fromWkb( unsigned char *wkb, int length ) SIP_SKIP;
388
392 void fromWkb( const QByteArray &wkb );
393
399
404 Qgis::GeometryType type() const SIP_HOLDGIL;
405
412 bool isEmpty() const SIP_HOLDGIL;
413
415 bool isMultipart() const SIP_HOLDGIL;
416
430 bool equals( const QgsGeometry &geometry ) const;
431
447 bool isGeosEqual( const QgsGeometry & ) const;
448
455 bool isGeosValid( Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const;
456
464 bool isSimple() const;
465
479 bool isAxisParallelRectangle( double maximumDeviation, bool simpleRectanglesOnly = false ) const;
480
492 double area() const;
493
507 double length() const;
508
516 double distance( const QgsGeometry &geom ) const;
517
518#ifndef SIP_RUN
519
520 // TODO QGIS 4: consider renaming vertices_begin, vertices_end, parts_begin, parts_end, etc
521 // to camelCase
522
527
532#endif
533
557
558#ifndef SIP_RUN
559
569
579
589
599#endif
600
639
673
690 double hausdorffDistance( const QgsGeometry &geom ) const;
691
709 double hausdorffDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const;
710
725 double frechetDistance( const QgsGeometry &geom ) const SIP_THROW( QgsNotSupportedException );
726
749 double frechetDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const SIP_THROW( QgsNotSupportedException );
750
763 QgsPointXY closestVertex( const QgsPointXY &point, int &closestVertexIndex SIP_OUT, int &previousVertexIndex SIP_OUT, int &nextVertexIndex SIP_OUT, double &sqrDist SIP_OUT ) const;
764
772 double distanceToVertex( int vertex ) const;
773
780 double angleAtVertex( int vertex ) const;
781
794 void adjacentVertices( int atVertex, int &beforeVertex SIP_OUT, int &afterVertex SIP_OUT ) const;
795
808 bool insertVertex( double x, double y, int beforeVertex );
809
822 bool insertVertex( const QgsPoint &point, int beforeVertex );
823
831 bool addTopologicalPoint( const QgsPoint &point, double snappingTolerance = 1e-8, double segmentSearchEpsilon = 1e-12 );
832
840 bool moveVertex( double x, double y, int atVertex );
841
849 bool moveVertex( const QgsPoint &p, int atVertex );
850
862 bool deleteVertex( int atVertex );
863
871 bool toggleCircularAtVertex( int atVertex );
872
878 QgsPoint vertexAt( int atVertex ) const;
879
885 double sqrDistToVertexAt( QgsPointXY &point SIP_IN, int atVertex ) const;
886
891 QgsGeometry nearestPoint( const QgsGeometry &other ) const;
892
902 QgsGeometry shortestLine( const QgsGeometry &other ) const;
903
910 double closestVertexWithContext( const QgsPointXY &point, int &atVertex SIP_OUT ) const;
911
923 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;
924
930 Qgis::GeometryOperationResult addRing( const QVector<QgsPointXY> &ring );
931
938
946 Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) SIP_PYNAME( addPointsXY ) SIP_DEPRECATED;
947
955 Qgis::GeometryOperationResult addPartV2( const QVector<QgsPointXY> &points, Qgis::WkbType wkbType = Qgis::WkbType::Unknown ) SIP_PYNAME( addPointsXYV2 );
956
965
974
983
992
998 Qgis::GeometryOperationResult addPart( const QgsGeometry &newPart ) SIP_PYNAME( addPartGeometry );
999
1005 QgsGeometry removeInteriorRings( double minimumAllowedArea = -1 ) const;
1006
1011 Qgis::GeometryOperationResult translate( double dx, double dy, double dz = 0.0, double dm = 0.0 );
1012
1028
1037 Qgis::GeometryOperationResult transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 );
1038
1045 Qgis::GeometryOperationResult rotate( double rotation, const QgsPointXY &center );
1046
1057 Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitGeometry( const QVector<QgsPointXY> &splitLine, QVector<QgsGeometry> &newGeometries, bool topological, QVector<QgsPointXY> &topologyTestPoints, bool splitFeature = true ) SIP_SKIP;
1058
1080 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;
1081
1082
1083 /*
1084 This SIP code is to support overloaded methods of splitGeometry.
1085 When the deprecated method is removed in QGIS 4.0 this code can be dropped
1086 TODO QGIS 4 remove MethodCode
1087 */
1088#ifdef SIP_RUN
1089
1108 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]]] );
1109 % MethodCode
1110 {
1111 int sipIsErr = 0;
1112 int state;
1113
1114 if ( PyList_Check( a0 ) && PyList_GET_SIZE( a0 ) )
1115 {
1116 PyObject *p0 = PyList_GetItem( a0, 0 );
1117 if ( sipCanConvertToType( p0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1118 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1119 {
1120 QVector<QgsGeometry> newGeometries;
1121 QVector<QgsPointXY> topologyTestPoints;
1122
1123 QVector<QgsPointXY> *splitLine = reinterpret_cast<QVector<QgsPointXY> *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1124 if ( !sipIsErr )
1125 {
1126 Qgis::GeometryOperationResult result = sipCpp->splitGeometry( *splitLine, newGeometries, a1, topologyTestPoints, a2 );
1127
1128 PyObject *o0 = sipConvertFromEnum( static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1129 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1130 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPointXY, Py_None );
1131
1132 sipRes = PyTuple_New( 3 );
1133 PyTuple_SET_ITEM( sipRes, 0, o0 );
1134 PyTuple_SET_ITEM( sipRes, 1, o1 );
1135 PyTuple_SET_ITEM( sipRes, 2, o2 );
1136 }
1137 sipReleaseType( splitLine, sipType_QVector_0100QgsPointXY, state );
1138 }
1139
1140 else if ( sipCanConvertToType( p0, sipType_QgsPoint, SIP_NOT_NONE ) &&
1141 sipCanConvertToType( a0, sipType_QVector_0100QgsPoint, SIP_NOT_NONE ) )
1142 {
1143 QVector<QgsGeometry> newGeometries;
1144 QVector<QgsPoint> topologyTestPoints;
1145
1146 QVector<QgsPoint> *splitLine = reinterpret_cast<QVector<QgsPoint> *>( sipConvertToType( a0, sipType_QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1147 if ( !sipIsErr )
1148 {
1149 Qgis::GeometryOperationResult result = sipCpp->splitGeometry( *splitLine, newGeometries, a1, topologyTestPoints, a2 );
1150
1151 PyObject *o0 = sipConvertFromEnum( static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1152 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1153 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPoint, Py_None );
1154
1155 sipRes = PyTuple_New( 3 );
1156 PyTuple_SET_ITEM( sipRes, 0, o0 );
1157 PyTuple_SET_ITEM( sipRes, 1, o1 );
1158 PyTuple_SET_ITEM( sipRes, 2, o2 );
1159 }
1160 sipReleaseType( splitLine, sipType_QVector_0100QgsPoint, state );
1161 }
1162 else
1163 {
1164 sipIsErr = 1;
1165 PyErr_SetString( PyExc_TypeError, QStringLiteral( "Could not convert first argument to a list of QgsPoint or QgsPointXY." ).toUtf8().constData() );
1166 }
1167 }
1168 else
1169 {
1170 sipIsErr = 1;
1171 PyErr_SetString( PyExc_TypeError, QStringLiteral( "First argument is not a list of points or is empty." ).toUtf8().constData() );
1172 }
1173 }
1174 % End
1175#endif
1176
1188 Qgis::GeometryOperationResult splitGeometry( const QgsCurve *curve, QVector<QgsGeometry> &newGeometries SIP_OUT, bool preserveCircular, bool topological, QgsPointSequence &topologyTestPoints SIP_OUT, bool splitFeature = true );
1189
1194 Qgis::GeometryOperationResult reshapeGeometry( const QgsLineString &reshapeLineString );
1195
1201 int makeDifferenceInPlace( const QgsGeometry &other ) SIP_SKIP;
1202
1209 QgsGeometry makeDifference( const QgsGeometry &other ) const;
1210
1215 QgsRectangle boundingBox() const;
1216
1222 QgsBox3D boundingBox3D() const;
1223
1236 QgsGeometry orientedMinimumBoundingBox( double &area SIP_OUT, double &angle SIP_OUT, double &width SIP_OUT, double &height SIP_OUT ) const;
1237
1247 QgsGeometry orientedMinimumBoundingBox() const SIP_SKIP;
1248
1256 QgsGeometry minimalEnclosingCircle( QgsPointXY &center SIP_OUT, double &radius SIP_OUT, unsigned int segments = 36 ) const;
1257
1262 QgsGeometry minimalEnclosingCircle( unsigned int segments = 36 ) const SIP_SKIP;
1263
1271 QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
1272
1285 QgsGeometry triangularWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1286
1305 QgsGeometry triangularWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1306
1319 QgsGeometry squareWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1320
1339 QgsGeometry squareWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1340
1353 QgsGeometry roundWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
1354
1373 QgsGeometry roundWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
1374
1388 QgsGeometry applyDashPattern( const QVector< double > &pattern,
1389 Qgis::DashPatternLineEndingRule startRule = Qgis::DashPatternLineEndingRule::NoRule,
1390 Qgis::DashPatternLineEndingRule endRule = Qgis::DashPatternLineEndingRule::NoRule,
1391 Qgis::DashPatternSizeAdjustment adjustment = Qgis::DashPatternSizeAdjustment::ScaleBothDashAndGap,
1392 double patternOffset = 0 ) const;
1393
1405 QgsGeometry snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const;
1406
1426 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false );
1427
1437 bool intersects( const QgsRectangle &rectangle ) const;
1438
1453 bool intersects( const QgsGeometry &geometry ) const;
1454
1463 bool boundingBoxIntersects( const QgsRectangle &rectangle ) const;
1464
1473 bool boundingBoxIntersects( const QgsGeometry &geometry ) const;
1474
1478 bool contains( const QgsPointXY *p ) const;
1479
1485 bool contains( double x, double y ) const;
1486
1496 bool contains( const QgsGeometry &geometry ) const;
1497
1507 bool disjoint( const QgsGeometry &geometry ) const;
1508
1518 bool touches( const QgsGeometry &geometry ) const;
1519
1529 bool overlaps( const QgsGeometry &geometry ) const;
1530
1540 bool within( const QgsGeometry &geometry ) const;
1541
1551 bool crosses( const QgsGeometry &geometry ) const;
1552
1560 QgsGeometry buffer( double distance, int segments ) const;
1561
1573 QgsGeometry buffer( double distance, int segments, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit ) const;
1574
1582 QgsGeometry offsetCurve( double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit ) const;
1583
1598 QgsGeometry singleSidedBuffer( double distance, int segments, Qgis::BufferSide side,
1599 Qgis::JoinStyle joinStyle = Qgis::JoinStyle::Round,
1600 double miterLimit = 2.0 ) const;
1601
1619 QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const;
1620
1635 QgsGeometry variableWidthBufferByM( int segments ) const;
1636
1642 QgsGeometry extendLine( double startDistance, double endDistance ) const;
1643
1645 QgsGeometry simplify( double tolerance ) const;
1646
1655 QgsGeometry densifyByCount( int extraNodesPerSegment ) const;
1656
1670 QgsGeometry densifyByDistance( double distance ) const;
1671
1687 QgsGeometry convertToCurves( double distanceTolerance = 1e-8, double angleTolerance = 1e-8 ) const;
1688
1702 QgsGeometry centroid() const;
1703
1717 QgsGeometry pointOnSurface() const;
1718
1730 QgsGeometry poleOfInaccessibility( double precision, double *distanceToBoundary SIP_OUT = nullptr ) const;
1731
1755 QgsGeometry largestEmptyCircle( double tolerance, const QgsGeometry &boundary = QgsGeometry() ) const SIP_THROW( QgsNotSupportedException );
1756
1771 QgsGeometry minimumWidth() const SIP_THROW( QgsNotSupportedException );
1772
1794 double minimumClearance() const SIP_THROW( QgsNotSupportedException );
1795
1807 QgsGeometry minimumClearanceLine() const SIP_THROW( QgsNotSupportedException );
1808
1817 QgsGeometry convexHull() const;
1818
1832 QgsGeometry concaveHull( double targetPercent, bool allowHoles = false ) const SIP_THROW( QgsNotSupportedException );
1833
1848 QgsGeometry voronoiDiagram( const QgsGeometry &extent = QgsGeometry(), double tolerance = 0.0, bool edgesOnly = false ) const;
1849
1860 QgsGeometry delaunayTriangulation( double tolerance = 0.0, bool edgesOnly = false ) const;
1861
1874 QgsGeometry constrainedDelaunayTriangulation() const SIP_THROW( QgsNotSupportedException );
1875
1893 Qgis::CoverageValidityResult validateCoverage( double gapWidth, QgsGeometry *invalidEdges SIP_OUT = nullptr ) const SIP_THROW( QgsNotSupportedException );
1894
1915 QgsGeometry simplifyCoverageVW( double tolerance, bool preserveBoundary ) const SIP_THROW( QgsNotSupportedException );
1916
1928 QgsGeometry unionCoverage() const;
1929
1940 QgsGeometry node() const;
1941
1956 QgsGeometry sharedPaths( const QgsGeometry &other ) const;
1957
1979 QgsGeometry subdivide( int maxNodes = 256, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
1980
1995 QgsGeometry interpolate( double distance ) const;
1996
2007 double lineLocatePoint( const QgsGeometry &point ) const;
2008
2017 double interpolateAngle( double distance ) const;
2018
2030 QgsGeometry intersection( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2031
2038 QgsGeometry clipped( const QgsRectangle &rectangle );
2039
2054 QgsGeometry combine( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2055
2066 QgsGeometry mergeLines( const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2067
2079 QgsGeometry difference( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2080
2092 QgsGeometry symDifference( const QgsGeometry &geometry, const QgsGeometryParameters &parameters = QgsGeometryParameters() ) const;
2093
2095 QgsGeometry extrude( double x, double y );
2096
2097#ifndef SIP_RUN
2098
2120 QVector< QgsPointXY > randomPointsInPolygon( int count, const std::function< bool( const QgsPointXY & ) > &acceptPoint, unsigned long seed = 0, QgsFeedback *feedback = nullptr, int maxTriesPerPoint = 0 ) const;
2121
2135 QVector< QgsPointXY > randomPointsInPolygon( int count, unsigned long seed = 0, QgsFeedback *feedback = nullptr ) const;
2137#else
2138
2152 SIP_PYOBJECT randomPointsInPolygon( int count, unsigned long seed = 0 ) const SIP_TYPEHINT( QgsPolylineXY );
2153 % MethodCode
2154 const Qgis::GeometryType type = sipCpp->type();
2155 if ( sipCpp->isNull() )
2156 {
2157 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Cannot generate points inside a null geometry." ).toUtf8().constData() );
2158 sipIsErr = 1;
2159 }
2160 else if ( type != Qgis::GeometryType::Polygon )
2161 {
2162 PyErr_SetString( PyExc_TypeError, QStringLiteral( "Cannot generate points inside a %1 geometry. Only Polygon types are permitted." ).arg( QgsWkbTypes::displayString( sipCpp->wkbType() ) ).toUtf8().constData() );
2163 sipIsErr = 1;
2164 }
2165 else
2166 {
2167 const sipTypeDef *qvector_type = sipFindType( "QVector<QgsPointXY>" );
2168 sipRes = sipConvertFromNewType( new QVector< QgsPointXY >( sipCpp->randomPointsInPolygon( a0, a1 ) ), qvector_type, Py_None );
2169 }
2170 % End
2171
2172
2173#endif
2175
2183 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const;
2184
2191 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const;
2192
2198 Q_INVOKABLE QString asWkt( int precision = 17 ) const;
2199
2200#ifdef SIP_RUN
2201 SIP_PYOBJECT __repr__();
2202 % MethodCode
2203 QString str;
2204 if ( sipCpp->isNull() )
2205 str = QStringLiteral( "<QgsGeometry: null>" );
2206 else
2207 {
2208 QString wkt = sipCpp->asWkt();
2209 if ( wkt.length() > 1000 )
2210 wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
2211 str = QStringLiteral( "<QgsGeometry: %1>" ).arg( wkt );
2212 }
2213 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
2214 % End
2215#endif
2216
2220 QString asJson( int precision = 17 ) const;
2221
2227 virtual json asJsonObject( int precision = 17 ) const SIP_SKIP;
2228
2259 QVector< QgsGeometry > coerceToType( Qgis::WkbType type, double defaultZ = 0, double defaultM = 0, bool avoidDuplicates = true ) const;
2260
2272 QgsGeometry convertToType( Qgis::GeometryType destType, bool destMultipart = false ) const;
2273
2274 /* Accessor functions for getting geometry data */
2275
2276#ifndef SIP_RUN
2277
2286 QgsPointXY asPoint() const;
2287#else
2288
2299 SIP_PYOBJECT asPoint() const SIP_TYPEHINT( QgsPointXY );
2300 % MethodCode
2301 if ( sipCpp->isNull() )
2302 {
2303 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a point." ).toUtf8().constData() );
2304 sipIsErr = 1;
2305 }
2306 else
2307 {
2308 const QgsAbstractGeometry *geom = sipCpp->constGet();
2310 {
2311 PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a point. Only Point types are permitted." ).arg( QgsWkbTypes::displayString( geom->wkbType() ) ).toUtf8().constData() );
2312 sipIsErr = 1;
2313 }
2314 else
2315 {
2316 sipRes = sipConvertFromNewType( new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
2317 }
2318 }
2319 % End
2320#endif
2321
2322#ifndef SIP_RUN
2323
2332 QgsPolylineXY asPolyline() const;
2333#else
2334
2346 SIP_PYOBJECT asPolyline() const SIP_TYPEHINT( QgsPolylineXY );
2347 % MethodCode
2348 const Qgis::WkbType type = sipCpp->wkbType();
2349 if ( sipCpp->isNull() )
2350 {
2351 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a polyline." ).toUtf8().constData() );
2352 sipIsErr = 1;
2353 }
2355 {
2356 PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a polyline. Only single line or curve types are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2357 sipIsErr = 1;
2358 }
2359 else
2360 {
2361 const sipTypeDef *qvector_type = sipFindType( "QVector< QgsPointXY >" );
2362 sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
2363 }
2364 % End
2365#endif
2366
2367#ifndef SIP_RUN
2368
2377 QgsPolygonXY asPolygon() const;
2378#else
2379
2391 SIP_PYOBJECT asPolygon() const SIP_TYPEHINT( QgsPolygonXY );
2392 % MethodCode
2393 const Qgis::WkbType type = sipCpp->wkbType();
2394 if ( sipCpp->isNull() )
2395 {
2396 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a polygon." ).toUtf8().constData() );
2397 sipIsErr = 1;
2398 }
2400 {
2401 PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a polygon. Only single polygon or curve polygon types are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2402 sipIsErr = 1;
2403 }
2404 else
2405 {
2406 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QgsPointXY>>" );
2407 sipRes = sipConvertFromNewType( new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
2408 }
2409 % End
2410#endif
2411
2412#ifndef SIP_RUN
2413
2421 QgsMultiPointXY asMultiPoint() const;
2422#else
2423
2434 SIP_PYOBJECT asMultiPoint() const SIP_TYPEHINT( QgsMultiPointXY );
2435 % MethodCode
2436 const Qgis::WkbType type = sipCpp->wkbType();
2437 if ( sipCpp->isNull() )
2438 {
2439 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a multipoint." ).toUtf8().constData() );
2440 sipIsErr = 1;
2441 }
2443 {
2444 PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a multipoint. Only multipoint types are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2445 sipIsErr = 1;
2446 }
2447 else
2448 {
2449 const sipTypeDef *qvector_type = sipFindType( "QVector< QgsPointXY >" );
2450 sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
2451 }
2452 % End
2453#endif
2454
2455#ifndef SIP_RUN
2456
2465 QgsMultiPolylineXY asMultiPolyline() const;
2466#else
2467
2479 SIP_PYOBJECT asMultiPolyline() const SIP_TYPEHINT( QgsMultiPolylineXY );
2480 % MethodCode
2481 const Qgis::WkbType type = sipCpp->wkbType();
2482 if ( sipCpp->isNull() )
2483 {
2484 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a multilinestring." ).toUtf8().constData() );
2485 sipIsErr = 1;
2486 }
2488 {
2489 PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a multilinestring. Only multi linestring or curves are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2490 sipIsErr = 1;
2491 }
2492 else
2493 {
2494 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QgsPointXY>>" );
2495 sipRes = sipConvertFromNewType( new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
2496 }
2497 % End
2498#endif
2499
2500#ifndef SIP_RUN
2501
2510 QgsMultiPolygonXY asMultiPolygon() const;
2511#else
2512
2524 SIP_PYOBJECT asMultiPolygon() const SIP_TYPEHINT( QgsMultiPolygonXY );
2525 % MethodCode
2526 const Qgis::WkbType type = sipCpp->wkbType();
2527 if ( sipCpp->isNull() )
2528 {
2529 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a multipolygon." ).toUtf8().constData() );
2530 sipIsErr = 1;
2531 }
2533 {
2534 PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a multipolygon. Only multi polygon or curves are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2535 sipIsErr = 1;
2536 }
2537 else
2538 {
2539 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QVector<QgsPointXY>>>" );
2540 sipRes = sipConvertFromNewType( new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
2541 }
2542 % End
2543#endif
2544
2548 QVector<QgsGeometry> asGeometryCollection() const;
2549
2554 QPointF asQPointF() const SIP_HOLDGIL;
2555
2567 QPolygonF asQPolygonF() const SIP_HOLDGIL;
2568
2574 bool deleteRing( int ringNum, int partNum = 0 );
2575
2580 bool deletePart( int partNum );
2581
2590 bool convertToMultiType();
2591
2607 bool convertToCurvedMultiType();
2608
2618 bool convertToSingleType();
2619
2629 bool convertGeometryCollectionToSubclass( Qgis::GeometryType geomType );
2630
2642 Q_DECL_DEPRECATED int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
2643 const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) ) SIP_DEPRECATED;
2644
2656 Qgis::GeometryOperationResult avoidIntersectionsV2( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
2657 const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
2658
2679 QgsGeometry makeValid( Qgis::MakeValidMethod method = Qgis::MakeValidMethod::Linework, bool keepCollapsed = false ) const SIP_THROW( QgsNotSupportedException );
2680
2690 Qgis::AngularDirection polygonOrientation() const;
2691
2706
2721
2722
2737 QgsGeometry forceRHR() const;
2738
2749 QgsGeometry forcePolygonClockwise() const;
2750
2761 QgsGeometry forcePolygonCounterClockwise() const;
2762
2767 class CORE_EXPORT Error
2768 {
2769 public:
2771 : mMessage( QStringLiteral( "none" ) )
2772 {}
2773
2774 explicit Error( const QString &m )
2775 : mMessage( m )
2776 {}
2777
2778 Error( const QString &m, const QgsPointXY &p )
2779 : mMessage( m )
2780 , mLocation( p )
2781 , mHasLocation( true ) {}
2782
2786 QString what() const;
2787
2791 QgsPointXY where() const;
2792
2796 bool hasWhere() const;
2797
2798#ifdef SIP_RUN
2799 SIP_PYOBJECT __repr__();
2800 % MethodCode
2801 QString str = QStringLiteral( "<QgsGeometry.Error: %1>" ).arg( sipCpp->what() );
2802 sipRes = PyUnicode_FromString( str.toUtf8().data() );
2803 % End
2804#endif
2805
2806 // TODO c++20 - replace with = default
2807 bool operator==( const QgsGeometry::Error &other ) const
2808 {
2809 return other.mMessage == mMessage && other.mHasLocation == mHasLocation && other.mLocation == mLocation;
2810 }
2811
2812 private:
2813 QString mMessage;
2814 QgsPointXY mLocation;
2815 bool mHasLocation = false;
2816 };
2817
2825 void validateGeometry( QVector<QgsGeometry::Error> &errors SIP_OUT, Qgis::GeometryValidationEngine method = Qgis::GeometryValidationEngine::QgisInternal, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const;
2826
2836 void normalize();
2837
2846 static QgsGeometry unaryUnion( const QVector<QgsGeometry> &geometries, const QgsGeometryParameters &parameters = QgsGeometryParameters() );
2847
2855 static QgsGeometry polygonize( const QVector<QgsGeometry> &geometries );
2856
2863 void convertToStraightSegment( double tolerance = M_PI / 180., QgsAbstractGeometry::SegmentationToleranceType toleranceType = QgsAbstractGeometry::MaximumAngle );
2864
2870 bool requiresConversionToStraightSegments() const;
2871
2876 void mapToPixel( const QgsMapToPixel &mtp );
2877
2882 void draw( QPainter &p ) const;
2883
2893 bool vertexIdFromVertexNr( int number, QgsVertexId &id SIP_OUT ) const;
2894
2905 int vertexNrFromVertexId( QgsVertexId id ) const;
2906
2913 QString lastError() const SIP_HOLDGIL;
2914
2924 void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) SIP_SKIP;
2925
2940 void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) SIP_SKIP;
2941
2946 static QgsGeometry fromQPointF( QPointF point ) SIP_HOLDGIL;
2947
2954 static QgsGeometry fromQPolygonF( const QPolygonF &polygon );
2955
2963 Q_DECL_DEPRECATED static QgsPolylineXY createPolylineFromQPolygonF( const QPolygonF &polygon ) SIP_DEPRECATED;
2964
2972 Q_DECL_DEPRECATED static QgsPolygonXY createPolygonFromQPolygonF( const QPolygonF &polygon ) SIP_DEPRECATED;
2973
2974#ifndef SIP_RUN
2975
2984 static bool compare( const QgsPolylineXY &p1, const QgsPolylineXY &p2,
2985 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2986
2995 static bool compare( const QgsPolygonXY &p1, const QgsPolygonXY &p2,
2996 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2997
3007 static bool compare( const QgsMultiPolygonXY &p1, const QgsMultiPolygonXY &p2,
3008 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3009#else
3010
3029 static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3030 % MethodCode
3031 {
3032 sipRes = false;
3033 int state0;
3034 int state1;
3035 int sipIsErr = 0;
3036
3037 if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
3038 PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
3039 {
3040 PyObject *o0 = PyList_GetItem( a0, 0 );
3041 PyObject *o1 = PyList_GetItem( a1, 0 );
3042 if ( o0 && o1 )
3043 {
3044 // compare polyline - polyline
3045 if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3046 sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3047 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
3048 sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3049 {
3050 QgsPolylineXY *p0;
3051 QgsPolylineXY *p1;
3052 p0 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3053 p1 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3054 if ( !sipIsErr )
3055 {
3056 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3057 }
3058 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
3059 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
3060 }
3061 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
3062 PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
3063 {
3064 PyObject *oo0 = PyList_GetItem( o0, 0 );
3065 PyObject *oo1 = PyList_GetItem( o1, 0 );
3066 if ( oo0 && oo1 )
3067 {
3068 // compare polygon - polygon
3069 if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3070 sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3071 sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
3072 sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3073 {
3074 QgsPolygonXY *p0;
3075 QgsPolygonXY *p1;
3076 p0 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3077 p1 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3078 if ( !sipIsErr )
3079 {
3080 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3081 }
3082 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
3083 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
3084 }
3085 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
3086 PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
3087 {
3088 PyObject *ooo0 = PyList_GetItem( oo0, 0 );
3089 PyObject *ooo1 = PyList_GetItem( oo1, 0 );
3090 if ( ooo0 && ooo1 )
3091 {
3092 // compare multipolygon - multipolygon
3093 if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3094 sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3095 sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
3096 sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3097 {
3100 p0 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3101 p1 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3102 if ( !sipIsErr )
3103 {
3104 sipRes = QgsGeometry::compare( *p0, *p1, a2 );
3105 }
3106 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
3107 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
3108 }
3109 }
3110 }
3111 }
3112 }
3113 }
3114 }
3115 }
3116 % End
3117#endif
3118
3134 QgsGeometry smooth( unsigned int iterations = 1, double offset = 0.25,
3135 double minimumDistance = -1.0, double maxAngle = 180.0 ) const;
3136
3176 static QgsGeometryEngine *createGeometryEngine( const QgsAbstractGeometry *geometry, double precision = 0.0, Qgis::GeosCreationFlags flags = Qgis::GeosCreationFlag::SkipEmptyInteriorRings ) SIP_FACTORY;
3177
3183 static void convertPointList( const QVector<QgsPointXY> &input, QgsPointSequence &output );
3184
3190 static void convertPointList( const QgsPointSequence &input, QVector<QgsPointXY> &output );
3191
3193 operator QVariant() const
3194 {
3195 return QVariant::fromValue( *this );
3196 }
3197
3203 {
3204 Chamfer = 1,
3205 Fillet,
3206 };
3207#ifndef SIP_RUN
3208 Q_ENUM( ChamferFilletOperationType )
3209#endif
3210
3227 QgsGeometry fillet( int vertexIndex, double radius, int segments = 8 ) const;
3228
3247 static QgsGeometry fillet( const QgsPoint &segment1Start, const QgsPoint &segment1End, const QgsPoint &segment2Start, const QgsPoint &segment2End, double radius, int segments = 8 ) SIP_THROW( QgsInvalidArgumentException );
3248
3262 QgsGeometry chamfer( int vertexIndex, double distance1, double distance2 = -1.0 ) const;
3263
3282 static QgsGeometry chamfer( const QgsPoint &segment1Start, const QgsPoint &segment1End, const QgsPoint &segment2Start, const QgsPoint &segment2End, double distance1, double distance2 = -1.0 ) SIP_THROW( QgsInvalidArgumentException );
3283
3284
3285 private:
3286
3287 QgsGeometryPrivate *d; //implicitly shared data pointer
3288
3290 mutable QString mLastError;
3291
3296 void detach();
3297
3302 void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
3303
3304 static void convertPolygon( const QgsPolygon &input, QgsPolygonXY &output );
3305
3307 QgsGeometry convertToPoint( bool destMultipart ) const;
3309 QgsGeometry convertToLine( bool destMultipart ) const;
3311 QgsGeometry convertToPolygon( bool destMultipart ) const;
3312
3324 std::unique_ptr< QgsLineString > smoothLine( const QgsLineString &line, unsigned int iterations = 1, double offset = 0.25,
3325 double minimumDistance = -1, double maxAngle = 180.0 ) const;
3326
3338 std::unique_ptr< QgsPolygon > smoothPolygon( const QgsPolygon &polygon, unsigned int iterations = 1, double offset = 0.25,
3339 double minimumDistance = -1, double maxAngle = 180.0 ) const;
3340
3341 QgsGeometry doChamferFillet( ChamferFilletOperationType op, int vertexIndex, double distance1, double distance2, int segments ) const;
3342
3344
3345}; // class QgsGeometry
3346
3348
3350CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsGeometry &geometry );
3352CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry );
3353
3354#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
@ CounterClockwise
Counter-clockwise direction.
Definition qgis.h:3434
@ Clockwise
Clockwise direction.
Definition qgis.h:3433
GeometryOperationResult
Success or failure of a geometry operation.
Definition qgis.h:2042
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
Definition qgis.h:2075
GeometryValidationEngine
Available engines for validating geometries.
Definition qgis.h:2084
@ QgisInternal
Use internal QgsGeometryValidator method.
Definition qgis.h:2085
@ SkipEmptyInteriorRings
Skip any empty polygon interior ring.
Definition qgis.h:2149
QFlags< GeosCreationFlag > GeosCreationFlags
Geos geometry creation behavior flags.
Definition qgis.h:2158
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
@ Point
Points.
Definition qgis.h:359
@ Line
Lines.
Definition qgis.h:360
@ Polygon
Polygons.
Definition qgis.h:361
@ Unknown
Unknown types.
Definition qgis.h:362
static const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
Definition qgis.h:6246
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ Point
Point.
Definition qgis.h:279
@ Unknown
Unknown.
Definition qgis.h:278
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition qgis.h:2671
@ Forward
Forward transform (from source to destination).
Definition qgis.h:2672
The part_iterator class provides an STL-style iterator for const references to geometry parts.
The part_iterator class provides an STL-style iterator for geometry parts.
The vertex_iterator class provides an STL-style iterator for vertices.
Abstract base class for all geometries.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices).
virtual const QgsAbstractGeometry * simplifiedTypeRef() const
Returns a reference to the simplest lossless representation of this geometry, e.g.
QFlags< WkbFlag > WkbFlags
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:42
Compound curve geometry type.
A const WKB pointer.
Definition qgswkbptr.h:139
Handles coordinate transforms between two coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
Definition qgscurve.h:36
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Java-style iterator for const traversal of parts of a geometry.
A geometry engine is a low-level representation of a QgsAbstractGeometry object, optimised for use wi...
Encapsulates parameters under which a geometry operation is performed.
double gridSize() const
Returns the grid size which will be used to snap vertices of a geometry.
void setGridSize(double size)
Sets the grid size which will be used to snap vertices of a geometry.
Java-style iterator for traversal of parts of a geometry.
A geometry error.
Error(const QString &m)
Error(const QString &m, const QgsPointXY &p)
bool operator==(const QgsGeometry::Error &other) const
A geometry is the spatial representation of a feature.
double closestSegmentWithContext(const QgsPointXY &point, QgsPointXY &minDistPoint, int &nextVertexIndex, int *leftOrRightOfSegment=nullptr, double epsilon=Qgis::DEFAULT_SEGMENT_EPSILON) const
Searches for the closest segment of geometry to the given point.
QVector< QgsPointXY > randomPointsInPolygon(int count, const std::function< bool(const QgsPointXY &) > &acceptPoint, unsigned long seed=0, QgsFeedback *feedback=nullptr, int maxTriesPerPoint=0) const
Returns a list of count random points generated inside a (multi)polygon geometry (if acceptPoint is s...
double hausdorffDistanceDensify(const QgsGeometry &geom, double densifyFraction) const
Returns the Hausdorff distance between this geometry and geom.
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.
bool addTopologicalPoint(const QgsPoint &point, double snappingTolerance=1e-8, double segmentSearchEpsilon=1e-12)
Adds a vertex to the segment which intersect point but don't already have a vertex there.
QgsGeometry nearestPoint(const QgsGeometry &other) const
Returns the nearest (closest) point on this geometry to another geometry.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
static QgsGeometry fromMultiPolylineXY(const QgsMultiPolylineXY &multiline)
Creates a new geometry from a QgsMultiPolylineXY object.
double frechetDistance(const QgsGeometry &geom) const
Returns the Fréchet distance between this geometry and geom, restricted to discrete points for both g...
bool isAxisParallelRectangle(double maximumDeviation, bool simpleRectanglesOnly=false) const
Returns true if the geometry is a polygon that is almost an axis-parallel rectangle.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static QgsGeometry fromPolylineXY(const QgsPolylineXY &polyline)
Creates a new LineString geometry from a list of QgsPointXY points.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
QgsPointXY closestVertex(const QgsPointXY &point, int &closestVertexIndex, int &previousVertexIndex, int &nextVertexIndex, double &sqrDist) const
Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap ...
double distance(const QgsGeometry &geom) const
Returns the minimum distance between this geometry and another geometry.
static QgsGeometry fromMultiPointXY(const QgsMultiPointXY &multipoint)
Creates a new geometry from a QgsMultiPointXY object.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
friend class QgsInternalGeometryEngine
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsAbstractGeometry::part_iterator parts_begin()
Returns STL-style iterator pointing to the first part of the geometry.
bool equals(const QgsGeometry &geometry) const
Test if this geometry is exactly equal to another geometry.
bool isGeosValid(Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const
Checks validity of the geometry using GEOS.
bool insertVertex(double x, double y, int beforeVertex)
Insert a new vertex before the given vertex index, ring and item (first number is index 0) If the req...
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Qgis::GeometryOperationResult addRing(const QVector< QgsPointXY > &ring)
Adds a new ring to this geometry.
Qgis::GeometryType type
bool isSimple() const
Determines whether the geometry is simple (according to OGC definition), i.e.
static QgsGeometry fromPolyline(const QgsPolyline &polyline)
Creates a new LineString geometry from a list of QgsPoint points.
double area() const
Returns the planar, 2-dimensional area of the geometry.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
Qgis::AngularDirection polygonOrientation() const
Returns the orientation of the polygon.
double hausdorffDistance(const QgsGeometry &geom) const
Returns the Hausdorff distance between this geometry and geom.
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart(const QVector< QgsPointXY > &points, Qgis::GeometryType geomType=Qgis::GeometryType::Unknown)
Adds a new part to a the geometry.
QgsGeometryPartIterator parts()
Returns Java-style iterator for traversal of parts of the geometry.
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygonXY.
double sqrDistToVertexAt(QgsPointXY &point, int atVertex) const
Returns the squared Cartesian distance between the given point to the given vertex index (vertex at t...
void fromWkb(unsigned char *wkb, int length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
static QgsGeometry fromMultiPolygonXY(const QgsMultiPolygonXY &multipoly)
Creates a new geometry from a QgsMultiPolygonXY.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
bool isPolygonClockwise() const
Returns True if the Polygon is clockwise.
double distanceToVertex(int vertex) const
Returns the distance along this geometry from its first vertex to the specified vertex.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
QgsAbstractGeometry::part_iterator parts_end()
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
static QgsGeometry createWedgeBuffer(const QgsPoint &center, double azimuth, double angularWidth, double outerRadius, double innerRadius=0)
Creates a wedge shaped buffer from a center point.
double frechetDistanceDensify(const QgsGeometry &geom, double densifyFraction) const
Returns the Fréchet distance between this geometry and geom, restricted to discrete points for both g...
QgsGeometryConstPartIterator constParts() const
Returns Java-style iterator for traversal of parts of the geometry.
bool isPolygonCounterClockwise() const
Returns True if the Polygon is counter-clockwise.
Qgis::GeometryOperationResult addPartV2(const QVector< QgsPointXY > &points, Qgis::WkbType wkbType=Qgis::WkbType::Unknown)
Adds a new part to a the geometry.
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY &center)
Rotate this geometry around the Z axis.
Qgis::GeometryOperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
double angleAtVertex(int vertex) const
Returns the bisector angle for this geometry at the specified vertex.
double closestVertexWithContext(const QgsPointXY &point, int &atVertex) const
Searches for the closest vertex in this geometry to the given point.
Q_DECL_DEPRECATED Qgis::GeometryOperationResult splitGeometry(const QVector< QgsPointXY > &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QVector< QgsPointXY > &topologyTestPoints, bool splitFeature=true)
Splits this geometry according to a given line.
bool toggleCircularAtVertex(int atVertex)
Converts the vertex at the given position from/to circular.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.).
bool moveVertex(double x, double y, int atVertex)
Moves the vertex at the given position number and item (first number is index 0) to the given coordin...
bool isGeosEqual(const QgsGeometry &) const
Compares the geometry with another geometry using GEOS.
static QgsGeometry fromBox3D(const QgsBox3D &box)
Creates a new geometry from a QgsBox3D object Returns a 2D polygon geometry if the box is purely 2d,...
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
static QgsGeometry createWedgeBufferFromAngles(const QgsPoint &center, double startAngle, double endAngle, double outerRadius, double innerRadius=0)
Creates a wedge shaped buffer from a center point.
QgsGeometry removeInteriorRings(double minimumAllowedArea=-1) const
Removes the interior rings from a (multi)polygon geometry.
static QgsGeometry fromPoint(const QgsPoint &point)
Creates a new geometry from a QgsPoint object.
QgsGeometry shortestLine(const QgsGeometry &other) const
Returns the shortest line joining this geometry to another geometry.
Custom exception class when argument are invalid.
Line string geometry type, with support for z-dimension and m-values.
Perform transforms between map coordinates and device coordinates.
Custom exception class which is raised when an operation is not supported.
Represents a 2D point.
Definition qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Polygon geometry type.
Definition qgspolygon.h:33
A rectangle specified with double values.
Represents a vector layer which manages a vector based dataset.
Java-style iterator for traversal of vertices of a geometry.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static Q_INVOKABLE QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
static Q_INVOKABLE bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:240
#define SIP_IN
Definition qgis_sip.h:71
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_PYNAME(name)
Definition qgis_sip.h:89
#define SIP_PYARGREMOVE
Definition qgis_sip.h:159
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_HOLDGIL
Definition qgis_sip.h:179
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_THROW(name,...)
Definition qgis_sip.h:211
QVector< QgsPoint > QgsPointSequence
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition qgsgeometry.h:90
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
Definition qgsgeometry.h:96
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition qgsgeometry.h:61
QVector< QgsPolyline > QgsMultiPolyline
Multi polyline represented as a vector of polylines.
Definition qgsgeometry.h:83
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
Definition qgsgeometry.h:70
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30