QGIS API Documentation  3.4.3-Madeira (2f64a3c)
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 *
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 <functional>
20 
21 #include <QDomDocument>
22 #include <QSet>
23 #include <QString>
24 #include <QVector>
25 
26 #include <climits>
27 #include <limits>
28 #include <memory>
29 
30 #include "qgis_core.h"
31 #include "qgis.h"
32 
33 #include "qgsabstractgeometry.h"
34 #include "qgspointxy.h"
35 #include "qgspoint.h"
36 #include "qgsfeatureid.h"
37 
38 
39 class QgsGeometryEngine;
40 class QgsVectorLayer;
41 class QgsMapToPixel;
42 class QPainter;
43 class QgsPolygon;
45 
55 typedef QVector<QgsPointXY> QgsPolylineXY;
56 
64 typedef QVector<QgsPoint> QgsPolyline;
65 
67 #ifndef SIP_RUN
68 typedef QVector<QgsPolylineXY> QgsPolygonXY;
69 #else
70 typedef QVector<QVector<QgsPointXY>> QgsPolygonXY;
71 #endif
72 
74 typedef QVector<QgsPointXY> QgsMultiPointXY;
75 
77 #ifndef SIP_RUN
78 typedef QVector<QgsPolylineXY> QgsMultiPolylineXY;
79 #else
80 typedef QVector<QVector<QgsPointXY>> QgsMultiPolylineXY;
81 #endif
82 
84 #ifndef SIP_RUN
85 typedef QVector<QgsPolygonXY> QgsMultiPolygonXY;
86 #else
87 typedef QVector<QVector<QVector<QgsPointXY>>> QgsMultiPolygonXY;
88 #endif
89 
90 class QgsRectangle;
91 
92 class QgsConstWkbPtr;
93 
94 struct QgsGeometryPrivate;
95 
106 class CORE_EXPORT QgsGeometry
107 {
108  Q_GADGET
109  public:
110 
116  {
117  Success = 0,
118  NothingHappened = 1000,
125  /* Add part issues */
128  /* Add ring issues*/
133  /* Split features */
135  };
136 
138  QgsGeometry();
139 
141  QgsGeometry( const QgsGeometry & );
142 
147  QgsGeometry &operator=( QgsGeometry const &rhs ) SIP_SKIP;
148 
154  explicit QgsGeometry( QgsAbstractGeometry *geom SIP_TRANSFER );
155 
161  explicit QgsGeometry( std::unique_ptr< QgsAbstractGeometry > geom ) SIP_SKIP;
162 
163  ~QgsGeometry();
164 
176  const QgsAbstractGeometry *constGet() const;
177 
190  QgsAbstractGeometry *get();
191 
201  void set( QgsAbstractGeometry *geometry SIP_TRANSFER );
202 
210  bool isNull() const;
211 
213  static QgsGeometry fromWkt( const QString &wkt );
215  static QgsGeometry fromPointXY( const QgsPointXY &point );
217  static QgsGeometry fromMultiPointXY( const QgsMultiPointXY &multipoint );
218 
230  static QgsGeometry fromPolylineXY( const QgsPolylineXY &polyline );
231 
241  static QgsGeometry fromPolyline( const QgsPolyline &polyline );
242 
244  static QgsGeometry fromMultiPolylineXY( const QgsMultiPolylineXY &multiline );
246  static QgsGeometry fromPolygonXY( const QgsPolygonXY &polygon );
248  static QgsGeometry fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly );
250  static QgsGeometry fromRect( const QgsRectangle &rect );
252  static QgsGeometry collectGeometry( const QVector<QgsGeometry> &geometries );
253 
269  static QgsGeometry createWedgeBuffer( const QgsPoint &center, double azimuth, double angularWidth,
270  double outerRadius, double innerRadius = 0 );
271 
277  void fromWkb( unsigned char *wkb, int length ) SIP_SKIP;
278 
283  void fromWkb( const QByteArray &wkb );
284 
289  QgsWkbTypes::Type wkbType() const;
290 
295  QgsWkbTypes::GeometryType type() const;
296 
303  bool isEmpty() const;
304 
306  bool isMultipart() const;
307 
322  bool equals( const QgsGeometry &geometry ) const;
323 
340  bool isGeosEqual( const QgsGeometry & ) const;
341 
346  bool isGeosValid() const;
347 
356  bool isSimple() const;
357 
362  double area() const;
363 
368  double length() const;
369 
376  double distance( const QgsGeometry &geom ) const;
377 
378 #ifndef SIP_RUN
379 
380  // TODO QGIS 4: consider renaming vertices_begin, vertices_end, parts_begin, parts_end, etc
381  // to camelCase
382 
387  QgsAbstractGeometry::vertex_iterator vertices_begin() const;
388 
393  QgsAbstractGeometry::vertex_iterator vertices_end() const;
394 #endif
395 
418  QgsVertexIterator vertices() const;
419 
420 #ifndef SIP_RUN
421 
431 
441 
450  QgsAbstractGeometry::const_part_iterator const_parts_begin() const;
451 
460  QgsAbstractGeometry::const_part_iterator const_parts_end() const;
461 #endif
462 
499  QgsGeometryPartIterator parts();
500 
532  QgsGeometryConstPartIterator constParts() const;
533 
551  double hausdorffDistance( const QgsGeometry &geom ) const;
552 
571  double hausdorffDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const;
572 
585  //TODO QGIS 3.0 - rename beforeVertex to previousVertex, afterVertex to nextVertex
586  QgsPointXY closestVertex( const QgsPointXY &point, int &atVertex SIP_OUT, int &beforeVertex SIP_OUT, int &afterVertex SIP_OUT, double &sqrDist SIP_OUT ) const;
587 
594  double distanceToVertex( int vertex ) const;
595 
603  double angleAtVertex( int vertex ) const;
604 
617  void adjacentVertices( int atVertex, int &beforeVertex SIP_OUT, int &afterVertex SIP_OUT ) const;
618 
631  bool insertVertex( double x, double y, int beforeVertex );
632 
645  bool insertVertex( const QgsPoint &point, int beforeVertex );
646 
654  bool moveVertex( double x, double y, int atVertex );
655 
663  bool moveVertex( const QgsPoint &p, int atVertex );
664 
676  bool deleteVertex( int atVertex );
677 
683  QgsPoint vertexAt( int atVertex ) const;
684 
690  double sqrDistToVertexAt( QgsPointXY &point SIP_IN, int atVertex ) const;
691 
697  QgsGeometry nearestPoint( const QgsGeometry &other ) const;
698 
704  QgsGeometry shortestLine( const QgsGeometry &other ) const;
705 
712  double closestVertexWithContext( const QgsPointXY &point, int &atVertex SIP_OUT ) const;
713 
725  double closestSegmentWithContext( const QgsPointXY &point, QgsPointXY &minDistPoint SIP_OUT, int &afterVertex SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
726 
732  OperationResult addRing( const QVector<QgsPointXY> &ring );
733 
739  OperationResult addRing( QgsCurve *ring SIP_TRANSFER );
740 
747  OperationResult addPart( const QVector<QgsPointXY> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) SIP_PYNAME( addPointsXY );
748 
756 
764 
770  OperationResult addPart( const QgsGeometry &newPart ) SIP_PYNAME( addPartGeometry );
771 
778  QgsGeometry removeInteriorRings( double minimumAllowedArea = -1 ) const;
779 
784  OperationResult translate( double dx, double dy, double dz = 0.0, double dm = 0.0 );
785 
801 
810  OperationResult transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 );
811 
818  OperationResult rotate( double rotation, const QgsPointXY &center );
819 
828  OperationResult splitGeometry( const QVector<QgsPointXY> &splitLine, QVector<QgsGeometry> &newGeometries SIP_OUT, bool topological, QVector<QgsPointXY> &topologyTestPoints SIP_OUT );
829 
834  OperationResult reshapeGeometry( const QgsLineString &reshapeLineString );
835 
841  int makeDifferenceInPlace( const QgsGeometry &other ) SIP_SKIP;
842 
850  QgsGeometry makeDifference( const QgsGeometry &other ) const;
851 
856  QgsRectangle boundingBox() const;
857 
865  QgsGeometry orientedMinimumBoundingBox( double &area SIP_OUT, double &angle SIP_OUT, double &width SIP_OUT, double &height SIP_OUT ) const;
866 
872  QgsGeometry orientedMinimumBoundingBox() const SIP_SKIP;
873 
881  QgsGeometry minimalEnclosingCircle( QgsPointXY &center SIP_OUT, double &radius SIP_OUT, unsigned int segments = 36 ) const;
882 
888  QgsGeometry minimalEnclosingCircle( unsigned int segments = 36 ) const SIP_SKIP;
889 
898  QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
899 
912  QgsGeometry snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const;
913 
934  bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false );
935 
945  bool intersects( const QgsRectangle &rectangle ) const;
946 
956  bool intersects( const QgsGeometry &geometry ) const;
957 
967  bool boundingBoxIntersects( const QgsRectangle &rectangle ) const;
968 
978  bool boundingBoxIntersects( const QgsGeometry &geometry ) const;
979 
981  bool contains( const QgsPointXY *p ) const;
982 
987  bool contains( const QgsGeometry &geometry ) const;
988 
993  bool disjoint( const QgsGeometry &geometry ) const;
994 
999  bool touches( const QgsGeometry &geometry ) const;
1000 
1005  bool overlaps( const QgsGeometry &geometry ) const;
1006 
1011  bool within( const QgsGeometry &geometry ) const;
1012 
1017  bool crosses( const QgsGeometry &geometry ) const;
1018 
1021  {
1022  SideLeft = 0,
1024  };
1025  Q_ENUM( BufferSide )
1026 
1027 
1029  {
1030  CapRound = 1,
1033  };
1034  Q_ENUM( EndCapStyle )
1035 
1036 
1038  {
1039  JoinStyleRound = 1,
1042  };
1043  Q_ENUM( JoinStyle )
1044 
1045 
1052  QgsGeometry buffer( double distance, int segments ) const;
1053 
1066  QgsGeometry buffer( double distance, int segments, EndCapStyle endCapStyle, JoinStyle joinStyle, double miterLimit ) const;
1067 
1076  QgsGeometry offsetCurve( double distance, int segments, JoinStyle joinStyle, double miterLimit ) const;
1077 
1093  QgsGeometry singleSidedBuffer( double distance, int segments, BufferSide side,
1094  JoinStyle joinStyle = JoinStyleRound,
1095  double miterLimit = 2.0 ) const;
1096 
1114  QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const;
1115 
1130  QgsGeometry variableWidthBufferByM( int segments ) const;
1131 
1138  QgsGeometry extendLine( double startDistance, double endDistance ) const;
1139 
1141  QgsGeometry simplify( double tolerance ) const;
1142 
1152  QgsGeometry densifyByCount( int extraNodesPerSegment ) const;
1153 
1168  QgsGeometry densifyByDistance( double distance ) const;
1169 
1183  QgsGeometry centroid() const;
1184 
1198  QgsGeometry pointOnSurface() const;
1199 
1212  QgsGeometry poleOfInaccessibility( double precision, double *distanceToBoundary SIP_OUT = nullptr ) const;
1213 
1222  QgsGeometry convexHull() const;
1223 
1239  QgsGeometry voronoiDiagram( const QgsGeometry &extent = QgsGeometry(), double tolerance = 0.0, bool edgesOnly = false ) const;
1240 
1250  QgsGeometry delaunayTriangulation( double tolerance = 0.0, bool edgesOnly = false ) const;
1251 
1271  QgsGeometry subdivide( int maxNodes = 256 ) const;
1272 
1288  QgsGeometry interpolate( double distance ) const;
1289 
1301  double lineLocatePoint( const QgsGeometry &point ) const;
1302 
1312  double interpolateAngle( double distance ) const;
1313 
1322  QgsGeometry intersection( const QgsGeometry &geometry ) const;
1323 
1331  QgsGeometry clipped( const QgsRectangle &rectangle );
1332 
1344  QgsGeometry combine( const QgsGeometry &geometry ) const;
1345 
1354  QgsGeometry mergeLines() const;
1355 
1364  QgsGeometry difference( const QgsGeometry &geometry ) const;
1365 
1374  QgsGeometry symDifference( const QgsGeometry &geometry ) const;
1375 
1377  QgsGeometry extrude( double x, double y );
1378 
1383  QByteArray asWkb() const;
1384 
1390  QString asWkt( int precision = 17 ) const;
1391 
1392 #ifdef SIP_RUN
1393  SIP_PYOBJECT __repr__();
1394  % MethodCode
1395  QString str;
1396  if ( sipCpp->isNull() )
1397  str = QStringLiteral( "<QgsGeometry: null>" );
1398  else
1399  {
1400  QString wkt = sipCpp->asWkt();
1401  if ( wkt.length() > 1000 )
1402  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
1403  str = QStringLiteral( "<QgsGeometry: %1>" ).arg( wkt );
1404  }
1405  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1406  % End
1407 #endif
1408 
1412  QString asJson( int precision = 17 ) const;
1413 
1421  QgsGeometry convertToType( QgsWkbTypes::GeometryType destType, bool destMultipart = false ) const SIP_FACTORY;
1422 
1423  /* Accessor functions for getting geometry data */
1424 
1425 #ifndef SIP_RUN
1426 
1434  QgsPointXY asPoint() const;
1435 #else
1436 
1446  SIP_PYOBJECT asPoint() const SIP_TYPEHINT( QgsPointXY );
1447  % MethodCode
1448  const QgsWkbTypes::Type type = sipCpp->wkbType();
1449  if ( sipCpp->isNull() )
1450  {
1451  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a point." ).toUtf8().constData() );
1452  sipIsErr = 1;
1453  }
1454  else if ( QgsWkbTypes::flatType( type ) != QgsWkbTypes::Point )
1455  {
1456  PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a point. Only Point types are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1457  sipIsErr = 1;
1458  }
1459  else
1460  {
1461  sipRes = sipConvertFromNewType( new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
1462  }
1463  % End
1464 #endif
1465 
1466 #ifndef SIP_RUN
1467 
1476  QgsPolylineXY asPolyline() const;
1477 #else
1478 
1489  SIP_PYOBJECT asPolyline() const SIP_TYPEHINT( QgsPolylineXY );
1490  % MethodCode
1491  const QgsWkbTypes::Type type = sipCpp->wkbType();
1492  if ( sipCpp->isNull() )
1493  {
1494  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a polyline." ).toUtf8().constData() );
1495  sipIsErr = 1;
1496  }
1498  {
1499  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() );
1500  sipIsErr = 1;
1501  }
1502  else
1503  {
1504  const sipMappedType *qvector_type = sipFindMappedType( "QVector< QgsPointXY >" );
1505  sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
1506  }
1507  % End
1508 #endif
1509 
1510 #ifndef SIP_RUN
1511 
1520  QgsPolygonXY asPolygon() const;
1521 #else
1522 
1533  SIP_PYOBJECT asPolygon() const SIP_TYPEHINT( QgsPolygonXY );
1534  % MethodCode
1535  const QgsWkbTypes::Type type = sipCpp->wkbType();
1536  if ( sipCpp->isNull() )
1537  {
1538  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a polygon." ).toUtf8().constData() );
1539  sipIsErr = 1;
1540  }
1542  {
1543  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() );
1544  sipIsErr = 1;
1545  }
1546  else
1547  {
1548  const sipMappedType *qvector_type = sipFindMappedType( "QVector<QVector<QgsPointXY>>" );
1549  sipRes = sipConvertFromNewType( new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
1550  }
1551  % End
1552 #endif
1553 
1558  QgsMultiPointXY asMultiPoint() const;
1559 
1564  QgsMultiPolylineXY asMultiPolyline() const;
1565 
1570  QgsMultiPolygonXY asMultiPolygon() const;
1571 
1576  QVector<QgsGeometry> asGeometryCollection() const;
1577 
1583  QPointF asQPointF() const;
1584 
1591  QPolygonF asQPolygonF() const;
1592 
1599  bool deleteRing( int ringNum, int partNum = 0 );
1600 
1606  bool deletePart( int partNum );
1607 
1616  bool convertToMultiType();
1617 
1627  bool convertToSingleType();
1628 
1638  bool convertGeometryCollectionToSubclass( QgsWkbTypes::GeometryType geomType );
1639 
1650  int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
1651  const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
1652 
1671  QgsGeometry makeValid() const;
1672 
1680  QgsGeometry forceRHR() const;
1681 
1685  class CORE_EXPORT Error
1686  {
1687  public:
1689  : mMessage( QStringLiteral( "none" ) )
1690  {}
1691 
1692  explicit Error( const QString &m )
1693  : mMessage( m )
1694  {}
1695 
1696  Error( const QString &m, const QgsPointXY &p )
1697  : mMessage( m )
1698  , mLocation( p )
1699  , mHasLocation( true ) {}
1700 
1704  QString what() const;
1705 
1709  QgsPointXY where() const;
1710 
1714  bool hasWhere() const;
1715 
1716 #ifdef SIP_RUN
1717  SIP_PYOBJECT __repr__();
1718  % MethodCode
1719  QString str = QStringLiteral( "<QgsGeometry.Error: %1>" ).arg( sipCpp->what() );
1720  sipRes = PyUnicode_FromString( str.toUtf8().data() );
1721  % End
1722 #endif
1723 
1724  private:
1725  QString mMessage;
1726  QgsPointXY mLocation;
1727  bool mHasLocation = false;
1728  };
1729 
1735  {
1738  };
1739 
1746  void validateGeometry( QVector<QgsGeometry::Error> &errors SIP_OUT, ValidationMethod method = ValidatorQgisInternal ) const;
1747 
1753  static QgsGeometry unaryUnion( const QVector<QgsGeometry> &geometries );
1754 
1763  static QgsGeometry polygonize( const QVector<QgsGeometry> &geometries );
1764 
1772  void convertToStraightSegment( double tolerance = M_PI / 180., QgsAbstractGeometry::SegmentationToleranceType toleranceType = QgsAbstractGeometry::MaximumAngle );
1773 
1780  bool requiresConversionToStraightSegments() const;
1781 
1787  void mapToPixel( const QgsMapToPixel &mtp );
1788 
1794  void draw( QPainter &p ) const;
1795 
1806  bool vertexIdFromVertexNr( int number, QgsVertexId &id SIP_OUT ) const;
1807 
1819  int vertexNrFromVertexId( QgsVertexId id ) const;
1820 
1828  QString lastError() const;
1829 
1839  void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) SIP_SKIP;
1840 
1855  void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) SIP_SKIP;
1856 
1862  static QgsGeometry fromQPointF( QPointF point );
1863 
1871  static QgsGeometry fromQPolygonF( const QPolygonF &polygon );
1872 
1879  static QgsPolylineXY createPolylineFromQPolygonF( const QPolygonF &polygon ) SIP_FACTORY;
1880 
1887  static QgsPolygonXY createPolygonFromQPolygonF( const QPolygonF &polygon ) SIP_FACTORY;
1888 
1889 #ifndef SIP_RUN
1890 
1900  static bool compare( const QgsPolylineXY &p1, const QgsPolylineXY &p2,
1901  double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1902 
1912  static bool compare( const QgsPolygonXY &p1, const QgsPolygonXY &p2,
1913  double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1914 
1925  static bool compare( const QgsMultiPolygonXY &p1, const QgsMultiPolygonXY &p2,
1926  double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1927 #else
1928 
1947  static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1948  % MethodCode
1949  {
1950  sipRes = false;
1951  int state0;
1952  int state1;
1953  int sipIsErr = 0;
1954 
1955  if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
1956  PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
1957  {
1958  PyObject *o0 = PyList_GetItem( a0, 0 );
1959  PyObject *o1 = PyList_GetItem( a1, 0 );
1960  if ( o0 && o1 )
1961  {
1962  // compare polyline - polyline
1963  if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1964  sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1965  sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
1966  sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1967  {
1968  QgsPolylineXY *p0;
1969  QgsPolylineXY *p1;
1970  p0 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1971  p1 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1972  if ( sipIsErr )
1973  {
1974  sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
1975  sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
1976  }
1977  else
1978  {
1979  sipRes = QgsGeometry::compare( *p0, *p1, a2 );
1980  }
1981  }
1982  else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
1983  PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
1984  {
1985  PyObject *oo0 = PyList_GetItem( o0, 0 );
1986  PyObject *oo1 = PyList_GetItem( o1, 0 );
1987  if ( oo0 && oo1 )
1988  {
1989  // compare polygon - polygon
1990  if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1991  sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1992  sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
1993  sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1994  {
1995  QgsPolygonXY *p0;
1996  QgsPolygonXY *p1;
1997  p0 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1998  p1 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1999  if ( sipIsErr )
2000  {
2001  sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
2002  sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
2003  }
2004  else
2005  {
2006  sipRes = QgsGeometry::compare( *p0, *p1, a2 );
2007  }
2008  }
2009  else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
2010  PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
2011  {
2012  PyObject *ooo0 = PyList_GetItem( oo0, 0 );
2013  PyObject *ooo1 = PyList_GetItem( oo1, 0 );
2014  if ( ooo0 && ooo1 )
2015  {
2016  // compare multipolygon - multipolygon
2017  if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2018  sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2019  sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2020  sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2021  {
2022  QgsMultiPolygonXY *p0;
2023  QgsMultiPolygonXY *p1;
2024  p0 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2025  p1 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2026  if ( sipIsErr )
2027  {
2028  sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
2029  sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
2030  }
2031  else
2032  {
2033  sipRes = QgsGeometry::compare( *p0, *p1, a2 );
2034  }
2035  }
2036  }
2037  }
2038  }
2039  }
2040  }
2041  }
2042  }
2043  % End
2044 #endif
2045 
2062  QgsGeometry smooth( unsigned int iterations = 1, double offset = 0.25,
2063  double minimumDistance = -1.0, double maxAngle = 180.0 ) const;
2064 
2068  static QgsGeometryEngine *createGeometryEngine( const QgsAbstractGeometry *geometry ) SIP_FACTORY;
2069 
2075  static void convertPointList( const QVector<QgsPointXY> &input, QgsPointSequence &output );
2076 
2082  static void convertPointList( const QgsPointSequence &input, QVector<QgsPointXY> &output );
2083 
2085  operator QVariant() const
2086  {
2087  return QVariant::fromValue( *this );
2088  }
2089 
2090  private:
2091 
2092  QgsGeometryPrivate *d; //implicitly shared data pointer
2093 
2095  mutable QString mLastError;
2096 
2101  void detach();
2102 
2107  void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
2108 
2109  static void convertToPolyline( const QgsPointSequence &input, QgsPolylineXY &output );
2110  static void convertPolygon( const QgsPolygon &input, QgsPolygonXY &output );
2111 
2113  QgsGeometry convertToPoint( bool destMultipart ) const;
2115  QgsGeometry convertToLine( bool destMultipart ) const;
2117  QgsGeometry convertToPolygon( bool destMultipart ) const;
2118 
2130  std::unique_ptr< QgsLineString > smoothLine( const QgsLineString &line, unsigned int iterations = 1, double offset = 0.25,
2131  double minimumDistance = -1, double maxAngle = 180.0 ) const;
2132 
2144  std::unique_ptr< QgsPolygon > smoothPolygon( const QgsPolygon &polygon, unsigned int iterations = 1, double offset = 0.25,
2145  double minimumDistance = -1, double maxAngle = 180.0 ) const;
2146 
2147 
2149 
2150 }; // class QgsGeometry
2151 
2153 
2154 CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsGeometry &geometry );
2157 CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry );
2158 
2159 #endif
Geometry engine misses a method implemented or an error occurred in the geometry engine.
Definition: qgsgeometry.h:123
int precision
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Java-style iterator for traversal of parts of a geometry.
The input ring doesn&#39;t have any existing ring to fit into.
Definition: qgsgeometry.h:132
Java-style iterator for traversal of vertices of a geometry.
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
Definition: qgswkbtypes.h:559
The source geometry is not multi.
Definition: qgsgeometry.h:127
Maximum angle between generating radii (lines from arc center to output vertices) ...
Use GEOS validation methods.
Definition: qgsgeometry.h:1737
Error(const QString &m)
Definition: qgsgeometry.h:1692
Java-style iterator for const traversal of parts of a geometry.
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:40
A class to represent a 2D point.
Definition: qgspointxy.h:43
QVector< QgsPoint > QgsPolyline
Polyline as represented as a vector of points.
Definition: qgsgeometry.h:64
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
Definition: qgsgeometry.h:68
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
Use mitered joins.
Definition: qgsgeometry.h:1040
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
Definition: qgsgeometry.h:74
The part_iterator class provides STL-style iterator for const references to geometry parts...
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
EndCapStyle
End cap styles for buffers.
Definition: qgsgeometry.h:1028
Q_DECLARE_METATYPE(QModelIndex)
OperationResult
Success or failure of a geometry operation.
Definition: qgsgeometry.h:115
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
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
Definition: qgsgeometry.h:85
Error(const QString &m, const QgsPointXY &p)
Definition: qgsgeometry.h:1696
#define SIP_IN
Definition: qgis_sip.h:56
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
Definition: qgsgeometry.h:78
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsGeometry &geometry)
Writes the geometry to stream out. QGIS version compatibility is not guaranteed.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:36
Cannot edit layer.
Definition: qgsgeometry.h:124
The selected geometry cannot be found.
Definition: qgsgeometry.h:126
No features were selected.
Definition: qgsgeometry.h:121
More than one features were selected.
Definition: qgsgeometry.h:122
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
Utility class for identifying a unique vertex within a geometry.
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
Definition: qgis.h:556
The input ring crosses existing rings (it is not disjoint)
Definition: qgsgeometry.h:131
#define SIP_SKIP
Definition: qgis_sip.h:119
The part_iterator class provides STL-style iterator for geometry parts.
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:665
Use internal QgsGeometryValidator method.
Definition: qgsgeometry.h:1736
#define SIP_TRANSFER
Definition: qgis_sip.h:36
The input ring is not closed.
Definition: qgsgeometry.h:129
Square cap (extends past start/end of line by buffer distance)
Definition: qgsgeometry.h:1032
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
#define SIP_FACTORY
Definition: qgis_sip.h:69
Abstract base class for all geometries.
The vertex_iterator class provides STL-style iterator for vertices.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
This class offers geometry processing methods.
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsGeometry &geometry)
Reads a geometry from stream in into geometry. QGIS version compatibility is not guaranteed.
BufferSide
Side of line to buffer.
Definition: qgsgeometry.h:1020
QVector< QgsPoint > QgsPointSequence
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:138
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:139
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:44
The base geometry on which the operation is done is invalid or empty.
Definition: qgsgeometry.h:119
The input geometry (ring, part, split line, etc.) has not the correct geometry type.
Definition: qgsgeometry.h:120
#define SIP_OUT
Definition: qgis_sip.h:51
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:43
ValidationMethod
Available methods for validating geometries.
Definition: qgsgeometry.h:1734
Buffer to right of line.
Definition: qgsgeometry.h:1023
Class for doing transforms between two map coordinate systems.
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
The input ring is not valid.
Definition: qgsgeometry.h:130
#define SIP_THROW(name)
Definition: qgis_sip.h:177
Contains geometry relation and modification algorithms.
Use beveled joins.
Definition: qgsgeometry.h:1041
Transform from source to destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
Polygon geometry type.
Definition: qgspolygon.h:31
JoinStyle
Join styles for buffers.
Definition: qgsgeometry.h:1037
Flat cap (in line with start/end of line)
Definition: qgsgeometry.h:1031
Represents a vector layer which manages a vector based data sets.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:429
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether &#39;thepoint&#39; is left or right of the line from &#39;p1&#39; to &#39;p2&#39;. Negativ values mean left a...
Definition: MathUtils.cpp:292
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.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:74