1/************************************************************************ 2 * This file has been generated automatically from * 3 * * 4 * src/core/geometry/qgsgeometry.h * 5 * * 6 * Do not edit manually ! Edit header and run scripts/sipify.pl again * 7 ************************************************************************/ 8 9 10 11 12 13 14 15 16 17typedef QVector<QgsPointXY> QgsPolylineXY; 18 19typedef QgsPointSequence QgsPolyline; 20 21typedef QVector<QVector<QgsPointXY>> QgsPolygonXY; 22 23typedef QVector<QgsPointXY> QgsMultiPointXY; 24 25typedef QVector<QVector<QgsPointXY>> QgsMultiPolylineXY; 26 27typedef QVector<QVector<QVector<QgsPointXY>>> QgsMultiPolygonXY; 28 29 30 31 32class QgsGeometry 33{ 34%Docstring(signature="appended") 35A geometry is the spatial representation of a feature. 36 37:py:class:`QgsGeometry` acts as a generic container for geometry objects. :py:class:`QgsGeometry` objects are implicitly shared, 38so making copies of geometries is inexpensive. The geometry container class can also be stored inside 39a QVariant object. 40 41The actual geometry representation is stored as a :py:class:`QgsAbstractGeometry` within the container, and 42can be accessed via the :py:func:`~get` method or set using the :py:func:`~set` method. This gives access to the underlying 43raw geometry primitive, such as the point, line, polygon, curve or other geometry subclasses. 44 45.. note:: 46 47 :py:class:`QgsGeometry` objects are inherently Cartesian/planar geometries. They have no concept of geodesy, and none 48 of the methods or properties exposed from the :py:class:`QgsGeometry` API (or :py:class:`QgsAbstractGeometry` subclasses) utilize 49 geodesic calculations. Accordingly, properties like :py:func:`~length` and :py:func:`~area` or spatial operations like :py:func:`~buffer` 50 are always calculated using strictly Cartesian mathematics. In contrast, the :py:class:`QgsDistanceArea` class exposes 51 methods for working with geodesic calculations and spatial operations on geometries, 52 and should be used whenever calculations which account for the curvature of the Earth (or any other celestial body) 53 are required. 54%End 55 56%TypeHeaderCode 57#include "qgsgeometry.h" 58%End 59 public: 60 static const QMetaObject staticMetaObject; 61 62 public: 63 64 QgsGeometry() /HoldGIL/; 65%Docstring 66Constructor 67%End 68 69 QgsGeometry( const QgsGeometry & ); 70%Docstring 71Copy constructor will prompt a deep copy of the object 72%End 73 74 75 explicit QgsGeometry( QgsAbstractGeometry *geom /Transfer/ ); 76%Docstring 77Creates a geometry from an abstract geometry object. Ownership of 78geom is transferred. 79 80.. versionadded:: 2.10 81%End 82 83 84 virtual ~QgsGeometry(); 85 86 const QgsAbstractGeometry *constGet() const /HoldGIL/; 87%Docstring 88Returns a non-modifiable (const) reference to the underlying abstract geometry primitive. 89 90This is much faster then calling the non-const :py:func:`~QgsGeometry.get` method. 91 92.. note:: 93 94 In QGIS 2.x this method was named :py:func:`~QgsGeometry.geometry`. 95 96.. seealso:: :py:func:`set` 97 98.. seealso:: :py:func:`get` 99 100.. versionadded:: 3.0 101%End 102 103 QgsAbstractGeometry *get(); 104%Docstring 105Returns a modifiable (non-const) reference to the underlying abstract geometry primitive. 106 107This method can be slow to call, as it may trigger a detachment of the geometry 108and a deep copy. Where possible, use :py:func:`~QgsGeometry.constGet` instead. 109 110.. note:: 111 112 In QGIS 2.x this method was named :py:func:`~QgsGeometry.geometry`. 113 114.. seealso:: :py:func:`constGet` 115 116.. seealso:: :py:func:`set` 117 118.. versionadded:: 3.0 119%End 120 121 void set( QgsAbstractGeometry *geometry /Transfer/ ) /Deprecated/; 122%Docstring 123Sets the underlying geometry store. Ownership of geometry is transferred. 124 125.. note:: 126 127 In QGIS 2.x this method was named :py:func:`~QgsGeometry.setGeometry`. 128 129.. note:: 130 131 This method is deprecated for usage in Python and will be removed from Python bindings with QGIS 4. 132 Using this method will confuse Python's memory management and type information system. 133 Better create a new QgsGeometry object instead. 134 135.. seealso:: :py:func:`get` 136 137.. seealso:: :py:func:`constGet` 138 139.. versionadded:: 3.0 140%End 141 142 bool isNull() const /HoldGIL/; 143%Docstring 144Returns ``True`` if the geometry is null (ie, contains no underlying geometry 145accessible via :py:func:`~QgsGeometry.geometry` ). 146 147.. seealso:: :py:func:`get` 148 149.. seealso:: :py:func:`isEmpty` 150 151.. versionadded:: 2.10 152%End 153 154 static QgsGeometry fromWkt( const QString &wkt ); 155%Docstring 156Creates a new geometry from a WKT string 157%End 158 static QgsGeometry fromPointXY( const QgsPointXY &point ) /HoldGIL/; 159%Docstring 160Creates a new geometry from a :py:class:`QgsPointXY` object 161%End 162 static QgsGeometry fromMultiPointXY( const QgsMultiPointXY &multipoint ); 163%Docstring 164Creates a new geometry from a :py:class:`QgsMultiPointXY` object 165%End 166 167 static QgsGeometry fromPolylineXY( const QgsPolylineXY &polyline ); 168%Docstring 169Creates a new LineString geometry from a list of :py:class:`QgsPointXY` points. 170 171Using :py:func:`~QgsGeometry.fromPolyline` is preferred, as :py:func:`~QgsGeometry.fromPolyline` is more efficient 172and will respect any Z or M dimensions present in the input points. 173 174.. note:: 175 176 In QGIS 2.x this method was available as :py:func:`~QgsGeometry.fromPolyline`. 177 178.. seealso:: :py:func:`fromPolyline` 179 180.. versionadded:: 3.0 181%End 182 183 static QgsGeometry fromPolyline( const QgsPolyline &polyline ); 184%Docstring 185Creates a new LineString geometry from a list of :py:class:`QgsPoint` points. 186 187This method will respect any Z or M dimensions present in the input points. 188E.g. if input points are PointZ type, the resultant linestring will be 189a LineStringZ type. 190 191.. versionadded:: 3.0 192%End 193 194 static QgsGeometry fromMultiPolylineXY( const QgsMultiPolylineXY &multiline ); 195%Docstring 196Creates a new geometry from a :py:class:`QgsMultiPolylineXY` object. 197%End 198 199 200 static QgsGeometry fromPolygonXY( const QgsPolygonXY &polygon ); 201%Docstring 202Creates a new polygon geometry from a list of lists of :py:class:`QgsPointXY`. 203 204The first list of :py:class:`QgsPointXY` objects specifies the exterior ring of the polygon, and the remaining 205lists specify any interior rings. 206 207Example 208------- 209 210.. code-block:: python 211 212 # Create a polygon geometry with a single exterior ring (a triangle) 213 polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 2)]])) 214 215 # Create a donut shaped polygon geometry with an interior ring 216 polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 10), QgsPointXY(1, 2)], 217 [QgsPointXY(3, 4), QgsPointXY(4, 4), QgsPointXY(4, 6), QgsPointXY(3, 6), QgsPointXY(3, 4)]]) 218%End 219 220 static QgsGeometry fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly ); 221%Docstring 222Creates a new geometry from a :py:class:`QgsMultiPolygonXY`. 223%End 224 225 static QgsGeometry fromRect( const QgsRectangle &rect ) /HoldGIL/; 226%Docstring 227Creates a new geometry from a :py:class:`QgsRectangle` 228%End 229 static QgsGeometry collectGeometry( const QVector<QgsGeometry> &geometries ); 230%Docstring 231Creates a new multipart geometry from a list of QgsGeometry objects 232%End 233 234 static QgsGeometry createWedgeBuffer( const QgsPoint ¢er, double azimuth, double angularWidth, 235 double outerRadius, double innerRadius = 0 ); 236%Docstring 237Creates a wedge shaped buffer from a ``center`` point. 238 239The ``azimuth`` gives the angle (in degrees) for the middle of the wedge to point. 240The buffer width (in degrees) is specified by the ``angularWidth`` parameter. Note that the 241wedge will extend to half of the ``angularWidth`` either side of the ``azimuth`` direction. 242 243The outer radius of the buffer is specified via ``outerRadius``, and optionally an 244``innerRadius`` can also be specified. 245 246The returned geometry will be a CurvePolygon geometry containing circular strings. It may 247need to be segmentized to convert to a standard Polygon geometry. 248 249.. versionadded:: 3.2 250%End 251 252 253 void fromWkb( const QByteArray &wkb ); 254%Docstring 255Set the geometry, feeding in the buffer containing OGC Well-Known Binary 256 257.. versionadded:: 3.0 258%End 259 260 QgsWkbTypes::Type wkbType() const /HoldGIL/; 261%Docstring 262Returns type of the geometry as a WKB type (point / linestring / polygon etc.) 263 264.. seealso:: :py:func:`type` 265%End 266 267 QgsWkbTypes::GeometryType type() const /HoldGIL/; 268%Docstring 269Returns type of the geometry as a :py:class:`QgsWkbTypes`.GeometryType 270 271.. seealso:: :py:func:`wkbType` 272%End 273 274 bool isEmpty() const; 275%Docstring 276Returns ``True`` if the geometry is empty (eg a linestring with no vertices, 277or a collection with no geometries). A null geometry will always 278return ``True`` for :py:func:`~QgsGeometry.isEmpty`. 279 280.. seealso:: :py:func:`isNull` 281%End 282 283 bool isMultipart() const /HoldGIL/; 284%Docstring 285Returns ``True`` if WKB of the geometry is of WKBMulti* type 286%End 287 288 bool equals( const QgsGeometry &geometry ) const; 289%Docstring 290Test if this geometry is exactly equal to another ``geometry``. 291 292This is a strict equality check, where the underlying geometries must 293have exactly the same type, component vertices and vertex order. 294 295Calling this method is dramatically faster than the topological 296equality test performed by :py:func:`~QgsGeometry.isGeosEqual`. 297 298.. note:: 299 300 Comparing two null geometries will return ``False``. 301 302.. seealso:: :py:func:`isGeosEqual` 303 304.. versionadded:: 1.5 305%End 306 307 bool isGeosEqual( const QgsGeometry & ) const; 308%Docstring 309Compares the geometry with another geometry using GEOS. 310 311This method performs a slow, topological check, where geometries 312are considered equal if all of the their component edges overlap. E.g. 313lines with the same vertex locations but opposite direction will be 314considered equal by this method. 315 316Consider using the much faster, stricter equality test performed 317by :py:func:`~QgsGeometry.equals` instead. 318 319.. note:: 320 321 Comparing two null geometries will return ``False``. 322 323.. seealso:: :py:func:`equals` 324 325.. versionadded:: 1.5 326%End 327 328 bool isGeosValid( Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const; 329%Docstring 330Checks validity of the geometry using GEOS. 331 332The ``flags`` parameter indicates optional flags which control the type of validity checking performed. 333 334.. versionadded:: 1.5 335%End 336 337 bool isSimple() const; 338%Docstring 339Determines whether the geometry is simple (according to OGC definition), 340i.e. it has no anomalous geometric points, such as self-intersection or self-tangency. 341Uses GEOS library for the test. 342 343.. note:: 344 345 This is useful mainly for linestrings and linear rings. Polygons are simple by definition, 346 for checking anomalies in polygon geometries one can use :py:func:`~QgsGeometry.isGeosValid`. 347 348.. versionadded:: 3.0 349%End 350 351 bool isAxisParallelRectangle( double maximumDeviation, bool simpleRectanglesOnly = false ) const; 352%Docstring 353Returns ``True`` if the geometry is a polygon that is almost an axis-parallel rectangle. 354 355The ``maximumDeviation`` argument specifes the maximum angle (in degrees) that the polygon edges 356are allowed to deviate from axis parallel lines. 357 358By default the check will permit polygons with more than 4 edges, so long as the overall shape of 359the polygon is an axis-parallel rectangle (i.e. it is tolerant to rectangles with additional vertices 360added along the rectangle sides). If ``simpleRectanglesOnly`` is set to ``True`` then the method will 361only return ``True`` if the geometry is a simple rectangle consisting of 4 edges. 362 363.. versionadded:: 3.20 364%End 365 366 double area() const; 367%Docstring 368Returns the planar, 2-dimensional area of the geometry. 369 370.. warning:: 371 372 QgsGeometry objects are inherently Cartesian/planar geometries, and the area 373 returned by this method is calculated using strictly Cartesian mathematics. In contrast, 374 the :py:class:`QgsDistanceArea` class exposes methods for calculating the areas of geometries using 375 geodesic calculations which account for the curvature of the Earth (or any other 376 celestial body). 377 378.. seealso:: :py:func:`length` 379 380.. versionadded:: 1.5 381%End 382 383 double length() const; 384%Docstring 385Returns the planar, 2-dimensional length of geometry. 386 387.. warning:: 388 389 QgsGeometry objects are inherently Cartesian/planar geometries, and the length 390 returned by this method is calculated using strictly Cartesian mathematics. In contrast, 391 the :py:class:`QgsDistanceArea` class exposes methods for calculating the lengths of geometries using 392 geodesic calculations which account for the curvature of the Earth (or any other 393 celestial body). 394 395.. seealso:: :py:func:`area` 396 397.. versionadded:: 1.5 398%End 399 400 double distance( const QgsGeometry &geom ) const; 401%Docstring 402Returns the minimum distance between this geometry and another geometry. 403Will return a negative value if either geometry is empty or null. 404 405.. warning:: 406 407 QgsGeometry objects are inherently Cartesian/planar geometries, and the distance 408 returned by this method is calculated using strictly Cartesian mathematics. 409%End 410 411 412 QgsVertexIterator vertices() const; 413%Docstring 414Returns a read-only, Java-style iterator for traversal of vertices of all the geometry, including all geometry parts and rings. 415 416.. warning:: 417 418 The iterator returns a copy of individual vertices, and accordingly geometries cannot be 419 modified using the iterator. See :py:func:`~QgsGeometry.transformVertices` for a safe method to modify vertices "in-place". 420 421Example 422------- 423 424.. code-block:: python 425 426 # print the x and y coordinate for each vertex in a LineString 427 geometry = QgsGeometry.fromWkt( 'LineString( 0 0, 1 1, 2 2)' ) 428 for v in geometry.vertices(): 429 print(v.x(), v.y()) 430 431 # vertex iteration includes all parts and rings 432 geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' ) 433 for v in geometry.vertices(): 434 print(v.x(), v.y()) 435 436 437 438.. seealso:: :py:func:`parts` 439 440.. versionadded:: 3.0 441%End 442 443 444 QgsGeometryPartIterator parts(); 445%Docstring 446Returns Java-style iterator for traversal of parts of the geometry. This iterator 447can safely be used to modify parts of the geometry. 448 449This method forces a detach. Use :py:func:`~QgsGeometry.constParts` to avoid the detach 450if the parts are not going to be modified. 451 452Example 453------- 454 455.. code-block:: python 456 457 # print the WKT representation of each part in a multi-point geometry 458 geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' ) 459 for part in geometry.parts(): 460 print(part.asWkt()) 461 462 # single part geometries only have one part - this loop will iterate once only 463 geometry = QgsGeometry.fromWkt( 'LineString( 0 0, 10 10 )' ) 464 for part in geometry.parts(): 465 print(part.asWkt()) 466 467 # parts can be modified during the iteration 468 geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' ) 469 for part in geometry.parts(): 470 part.transform(ct) 471 472 # part iteration can also be combined with vertex iteration 473 geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' ) 474 for part in geometry.parts(): 475 for v in part.vertices(): 476 print(v.x(), v.y()) 477 478.. seealso:: :py:func:`constParts` 479 480.. seealso:: :py:func:`vertices` 481 482.. versionadded:: 3.6 483%End 484 485 QgsGeometryConstPartIterator constParts() const; 486%Docstring 487Returns Java-style iterator for traversal of parts of the geometry. This iterator 488returns read-only references to parts and cannot be used to modify the parts. 489 490Unlike :py:func:`~QgsGeometry.parts`, this method does not force a detach and is more efficient if read-only 491iteration only is required. 492 493Example 494------- 495 496.. code-block:: python 497 498 # print the WKT representation of each part in a multi-point geometry 499 geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' ) 500 for part in geometry.constParts(): 501 print(part.asWkt()) 502 503 # single part geometries only have one part - this loop will iterate once only 504 geometry = QgsGeometry.fromWkt( 'LineString( 0 0, 10 10 )' ) 505 for part in geometry.constParts(): 506 print(part.asWkt()) 507 508 # part iteration can also be combined with vertex iteration 509 geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' ) 510 for part in geometry.constParts(): 511 for v in part.vertices(): 512 print(v.x(), v.y()) 513 514.. seealso:: :py:func:`parts` 515 516.. seealso:: :py:func:`vertices` 517 518.. versionadded:: 3.6 519%End 520 521 double hausdorffDistance( const QgsGeometry &geom ) const; 522%Docstring 523Returns the Hausdorff distance between this geometry and ``geom``. This is basically a measure of how similar or dissimilar 2 geometries are. 524 525This algorithm is an approximation to the standard Hausdorff distance. This approximation is exact or close enough for a large 526subset of useful cases. Examples of these are: 527 528- computing distance between Linestrings that are roughly parallel to each other, 529 and roughly equal in length. This occurs in matching linear networks. 530- Testing similarity of geometries. 531 532If the default approximate provided by this method is insufficient, use :py:func:`~QgsGeometry.hausdorffDistanceDensify` instead. 533 534In case of error -1 will be returned. 535 536.. seealso:: :py:func:`hausdorffDistanceDensify` 537 538.. versionadded:: 3.0 539%End 540 541 double hausdorffDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const; 542%Docstring 543Returns the Hausdorff distance between this geometry and ``geom``. This is basically a measure of how similar or dissimilar 2 geometries are. 544 545This function accepts a ``densifyFraction`` argument. The function performs a segment 546densification before computing the discrete Hausdorff distance. The ``densifyFraction`` parameter 547sets the fraction by which to densify each segment. Each segment will be split into a 548number of equal-length subsegments, whose fraction of the total length is 549closest to the given fraction. 550 551This method can be used when the default approximation provided by :py:func:`~QgsGeometry.hausdorffDistance` 552is not sufficient. Decreasing the ``densifyFraction`` parameter will make the 553distance returned approach the true Hausdorff distance for the geometries. 554 555In case of error -1 will be returned. 556 557.. seealso:: :py:func:`hausdorffDistance` 558 559.. versionadded:: 3.0 560%End 561 562 double frechetDistance( const QgsGeometry &geom ) const throw( QgsNotSupportedException ); 563%Docstring 564Returns the Fréchet distance between this geometry and ``geom``, restricted to discrete points for both geometries. 565 566The Fréchet distance is a measure of similarity between curves that takes into account the location and ordering of the points along the curves. 567Therefore it is often better than the Hausdorff distance. 568 569In case of error -1 will be returned. 570 571This method requires a QGIS build based on GEOS 3.7 or later. 572 573:raises QgsNotSupportedException: on QGIS builds based on GEOS 3.6 or earlier. 574 575.. seealso:: :py:func:`frechetDistanceDensify` 576 577.. versionadded:: 3.20 578%End 579 580 double frechetDistanceDensify( const QgsGeometry &geom, double densifyFraction ) const throw( QgsNotSupportedException ); 581%Docstring 582Returns the Fréchet distance between this geometry and ``geom``, restricted to discrete points for both geometries. 583 584The Fréchet distance is a measure of similarity between curves that takes into account the location and ordering of the points along the curves. 585Therefore it is often better than the Hausdorff distance. 586 587This function accepts a ``densifyFraction`` argument. The function performs a segment 588densification before computing the discrete Fréchet distance. The ``densifyFraction`` parameter 589sets the fraction by which to densify each segment. Each segment will be split into a 590number of equal-length subsegments, whose fraction of the total length is 591closest to the given fraction. 592 593This method can be used when the default approximation provided by :py:func:`~QgsGeometry.frechetDistance` 594is not sufficient. Decreasing the ``densifyFraction`` parameter will make the 595distance returned approach the true Fréchet distance for the geometries. 596 597This method requires a QGIS build based on GEOS 3.7 or later. 598 599:raises QgsNotSupportedException: on QGIS builds based on GEOS 3.6 or earlier. 600 601.. seealso:: :py:func:`frechetDistance` 602 603.. versionadded:: 3.20 604%End 605 606 QgsPointXY closestVertex( const QgsPointXY &point, int &closestVertexIndex /Out/, int &previousVertexIndex /Out/, int &nextVertexIndex /Out/, double &sqrDist /Out/ ) const; 607%Docstring 608Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap point / target point 609and the indices of the vertices before and after the closest vertex. 610 611:param point: point to search for 612 613:return: - closest point in geometry. If not found (empty geometry), returns null point and sqrDist is negative. 614 - closestVertexIndex: will be set to the vertex index of the closest found vertex 615 - previousVertexIndex: will be set to the vertex index of the previous vertex from the closest one. Will be set to -1 if not present. 616 - nextVertexIndex: will be set to the vertex index of the next vertex after the closest one. Will be set to -1 if not present. 617 - sqrDist: will be set to the square distance between the closest vertex and the specified point 618%End 619 620 double distanceToVertex( int vertex ) const; 621%Docstring 622Returns the distance along this geometry from its first vertex to the specified vertex. 623 624:param vertex: vertex index to calculate distance to 625 626:return: distance to vertex (following geometry), or -1 for invalid vertex numbers 627 628.. warning:: 629 630 QgsGeometry objects are inherently Cartesian/planar geometries, and the distance 631 returned by this method is calculated using strictly Cartesian mathematics. 632 633.. versionadded:: 2.16 634%End 635 636 double angleAtVertex( int vertex ) const; 637%Docstring 638Returns the bisector angle for this geometry at the specified vertex. 639 640:param vertex: vertex index to calculate bisector angle at 641 642:return: bisector angle, in radians clockwise from north 643 644.. seealso:: :py:func:`interpolateAngle` 645 646.. versionadded:: 3.0 647%End 648 649 void adjacentVertices( int atVertex, int &beforeVertex /Out/, int &afterVertex /Out/ ) const; 650%Docstring 651Returns the indexes of the vertices before and after the given vertex index. 652 653This function takes into account the following factors: 654 655# If the given vertex index is at the end of a linestring, 656 the adjacent index will be -1 (for "no adjacent vertex") 657# If the given vertex index is at the end of a linear ring 658 (such as in a polygon), the adjacent index will take into 659 account the first vertex is equal to the last vertex (and will 660 skip equal vertex positions). 661%End 662 663 bool insertVertex( double x, double y, int beforeVertex ); 664%Docstring 665Insert a new vertex before the given vertex index, 666ring and item (first number is index 0) 667If the requested vertex number (beforeVertex.back()) is greater 668than the last actual vertex on the requested ring and item, 669it is assumed that the vertex is to be appended instead of inserted. 670Returns ``False`` if atVertex does not correspond to a valid vertex 671on this geometry (including if this geometry is a Point). 672It is up to the caller to distinguish between 673these error conditions. (Or maybe we add another method to this 674object to help make the distinction?) 675%End 676 677 bool insertVertex( const QgsPoint &point, int beforeVertex ); 678%Docstring 679Insert a new vertex before the given vertex index, 680ring and item (first number is index 0) 681If the requested vertex number (beforeVertex.back()) is greater 682than the last actual vertex on the requested ring and item, 683it is assumed that the vertex is to be appended instead of inserted. 684Returns ``False`` if atVertex does not correspond to a valid vertex 685on this geometry (including if this geometry is a Point). 686It is up to the caller to distinguish between 687these error conditions. (Or maybe we add another method to this 688object to help make the distinction?) 689%End 690 691 bool moveVertex( double x, double y, int atVertex ); 692%Docstring 693Moves the vertex at the given position number 694and item (first number is index 0) 695to the given coordinates. 696Returns ``False`` if atVertex does not correspond to a valid vertex 697on this geometry 698%End 699 700 bool moveVertex( const QgsPoint &p, int atVertex ); 701%Docstring 702Moves the vertex at the given position number 703and item (first number is index 0) 704to the given coordinates. 705Returns ``False`` if atVertex does not correspond to a valid vertex 706on this geometry 707%End 708 709 bool deleteVertex( int atVertex ); 710%Docstring 711Deletes the vertex at the given position number and item 712(first number is index 0) 713 714:return: ``False`` if atVertex does not correspond to a valid vertex 715 on this geometry (including if this geometry is a Point), 716 or if the number of remaining vertices in the linestring 717 would be less than two. 718 It is up to the caller to distinguish between 719 these error conditions. (Or maybe we add another method to this 720 object to help make the distinction?) 721%End 722 723 bool toggleCircularAtVertex( int atVertex ); 724%Docstring 725Converts the vertex at the given position from/to circular 726 727:return: ``False`` if atVertex does not correspond to a valid vertex 728 on this geometry (including if this geometry is a Point), 729 or if the specified vertex can't be converted (e.g. start/end points). 730 731.. versionadded:: 3.20 732%End 733 734 QgsPoint vertexAt( int atVertex ) const; 735%Docstring 736Returns coordinates of a vertex. 737 738:param atVertex: index of the vertex 739 740:return: Coordinates of the vertex or empty :py:class:`QgsPoint` on error 741%End 742 743 double sqrDistToVertexAt( QgsPointXY &point /In/, int atVertex ) const; 744%Docstring 745Returns the squared Cartesian distance between the given point 746to the given vertex index (vertex at the given position number, 747ring and item (first number is index 0)) 748%End 749 750 QgsGeometry nearestPoint( const QgsGeometry &other ) const; 751%Docstring 752Returns the nearest (closest) point on this geometry to another geometry. 753 754.. seealso:: :py:func:`shortestLine` 755 756.. versionadded:: 2.14 757%End 758 759 QgsGeometry shortestLine( const QgsGeometry &other ) const; 760%Docstring 761Returns the shortest line joining this geometry to another geometry. 762 763.. seealso:: :py:func:`nearestPoint` 764 765.. warning:: 766 767 QgsGeometry objects are inherently Cartesian/planar geometries, and the line 768 returned by this method is calculated using strictly Cartesian mathematics. See :py:class:`QgsDistanceArea` 769 for similar methods which account for the curvature of an ellipsoidal body such as the Earth. 770 771.. versionadded:: 2.14 772%End 773 774 double closestVertexWithContext( const QgsPointXY &point, int &atVertex /Out/ ) const; 775%Docstring 776Searches for the closest vertex in this geometry to the given point. 777 778:param point: Specifiest the point for search 779 780:return: - The squared Cartesian distance is also returned in sqrDist, negative number on error 781 - atVertex: Receives index of the closest vertex 782%End 783 784 double closestSegmentWithContext( const QgsPointXY &point, QgsPointXY &minDistPoint /Out/, int &nextVertexIndex /Out/, int *leftOrRightOfSegment /Out/ = 0, double epsilon = DEFAULT_SEGMENT_EPSILON ) const; 785%Docstring 786Searches for the closest segment of geometry to the given point 787 788:param point: Specifies the point for search 789:param epsilon: epsilon for segment snapping 790 791:return: - The squared Cartesian distance is also returned in sqrDist, negative number on error 792 - minDistPoint: Receives the nearest point on the segment 793 - nextVertexIndex: Receives index of the next vertex after the closest segment. The vertex before the closest segment is always nextVertexIndex - 1 794 - leftOrRightOfSegment: Out: Returns if the point is located on the left or right side of the geometry ( < 0 means left, > 0 means right, 0 indicates that the test was unsuccessful, e.g. for a point exactly on the line) 795%End 796 797 Qgis::GeometryOperationResult addRing( const QVector<QgsPointXY> &ring ); 798%Docstring 799Adds a new ring to this geometry. This makes only sense for polygon and multipolygons. 800 801:param ring: The ring to be added 802 803:return: OperationResult a result code: success or reason of failure 804%End 805 806 Qgis::GeometryOperationResult addRing( QgsCurve *ring /Transfer/ ); 807%Docstring 808Adds a new ring to this geometry. This makes only sense for polygon and multipolygons. 809 810:param ring: The ring to be added 811 812:return: OperationResult a result code: success or reason of failure 813%End 814 815 Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) /PyName=addPointsXY/; 816%Docstring 817Adds a new part to a the geometry. 818 819:param points: points describing part to add 820:param geomType: default geometry type to create if no existing geometry 821 822:return: OperationResult a result code: success or reason of failure 823%End 824 825 Qgis::GeometryOperationResult addPart( const QgsPointSequence &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) /PyName=addPoints/; 826%Docstring 827Adds a new part to a the geometry. 828 829:param points: points describing part to add 830:param geomType: default geometry type to create if no existing geometry 831 832:return: OperationResult a result code: success or reason of failure 833%End 834 835 Qgis::GeometryOperationResult addPart( QgsAbstractGeometry *part /Transfer/, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ); 836%Docstring 837Adds a new part to this geometry. 838 839:param part: part to add (ownership is transferred) 840:param geomType: default geometry type to create if no existing geometry 841 842:return: OperationResult a result code: success or reason of failure 843%End 844 845 Qgis::GeometryOperationResult addPart( const QgsGeometry &newPart ) /PyName=addPartGeometry/; 846%Docstring 847Adds a new island polygon to a multipolygon feature 848 849:return: OperationResult a result code: success or reason of failure 850 851.. note:: 852 853 available in python bindings as addPartGeometry 854%End 855 856 QgsGeometry removeInteriorRings( double minimumAllowedArea = -1 ) const; 857%Docstring 858Removes the interior rings from a (multi)polygon geometry. If the minimumAllowedArea 859parameter is specified then only rings smaller than this minimum 860area will be removed. 861 862.. versionadded:: 3.0 863%End 864 865 Qgis::GeometryOperationResult translate( double dx, double dy, double dz = 0.0, double dm = 0.0 ); 866%Docstring 867Translates this geometry by dx, dy, dz and dm. 868 869:return: OperationResult a result code: success or reason of failure 870%End 871 872 Qgis::GeometryOperationResult transform( const QgsCoordinateTransform &ct, Qgis::TransformDirection direction = Qgis::TransformDirection::Forward, bool transformZ = false ) throw( QgsCsException ); 873%Docstring 874Transforms this geometry as described by the coordinate transform ``ct``. 875 876The transformation defaults to a forward transform, but the direction can be swapped 877by setting the ``direction`` argument. 878 879By default, z-coordinates are not transformed, even if the coordinate transform 880includes a vertical datum transformation. To transform z-coordinates, set 881``transformZ`` to ``True``. This requires that the z coordinates in the geometry represent 882height relative to the vertical datum of the source CRS (generally ellipsoidal heights) 883and are expressed in its vertical units (generally meters). 884 885:return: OperationResult a result code: success or reason of failure 886%End 887 888 Qgis::GeometryOperationResult transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ); 889%Docstring 890Transforms the x and y components of the geometry using a QTransform object ``t``. 891 892Optionally, the geometry's z values can be scaled via ``zScale`` and translated via ``zTranslate``. 893Similarly, m-values can be scaled via ``mScale`` and translated via ``mTranslate``. 894 895:return: OperationResult a result code: success or reason of failure 896%End 897 898 Qgis::GeometryOperationResult rotate( double rotation, const QgsPointXY ¢er ); 899%Docstring 900Rotate this geometry around the Z axis 901 902:param rotation: clockwise rotation in degrees 903:param center: rotation center 904 905:return: OperationResult a result code: success or reason of failure 906%End 907 908 Qgis::GeometryOperationResult splitGeometry( const QVector<QgsPointXY> &splitLine, QVector<QgsGeometry> &newGeometries /Out/, bool topological, QVector<QgsPointXY> &topologyTestPoints /Out/, bool splitFeature = true ) /Deprecated/; 909%Docstring 910Splits this geometry according to a given line. 911 912:param splitLine: the line that splits the geometry 913\param[out] newGeometries list of new geometries that have been created with the split 914:param topological: ``True`` if topological editing is enabled 915\param[out] topologyTestPoints points that need to be tested for topological completeness in the dataset 916:param splitFeature: Set to ``True`` if you want to split a feature, otherwise set to ``False`` to split parts 917 918:return: OperationResult a result code: success or reason of failure 919 920.. deprecated:: QGIS 3.12 921 - will be removed in QGIS 4.0. Use the variant which accepts :py:class:`QgsPoint` objects instead of :py:class:`QgsPointXY`. 922%End 923 924 Qgis::GeometryOperationResult splitGeometry( const QgsPointSequence &splitLine, QVector<QgsGeometry> &newGeometries /Out/, bool topological, QgsPointSequence &topologyTestPoints /Out/, bool splitFeature = true); 925%Docstring 926Splits this geometry according to a given line. 927 928:param splitLine: the line that splits the geometry 929\param[out] newGeometries list of new geometries that have been created with the ``splitLine``. If the geometry is 3D, a linear interpolation of the z value is performed on the geometry at split points, see example. 930:param topological: ``True`` if topological editing is enabled 931\param[out] topologyTestPoints points that need to be tested for topological completeness in the dataset 932:param splitFeature: Set to ``True`` if you want to split a feature, otherwise set to ``False`` to split parts 933 fix this bug? 934 935:return: OperationResult a result code: success or reason of failure 936 937Example: 938 939.. code-block:: python 940 941 geometry = QgsGeometry.fromWkt('CompoundCurveZ ((2749546.2003820720128715 1262904.45356595050543547 100, 2749557.82053794478997588 1262920.05570670193992555 200))') 942 split_line = [QgsPoint(2749544.19, 1262914.79), QgsPoint(2749557.64, 1262897.30)] 943 result, new_geometries, point_xy = geometry.splitGeometry(split_line, False) 944 print(geometry.asWkt(2)) 945 > LineStringZ (2749549.12 1262908.38 125.14, 2749557.82 1262920.06 200) 946%End 947 948 Qgis::GeometryOperationResult splitGeometry( const QgsCurve *curve, QVector<QgsGeometry> &newGeometries /Out/, bool preserveCircular, bool topological, QgsPointSequence &topologyTestPoints /Out/, bool splitFeature = true ); 949%Docstring 950Splits this geometry according to a given curve. 951 952:param curve: the curve that splits the geometry 953\param[out] newGeometries list of new geometries that have been created with the ``splitLine``. If the geometry is 3D, a linear interpolation of the z value is performed on the geometry at split points, see example. 954:param preserveCircular: whether if circular strings are preserved after splitting 955:param topological: ``True`` if topological editing is enabled 956\param[out] topologyTestPoints points that need to be tested for topological completeness in the dataset 957:param splitFeature: Set to ``True`` if you want to split a feature, otherwise set to ``False`` to split parts 958 959:return: OperationResult a result code: success or reason of failure 960 961.. versionadded:: 3.16 962%End 963 964 Qgis::GeometryOperationResult reshapeGeometry( const QgsLineString &reshapeLineString ); 965%Docstring 966Replaces a part of this geometry with another line 967 968:return: OperationResult a result code: success or reason of failure 969%End 970 971 972 QgsGeometry makeDifference( const QgsGeometry &other ) const; 973%Docstring 974Returns the geometry formed by modifying this geometry such that it does not 975intersect the other geometry. 976 977:param other: geometry that should not be intersect 978 979:return: difference geometry, or empty geometry if difference could not be calculated 980 981.. versionadded:: 3.0 982%End 983 984 QgsRectangle boundingBox() const; 985%Docstring 986Returns the bounding box of the geometry. 987 988.. seealso:: :py:func:`orientedMinimumBoundingBox` 989%End 990 991 QgsGeometry orientedMinimumBoundingBox( double &area /Out/, double &angle /Out/, double &width /Out/, double &height /Out/ ) const; 992%Docstring 993Returns the oriented minimum bounding box for the geometry, which is the smallest (by area) 994rotated rectangle which fully encompasses the geometry. The area, angle (clockwise in degrees from North), 995width and height of the rotated bounding box will also be returned. 996 997If an error was encountered while creating the result, more information can be retrieved 998by calling :py:func:`~QgsGeometry.lastError` on the returned geometry. 999 1000.. seealso:: :py:func:`boundingBox` 1001 1002.. versionadded:: 3.0 1003%End 1004 1005 1006 QgsGeometry minimalEnclosingCircle( QgsPointXY ¢er /Out/, double &radius /Out/, unsigned int segments = 36 ) const; 1007%Docstring 1008Returns the minimal enclosing circle for the geometry. 1009 1010:param segments: Number of segments used to segment geometry. :py:func:`QgsEllipse.toPolygon` 1011 1012:return: - the minimal enclosing circle as a QGIS geometry 1013 - center: Center of the minimal enclosing circle returneds 1014 - radius: Radius of the minimal enclosing circle returned 1015 1016.. versionadded:: 3.0 1017%End 1018 1019 1020 QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const; 1021%Docstring 1022Attempts to orthogonalize a line or polygon geometry by shifting vertices to make the geometries 1023angles either right angles or flat lines. This is an iterative algorithm which will loop until 1024either the vertices are within a specified tolerance of right angles or a set number of maximum 1025iterations is reached. The angle threshold parameter specifies how close to a right angle or 1026straight line an angle must be before it is attempted to be straightened. 1027 1028.. versionadded:: 3.0 1029%End 1030 1031 QgsGeometry snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const; 1032%Docstring 1033Returns a new geometry with all points or vertices snapped to the closest point of the grid. 1034 1035If the gridified geometry could not be calculated (or was totally collapsed) an empty geometry will be returned. 1036Note that snapping to grid may generate an invalid geometry in some corner cases. 1037It can also be thought as rounding the edges and it may be useful for removing errors. 1038 1039:param hSpacing: Horizontal spacing of the grid (x axis). 0 to disable. 1040:param vSpacing: Vertical spacing of the grid (y axis). 0 to disable. 1041:param dSpacing: Depth spacing of the grid (z axis). 0 (default) to disable. 1042:param mSpacing: Custom dimension spacing of the grid (m axis). 0 (default) to disable. 1043 1044.. versionadded:: 3.0 1045%End 1046 1047 bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ); 1048%Docstring 1049Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a 1050degenerate geometry. 1051 1052The ``epsilon`` parameter specifies the tolerance for coordinates when determining that 1053vertices are identical. 1054 1055By default, z values are not considered when detecting duplicate nodes. E.g. two nodes 1056with the same x and y coordinate but different z values will still be considered 1057duplicate and one will be removed. If ``useZValues`` is ``True``, then the z values are 1058also tested and nodes with the same x and y but different z will be maintained. 1059 1060Note that duplicate nodes are not tested between different parts of a multipart geometry. E.g. 1061a multipoint geometry with overlapping points will not be changed by this method. 1062 1063The function will return ``True`` if nodes were removed, or ``False`` if no duplicate nodes 1064were found. 1065 1066.. versionadded:: 3.0 1067%End 1068 1069 bool intersects( const QgsRectangle &rectangle ) const; 1070%Docstring 1071Returns ``True`` if this geometry exactly intersects with a ``rectangle``. This test is exact 1072and can be slow for complex geometries. 1073 1074The GEOS library is used to perform the intersection test. Geometries which are not 1075valid may return incorrect results. 1076 1077.. seealso:: :py:func:`boundingBoxIntersects` 1078%End 1079 1080 bool intersects( const QgsGeometry &geometry ) const; 1081%Docstring 1082Returns ``True`` if this geometry exactly intersects with another ``geometry``. This test is exact 1083and can be slow for complex geometries. 1084 1085The GEOS library is used to perform the intersection test. Geometries which are not 1086valid may return incorrect results. 1087 1088.. note:: 1089 1090 For performance critical code, or when testing for intersection against many different 1091 geometries, consider using :py:class:`QgsGeometryEngine` instead. This approach can be many orders of magnitude 1092 faster than calling :py:func:`~QgsGeometry.intersects` directly. See :py:func:`~QgsGeometry.createGeometryEngine` for details on how to use the 1093 :py:class:`QgsGeometryEngine` class. 1094 1095.. seealso:: :py:func:`boundingBoxIntersects` 1096%End 1097 1098 bool boundingBoxIntersects( const QgsRectangle &rectangle ) const; 1099%Docstring 1100Returns ``True`` if the bounding box of this geometry intersects with a ``rectangle``. Since this 1101test only considers the bounding box of the geometry, is is very fast to calculate and handles invalid 1102geometries. 1103 1104.. seealso:: :py:func:`intersects` 1105 1106.. versionadded:: 3.0 1107%End 1108 1109 bool boundingBoxIntersects( const QgsGeometry &geometry ) const; 1110%Docstring 1111Returns ``True`` if the bounding box of this geometry intersects with the bounding box of another ``geometry``. Since this 1112test only considers the bounding box of the geometries, is is very fast to calculate and handles invalid 1113geometries. 1114 1115.. seealso:: :py:func:`intersects` 1116 1117.. versionadded:: 3.0 1118%End 1119 1120 bool contains( const QgsPointXY *p ) const; 1121%Docstring 1122Returns ``True`` if the geometry contains the point ``p``. 1123%End 1124 1125 bool contains( const QgsGeometry &geometry ) const; 1126%Docstring 1127Returns ``True`` if the geometry completely contains another ``geometry``. 1128 1129.. note:: 1130 1131 For performance critical code, or when testing for contains against many different 1132 geometries, consider using :py:class:`QgsGeometryEngine` instead. This approach can be many orders of magnitude 1133 faster than calling :py:func:`~QgsGeometry.contains` directly. See :py:func:`~QgsGeometry.createGeometryEngine` for details on how to use the 1134 :py:class:`QgsGeometryEngine` class. 1135 1136.. versionadded:: 1.5 1137%End 1138 1139 bool disjoint( const QgsGeometry &geometry ) const; 1140%Docstring 1141Returns ``True`` if the geometry is disjoint of another ``geometry``. 1142 1143.. note:: 1144 1145 For performance critical code, or when testing for disjoint against many different 1146 geometries, consider using :py:class:`QgsGeometryEngine` instead. This approach can be many orders of magnitude 1147 faster than calling :py:func:`~QgsGeometry.disjoint` directly. See :py:func:`~QgsGeometry.createGeometryEngine` for details on how to use the 1148 :py:class:`QgsGeometryEngine` class. 1149 1150.. versionadded:: 1.5 1151%End 1152 1153 bool touches( const QgsGeometry &geometry ) const; 1154%Docstring 1155Returns ``True`` if the geometry touches another ``geometry``. 1156 1157.. note:: 1158 1159 For performance critical code, or when testing for touches against many different 1160 geometries, consider using :py:class:`QgsGeometryEngine` instead. This approach can be many orders of magnitude 1161 faster than calling :py:func:`~QgsGeometry.touches` directly. See :py:func:`~QgsGeometry.createGeometryEngine` for details on how to use the 1162 :py:class:`QgsGeometryEngine` class. 1163 1164.. versionadded:: 1.5 1165%End 1166 1167 bool overlaps( const QgsGeometry &geometry ) const; 1168%Docstring 1169Returns ``True`` if the geometry overlaps another ``geometry``. 1170 1171.. note:: 1172 1173 For performance critical code, or when testing for overlaps against many different 1174 geometries, consider using :py:class:`QgsGeometryEngine` instead. This approach can be many orders of magnitude 1175 faster than calling :py:func:`~QgsGeometry.overlaps` directly. See :py:func:`~QgsGeometry.createGeometryEngine` for details on how to use the 1176 :py:class:`QgsGeometryEngine` class. 1177 1178.. versionadded:: 1.5 1179%End 1180 1181 bool within( const QgsGeometry &geometry ) const; 1182%Docstring 1183Returns ``True`` if the geometry is completely within another ``geometry``. 1184 1185.. note:: 1186 1187 For performance critical code, or when testing for within against many different 1188 geometries, consider using :py:class:`QgsGeometryEngine` instead. This approach can be many orders of magnitude 1189 faster than calling :py:func:`~QgsGeometry.within` directly. See :py:func:`~QgsGeometry.createGeometryEngine` for details on how to use the 1190 :py:class:`QgsGeometryEngine` class. 1191 1192.. versionadded:: 1.5 1193%End 1194 1195 bool crosses( const QgsGeometry &geometry ) const; 1196%Docstring 1197Returns ``True`` if the geometry crosses another ``geometry``. 1198 1199.. note:: 1200 1201 For performance critical code, or when testing for crosses against many different 1202 geometries, consider using :py:class:`QgsGeometryEngine` instead. This approach can be many orders of magnitude 1203 faster than calling :py:func:`~QgsGeometry.crosses` directly. See :py:func:`~QgsGeometry.createGeometryEngine` for details on how to use the 1204 :py:class:`QgsGeometryEngine` class. 1205 1206.. versionadded:: 1.5 1207%End 1208 1209 QgsGeometry buffer( double distance, int segments ) const; 1210%Docstring 1211Returns a buffer region around this geometry having the given width and with a specified number 1212of segments used to approximate curves 1213 1214.. seealso:: :py:func:`singleSidedBuffer` 1215 1216.. seealso:: :py:func:`taperedBuffer` 1217%End 1218 1219 QgsGeometry buffer( double distance, int segments, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit ) const; 1220%Docstring 1221Returns a buffer region around the geometry, with additional style options. 1222 1223:param distance: buffer distance 1224:param segments: for round joins, number of segments to approximate quarter-circle 1225:param endCapStyle: end cap style 1226:param joinStyle: join style for corners in geometry 1227:param miterLimit: limit on the miter ratio used for very sharp corners (JoinStyleMiter only) 1228 1229.. seealso:: :py:func:`singleSidedBuffer` 1230 1231.. seealso:: :py:func:`taperedBuffer` 1232 1233.. versionadded:: 2.4 1234%End 1235 1236 QgsGeometry offsetCurve( double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit ) const; 1237%Docstring 1238Returns an offset line at a given distance and side from an input line. 1239 1240:param distance: buffer distance 1241:param segments: for round joins, number of segments to approximate quarter-circle 1242:param joinStyle: join style for corners in geometry 1243:param miterLimit: limit on the miter ratio used for very sharp corners (JoinStyleMiter only) 1244 1245.. versionadded:: 2.4 1246%End 1247 1248 QgsGeometry singleSidedBuffer( double distance, int segments, Qgis::BufferSide side, 1249 Qgis::JoinStyle joinStyle = Qgis::JoinStyle::Round, 1250 double miterLimit = 2.0 ) const; 1251%Docstring 1252Returns a single sided buffer for a (multi)line geometry. The buffer is only 1253applied to one side of the line. 1254 1255:param distance: buffer distance 1256:param segments: for round joins, number of segments to approximate quarter-circle 1257:param side: side of geometry to buffer 1258:param joinStyle: join style for corners 1259:param miterLimit: limit on the miter ratio used for very sharp corners 1260 1261:return: buffered geometry, or an empty geometry if buffer could not be 1262 calculated 1263 1264.. seealso:: :py:func:`buffer` 1265 1266.. seealso:: :py:func:`taperedBuffer` 1267 1268.. versionadded:: 3.0 1269%End 1270 1271 QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const; 1272%Docstring 1273Calculates a variable width buffer ("tapered buffer") for a (multi)curve geometry. 1274 1275The buffer begins at a width of ``startWidth`` at the start of each curve, and 1276ends at a width of ``endWidth``. Note that unlike :py:func:`~QgsGeometry.buffer` methods, ``startWidth`` 1277and ``endWidth`` are the diameter of the buffer at these points, not the radius. 1278 1279The ``segments`` argument specifies the number of segments to approximate quarter-circle 1280curves in the buffer. 1281 1282Non (multi)curve input geometries will return a null output geometry. 1283 1284.. seealso:: :py:func:`buffer` 1285 1286.. seealso:: :py:func:`singleSidedBuffer` 1287 1288.. seealso:: :py:func:`variableWidthBufferByM` 1289 1290.. versionadded:: 3.2 1291%End 1292 1293 QgsGeometry variableWidthBufferByM( int segments ) const; 1294%Docstring 1295Calculates a variable width buffer for a (multi)linestring geometry, where 1296the width at each node is taken from the linestring m values. 1297 1298The ``segments`` argument specifies the number of segments to approximate quarter-circle 1299curves in the buffer. 1300 1301Non (multi)linestring input geometries will return a null output geometry. 1302 1303.. seealso:: :py:func:`buffer` 1304 1305.. seealso:: :py:func:`singleSidedBuffer` 1306 1307.. seealso:: :py:func:`taperedBuffer` 1308 1309.. versionadded:: 3.2 1310%End 1311 1312 QgsGeometry extendLine( double startDistance, double endDistance ) const; 1313%Docstring 1314Extends a (multi)line geometry by extrapolating out the start or end of the line 1315by a specified distance. Lines are extended using the bearing of the first or last 1316segment in the line. 1317 1318.. versionadded:: 3.0 1319%End 1320 1321 QgsGeometry simplify( double tolerance ) const; 1322%Docstring 1323Returns a simplified version of this geometry using a specified tolerance value 1324%End 1325 1326 QgsGeometry densifyByCount( int extraNodesPerSegment ) const; 1327%Docstring 1328Returns a copy of the geometry which has been densified by adding the specified 1329number of extra nodes within each segment of the geometry. 1330If the geometry has z or m values present then these will be linearly interpolated 1331at the added nodes. 1332Curved geometry types are automatically segmentized by this routine. 1333 1334.. seealso:: :py:func:`densifyByDistance` 1335 1336.. versionadded:: 3.0 1337%End 1338 1339 QgsGeometry densifyByDistance( double distance ) const; 1340%Docstring 1341Densifies the geometry by adding regularly placed extra nodes inside each segment 1342so that the maximum distance between any two nodes does not exceed the 1343specified ``distance``. 1344E.g. specifying a distance 3 would cause the segment [0 0] -> [10 0] 1345to be converted to [0 0] -> [2.5 0] -> [5 0] -> [7.5 0] -> [10 0], since 13463 extra nodes are required on the segment and spacing these at 2.5 increments 1347allows them to be evenly spaced over the segment. 1348If the geometry has z or m values present then these will be linearly interpolated 1349at the added nodes. 1350Curved geometry types are automatically segmentized by this routine. 1351 1352.. seealso:: :py:func:`densifyByCount` 1353 1354.. versionadded:: 3.0 1355%End 1356 1357 QgsGeometry convertToCurves( double distanceTolerance = 1e-8, double angleTolerance = 1e-8 ) const; 1358%Docstring 1359Attempts to convert a non-curved geometry into a curved geometry type (e.g. 1360LineString to CompoundCurve, Polygon to CurvePolygon). 1361 1362The ``distanceTolerance`` specifies the maximum deviation allowed between the original location 1363of vertices and where they would fall on the candidate curved geometry. 1364 1365This method only consider a segments as suitable for replacing with an arc if the points are all 1366regularly spaced on the candidate arc. The ``pointSpacingAngleTolerance`` parameter specifies the maximum 1367angular deviation (in radians) allowed when testing for regular point spacing. 1368 1369.. note:: 1370 1371 The API is considered EXPERIMENTAL and can be changed without a notice 1372 1373.. versionadded:: 3.14 1374%End 1375 1376 QgsGeometry centroid() const; 1377%Docstring 1378Returns the center of mass of a geometry. 1379 1380If the input is a NULL geometry, the output will also be a NULL geometry. 1381 1382If an error was encountered while creating the result, more information can be retrieved 1383by calling :py:func:`~QgsGeometry.lastError` on the returned geometry. 1384 1385.. note:: 1386 1387 for line based geometries, the center point of the line is returned, 1388 and for point based geometries, the point itself is returned 1389 1390.. seealso:: :py:func:`pointOnSurface` 1391 1392.. seealso:: :py:func:`poleOfInaccessibility` 1393%End 1394 1395 QgsGeometry pointOnSurface() const; 1396%Docstring 1397Returns a point guaranteed to lie on the surface of a geometry. While the :py:func:`~QgsGeometry.centroid` 1398of a geometry may be located outside of the geometry itself (e.g., for concave shapes), 1399the point on surface will always be inside the geometry. 1400 1401If the input is a NULL geometry, the output will also be a NULL geometry. 1402 1403If an error was encountered while creating the result, more information can be retrieved 1404by calling :py:func:`~QgsGeometry.lastError` on the returned geometry. 1405 1406.. seealso:: :py:func:`centroid` 1407 1408.. seealso:: :py:func:`poleOfInaccessibility` 1409%End 1410 1411 QgsGeometry poleOfInaccessibility( double precision, double *distanceToBoundary /Out/ = 0 ) const; 1412%Docstring 1413Calculates the approximate pole of inaccessibility for a surface, which is the 1414most distant internal point from the boundary of the surface. This function 1415uses the 'polylabel' algorithm (Vladimir Agafonkin, 2016), which is an iterative 1416approach guaranteed to find the true pole of inaccessibility within a specified 1417tolerance. More precise tolerances require more iterations and will take longer 1418to calculate. 1419Optionally, the distance to the polygon boundary from the pole can be stored. 1420 1421.. seealso:: :py:func:`centroid` 1422 1423.. seealso:: :py:func:`pointOnSurface` 1424 1425.. versionadded:: 3.0 1426%End 1427 1428 QgsGeometry largestEmptyCircle( double tolerance, const QgsGeometry &boundary = QgsGeometry() ) const throw( QgsNotSupportedException ); 1429%Docstring 1430Constructs the Largest Empty Circle for a set of obstacle geometries, up to a 1431specified tolerance. 1432 1433The Largest Empty Circle is the largest circle which has its center in the convex hull of the 1434obstacles (the boundary), and whose interior does not intersect with any obstacle. 1435The circle center is the point in the interior of the boundary which has the farthest distance from 1436the obstacles (up to tolerance). The circle is determined by the center point and a point lying on an 1437obstacle indicating the circle radius. 1438The implementation uses a successive-approximation technique over a grid of square cells covering the obstacles and boundary. 1439The grid is refined using a branch-and-bound algorithm. Point containment and distance are computed in a performant 1440way by using spatial indexes. 1441Returns a two-point linestring, with one point at the center of the inscribed circle and the other 1442on the boundary of the inscribed circle. 1443 1444This method requires QGIS builds based on GEOS 3.9 or later. 1445 1446.. warning:: 1447 1448 the ``tolerance`` value must be a value greater than 0, or the algorithm may never converge on a solution 1449 1450:raises QgsNotSupportedException: on QGIS builds based on GEOS 3.8 or earlier. 1451 1452 1453.. versionadded:: 3.20 1454%End 1455 1456 QgsGeometry minimumWidth() const throw( QgsNotSupportedException ); 1457%Docstring 1458Returns a linestring geometry which represents the minimum diameter of the geometry. 1459 1460The minimum diameter is defined to be the width of the smallest band that 1461contains the geometry, where a band is a strip of the plane defined 1462by two parallel lines. This can be thought of as the smallest hole that the geometry 1463can be moved through, with a single rotation. 1464 1465This method requires a QGIS build based on GEOS 3.6 or later. 1466 1467:raises QgsNotSupportedException: on QGIS builds based on GEOS 3.5 or earlier. 1468 1469.. versionadded:: 3.20 1470%End 1471 1472 double minimumClearance() const throw( QgsNotSupportedException ); 1473%Docstring 1474Computes the minimum clearance of a geometry. 1475 1476The minimum clearance is the smallest amount by which 1477a vertex could be moved to produce an invalid polygon, a non-simple linestring, or a multipoint with 1478repeated points. If a geometry has a minimum clearance of 'eps', it can be said that: 1479 1480- No two distinct vertices in the geometry are separated by less than 'eps' 1481- No vertex is closer than 'eps' to a line segment of which it is not an endpoint. 1482 1483If the minimum clearance cannot be defined for a geometry (such as with a single point, or a multipoint 1484whose points are identical) a value of infinity will be returned. 1485 1486If an error occurs while calculating the clearance NaN will be returned. 1487 1488This method requires a QGIS build based on GEOS 3.6 or later. 1489 1490:raises QgsNotSupportedException: on QGIS builds based on GEOS 3.5 or earlier. 1491 1492.. versionadded:: 3.20 1493%End 1494 1495 QgsGeometry minimumClearanceLine() const throw( QgsNotSupportedException ); 1496%Docstring 1497Returns a LineString whose endpoints define the minimum clearance of a geometry. 1498 1499If the geometry has no minimum clearance, an empty LineString will be returned. 1500 1501This method requires a QGIS build based on GEOS 3.6 or later. 1502 1503:raises QgsNotSupportedException: on QGIS builds based on GEOS 3.5 or earlier. 1504 1505.. versionadded:: 3.20 1506%End 1507 1508 QgsGeometry convexHull() const; 1509%Docstring 1510Returns the smallest convex polygon that contains all the points in the geometry. 1511 1512If the input is a NULL geometry, the output will also be a NULL geometry. 1513 1514If an error was encountered while creating the result, more information can be retrieved 1515by calling :py:func:`~QgsGeometry.lastError` on the returned geometry. 1516%End 1517 1518 QgsGeometry voronoiDiagram( const QgsGeometry &extent = QgsGeometry(), double tolerance = 0.0, bool edgesOnly = false ) const; 1519%Docstring 1520Creates a Voronoi diagram for the nodes contained within the geometry. 1521 1522Returns the Voronoi polygons for the nodes contained within the geometry. 1523If ``extent`` is specified then it will be used as a clipping envelope for the diagram. 1524If no extent is set then the clipping envelope will be automatically calculated. 1525In either case the diagram will be clipped to the larger of the provided envelope 1526OR the envelope surrounding all input nodes. 1527The ``tolerance`` parameter specifies an optional snapping tolerance which can 1528be used to improve the robustness of the diagram calculation. 1529If ``edgesOnly`` is ``True`` than line string boundary geometries will be returned 1530instead of polygons. 1531An empty geometry will be returned if the diagram could not be calculated. 1532 1533.. versionadded:: 3.0 1534%End 1535 1536 QgsGeometry delaunayTriangulation( double tolerance = 0.0, bool edgesOnly = false ) const; 1537%Docstring 1538Returns the Delaunay triangulation for the vertices of the geometry. 1539The ``tolerance`` parameter specifies an optional snapping tolerance which can 1540be used to improve the robustness of the triangulation. 1541If ``edgesOnly`` is ``True`` than line string boundary geometries will be returned 1542instead of polygons. 1543An empty geometry will be returned if the diagram could not be calculated. 1544 1545.. versionadded:: 3.0 1546%End 1547 1548 QgsGeometry node() const; 1549%Docstring 1550Returns a (Multi)LineString representing the fully noded version of a collection of linestrings. 1551 1552The noding preserves all of the input nodes, and introduces the least possible number of new nodes. 1553The resulting linework is dissolved (duplicate lines are removed). 1554 1555The input geometry type should be a (Multi)LineString. 1556 1557.. versionadded:: 3.20 1558%End 1559 1560 QgsGeometry sharedPaths( const QgsGeometry &other ) const; 1561%Docstring 1562Find paths shared between the two given lineal geometries (this and ``other``). 1563 1564Returns a GeometryCollection having two elements: 1565 1566- first element is a MultiLineString containing shared paths 1567 having the same direction on both inputs 1568- second element is a MultiLineString containing shared paths 1569 having the opposite direction on the two inputs 1570 1571Returns a null geometry on exception. 1572 1573.. versionadded:: 3.20 1574%End 1575 1576 QgsGeometry subdivide( int maxNodes = 256 ) const; 1577%Docstring 1578Subdivides the geometry. The returned geometry will be a collection containing subdivided parts 1579from the original geometry, where no part has more then the specified maximum number of nodes (``maxNodes``). 1580 1581This is useful for dividing a complex geometry into less complex parts, which are better able to be spatially 1582indexed and faster to perform further operations such as intersects on. The returned geometry parts may 1583not be valid and may contain self-intersections. 1584 1585The minimum allowed value for ``maxNodes`` is 8. 1586 1587Curved geometries will be segmentized before subdivision. 1588 1589If the input is a NULL geometry, the output will also be a NULL geometry. 1590 1591If an error was encountered while creating the result, more information can be retrieved 1592by calling :py:func:`~QgsGeometry.lastError` on the returned geometry. 1593 1594.. versionadded:: 3.0 1595%End 1596 1597 QgsGeometry interpolate( double distance ) const; 1598%Docstring 1599Returns an interpolated point on the geometry at the specified ``distance``. 1600 1601If the original geometry is a polygon type, the boundary of the polygon 1602will be used during interpolation. If the original geometry is a point 1603type, a null geometry will be returned. 1604 1605If z or m values are present, the output z and m will be interpolated using 1606the existing vertices' z or m values. 1607 1608If the input is a NULL geometry, the output will also be a NULL geometry. 1609 1610.. seealso:: :py:func:`lineLocatePoint` 1611 1612.. versionadded:: 2.0 1613%End 1614 1615 double lineLocatePoint( const QgsGeometry &point ) const; 1616%Docstring 1617Returns a distance representing the location along this linestring of the closest point 1618on this linestring geometry to the specified point. Ie, the returned value indicates 1619how far along this linestring you need to traverse to get to the closest location 1620where this linestring comes to the specified point. 1621 1622:param point: point to seek proximity to 1623 1624:return: distance along line, or -1 on error 1625 1626.. note:: 1627 1628 only valid for linestring geometries 1629 1630.. seealso:: :py:func:`interpolate` 1631 1632.. versionadded:: 3.0 1633%End 1634 1635 double interpolateAngle( double distance ) const; 1636%Docstring 1637Returns the angle parallel to the linestring or polygon boundary at the specified distance 1638along the geometry. Angles are in radians, clockwise from north. 1639If the distance coincides precisely at a node then the average angle from the segment either side 1640of the node is returned. 1641 1642:param distance: distance along geometry 1643 1644.. seealso:: :py:func:`angleAtVertex` 1645 1646.. versionadded:: 3.0 1647%End 1648 1649 QgsGeometry intersection( const QgsGeometry &geometry ) const; 1650%Docstring 1651Returns a geometry representing the points shared by this geometry and other. 1652 1653If the input is a NULL geometry, the output will also be a NULL geometry. 1654 1655If an error was encountered while creating the result, more information can be retrieved 1656by calling :py:func:`~QgsGeometry.lastError` on the returned geometry. 1657%End 1658 1659 QgsGeometry clipped( const QgsRectangle &rectangle ); 1660%Docstring 1661Clips the geometry using the specified ``rectangle``. 1662 1663Performs a fast, non-robust intersection between the geometry and 1664a ``rectangle``. The returned geometry may be invalid. 1665 1666.. versionadded:: 3.0 1667%End 1668 1669 QgsGeometry combine( const QgsGeometry &geometry ) const; 1670%Docstring 1671Returns a geometry representing all the points in this geometry and other (a 1672union geometry operation). 1673 1674If the input is a NULL geometry, the output will also be a NULL geometry. 1675 1676If an error was encountered while creating the result, more information can be retrieved 1677by calling :py:func:`~QgsGeometry.lastError` on the returned geometry. 1678 1679.. note:: 1680 1681 this operation is not called union since its a reserved word in C++. 1682%End 1683 1684 QgsGeometry mergeLines() const; 1685%Docstring 1686Merges any connected lines in a LineString/MultiLineString geometry and 1687converts them to single line strings. 1688 1689:return: a LineString or MultiLineString geometry, with any connected lines 1690 joined. An empty geometry will be returned if the input geometry was not a 1691 MultiLineString geometry. 1692 1693.. versionadded:: 3.0 1694%End 1695 1696 QgsGeometry difference( const QgsGeometry &geometry ) const; 1697%Docstring 1698Returns a geometry representing the points making up this geometry that do not make up other. 1699 1700If the input is a NULL geometry, the output will also be a NULL geometry. 1701 1702If an error was encountered while creating the result, more information can be retrieved 1703by calling :py:func:`~QgsGeometry.lastError` on the returned geometry. 1704%End 1705 1706 QgsGeometry symDifference( const QgsGeometry &geometry ) const; 1707%Docstring 1708Returns a geometry representing the points making up this geometry that do not make up other. 1709 1710If the input is a NULL geometry, the output will also be a NULL geometry. 1711 1712If an error was encountered while creating the result, more information can be retrieved 1713by calling :py:func:`~QgsGeometry.lastError` on the returned geometry. 1714%End 1715 1716 QgsGeometry extrude( double x, double y ); 1717%Docstring 1718Returns an extruded version of this geometry. 1719%End 1720 1721 1722 SIP_PYOBJECT randomPointsInPolygon( int count, unsigned long seed = 0 ) const /TypeHint="QgsPolylineXY"/; 1723%Docstring 1724Returns a list of ``count`` random points generated inside a (multi)polygon geometry. 1725 1726Optionally, a specific random ``seed`` can be used when generating points. If ``seed`` 1727is 0, then a completely random sequence of points will be generated. 1728 1729This method works only with (multi)polygon geometry types. 1730 1731:raises TypeError: if the geometry is not a polygon type 1732 1733:raises ValueError: if the geometry is null 1734 1735.. versionadded:: 3.10 1736%End 1737%MethodCode 1738 const QgsWkbTypes::GeometryType type = sipCpp->type(); 1739 if ( sipCpp->isNull() ) 1740 { 1741 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Cannot generate points inside a null geometry." ).toUtf8().constData() ); 1742 sipIsErr = 1; 1743 } 1744 else if ( type != QgsWkbTypes::PolygonGeometry ) 1745 { 1746 PyErr_SetString( PyExc_TypeError, QStringLiteral( "Cannot generate points inside a %1 geometry. Only Polygon types are permitted." ).arg( QgsWkbTypes::displayString( sipCpp->wkbType() ) ).toUtf8().constData() ); 1747 sipIsErr = 1; 1748 } 1749 else 1750 { 1751 const sipTypeDef *qvector_type = sipFindType( "QVector<QgsPointXY>" ); 1752 sipRes = sipConvertFromNewType( new QVector< QgsPointXY >( sipCpp->randomPointsInPolygon( a0, a1 ) ), qvector_type, Py_None ); 1753 } 1754%End 1755 1756 1757 1758 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const; 1759%Docstring 1760Returns the length of the QByteArray returned by :py:func:`~QgsGeometry.asWkb` 1761 1762The optional ``flags`` argument specifies flags controlling WKB export behavior 1763 1764.. versionadded:: 3.16 1765%End 1766 1767 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const; 1768%Docstring 1769Export the geometry to WKB 1770 1771The optional ``flags`` argument specifies flags controlling WKB export behavior (since QGIS 3.14). 1772 1773.. versionadded:: 3.0 1774%End 1775 1776 QString asWkt( int precision = 17 ) const; 1777%Docstring 1778Exports the geometry to WKT 1779 1780:return: ``True`` in case of success and ``False`` else 1781 1782.. note:: 1783 1784 precision parameter added in QGIS 2.4 1785%End 1786 1787 SIP_PYOBJECT __repr__(); 1788%MethodCode 1789 QString str; 1790 if ( sipCpp->isNull() ) 1791 str = QStringLiteral( "<QgsGeometry: null>" ); 1792 else 1793 { 1794 QString wkt = sipCpp->asWkt(); 1795 if ( wkt.length() > 1000 ) 1796 wkt = wkt.left( 1000 ) + QStringLiteral( "..." ); 1797 str = QStringLiteral( "<QgsGeometry: %1>" ).arg( wkt ); 1798 } 1799 sipRes = PyUnicode_FromString( str.toUtf8().constData() ); 1800%End 1801 1802 QString asJson( int precision = 17 ) const; 1803%Docstring 1804Exports the geometry to a GeoJSON string. 1805%End 1806 1807 1808 QVector< QgsGeometry > coerceToType( QgsWkbTypes::Type type ) const; 1809%Docstring 1810Attempts to coerce this geometry into the specified destination ``type``. 1811 1812This method will do anything possible to force the current geometry into the specified type. E.g. 1813 1814- lines or polygons will be converted to points by return either a single multipoint geometry or multiple 1815 single point geometries. 1816- polygons will be converted to lines by extracting their exterior and interior rings, returning 1817 either a multilinestring or multiple single line strings as dictated by ``type``. 1818- lines will be converted to polygon rings if ``type`` is a polygon type 1819- curved geometries will be segmented if ``type`` is non-curved. 1820- multi geometries will be converted to a list of single geometries 1821- single geometries will be upgraded to multi geometries 1822- z or m values will be added or dropped as required. 1823 1824.. note:: 1825 1826 This method is much stricter than :py:func:`~QgsGeometry.convertToType`, as it considers the exact WKB type 1827 of geometries instead of the geometry family (point/line/polygon), and tries more exhaustively 1828 to coerce geometries to the desired ``type``. It also correctly maintains curves and z/m values 1829 wherever appropriate. 1830 1831.. versionadded:: 3.14 1832%End 1833 1834 QgsGeometry convertToType( QgsWkbTypes::GeometryType destType, bool destMultipart = false ) const; 1835%Docstring 1836Try to convert the geometry to the requested type 1837 1838:param destType: the geometry type to be converted to 1839:param destMultipart: determines if the output geometry will be multipart or not 1840 1841:return: the converted geometry or ``None`` if the conversion fails. 1842 1843.. note:: 1844 1845 The :py:func:`~QgsGeometry.coerceToType` method applies much stricter and more exhaustive attempts to convert 1846 between geometry types, and is recommended instead of this method. This method force drops 1847 curves and any z or m values present in the geometry. 1848 1849.. versionadded:: 2.2 1850%End 1851 1852 1853 1854 SIP_PYOBJECT asPoint() const /TypeHint="QgsPointXY"/; 1855%Docstring 1856Returns the contents of the geometry as a 2-dimensional point. 1857 1858Any z or m values present in the geometry will be discarded. 1859 1860This method works only with single-point geometry types. 1861 1862:raises TypeError: if the geometry is not a single-point type 1863 1864:raises ValueError: if the geometry is null 1865%End 1866%MethodCode 1867 const QgsWkbTypes::Type type = sipCpp->wkbType(); 1868 if ( sipCpp->isNull() ) 1869 { 1870 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a point." ).toUtf8().constData() ); 1871 sipIsErr = 1; 1872 } 1873 else if ( QgsWkbTypes::flatType( type ) != QgsWkbTypes::Point ) 1874 { 1875 PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a point. Only Point types are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() ); 1876 sipIsErr = 1; 1877 } 1878 else 1879 { 1880 sipRes = sipConvertFromNewType( new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None ); 1881 } 1882%End 1883 1884 1885 SIP_PYOBJECT asPolyline() const /TypeHint="QgsPolylineXY"/; 1886%Docstring 1887Returns the contents of the geometry as a polyline. 1888 1889Any z or m values present in the geometry will be discarded. If the geometry is a curved line type 1890(such as a CircularString), it will be automatically segmentized. 1891 1892This method works only with single-line (or single-curve). 1893 1894:raises TypeError: if the geometry is not a single-line type 1895 1896:raises ValueError: if the geometry is null 1897%End 1898%MethodCode 1899 const QgsWkbTypes::Type type = sipCpp->wkbType(); 1900 if ( sipCpp->isNull() ) 1901 { 1902 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a polyline." ).toUtf8().constData() ); 1903 sipIsErr = 1; 1904 } 1905 else if ( QgsWkbTypes::geometryType( type ) != QgsWkbTypes::LineGeometry || QgsWkbTypes::isMultiType( type ) ) 1906 { 1907 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() ); 1908 sipIsErr = 1; 1909 } 1910 else 1911 { 1912 const sipTypeDef *qvector_type = sipFindType( "QVector< QgsPointXY >" ); 1913 sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None ); 1914 } 1915%End 1916 1917 1918 SIP_PYOBJECT asPolygon() const /TypeHint="QgsPolygonXY"/; 1919%Docstring 1920Returns the contents of the geometry as a polygon. 1921 1922Any z or m values present in the geometry will be discarded. If the geometry is a curved polygon type 1923(such as a CurvePolygon), it will be automatically segmentized. 1924 1925This method works only with single-polygon (or single-curve polygon) geometry types. 1926 1927:raises TypeError: if the geometry is not a single-polygon type 1928 1929:raises ValueError: if the geometry is null 1930%End 1931%MethodCode 1932 const QgsWkbTypes::Type type = sipCpp->wkbType(); 1933 if ( sipCpp->isNull() ) 1934 { 1935 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a polygon." ).toUtf8().constData() ); 1936 sipIsErr = 1; 1937 } 1938 else if ( QgsWkbTypes::geometryType( type ) != QgsWkbTypes::PolygonGeometry || QgsWkbTypes::isMultiType( type ) ) 1939 { 1940 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() ); 1941 sipIsErr = 1; 1942 } 1943 else 1944 { 1945 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QgsPointXY>>" ); 1946 sipRes = sipConvertFromNewType( new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None ); 1947 } 1948%End 1949 1950 1951 SIP_PYOBJECT asMultiPoint() const /TypeHint="QgsMultiPointXY"/; 1952%Docstring 1953Returns the contents of the geometry as a multi-point. 1954 1955Any z or m values present in the geometry will be discarded. 1956 1957This method works only with multi-point geometry types. 1958 1959:raises TypeError: if the geometry is not a multi-point type 1960 1961:raises ValueError: if the geometry is null 1962%End 1963%MethodCode 1964 const QgsWkbTypes::Type type = sipCpp->wkbType(); 1965 if ( sipCpp->isNull() ) 1966 { 1967 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a multipoint." ).toUtf8().constData() ); 1968 sipIsErr = 1; 1969 } 1970 else if ( QgsWkbTypes::geometryType( type ) != QgsWkbTypes::PointGeometry || !QgsWkbTypes::isMultiType( type ) ) 1971 { 1972 PyErr_SetString( PyExc_TypeError, QStringLiteral( "%1 geometry cannot be converted to a multipoint. Only multipoint types are permitted." ).arg( QgsWkbTypes::displayString( type ) ).toUtf8().constData() ); 1973 sipIsErr = 1; 1974 } 1975 else 1976 { 1977 const sipTypeDef *qvector_type = sipFindType( "QVector< QgsPointXY >" ); 1978 sipRes = sipConvertFromNewType( new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None ); 1979 } 1980%End 1981 1982 1983 SIP_PYOBJECT asMultiPolyline() const /TypeHint="QgsMultiPolylineXY"/; 1984%Docstring 1985Returns the contents of the geometry as a multi-linestring. 1986 1987Any z or m values present in the geometry will be discarded. If the geometry is a curved line type 1988(such as a MultiCurve), it will be automatically segmentized. 1989 1990This method works only with multi-linestring (or multi-curve) geometry types. 1991 1992:raises TypeError: if the geometry is not a multi-linestring type 1993 1994:raises ValueError: if the geometry is null 1995%End 1996%MethodCode 1997 const QgsWkbTypes::Type type = sipCpp->wkbType(); 1998 if ( sipCpp->isNull() ) 1999 { 2000 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a multilinestring." ).toUtf8().constData() ); 2001 sipIsErr = 1; 2002 } 2003 else if ( QgsWkbTypes::geometryType( type ) != QgsWkbTypes::LineGeometry || !QgsWkbTypes::isMultiType( type ) ) 2004 { 2005 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() ); 2006 sipIsErr = 1; 2007 } 2008 else 2009 { 2010 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QgsPointXY>>" ); 2011 sipRes = sipConvertFromNewType( new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None ); 2012 } 2013%End 2014 2015 2016 SIP_PYOBJECT asMultiPolygon() const /TypeHint="QgsMultiPolygonXY"/; 2017%Docstring 2018Returns the contents of the geometry as a multi-polygon. 2019 2020Any z or m values present in the geometry will be discarded. If the geometry is a curved polygon type 2021(such as a MultiSurface), it will be automatically segmentized. 2022 2023This method works only with multi-polygon (or multi-curve polygon) geometry types. 2024 2025:raises TypeError: if the geometry is not a multi-polygon type 2026 2027:raises ValueError: if the geometry is null 2028%End 2029%MethodCode 2030 const QgsWkbTypes::Type type = sipCpp->wkbType(); 2031 if ( sipCpp->isNull() ) 2032 { 2033 PyErr_SetString( PyExc_ValueError, QStringLiteral( "Null geometry cannot be converted to a multipolygon." ).toUtf8().constData() ); 2034 sipIsErr = 1; 2035 } 2036 else if ( QgsWkbTypes::geometryType( type ) != QgsWkbTypes::PolygonGeometry || !QgsWkbTypes::isMultiType( type ) ) 2037 { 2038 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() ); 2039 sipIsErr = 1; 2040 } 2041 else 2042 { 2043 const sipTypeDef *qvector_type = sipFindType( "QVector<QVector<QVector<QgsPointXY>>>" ); 2044 sipRes = sipConvertFromNewType( new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None ); 2045 } 2046%End 2047 2048 QVector<QgsGeometry> asGeometryCollection() const; 2049%Docstring 2050Returns contents of the geometry as a list of geometries 2051 2052.. versionadded:: 1.1 2053%End 2054 2055 QPointF asQPointF() const /HoldGIL/; 2056%Docstring 2057Returns contents of the geometry as a QPointF if wkbType is WKBPoint, 2058otherwise returns a null QPointF. 2059 2060.. versionadded:: 2.7 2061%End 2062 2063 QPolygonF asQPolygonF() const /HoldGIL/; 2064%Docstring 2065Returns contents of the geometry as a QPolygonF. 2066 2067If geometry is a linestring, then the result will be an open QPolygonF. 2068If the geometry is a polygon, then the result will be a closed QPolygonF 2069of the geometry's exterior ring. 2070 2071If the geometry is a multi-part geometry, then only the first part will 2072be considered when converting to a QPolygonF. 2073 2074.. versionadded:: 2.7 2075%End 2076 2077 bool deleteRing( int ringNum, int partNum = 0 ); 2078%Docstring 2079Deletes a ring in polygon or multipolygon. 2080Ring 0 is outer ring and can't be deleted. 2081 2082:return: ``True`` on success 2083 2084.. versionadded:: 1.2 2085%End 2086 2087 bool deletePart( int partNum ); 2088%Docstring 2089Deletes part identified by the part number 2090 2091:return: ``True`` on success 2092 2093.. versionadded:: 1.2 2094%End 2095 2096 bool convertToMultiType(); 2097%Docstring 2098Converts single type geometry into multitype geometry 2099e.g. a polygon into a multipolygon geometry with one polygon 2100If it is already a multipart geometry, it will return ``True`` and 2101not change the geometry. 2102 2103:return: ``True`` in case of success and ``False`` else 2104%End 2105 2106 bool convertToSingleType(); 2107%Docstring 2108Converts multi type geometry into single type geometry 2109e.g. a multipolygon into a polygon geometry. Only the first part of the 2110multi geometry will be retained. 2111If it is already a single part geometry, it will return ``True`` and 2112not change the geometry. 2113 2114:return: ``True`` in case of success and ``False`` else 2115%End 2116 2117 bool convertGeometryCollectionToSubclass( QgsWkbTypes::GeometryType geomType ); 2118%Docstring 2119Converts geometry collection to a the desired geometry type subclass (multi-point, 2120multi-linestring or multi-polygon). Child geometries of different type are filtered out. 2121Does nothing the geometry is not a geometry collection. May leave the geometry 2122empty if none of the child geometries match the desired type. 2123 2124:return: ``True`` in case of success and ``False`` else 2125 2126.. versionadded:: 3.2 2127%End 2128 2129 int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers ); 2130 2131%Docstring 2132Modifies geometry to avoid intersections with the layers specified in project properties 2133 2134:param avoidIntersectionsLayers: list of layers to check for intersections 2135 2136:return: 0 in case of success, 2137 1 if geometry is not of polygon type, 2138 2 if avoid intersection would change the geometry type, 2139 3 at least one geometry intersected is invalid. The algorithm may not work and return the same geometry as the input. You must fix your intersecting geometries. 2140 2141.. versionadded:: 1.5 2142%End 2143 2144 QgsGeometry makeValid() const; 2145%Docstring 2146Attempts to make an invalid geometry valid without losing vertices. 2147 2148Already-valid geometries are returned without further intervention. 2149In case of full or partial dimensional collapses, the output geometry may be a collection 2150of lower-to-equal dimension geometries or a geometry of lower dimension. 2151Single polygons may become multi-geometries in case of self-intersections. 2152It preserves Z values, but M values will be dropped. 2153 2154If an error was encountered during the process, more information can be retrieved 2155by calling :py:func:`~QgsGeometry.lastError` on the returned geometry. 2156 2157:return: new valid QgsGeometry or null geometry on error 2158 2159.. note:: 2160 2161 For QGIS builds using GEOS library versions older than 3.8 this method calls 2162 an internal fork of PostGIS' ST_MakeValid() function. For builds based on GEOS 3.8 or 2163 later this method calls the GEOS MakeValid method directly. 2164 2165 2166.. versionadded:: 3.0 2167%End 2168 2169 QgsGeometry forceRHR() const; 2170%Docstring 2171Forces geometries to respect the Right-Hand-Rule, in which the area that is bounded by a polygon 2172is to the right of the boundary. In particular, the exterior ring is oriented in a clockwise direction 2173and the interior rings in a counter-clockwise direction. 2174 2175.. versionadded:: 3.6 2176%End 2177 2178 class Error 2179{ 2180%Docstring(signature="appended") 2181A geometry error. 2182%End 2183 2184%TypeHeaderCode 2185#include "qgsgeometry.h" 2186%End 2187 public: 2188 Error(); 2189 2190 explicit Error( const QString &m ); 2191 2192 Error( const QString &m, const QgsPointXY &p ); 2193 QString what() const; 2194%Docstring 2195A human readable error message containing details about the error. 2196%End 2197 2198 QgsPointXY where() const; 2199%Docstring 2200The coordinates at which the error is located and should be visualized. 2201%End 2202 2203 bool hasWhere() const; 2204%Docstring 2205``True`` if the location available from :py:func:`where` is valid. 2206%End 2207 2208 SIP_PYOBJECT __repr__(); 2209%MethodCode 2210 QString str = QStringLiteral( "<QgsGeometry.Error: %1>" ).arg( sipCpp->what() ); 2211 sipRes = PyUnicode_FromString( str.toUtf8().data() ); 2212%End 2213 2214 bool operator==( const QgsGeometry::Error &other ) const; 2215 2216 }; 2217 2218 void validateGeometry( QVector<QgsGeometry::Error> &errors /Out/, Qgis::GeometryValidationEngine method = Qgis::GeometryValidationEngine::QgisInternal, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const; 2219%Docstring 2220Validates geometry and produces a list of geometry errors. 2221The ``method`` argument dictates which validator to utilize. 2222 2223The ``flags`` parameter indicates optional flags which control the type of validity checking performed. 2224 2225.. versionadded:: 1.5 2226%End 2227 2228 void normalize(); 2229%Docstring 2230Reorganizes the geometry into a normalized form (or "canonical" form). 2231 2232Polygon rings will be rearranged so that their starting vertex is the lower left and ring orientation follows the 2233right hand rule, collections are ordered by geometry type, and other normalization techniques are applied. The 2234resultant geometry will be geometrically equivalent to the original geometry. 2235 2236.. versionadded:: 3.20 2237%End 2238 2239 static QgsGeometry unaryUnion( const QVector<QgsGeometry> &geometries ); 2240%Docstring 2241Compute the unary union on a list of ``geometries``. May be faster than an iterative union on a set of geometries. 2242The returned geometry will be fully noded, i.e. a node will be created at every common intersection of the 2243input geometries. An empty geometry will be returned in the case of errors. 2244%End 2245 2246 static QgsGeometry polygonize( const QVector<QgsGeometry> &geometries ); 2247%Docstring 2248Creates a GeometryCollection geometry containing possible polygons formed from the constituent 2249linework of a set of ``geometries``. The input geometries must be fully noded (i.e. nodes exist 2250at every common intersection of the geometries). The easiest way to ensure this is to first 2251call :py:func:`~QgsGeometry.unaryUnion` on the set of input geometries and then pass the result to :py:func:`~QgsGeometry.polygonize`. 2252An empty geometry will be returned in the case of errors. 2253 2254.. versionadded:: 3.0 2255%End 2256 2257 void convertToStraightSegment( double tolerance = M_PI / 180., QgsAbstractGeometry::SegmentationToleranceType toleranceType = QgsAbstractGeometry::MaximumAngle ); 2258%Docstring 2259Converts the geometry to straight line segments, if it is a curved geometry type. 2260 2261:param tolerance: segmentation tolerance 2262:param toleranceType: maximum segmentation angle or maximum difference between approximation and curve 2263 2264.. seealso:: :py:func:`requiresConversionToStraightSegments` 2265 2266.. versionadded:: 2.10 2267%End 2268 2269 bool requiresConversionToStraightSegments() const; 2270%Docstring 2271Returns ``True`` if the geometry is a curved geometry type which requires conversion to 2272display as straight line segments. 2273 2274.. seealso:: :py:func:`convertToStraightSegment` 2275 2276.. versionadded:: 2.10 2277%End 2278 2279 void mapToPixel( const QgsMapToPixel &mtp ); 2280%Docstring 2281Transforms the geometry from map units to pixels in place. 2282 2283:param mtp: map to pixel transform 2284 2285.. versionadded:: 2.10 2286%End 2287 2288 void draw( QPainter &p ) const; 2289%Docstring 2290Draws the geometry onto a QPainter 2291 2292:param p: destination QPainter 2293 2294.. versionadded:: 2.10 2295%End 2296 2297 bool vertexIdFromVertexNr( int number, QgsVertexId &id /Out/ ) const; 2298%Docstring 2299Calculates the vertex ID from a vertex ``number``. 2300 2301If a matching vertex was found, it will be stored in ``id``. 2302 2303Returns ``True`` if vertex was found. 2304 2305.. seealso:: :py:func:`vertexNrFromVertexId` 2306 2307.. versionadded:: 2.10 2308%End 2309 2310 int vertexNrFromVertexId( QgsVertexId id ) const; 2311%Docstring 2312Returns the vertex number corresponding to a vertex ``id``. 2313 2314The vertex numbers start at 0, so a return value of 0 corresponds 2315to the first vertex. 2316 2317Returns -1 if a corresponding vertex could not be found. 2318 2319.. seealso:: :py:func:`vertexIdFromVertexNr` 2320 2321.. versionadded:: 2.10 2322%End 2323 2324 QString lastError() const /HoldGIL/; 2325%Docstring 2326Returns an error string referring to the last error encountered 2327either when this geometry was created or when an operation 2328was performed on the geometry. 2329 2330.. versionadded:: 3.0 2331%End 2332 2333 2334 2335 static QgsGeometry fromQPointF( QPointF point ) /HoldGIL/; 2336%Docstring 2337Construct geometry from a QPointF 2338 2339:param point: source QPointF 2340 2341.. versionadded:: 2.7 2342%End 2343 2344 static QgsGeometry fromQPolygonF( const QPolygonF &polygon ); 2345%Docstring 2346Construct geometry from a QPolygonF. If the polygon is closed than 2347the resultant geometry will be a polygon, if it is open than the 2348geometry will be a polyline. 2349 2350:param polygon: source QPolygonF 2351 2352.. versionadded:: 2.7 2353%End 2354 2355 static QgsPolylineXY createPolylineFromQPolygonF( const QPolygonF &polygon ) /Deprecated/; 2356%Docstring 2357Creates a :py:class:`QgsPolylineXY` from a QPolygonF. 2358 2359:param polygon: source polygon 2360 2361:return: :py:class:`QgsPolylineXY` 2362 2363.. seealso:: :py:func:`createPolygonFromQPolygonF` 2364 2365.. deprecated:: 2366 use :py:func:`QgsGeometry.fromQPolygonF()` or :py:func:`QgsLineString.fromQPolygonF()` instead. 2367%End 2368 2369 static QgsPolygonXY createPolygonFromQPolygonF( const QPolygonF &polygon ) /Deprecated/; 2370%Docstring 2371Creates a :py:class:`QgsPolygonXYfrom` a QPolygonF. 2372 2373:param polygon: source polygon 2374 2375:return: :py:class:`QgsPolygon` 2376 2377.. seealso:: :py:func:`createPolylineFromQPolygonF` 2378 2379.. deprecated:: 2380 use :py:func:`QgsGeometry.fromQPolygonF()` or :py:func:`QgsLineString.fromQPolygonF()` instead. 2381%End 2382 2383 2384 static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * DBL_EPSILON ); 2385%Docstring 2386Compares two geometry objects for equality within a specified tolerance. 2387The objects can be of type :py:class:`QgsPolylineXY`, :py:class:`QgsPolygonXYor` :py:class:`QgsMultiPolygon`. 2388The 2 types should match. 2389 2390:param p1: first geometry object 2391:param p2: second geometry object 2392:param epsilon: maximum difference for coordinates between the objects 2393 2394:return: ``True`` if objects are 2395 2396 - polylines and have the same number of points and all 2397 points are equal within the specified tolerance 2398 - polygons and have the same number of points and all 2399 points are equal within the specified tolerance 2400 - multipolygons and have the same number of polygons, the polygons have the same number 2401 of rings, and each ring has the same number of points and all points are equal 2402 within the specified tolerance 2403 2404.. versionadded:: 2.9 2405%End 2406%MethodCode 2407 { 2408 sipRes = false; 2409 int state0; 2410 int state1; 2411 int sipIsErr = 0; 2412 2413 if ( PyList_Check( a0 ) && PyList_Check( a1 ) && 2414 PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) ) 2415 { 2416 PyObject *o0 = PyList_GetItem( a0, 0 ); 2417 PyObject *o1 = PyList_GetItem( a1, 0 ); 2418 if ( o0 && o1 ) 2419 { 2420 // compare polyline - polyline 2421 if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) && 2422 sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) && 2423 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) && 2424 sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) ) 2425 { 2426 QgsPolylineXY *p0; 2427 QgsPolylineXY *p1; 2428 p0 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) ); 2429 p1 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) ); 2430 if ( sipIsErr ) 2431 { 2432 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 ); 2433 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 ); 2434 } 2435 else 2436 { 2437 sipRes = QgsGeometry::compare( *p0, *p1, a2 ); 2438 } 2439 } 2440 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) && 2441 PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) ) 2442 { 2443 PyObject *oo0 = PyList_GetItem( o0, 0 ); 2444 PyObject *oo1 = PyList_GetItem( o1, 0 ); 2445 if ( oo0 && oo1 ) 2446 { 2447 // compare polygon - polygon 2448 if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) && 2449 sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) && 2450 sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) && 2451 sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) ) 2452 { 2453 QgsPolygonXY *p0; 2454 QgsPolygonXY *p1; 2455 p0 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) ); 2456 p1 = reinterpret_cast<QgsPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) ); 2457 if ( sipIsErr ) 2458 { 2459 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 ); 2460 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 ); 2461 } 2462 else 2463 { 2464 sipRes = QgsGeometry::compare( *p0, *p1, a2 ); 2465 } 2466 } 2467 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) && 2468 PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) ) 2469 { 2470 PyObject *ooo0 = PyList_GetItem( oo0, 0 ); 2471 PyObject *ooo1 = PyList_GetItem( oo1, 0 ); 2472 if ( ooo0 && ooo1 ) 2473 { 2474 // compare multipolygon - multipolygon 2475 if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) && 2476 sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) && 2477 sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) && 2478 sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) ) 2479 { 2480 QgsMultiPolygonXY *p0; 2481 QgsMultiPolygonXY *p1; 2482 p0 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) ); 2483 p1 = reinterpret_cast<QgsMultiPolygonXY *>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) ); 2484 if ( sipIsErr ) 2485 { 2486 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 ); 2487 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 ); 2488 } 2489 else 2490 { 2491 sipRes = QgsGeometry::compare( *p0, *p1, a2 ); 2492 } 2493 } 2494 } 2495 } 2496 } 2497 } 2498 } 2499 } 2500 } 2501%End 2502 2503 QgsGeometry smooth( unsigned int iterations = 1, double offset = 0.25, 2504 double minimumDistance = -1.0, double maxAngle = 180.0 ) const; 2505%Docstring 2506Smooths a geometry by rounding off corners using the Chaikin algorithm. This operation 2507roughly doubles the number of vertices in a geometry. 2508 2509If input geometries contain Z or M values, these will also be smoothed and the output 2510geometry will retain the same dimensionality as the input geometry. 2511 2512:param iterations: number of smoothing iterations to run. More iterations results 2513 in a smoother geometry 2514:param offset: fraction of line to create new vertices along, between 0 and 1.0, 2515 e.g., the default value of 0.25 will create new vertices 25% and 75% along each line segment 2516 of the geometry for each iteration. Smaller values result in "tighter" smoothing. 2517:param minimumDistance: minimum segment length to apply smoothing to 2518:param maxAngle: maximum angle at node (0-180) at which smoothing will be applied 2519 2520.. versionadded:: 2.9 2521%End 2522 2523 static QgsGeometryEngine *createGeometryEngine( const QgsAbstractGeometry *geometry ) /Factory/; 2524%Docstring 2525Creates and returns a new geometry engine representing the specified ``geometry``. 2526 2527A geometry engine is a low-level representation of a :py:class:`QgsAbstractGeometry` object, optimised for use with external 2528geometry libraries such as GEOS. 2529 2530:py:class:`QgsGeometryEngine` objects provide a mechanism for optimized evaluation of geometric algorithms, including spatial relationships 2531between geometries and operations such as buffers or clipping. :py:class:`QgsGeometryEngine` is recommended for use in any 2532performance critical code instead of directly using the equivalent QgsGeometry methods such as :py:func:`QgsGeometry.intersects()`. 2533 2534Many methods available in the :py:class:`QgsGeometryEngine` class can benefit from pre-preparing geometries. For instance, whenever 2535a large number of spatial relationships will be tested (such as calling :py:func:`~QgsGeometry.intersects`, :py:func:`~QgsGeometry.within`, etc) then the 2536geometry should first be prepared by calling :py:func:`~QgsGeometry.prepareGeometry` before performing the tests. 2537 2538Example 2539------- 2540 2541.. code-block:: python 2542 2543 # polygon_geometry contains a complex polygon, with many vertices 2544 polygon_geometry = QgsGeometry.fromWkt('Polygon((...))') 2545 2546 # create a QgsGeometryEngine representation of the polygon 2547 polygon_geometry_engine = QgsGeometry.createGeometryEngine(polygon_geometry.constGet()) 2548 2549 # since we'll be performing many intersects tests, we can speed up these tests considerably 2550 # by first "preparing" the geometry engine 2551 polygon_geometry_engine.prepareGeometry() 2552 2553 # now we are ready to quickly test intersection against many other objects 2554 for feature in my_layer.getFeatures(): 2555 feature_geometry = feature.geometry() 2556 # test whether the feature's geometry intersects our original complex polygon 2557 if polygon_geometry_engine.intersects(feature_geometry.constGet()): 2558 print('feature intersects the polygon!') 2559 2560:py:class:`QgsGeometryEngine` operations are backed by the GEOS library (https://trac.osgeo.org/geos/). 2561%End 2562 2563 static void convertPointList( const QVector<QgsPointXY> &input, QgsPointSequence &output ); 2564%Docstring 2565Upgrades a point list from :py:class:`QgsPointXY` to :py:class:`QgsPoint` 2566 2567:param input: list of :py:class:`QgsPointXY` objects to be upgraded 2568:param output: destination for list of points converted to :py:class:`QgsPoint` 2569%End 2570 2571 static void convertPointList( const QgsPointSequence &input, QVector<QgsPointXY> &output ); 2572%Docstring 2573Downgrades a point list from :py:class:`QgsPoint` to :py:class:`QgsPointXY` 2574 2575:param input: list of :py:class:`QgsPoint` objects to be downgraded 2576:param output: destination for list of points converted to :py:class:`QgsPointXY` 2577%End 2578 2579 operator QVariant() const; 2580 2581}; // class QgsGeometry 2582 2583 2584 2585/************************************************************************ 2586 * This file has been generated automatically from * 2587 * * 2588 * src/core/geometry/qgsgeometry.h * 2589 * * 2590 * Do not edit manually ! Edit header and run scripts/sipify.pl again * 2591 ************************************************************************/ 2592