QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsgeometry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometry.h - Geometry (stored as Open Geospatial Consortium WKB)
3  -------------------------------------------------------------------
4 Date : 02 May 2005
5 Copyright : (C) 2005 by Brendan Morley
6 email : morb at ozemail dot com dot au
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
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 <functional>
20
21 #include <QDomDocument>
22 #include <QJsonObject>
23 #include <QSet>
24 #include <QString>
25 #include <QVector>
26
27 #include <climits>
28 #include <limits>
29 #include <memory>
30
31 #include "qgis_core.h"
32 #include "qgis_sip.h"
33
34 #include "qgsabstractgeometry.h"
35 #include "qgspointxy.h"
36 #include "qgspoint.h"
37 #include "qgsfeatureid.h"
38
39 #ifndef SIP_RUN
40 #include "json_fwd.hpp"
41 using namespace nlohmann;
42 #endif
43
44 class QgsGeometryEngine;
45 class QgsVectorLayer;
46 class QgsMapToPixel;
47 class QPainter;
48 class QgsPolygon;
49 class QgsLineString;
51
61 typedef QVector<QgsPointXY> QgsPolylineXY;
62
71
73 #ifndef SIP_RUN
74 typedef QVector<QgsPolylineXY> QgsPolygonXY;
75 #else
76 typedef QVector<QVector<QgsPointXY>> QgsPolygonXY;
77 #endif
78
80 typedef QVector<QgsPointXY> QgsMultiPointXY;
81
83 #ifndef SIP_RUN
84 typedef QVector<QgsPolylineXY> QgsMultiPolylineXY;
85 #else
86 typedef QVector<QVector<QgsPointXY>> QgsMultiPolylineXY;
87 #endif
88
90 #ifndef SIP_RUN
91 typedef QVector<QgsPolygonXY> QgsMultiPolygonXY;
92 #else
93 typedef QVector<QVector<QVector<QgsPointXY>>> QgsMultiPolygonXY;
94 #endif
95
96 class QgsRectangle;
97
98 class QgsConstWkbPtr;
99
100 struct QgsGeometryPrivate;
101
122 class CORE_EXPORT QgsGeometry
123 {
125  Q_PROPERTY( bool isNull READ isNull )
126  Q_PROPERTY( QgsWkbTypes::GeometryType type READ type )
127
128  public:
129
135  {
136  Success = 0,
137  NothingHappened = 1000,
144  /* Add part issues */
152  /* Split features */
154  };
155  Q_ENUM( OperationResult )
156
157
158  QgsGeometry();
159
161  QgsGeometry( const QgsGeometry & );
162
167  QgsGeometry &operator=( QgsGeometry const &rhs ) SIP_SKIP;
168
174  explicit QgsGeometry( QgsAbstractGeometry *geom SIP_TRANSFER );
175
181  explicit QgsGeometry( std::unique_ptr< QgsAbstractGeometry > geom ) SIP_SKIP;
182
183  virtual ~QgsGeometry();
184
196  const QgsAbstractGeometry *constGet() const;
197
210  QgsAbstractGeometry *get();
211
224  void set( QgsAbstractGeometry *geometry SIP_TRANSFER ) SIP_DEPRECATED;
225
233  bool isNull() const;
234
236  static QgsGeometry fromWkt( const QString &wkt );
238  static QgsGeometry fromPointXY( const QgsPointXY &point );
240  static QgsGeometry fromMultiPointXY( const QgsMultiPointXY &multipoint );
241
253  static QgsGeometry fromPolylineXY( const QgsPolylineXY &polyline );
254
264  static QgsGeometry fromPolyline( const QgsPolyline &polyline );
265
267  static QgsGeometry fromMultiPolylineXY( const QgsMultiPolylineXY &multiline );
269  static QgsGeometry fromPolygonXY( const QgsPolygonXY &polygon );
271  static QgsGeometry fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly );
273  static QgsGeometry fromRect( const QgsRectangle &rect );
275  static QgsGeometry collectGeometry( const QVector<QgsGeometry> &geometries );
276
292  static QgsGeometry createWedgeBuffer( const QgsPoint &center, double azimuth, double angularWidth,
294
300  void fromWkb( unsigned char *wkb, int length ) SIP_SKIP;
301
306  void fromWkb( const QByteArray &wkb );
307
312  QgsWkbTypes::Type wkbType() const;
313
318  QgsWkbTypes::GeometryType type() const;
319
326  bool isEmpty() const;
327
329  bool isMultipart() const;
330
345  bool equals( const QgsGeometry &geometry ) const;
346
363  bool isGeosEqual( const QgsGeometry & ) const;
364
367  {
368  FlagAllowSelfTouchingHoles = 1 << 0,
369  };
370  Q_DECLARE_FLAGS( ValidityFlags, ValidityFlag )
371
372
379  bool isGeosValid( QgsGeometry::ValidityFlags flags = QgsGeometry::ValidityFlags() ) const;
380
389  bool isSimple() const;
390
403  double area() const;
404
417  double length() const;
418
426  double distance( const QgsGeometry &geom ) const;
427
428 #ifndef SIP_RUN
429
430  // TODO QGIS 4: consider renaming vertices_begin, vertices_end, parts_begin, parts_end, etc
431  // to camelCase
432
437  QgsAbstractGeometry::vertex_iterator vertices_begin() const;
438
443  QgsAbstractGeometry::vertex_iterator vertices_end() const;
444 #endif
445
469  QgsVertexIterator vertices() const;
470
471 #ifndef SIP_RUN
472
482
492
501  QgsAbstractGeometry::const_part_iterator const_parts_begin() const;
502
511  QgsAbstractGeometry::const_part_iterator const_parts_end() const;
512 #endif
513
551  QgsGeometryPartIterator parts();
552
585  QgsGeometryConstPartIterator constParts() const;
586
604  double hausdorffDistance( const QgsGeometry &geom ) const;
605
624  double hausdorffDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const;
625
626  //TODO QGIS 4.0 - rename beforeVertex to previousVertex, afterVertex to nextVertex
627
640  QgsPointXY closestVertex( const QgsPointXY &point, int &atVertex SIP_OUT, int &beforeVertex SIP_OUT, int &afterVertex SIP_OUT, double &sqrDist SIP_OUT ) const;
641
650  double distanceToVertex( int vertex ) const;
651
659  double angleAtVertex( int vertex ) const;
660
673  void adjacentVertices( int atVertex, int &beforeVertex SIP_OUT, int &afterVertex SIP_OUT ) const;
674
687  bool insertVertex( double x, double y, int beforeVertex );
688
701  bool insertVertex( const QgsPoint &point, int beforeVertex );
702
710  bool moveVertex( double x, double y, int atVertex );
711
719  bool moveVertex( const QgsPoint &p, int atVertex );
720
732  bool deleteVertex( int atVertex );
733
739  QgsPoint vertexAt( int atVertex ) const;
740
746  double sqrDistToVertexAt( QgsPointXY &point SIP_IN, int atVertex ) const;
747
753  QgsGeometry nearestPoint( const QgsGeometry &other ) const;
754
765  QgsGeometry shortestLine( const QgsGeometry &other ) const;
766
773  double closestVertexWithContext( const QgsPointXY &point, int &atVertex SIP_OUT ) const;
774
786  double closestSegmentWithContext( const QgsPointXY &point, QgsPointXY &minDistPoint SIP_OUT, int &afterVertex SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
787
793  OperationResult addRing( const QVector<QgsPointXY> &ring );
794
800  OperationResult addRing( QgsCurve *ring SIP_TRANSFER );
801
808  OperationResult addPart( const QVector<QgsPointXY> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) SIP_PYNAME( addPointsXY );
809
816  OperationResult addPart( const QgsPointSequence &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) SIP_PYNAME( addPoints );
817
824  OperationResult addPart( QgsAbstractGeometry *part SIP_TRANSFER, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry );
825
832
839  QgsGeometry removeInteriorRings( double minimumAllowedArea = -1 ) const;
840
845  OperationResult translate( double dx, double dy, double dz = 0.0, double dm = 0.0 );
846
861  OperationResult transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) SIP_THROW( QgsCsException );
862
871  OperationResult transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 );
872
879  OperationResult rotate( double rotation, const QgsPointXY &center );
880
891  Q_DECL_DEPRECATED OperationResult splitGeometry( const QVector<QgsPointXY> &splitLine, QVector<QgsGeometry> &newGeometries SIP_OUT, bool topological, QVector<QgsPointXY> &topologyTestPoints SIP_OUT, bool splitFeature = true ) SIP_DEPRECATED;
892
912  OperationResult splitGeometry( const QgsPointSequence &splitLine, QVector<QgsGeometry> &newGeometries SIP_OUT, bool topological, QgsPointSequence &topologyTestPoints SIP_OUT, bool splitFeature = true );
913
918  OperationResult reshapeGeometry( const QgsLineString &reshapeLineString );
919
925  int makeDifferenceInPlace( const QgsGeometry &other ) SIP_SKIP;
926
934  QgsGeometry makeDifference( const QgsGeometry &other ) const;
935
940  QgsRectangle boundingBox() const;
941
949  QgsGeometry orientedMinimumBoundingBox( double &area SIP_OUT, double &angle SIP_OUT, double &width SIP_OUT, double &height SIP_OUT ) const;
950
956  QgsGeometry orientedMinimumBoundingBox() const SIP_SKIP;
957
966  QgsGeometry minimalEnclosingCircle( QgsPointXY &center SIP_OUT, double &radius SIP_OUT, unsigned int segments = 36 ) const;
967
973  QgsGeometry minimalEnclosingCircle( unsigned int segments = 36 ) const SIP_SKIP;
974
983  QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
984
997  QgsGeometry snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const;
998
1019  bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false );
1020
1030  bool intersects( const QgsRectangle &rectangle ) const;
1031
1041  bool intersects( const QgsGeometry &geometry ) const;
1042
1052  bool boundingBoxIntersects( const QgsRectangle &rectangle ) const;
1053
1063  bool boundingBoxIntersects( const QgsGeometry &geometry ) const;
1064
1068  bool contains( const QgsPointXY *p ) const;
1069
1074  bool contains( const QgsGeometry &geometry ) const;
1075
1080  bool disjoint( const QgsGeometry &geometry ) const;
1081
1086  bool touches( const QgsGeometry &geometry ) const;
1087
1092  bool overlaps( const QgsGeometry &geometry ) const;
1093
1098  bool within( const QgsGeometry &geometry ) const;
1099
1100
1105  bool crosses( const QgsGeometry &geometry ) const;
1106
1109  {
1110  SideLeft = 0,
1112  };
1113  Q_ENUM( BufferSide )
1114
1115
1117  {
1118  CapRound = 1,
1121  };
1122  Q_ENUM( EndCapStyle )
1123
1124
1126  {
1127  JoinStyleRound = 1,
1130  };
1131  Q_ENUM( JoinStyle )
1132
1133
1140  QgsGeometry buffer( double distance, int segments ) const;
1141
1154  QgsGeometry buffer( double distance, int segments, EndCapStyle endCapStyle, JoinStyle joinStyle, double miterLimit ) const;
1155
1164  QgsGeometry offsetCurve( double distance, int segments, JoinStyle joinStyle, double miterLimit ) const;
1165
1181  QgsGeometry singleSidedBuffer( double distance, int segments, BufferSide side,
1182  JoinStyle joinStyle = JoinStyleRound,
1183  double miterLimit = 2.0 ) const;
1184
1202  QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const;
1203
1218  QgsGeometry variableWidthBufferByM( int segments ) const;
1219
1226  QgsGeometry extendLine( double startDistance, double endDistance ) const;
1227
1229  QgsGeometry simplify( double tolerance ) const;
1230
1240  QgsGeometry densifyByCount( int extraNodesPerSegment ) const;
1241
1256  QgsGeometry densifyByDistance( double distance ) const;
1257
1273  QgsGeometry convertToCurves( double distanceTolerance = 1e-8, double angleTolerance = 1e-8 ) const;
1274
1288  QgsGeometry centroid() const;
1289
1303  QgsGeometry pointOnSurface() const;
1304
1317  QgsGeometry poleOfInaccessibility( double precision, double *distanceToBoundary SIP_OUT = nullptr ) const;
1318
1327  QgsGeometry convexHull() const;
1328
1344  QgsGeometry voronoiDiagram( const QgsGeometry &extent = QgsGeometry(), double tolerance = 0.0, bool edgesOnly = false ) const;
1345
1355  QgsGeometry delaunayTriangulation( double tolerance = 0.0, bool edgesOnly = false ) const;
1356
1376  QgsGeometry subdivide( int maxNodes = 256 ) const;
1377
1393  QgsGeometry interpolate( double distance ) const;
1394
1406  double lineLocatePoint( const QgsGeometry &point ) const;
1407
1417  double interpolateAngle( double distance ) const;
1418
1427  QgsGeometry intersection( const QgsGeometry &geometry ) const;
1428
1436  QgsGeometry clipped( const QgsRectangle &rectangle );
1437
1449  QgsGeometry combine( const QgsGeometry &geometry ) const;
1450
1459  QgsGeometry mergeLines() const;
1460
1469  QgsGeometry difference( const QgsGeometry &geometry ) const;
1470
1479  QgsGeometry symDifference( const QgsGeometry &geometry ) const;
1480
1482  QgsGeometry extrude( double x, double y );
1483
1484 #ifndef SIP_RUN
1485
1502  QVector< QgsPointXY > randomPointsInPolygon( int count, const std::function< bool( const QgsPointXY & ) > &acceptPoint, unsigned long seed = 0, QgsFeedback *feedback = nullptr ) const;
1503
1517  QVector< QgsPointXY > randomPointsInPolygon( int count, unsigned long seed = 0, QgsFeedback *feedback = nullptr ) const;
1519 #else
1520
1533  SIP_PYOBJECT randomPointsInPolygon( int count, unsigned long seed = 0 ) const SIP_TYPEHINT( QgsPolylineXY );
1534  % MethodCode
1535  const QgsWkbTypes::GeometryType type = sipCpp->type();
1536  if ( sipCpp->isNull() )
1537  {
1538  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Cannot generate points inside a null geometry." ).toUtf8().constData() );
1539  sipIsErr = 1;
1540  }
1541  else if ( type != QgsWkbTypes::PolygonGeometry )
1542  {
1543  PyErr_SetString( PyExc_TypeError, QStringLiteral( "Cannot generate points inside a %1 geometry. Only Polygon types are permitted." ).arg( QgsWkbTypes::displayString( sipCpp->wkbType() ) ).toUtf8().constData() );
1544  sipIsErr = 1;
1545  }
1546  else
1547  {
1548  const sipMappedType *qvector_type = sipFindMappedType( "QVector<QgsPointXY>" );
1549  sipRes = sipConvertFromNewType( new QVector< QgsPointXY >( sipCpp->randomPointsInPolygon( a0, a1 ) ), qvector_type, Py_None );
1550  }
1551  % End
1552
1553
1554 #endif
1555
1564  QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const;
1565
1571  QString asWkt( int precision = 17 ) const;
1572
1573 #ifdef SIP_RUN
1574  SIP_PYOBJECT __repr__();
1575  % MethodCode
1576  QString str;
1577  if ( sipCpp->isNull() )
1578  str = QStringLiteral( "<QgsGeometry: null>" );
1579  else
1580  {
1581  QString wkt = sipCpp->asWkt();
1582  if ( wkt.length() > 1000 )
1583  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
1584  str = QStringLiteral( "<QgsGeometry: %1>" ).arg( wkt );
1585  }
1586  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1587  % End
1588 #endif
1589
1593  QString asJson( int precision = 17 ) const;
1594
1600  virtual json asJsonObject( int precision = 17 ) const SIP_SKIP;
1601
1624  QVector< QgsGeometry > coerceToType( QgsWkbTypes::Type type ) const;
1625
1638  QgsGeometry convertToType( QgsWkbTypes::GeometryType destType, bool destMultipart = false ) const;
1639
1640  /* Accessor functions for getting geometry data */
1641
1642 #ifndef SIP_RUN
1643
1651  QgsPointXY asPoint() const;
1652 #else
1653
1663  SIP_PYOBJECT asPoint() const SIP_TYPEHINT( QgsPointXY );
1664  % MethodCode
1665  const QgsWkbTypes::Type type = sipCpp->wkbType();
1666  if ( sipCpp->isNull() )
1667  {
1668  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a point." ).toUtf8().constData() );
1669  sipIsErr = 1;
1670  }
1671  else if ( QgsWkbTypes::flatType( type ) != QgsWkbTypes::Point )
1672  {
1673  PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a point. Only Point types are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1674  sipIsErr = 1;
1675  }
1676  else
1677  {
1678  sipRes = sipConvertFromNewType( new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
1679  }
1680  % End
1681 #endif
1682
1683 #ifndef SIP_RUN
1684
1693  QgsPolylineXY asPolyline() const;
1694 #else
1695
1706  SIP_PYOBJECT asPolyline() const SIP_TYPEHINT( QgsPolylineXY );
1707  % MethodCode
1708  const QgsWkbTypes::Type type = sipCpp->wkbType();
1709  if ( sipCpp->isNull() )
1710  {
1711  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a polyline." ).toUtf8().constData() );
1712  sipIsErr = 1;
1713  }
1715  {
1716  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() );
1717  sipIsErr = 1;
1718  }
1719  else
1720  {
1721  const sipMappedType *qvector_type = sipFindMappedType( "QVector< QgsPointXY >" );
1722  sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
1723  }
1724  % End
1725 #endif
1726
1727 #ifndef SIP_RUN
1728
1737  QgsPolygonXY asPolygon() const;
1738 #else
1739
1750  SIP_PYOBJECT asPolygon() const SIP_TYPEHINT( QgsPolygonXY );
1751  % MethodCode
1752  const QgsWkbTypes::Type type = sipCpp->wkbType();
1753  if ( sipCpp->isNull() )
1754  {
1755  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a polygon." ).toUtf8().constData() );
1756  sipIsErr = 1;
1757  }
1759  {
1760  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() );
1761  sipIsErr = 1;
1762  }
1763  else
1764  {
1765  const sipMappedType *qvector_type = sipFindMappedType( "QVector<QVector<QgsPointXY>>" );
1766  sipRes = sipConvertFromNewType( new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
1767  }
1768  % End
1769 #endif
1770
1771 #ifndef SIP_RUN
1772
1780  QgsMultiPointXY asMultiPoint() const;
1781 #else
1782
1792  SIP_PYOBJECT asMultiPoint() const SIP_TYPEHINT( QgsMultiPointXY );
1793  % MethodCode
1794  const QgsWkbTypes::Type type = sipCpp->wkbType();
1795  if ( sipCpp->isNull() )
1796  {
1797  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a multipoint." ).toUtf8().constData() );
1798  sipIsErr = 1;
1799  }
1801  {
1802  PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a multipoint. Only multipoint types are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1803  sipIsErr = 1;
1804  }
1805  else
1806  {
1807  const sipMappedType *qvector_type = sipFindMappedType( "QVector< QgsPointXY >" );
1808  sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
1809  }
1810  % End
1811 #endif
1812
1813 #ifndef SIP_RUN
1814
1823  QgsMultiPolylineXY asMultiPolyline() const;
1824 #else
1825
1836  SIP_PYOBJECT asMultiPolyline() const SIP_TYPEHINT( QgsMultiPolylineXY );
1837  % MethodCode
1838  const QgsWkbTypes::Type type = sipCpp->wkbType();
1839  if ( sipCpp->isNull() )
1840  {
1841  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a multilinestring." ).toUtf8().constData() );
1842  sipIsErr = 1;
1843  }
1845  {
1846  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() );
1847  sipIsErr = 1;
1848  }
1849  else
1850  {
1851  const sipMappedType *qvector_type = sipFindMappedType( "QVector<QVector<QgsPointXY>>" );
1852  sipRes = sipConvertFromNewType( new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
1853  }
1854  % End
1855 #endif
1856
1857 #ifndef SIP_RUN
1858
1867  QgsMultiPolygonXY asMultiPolygon() const;
1868 #else
1869
1880  SIP_PYOBJECT asMultiPolygon() const SIP_TYPEHINT( QgsMultiPolygonXY );
1881  % MethodCode
1882  const QgsWkbTypes::Type type = sipCpp->wkbType();
1883  if ( sipCpp->isNull() )
1884  {
1885  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a multipolygon." ).toUtf8().constData() );
1886  sipIsErr = 1;
1887  }
1889  {
1890  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() );
1891  sipIsErr = 1;
1892  }
1893  else
1894  {
1895  const sipMappedType *qvector_type = sipFindMappedType( "QVector<QVector<QVector<QgsPointXY>>>" );
1896  sipRes = sipConvertFromNewType( new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
1897  }
1898  % End
1899 #endif
1900
1905  QVector<QgsGeometry> asGeometryCollection() const;
1906
1912  QPointF asQPointF() const;
1913
1920  QPolygonF asQPolygonF() const;
1921
1928  bool deleteRing( int ringNum, int partNum = 0 );
1929
1935  bool deletePart( int partNum );
1936
1945  bool convertToMultiType();
1946
1956  bool convertToSingleType();
1957
1967  bool convertGeometryCollectionToSubclass( QgsWkbTypes::GeometryType geomType );
1968
1979  int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
1980  const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
1981
2000  QgsGeometry makeValid() const;
2001
2009  QgsGeometry forceRHR() const;
2010
2014  class CORE_EXPORT Error
2015  {
2016  public:
2018  : mMessage( QStringLiteral( "none" ) )
2019  {}
2020
2021  explicit Error( const QString &m )
2022  : mMessage( m )
2023  {}
2024
2025  Error( const QString &m, const QgsPointXY &p )
2026  : mMessage( m )
2027  , mLocation( p )
2028  , mHasLocation( true ) {}
2029
2033  QString what() const;
2034
2038  QgsPointXY where() const;
2039
2043  bool hasWhere() const;
2044
2045 #ifdef SIP_RUN
2046  SIP_PYOBJECT __repr__();
2047  % MethodCode
2048  QString str = QStringLiteral( "<QgsGeometry.Error: %1>" ).arg( sipCpp->what() );
2049  sipRes = PyUnicode_FromString( str.toUtf8().data() );
2050  % End
2051 #endif
2052
2053  bool operator==( const QgsGeometry::Error &other ) const
2054  {
2055  return other.mMessage == mMessage && other.mHasLocation == mHasLocation && other.mLocation == mLocation;
2056  }
2057
2058  private:
2059  QString mMessage;
2060  QgsPointXY mLocation;
2061  bool mHasLocation = false;
2062  };
2063
2069  {
2072  };
2073
2082  void validateGeometry( QVector<QgsGeometry::Error> &errors SIP_OUT, ValidationMethod method = ValidatorQgisInternal, QgsGeometry::ValidityFlags flags = QgsGeometry::ValidityFlags() ) const;
2083
2089  static QgsGeometry unaryUnion( const QVector<QgsGeometry> &geometries );
2090
2099  static QgsGeometry polygonize( const QVector<QgsGeometry> &geometries );
2100
2108  void convertToStraightSegment( double tolerance = M_PI / 180., QgsAbstractGeometry::SegmentationToleranceType toleranceType = QgsAbstractGeometry::MaximumAngle );
2109
2116  bool requiresConversionToStraightSegments() const;
2117
2123  void mapToPixel( const QgsMapToPixel &mtp );
2124
2130  void draw( QPainter &p ) const;
2131
2142  bool vertexIdFromVertexNr( int number, QgsVertexId &id SIP_OUT ) const;
2143
2155  int vertexNrFromVertexId( QgsVertexId id ) const;
2156
2164  QString lastError() const;
2165
2175  void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) SIP_SKIP;
2176
2191  void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) SIP_SKIP;
2192
2198  static QgsGeometry fromQPointF( QPointF point );
2199
2207  static QgsGeometry fromQPolygonF( const QPolygonF &polygon );
2208
2216  Q_DECL_DEPRECATED static QgsPolylineXY createPolylineFromQPolygonF( const QPolygonF &polygon ) SIP_DEPRECATED;
2217
2225  Q_DECL_DEPRECATED static QgsPolygonXY createPolygonFromQPolygonF( const QPolygonF &polygon ) SIP_DEPRECATED;
2226
2227 #ifndef SIP_RUN
2228
2238  static bool compare( const QgsPolylineXY &p1, const QgsPolylineXY &p2,
2239  double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2240
2250  static bool compare( const QgsPolygonXY &p1, const QgsPolygonXY &p2,
2251  double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2252
2263  static bool compare( const QgsMultiPolygonXY &p1, const QgsMultiPolygonXY &p2,
2264  double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2265 #else
2266
2286  static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2287  % MethodCode
2288  {
2289  sipRes = false;
2290  int state0;
2291  int state1;
2292  int sipIsErr = 0;
2293
2294  if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
2295  PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
2296  {
2297  PyObject *o0 = PyList_GetItem( a0, 0 );
2298  PyObject *o1 = PyList_GetItem( a1, 0 );
2299  if ( o0 && o1 )
2300  {
2301  // compare polyline - polyline
2302  if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2303  sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2304  sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2305  sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2306  {
2307  QgsPolylineXY *p0;
2308  QgsPolylineXY *p1;
2309  p0 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2310  p1 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2311  if ( sipIsErr )
2312  {
2313  sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
2314  sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
2315  }
2316  else
2317  {
2318  sipRes = QgsGeometry::compare( *p0, *p1, a2 );
2319  }
2320  }
2321  else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
2322  PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
2323  {
2324  PyObject *oo0 = PyList_GetItem( o0, 0 );
2325  PyObject *oo1 = PyList_GetItem( o1, 0 );
2326  if ( oo0 && oo1 )
2327  {
2328  // compare polygon - polygon
2329  if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2330  sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2331  sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2332  sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2333  {
2334  QgsPolygonXY *p0;
2335  QgsPolygonXY *p1;
2336  p0 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2337  p1 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2338  if ( sipIsErr )
2339  {
2340  sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
2341  sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
2342  }
2343  else
2344  {
2345  sipRes = QgsGeometry::compare( *p0, *p1, a2 );
2346  }
2347  }
2348  else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
2349  PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
2350  {
2351  PyObject *ooo0 = PyList_GetItem( oo0, 0 );
2352  PyObject *ooo1 = PyList_GetItem( oo1, 0 );
2353  if ( ooo0 && ooo1 )
2354  {
2355  // compare multipolygon - multipolygon
2356  if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2357  sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2358  sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2359  sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2360  {
2361  QgsMultiPolygonXY *p0;
2362  QgsMultiPolygonXY *p1;
2363  p0 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2364  p1 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2365  if ( sipIsErr )
2366  {
2367  sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
2368  sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
2369  }
2370  else
2371  {
2372  sipRes = QgsGeometry::compare( *p0, *p1, a2 );
2373  }
2374  }
2375  }
2376  }
2377  }
2378  }
2379  }
2380  }
2381  }
2382  % End
2383 #endif
2384
2401  QgsGeometry smooth( unsigned int iterations = 1, double offset = 0.25,
2402  double minimumDistance = -1.0, double maxAngle = 180.0 ) const;
2403
2407  static QgsGeometryEngine *createGeometryEngine( const QgsAbstractGeometry *geometry ) SIP_FACTORY;
2408
2414  static void convertPointList( const QVector<QgsPointXY> &input, QgsPointSequence &output );
2415
2421  static void convertPointList( const QgsPointSequence &input, QVector<QgsPointXY> &output );
2422
2424  operator QVariant() const
2425  {
2426  return QVariant::fromValue( *this );
2427  }
2428
2429  private:
2430
2431  QgsGeometryPrivate *d; //implicitly shared data pointer
2432
2434  mutable QString mLastError;
2435
2440  void detach();
2441
2446  void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
2447
2448  static void convertToPolyline( const QgsPointSequence &input, QgsPolylineXY &output );
2449  static void convertPolygon( const QgsPolygon &input, QgsPolygonXY &output );
2450
2452  QgsGeometry convertToPoint( bool destMultipart ) const;
2454  QgsGeometry convertToLine( bool destMultipart ) const;
2456  QgsGeometry convertToPolygon( bool destMultipart ) const;
2457
2469  std::unique_ptr< QgsLineString > smoothLine( const QgsLineString &line, unsigned int iterations = 1, double offset = 0.25,
2470  double minimumDistance = -1, double maxAngle = 180.0 ) const;
2471
2483  std::unique_ptr< QgsPolygon > smoothPolygon( const QgsPolygon &polygon, unsigned int iterations = 1, double offset = 0.25,
2484  double minimumDistance = -1, double maxAngle = 180.0 ) const;
2485
2486
2488
2489 }; // class QgsGeometry
2490
2492 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsGeometry::ValidityFlags )
2493
2494 CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsGeometry &geometry );
2497 CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry );
2498
2499 #endif
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
QgsGeometry::CapFlat
@ CapFlat
Flat cap (in line with start/end of line)
Definition: qgsgeometry.h:1119
The source geometry is not multi.
Definition: qgsgeometry.h:146
QgsGeometry::ValidatorGeos
@ ValidatorGeos
Use GEOS validation methods.
Definition: qgsgeometry.h:2071
QgsAbstractGeometry::MaximumAngle
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices)
Definition: qgsabstractgeometry.h:118
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
QgsWkbTypes::Point
@ Point
Definition: qgswkbtypes.h:71
QgsPolygon
Polygon geometry type.
Definition: qgspolygon.h:33
QgsPolygonXY
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition: qgsgeometry.h:74
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
QgsGeometry::Error::Error
Error(const QString &m)
Definition: qgsgeometry.h:2021
QgsGeometry::Error::operator==
bool operator==(const QgsGeometry::Error &other) const
Definition: qgsgeometry.h:2053
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsPolylineXY
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:50
QgsCoordinateTransform::TransformDirection
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
Definition: qgscoordinatetransform.h:58
QgsWkbTypes::isMultiType
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
Definition: qgswkbtypes.h:831
QgsGeometryConstPartIterator
Java-style iterator for const traversal of parts of a geometry.
Definition: qgsabstractgeometry.h:1211
QgsGeometry::Error
Definition: qgsgeometry.h:2014
QgsMultiPolygonXY
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
Definition: qgsgeometry.h:91
QgsGeometry::EndCapStyle
EndCapStyle
End cap styles for buffers.
Definition: qgsgeometry.h:1116
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
qgsfeatureid.h
QgsGeometry::OperationResult
OperationResult
Success or failure of a geometry operation.
Definition: qgsgeometry.h:134
QgsAbstractGeometry::SegmentationToleranceType
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
Definition: qgsabstractgeometry.h:112
qgspoint.h
SIP_PYARGREMOVE
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:146
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:43
QgsGeometry::SelectionIsGreaterThanOne
@ SelectionIsGreaterThanOne
More than one features were selected.
Definition: qgsgeometry.h:141
DEFAULT_SEGMENT_EPSILON
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
Definition: qgis.h:712
QgsRectangle
Definition: qgsrectangle.h:41
QgsGeometryPrivate
Definition: qgsgeometry.cpp:51
QgsMultiPointXY
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
Definition: qgsgeometry.h:80
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:143
SIP_TYPEHINT
#define SIP_TYPEHINT(type)
Definition: qgis_sip.h:213
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsGeometry::Error::Error
Error(const QString &m, const QgsPointXY &p)
Definition: qgsgeometry.h:2025
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
QgsGeometry::JoinStyleMiter
@ JoinStyleMiter
Use mitered joins.
Definition: qgsgeometry.h:1128
QgsGeometry::LayerNotEditable
@ LayerNotEditable
Cannot edit layer.
Definition: qgsgeometry.h:143
The selected geometry cannot be found.
Definition: qgsgeometry.h:145
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsGeometry::SelectionIsEmpty
@ SelectionIsEmpty
No features were selected.
Definition: qgsgeometry.h:140
MathUtils::leftOf
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negative values mean left ...
Definition: MathUtils.cpp:292
precision
int precision
Definition: qgswfsgetfeature.cpp:103
QgsCsException
Definition: qgsexception.h:65
QgsGeometry::CapSquare
@ CapSquare
Square cap (extends past start/end of line by buffer distance)
Definition: qgsgeometry.h:1120
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
SIP_THROW
#define SIP_THROW(name)
Definition: qgis_sip.h:184
QgsGeometry::Error::Error
Error()
Definition: qgsgeometry.h:2017
The input ring crosses existing rings (it is not disjoint)
Definition: qgsgeometry.h:150
operator>>
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsGeometry &geometry)
Reads a geometry from stream in into geometry. QGIS version compatibility is not guaranteed.
Definition: qgsgeometry.cpp:3670
QgsConstWkbPtr
Definition: qgswkbptr.h:127
QgsFeedback
Definition: qgsfeedback.h:43
QgsGeometry::ValidatorQgisInternal
@ ValidatorQgisInternal
Use internal QgsGeometryValidator method.
Definition: qgsgeometry.h:2070
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsWkbTypes::geometryType
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:937
QgsMultiPolylineXY
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
Definition: qgsgeometry.h:84
operator<<
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsGeometry &geometry)
Writes the geometry to stream out. QGIS version compatibility is not guaranteed.
Definition: qgsgeometry.cpp:3664
QgsGeometry::InvalidInputGeometryType
@ InvalidInputGeometryType
The input geometry (ring, part, split line, etc.) has not the correct geometry type.
Definition: qgsgeometry.h:139
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:71
QgsCoordinateTransform::ForwardTransform
@ ForwardTransform
Transform from source to destination CRS.
Definition: qgscoordinatetransform.h:60
The input ring is not closed.
Definition: qgsgeometry.h:148
QgsPolyline
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
Definition: qgsgeometry.h:70
QgsPointXY
Definition: qgspointxy.h:43
QgsGeometry::SplitCannotSplitPoint
@ SplitCannotSplitPoint
Cannot split points.
Definition: qgsgeometry.h:153
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:142
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:141
QgsGeometry::BufferSide
BufferSide
Side of line to buffer.
Definition: qgsgeometry.h:1108
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:139
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:44
QgsGeometry
Definition: qgsgeometry.h:122
QgsMapToPixel
Definition: qgsmaptopixel.h:37
QgsGeometryPartIterator
Java-style iterator for traversal of parts of a geometry.
Definition: qgsabstractgeometry.h:1161
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsGeometry::InvalidBaseGeometry
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
Definition: qgsgeometry.h:138
QgsGeometry::ValidityFlag
ValidityFlag
Validity check flags.
Definition: qgsgeometry.h:366
QgsWkbTypes::displayString
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
Definition: qgswkbtypes.cpp:145
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition: qgsabstractgeometry.h:1033
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:144
The input ring is not valid.
Definition: qgsgeometry.h:149
QgsGeometry::SideRight
@ SideRight
Buffer to right of line.
Definition: qgsgeometry.h:1111
QgsGeometry::ValidationMethod
ValidationMethod
Available methods for validating geometries.
Definition: qgsgeometry.h:2068
QgsVertexIterator
Java-style iterator for traversal of vertices of a geometry.
Definition: qgsabstractgeometry.h:1112
QgsGeometry::JoinStyle
JoinStyle
Join styles for buffers.
Definition: qgsgeometry.h:1125
QgsWkbTypes
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:40
QgsGeometryEngine
Contains geometry relation and modification algorithms.
Definition: qgsgeometryengine.h:33
MathUtils::angle
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
QgsGeometry::compare
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.
Definition: qgsgeometry.cpp:3131
qgsabstractgeometry.h
The input ring doesn't have any existing ring to fit into.
Definition: qgsgeometry.h:151
QgsGeometry::JoinStyleBevel
@ JoinStyleBevel
Use beveled joins.
Definition: qgsgeometry.h:1129
qgspointxy.h
SIP_IN
#define SIP_IN
Definition: qgis_sip.h:63
QgsWkbTypes::flatType
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:701
QgsGeometry::GeometryEngineError
@ GeometryEngineError
Geometry engine misses a method implemented or an error occurred in the geometry engine.
Definition: qgsgeometry.h:142