QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
344  {
345  FlagAllowSelfTouchingHoles = 1 << 0,
346  };
347  Q_DECLARE_FLAGS( ValidityFlags, ValidityFlag )
348 
349 
356  bool isGeosValid( QgsGeometry::ValidityFlags flags = nullptr ) const;
357 
366  bool isSimple() const;
367 
372  double area() const;
373 
378  double length() const;
379 
386  double distance( const QgsGeometry &geom ) const;
387 
388 #ifndef SIP_RUN
389 
390  // TODO QGIS 4: consider renaming vertices_begin, vertices_end, parts_begin, parts_end, etc
391  // to camelCase
392 
397  QgsAbstractGeometry::vertex_iterator vertices_begin() const;
398 
403  QgsAbstractGeometry::vertex_iterator vertices_end() const;
404 #endif
405 
428  QgsVertexIterator vertices() const;
429 
430 #ifndef SIP_RUN
431 
441 
451 
460  QgsAbstractGeometry::const_part_iterator const_parts_begin() const;
461 
470  QgsAbstractGeometry::const_part_iterator const_parts_end() const;
471 #endif
472 
509  QgsGeometryPartIterator parts();
510 
542  QgsGeometryConstPartIterator constParts() const;
543 
561  double hausdorffDistance( const QgsGeometry &geom ) const;
562 
581  double hausdorffDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const;
582 
595  //TODO QGIS 3.0 - rename beforeVertex to previousVertex, afterVertex to nextVertex
596  QgsPointXY closestVertex( const QgsPointXY &point, int &atVertex SIP_OUT, int &beforeVertex SIP_OUT, int &afterVertex SIP_OUT, double &sqrDist SIP_OUT ) const;
597 
604  double distanceToVertex( int vertex ) const;
605 
613  double angleAtVertex( int vertex ) const;
614 
627  void adjacentVertices( int atVertex, int &beforeVertex SIP_OUT, int &afterVertex SIP_OUT ) const;
628 
641  bool insertVertex( double x, double y, int beforeVertex );
642 
655  bool insertVertex( const QgsPoint &point, int beforeVertex );
656 
664  bool moveVertex( double x, double y, int atVertex );
665 
673  bool moveVertex( const QgsPoint &p, int atVertex );
674 
686  bool deleteVertex( int atVertex );
687 
693  QgsPoint vertexAt( int atVertex ) const;
694 
700  double sqrDistToVertexAt( QgsPointXY &point SIP_IN, int atVertex ) const;
701 
707  QgsGeometry nearestPoint( const QgsGeometry &other ) const;
708 
714  QgsGeometry shortestLine( const QgsGeometry &other ) const;
715 
722  double closestVertexWithContext( const QgsPointXY &point, int &atVertex SIP_OUT ) const;
723 
735  double closestSegmentWithContext( const QgsPointXY &point, QgsPointXY &minDistPoint SIP_OUT, int &afterVertex SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
736 
742  OperationResult addRing( const QVector<QgsPointXY> &ring );
743 
749  OperationResult addRing( QgsCurve *ring SIP_TRANSFER );
750 
757  OperationResult addPart( const QVector<QgsPointXY> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) SIP_PYNAME( addPointsXY );
758 
765  OperationResult addPart( const QgsPointSequence &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) SIP_PYNAME( addPoints );
766 
773  OperationResult addPart( QgsAbstractGeometry *part SIP_TRANSFER, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry );
774 
780  OperationResult addPart( const QgsGeometry &newPart ) SIP_PYNAME( addPartGeometry );
781 
788  QgsGeometry removeInteriorRings( double minimumAllowedArea = -1 ) const;
789 
794  OperationResult translate( double dx, double dy, double dz = 0.0, double dm = 0.0 );
795 
810  OperationResult transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction = QgsCoordinateTransform::ForwardTransform, bool transformZ = false ) SIP_THROW( QgsCsException );
811 
820  OperationResult transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 );
821 
828  OperationResult rotate( double rotation, const QgsPointXY &center );
829 
838  OperationResult splitGeometry( const QVector<QgsPointXY> &splitLine, QVector<QgsGeometry> &newGeometries SIP_OUT, bool topological, QVector<QgsPointXY> &topologyTestPoints SIP_OUT );
839 
844  OperationResult reshapeGeometry( const QgsLineString &reshapeLineString );
845 
851  int makeDifferenceInPlace( const QgsGeometry &other ) SIP_SKIP;
852 
860  QgsGeometry makeDifference( const QgsGeometry &other ) const;
861 
866  QgsRectangle boundingBox() const;
867 
875  QgsGeometry orientedMinimumBoundingBox( double &area SIP_OUT, double &angle SIP_OUT, double &width SIP_OUT, double &height SIP_OUT ) const;
876 
882  QgsGeometry orientedMinimumBoundingBox() const SIP_SKIP;
883 
891  QgsGeometry minimalEnclosingCircle( QgsPointXY &center SIP_OUT, double &radius SIP_OUT, unsigned int segments = 36 ) const;
892 
898  QgsGeometry minimalEnclosingCircle( unsigned int segments = 36 ) const SIP_SKIP;
899 
908  QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
909 
922  QgsGeometry snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const;
923 
944  bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false );
945 
955  bool intersects( const QgsRectangle &rectangle ) const;
956 
966  bool intersects( const QgsGeometry &geometry ) const;
967 
977  bool boundingBoxIntersects( const QgsRectangle &rectangle ) const;
978 
988  bool boundingBoxIntersects( const QgsGeometry &geometry ) const;
989 
991  bool contains( const QgsPointXY *p ) const;
992 
997  bool contains( const QgsGeometry &geometry ) const;
998 
1003  bool disjoint( const QgsGeometry &geometry ) const;
1004 
1009  bool touches( const QgsGeometry &geometry ) const;
1010 
1015  bool overlaps( const QgsGeometry &geometry ) const;
1016 
1021  bool within( const QgsGeometry &geometry ) const;
1022 
1027  bool crosses( const QgsGeometry &geometry ) const;
1028 
1031  {
1032  SideLeft = 0,
1034  };
1035  Q_ENUM( BufferSide )
1036 
1037 
1039  {
1040  CapRound = 1,
1043  };
1044  Q_ENUM( EndCapStyle )
1045 
1046 
1048  {
1049  JoinStyleRound = 1,
1052  };
1053  Q_ENUM( JoinStyle )
1054 
1055 
1062  QgsGeometry buffer( double distance, int segments ) const;
1063 
1076  QgsGeometry buffer( double distance, int segments, EndCapStyle endCapStyle, JoinStyle joinStyle, double miterLimit ) const;
1077 
1086  QgsGeometry offsetCurve( double distance, int segments, JoinStyle joinStyle, double miterLimit ) const;
1087 
1103  QgsGeometry singleSidedBuffer( double distance, int segments, BufferSide side,
1104  JoinStyle joinStyle = JoinStyleRound,
1105  double miterLimit = 2.0 ) const;
1106 
1124  QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const;
1125 
1140  QgsGeometry variableWidthBufferByM( int segments ) const;
1141 
1148  QgsGeometry extendLine( double startDistance, double endDistance ) const;
1149 
1151  QgsGeometry simplify( double tolerance ) const;
1152 
1162  QgsGeometry densifyByCount( int extraNodesPerSegment ) const;
1163 
1178  QgsGeometry densifyByDistance( double distance ) const;
1179 
1193  QgsGeometry centroid() const;
1194 
1208  QgsGeometry pointOnSurface() const;
1209 
1222  QgsGeometry poleOfInaccessibility( double precision, double *distanceToBoundary SIP_OUT = nullptr ) const;
1223 
1232  QgsGeometry convexHull() const;
1233 
1249  QgsGeometry voronoiDiagram( const QgsGeometry &extent = QgsGeometry(), double tolerance = 0.0, bool edgesOnly = false ) const;
1250 
1260  QgsGeometry delaunayTriangulation( double tolerance = 0.0, bool edgesOnly = false ) const;
1261 
1281  QgsGeometry subdivide( int maxNodes = 256 ) const;
1282 
1298  QgsGeometry interpolate( double distance ) const;
1299 
1311  double lineLocatePoint( const QgsGeometry &point ) const;
1312 
1322  double interpolateAngle( double distance ) const;
1323 
1332  QgsGeometry intersection( const QgsGeometry &geometry ) const;
1333 
1341  QgsGeometry clipped( const QgsRectangle &rectangle );
1342 
1354  QgsGeometry combine( const QgsGeometry &geometry ) const;
1355 
1364  QgsGeometry mergeLines() const;
1365 
1374  QgsGeometry difference( const QgsGeometry &geometry ) const;
1375 
1384  QgsGeometry symDifference( const QgsGeometry &geometry ) const;
1385 
1387  QgsGeometry extrude( double x, double y );
1388 
1393  QByteArray asWkb() const;
1394 
1400  QString asWkt( int precision = 17 ) const;
1401 
1402 #ifdef SIP_RUN
1403  SIP_PYOBJECT __repr__();
1404  % MethodCode
1405  QString str;
1406  if ( sipCpp->isNull() )
1407  str = QStringLiteral( "<QgsGeometry: null>" );
1408  else
1409  {
1410  QString wkt = sipCpp->asWkt();
1411  if ( wkt.length() > 1000 )
1412  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
1413  str = QStringLiteral( "<QgsGeometry: %1>" ).arg( wkt );
1414  }
1415  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1416  % End
1417 #endif
1418 
1422  QString asJson( int precision = 17 ) const;
1423 
1431  QgsGeometry convertToType( QgsWkbTypes::GeometryType destType, bool destMultipart = false ) const SIP_FACTORY;
1432 
1433  /* Accessor functions for getting geometry data */
1434 
1435 #ifndef SIP_RUN
1436 
1444  QgsPointXY asPoint() const;
1445 #else
1446 
1456  SIP_PYOBJECT asPoint() const;
1457  % MethodCode
1458  const QgsWkbTypes::Type type = sipCpp->wkbType();
1459  if ( sipCpp->isNull() )
1460  {
1461  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a point." ).toUtf8().constData() );
1462  sipIsErr = 1;
1463  }
1464  else if ( QgsWkbTypes::flatType( type ) != QgsWkbTypes::Point )
1465  {
1466  PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a point. Only Point types are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1467  sipIsErr = 1;
1468  }
1469  else
1470  {
1471  sipRes = sipConvertFromNewType( new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
1472  }
1473  % End
1474 #endif
1475 
1476 #ifndef SIP_RUN
1477 
1486  QgsPolylineXY asPolyline() const;
1487 #else
1488 
1499  SIP_PYOBJECT asPolyline() const;
1500  % MethodCode
1501  const QgsWkbTypes::Type type = sipCpp->wkbType();
1502  if ( sipCpp->isNull() )
1503  {
1504  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a polyline." ).toUtf8().constData() );
1505  sipIsErr = 1;
1506  }
1508  {
1509  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() );
1510  sipIsErr = 1;
1511  }
1512  else
1513  {
1514  const sipMappedType *qvector_type = sipFindMappedType( "QVector< QgsPointXY >" );
1515  sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
1516  }
1517  % End
1518 #endif
1519 
1520 #ifndef SIP_RUN
1521 
1530  QgsPolygonXY asPolygon() const;
1531 #else
1532 
1543  SIP_PYOBJECT asPolygon() const;
1544  % MethodCode
1545  const QgsWkbTypes::Type type = sipCpp->wkbType();
1546  if ( sipCpp->isNull() )
1547  {
1548  PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a polygon." ).toUtf8().constData() );
1549  sipIsErr = 1;
1550  }
1552  {
1553  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() );
1554  sipIsErr = 1;
1555  }
1556  else
1557  {
1558  const sipMappedType *qvector_type = sipFindMappedType( "QVector<QVector<QgsPointXY>>" );
1559  sipRes = sipConvertFromNewType( new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
1560  }
1561  % End
1562 #endif
1563 
1568  QgsMultiPointXY asMultiPoint() const;
1569 
1574  QgsMultiPolylineXY asMultiPolyline() const;
1575 
1580  QgsMultiPolygonXY asMultiPolygon() const;
1581 
1586  QVector<QgsGeometry> asGeometryCollection() const;
1587 
1593  QPointF asQPointF() const;
1594 
1601  QPolygonF asQPolygonF() const;
1602 
1609  bool deleteRing( int ringNum, int partNum = 0 );
1610 
1616  bool deletePart( int partNum );
1617 
1626  bool convertToMultiType();
1627 
1637  bool convertToSingleType();
1638 
1648  bool convertGeometryCollectionToSubclass( QgsWkbTypes::GeometryType geomType );
1649 
1660  int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
1661  const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
1662 
1681  QgsGeometry makeValid() const;
1682 
1690  QgsGeometry forceRHR() const;
1691 
1695  class CORE_EXPORT Error
1696  {
1697  public:
1699  : mMessage( QStringLiteral( "none" ) )
1700  {}
1701 
1702  explicit Error( const QString &m )
1703  : mMessage( m )
1704  {}
1705 
1706  Error( const QString &m, const QgsPointXY &p )
1707  : mMessage( m )
1708  , mLocation( p )
1709  , mHasLocation( true ) {}
1710 
1714  QString what() const;
1715 
1719  QgsPointXY where() const;
1720 
1724  bool hasWhere() const;
1725 
1726 #ifdef SIP_RUN
1727  SIP_PYOBJECT __repr__();
1728  % MethodCode
1729  QString str = QStringLiteral( "<QgsGeometry.Error: %1>" ).arg( sipCpp->what() );
1730  sipRes = PyUnicode_FromString( str.toUtf8().data() );
1731  % End
1732 #endif
1733 
1734  bool operator==( const QgsGeometry::Error &other ) const
1735  {
1736  return other.mMessage == mMessage && other.mHasLocation == mHasLocation && other.mLocation == mLocation;
1737  }
1738 
1739  private:
1740  QString mMessage;
1741  QgsPointXY mLocation;
1742  bool mHasLocation = false;
1743  };
1744 
1750  {
1753  };
1754 
1763  void validateGeometry( QVector<QgsGeometry::Error> &errors SIP_OUT, ValidationMethod method = ValidatorQgisInternal, QgsGeometry::ValidityFlags flags = nullptr ) const;
1764 
1770  static QgsGeometry unaryUnion( const QVector<QgsGeometry> &geometries );
1771 
1780  static QgsGeometry polygonize( const QVector<QgsGeometry> &geometries );
1781 
1789  void convertToStraightSegment( double tolerance = M_PI / 180., QgsAbstractGeometry::SegmentationToleranceType toleranceType = QgsAbstractGeometry::MaximumAngle );
1790 
1797  bool requiresConversionToStraightSegments() const;
1798 
1804  void mapToPixel( const QgsMapToPixel &mtp );
1805 
1811  void draw( QPainter &p ) const;
1812 
1823  bool vertexIdFromVertexNr( int number, QgsVertexId &id SIP_OUT ) const;
1824 
1836  int vertexNrFromVertexId( QgsVertexId id ) const;
1837 
1845  QString lastError() const;
1846 
1856  void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) SIP_SKIP;
1857 
1872  void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) SIP_SKIP;
1873 
1879  static QgsGeometry fromQPointF( QPointF point );
1880 
1888  static QgsGeometry fromQPolygonF( const QPolygonF &polygon );
1889 
1896  static QgsPolylineXY createPolylineFromQPolygonF( const QPolygonF &polygon ) SIP_FACTORY;
1897 
1904  static QgsPolygonXY createPolygonFromQPolygonF( const QPolygonF &polygon ) SIP_FACTORY;
1905 
1906 #ifndef SIP_RUN
1907 
1917  static bool compare( const QgsPolylineXY &p1, const QgsPolylineXY &p2,
1918  double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1919 
1929  static bool compare( const QgsPolygonXY &p1, const QgsPolygonXY &p2,
1930  double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1931 
1942  static bool compare( const QgsMultiPolygonXY &p1, const QgsMultiPolygonXY &p2,
1943  double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1944 #else
1945 
1964  static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1965  % MethodCode
1966  {
1967  sipRes = false;
1968  int state0;
1969  int state1;
1970  int sipIsErr = 0;
1971 
1972  if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
1973  PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
1974  {
1975  PyObject *o0 = PyList_GetItem( a0, 0 );
1976  PyObject *o1 = PyList_GetItem( a1, 0 );
1977  if ( o0 && o1 )
1978  {
1979  // compare polyline - polyline
1980  if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1981  sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1982  sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
1983  sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1984  {
1985  QgsPolylineXY *p0;
1986  QgsPolylineXY *p1;
1987  p0 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1988  p1 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1989  if ( sipIsErr )
1990  {
1991  sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
1992  sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
1993  }
1994  else
1995  {
1996  sipRes = QgsGeometry::compare( *p0, *p1, a2 );
1997  }
1998  }
1999  else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
2000  PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
2001  {
2002  PyObject *oo0 = PyList_GetItem( o0, 0 );
2003  PyObject *oo1 = PyList_GetItem( o1, 0 );
2004  if ( oo0 && oo1 )
2005  {
2006  // compare polygon - polygon
2007  if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2008  sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2009  sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2010  sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2011  {
2012  QgsPolygonXY *p0;
2013  QgsPolygonXY *p1;
2014  p0 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2015  p1 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2016  if ( sipIsErr )
2017  {
2018  sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
2019  sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
2020  }
2021  else
2022  {
2023  sipRes = QgsGeometry::compare( *p0, *p1, a2 );
2024  }
2025  }
2026  else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
2027  PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
2028  {
2029  PyObject *ooo0 = PyList_GetItem( oo0, 0 );
2030  PyObject *ooo1 = PyList_GetItem( oo1, 0 );
2031  if ( ooo0 && ooo1 )
2032  {
2033  // compare multipolygon - multipolygon
2034  if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2035  sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2036  sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2037  sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2038  {
2039  QgsMultiPolygonXY *p0;
2040  QgsMultiPolygonXY *p1;
2041  p0 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2042  p1 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2043  if ( sipIsErr )
2044  {
2045  sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
2046  sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
2047  }
2048  else
2049  {
2050  sipRes = QgsGeometry::compare( *p0, *p1, a2 );
2051  }
2052  }
2053  }
2054  }
2055  }
2056  }
2057  }
2058  }
2059  }
2060  % End
2061 #endif
2062 
2079  QgsGeometry smooth( unsigned int iterations = 1, double offset = 0.25,
2080  double minimumDistance = -1.0, double maxAngle = 180.0 ) const;
2081 
2085  static QgsGeometryEngine *createGeometryEngine( const QgsAbstractGeometry *geometry ) SIP_FACTORY;
2086 
2092  static void convertPointList( const QVector<QgsPointXY> &input, QgsPointSequence &output );
2093 
2099  static void convertPointList( const QgsPointSequence &input, QVector<QgsPointXY> &output );
2100 
2102  operator QVariant() const
2103  {
2104  return QVariant::fromValue( *this );
2105  }
2106 
2107  private:
2108 
2109  QgsGeometryPrivate *d; //implicitly shared data pointer
2110 
2112  mutable QString mLastError;
2113 
2118  void detach();
2119 
2124  void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
2125 
2126  static void convertToPolyline( const QgsPointSequence &input, QgsPolylineXY &output );
2127  static void convertPolygon( const QgsPolygon &input, QgsPolygonXY &output );
2128 
2130  QgsGeometry convertToPoint( bool destMultipart ) const;
2132  QgsGeometry convertToLine( bool destMultipart ) const;
2134  QgsGeometry convertToPolygon( bool destMultipart ) const;
2135 
2147  std::unique_ptr< QgsLineString > smoothLine( const QgsLineString &line, unsigned int iterations = 1, double offset = 0.25,
2148  double minimumDistance = -1, double maxAngle = 180.0 ) const;
2149 
2161  std::unique_ptr< QgsPolygon > smoothPolygon( const QgsPolygon &polygon, unsigned int iterations = 1, double offset = 0.25,
2162  double minimumDistance = -1, double maxAngle = 180.0 ) const;
2163 
2164 
2166 
2167 }; // class QgsGeometry
2168 
2169 Q_DECLARE_METATYPE( QgsGeometry )
2170 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsGeometry::ValidityFlags )
2171 
2173 CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsGeometry &geometry );
2175 CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry );
2176 
2177 #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:695
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:1752
Error(const QString &m)
Definition: qgsgeometry.h:1702
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
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:1050
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:1038
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:1706
#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
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:563
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:801
Use internal QgsGeometryValidator method.
Definition: qgsgeometry.h:1751
#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:1042
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.
BufferSide
Side of line to buffer.
Definition: qgsgeometry.h:1030
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:1749
bool operator==(const QgsGeometry::Error &other) const
Definition: qgsgeometry.h:1734
Buffer to right of line.
Definition: qgsgeometry.h:1033
Class for doing transforms between two map coordinate systems.
ValidityFlag
Validity check flags.
Definition: qgsgeometry.h:343
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:1051
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:1047
Flat cap (in line with start/end of line)
Definition: qgsgeometry.h:1041
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:565
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