QgsGeometryUtils Class Reference

Contains various geometry utility functions. More...

`#include <qgsgeometryutils.h>`

## Classes

struct  SelfIntersection

## Public Types

enum  ComponentType { Vertex, Ring, Part }

## Static Public Member Functions

static double angleBetweenThreePoints (double x1, double y1, double x2, double y2, double x3, double y3)
Calculates the angle between the lines AB and BC, where AB and BC described by points a, b and b, c. More...

static bool angleOnCircle (double angle, double angle1, double angle2, double angle3)
Returns true if an angle is between angle1 and angle3 on a circle described by angle1, angle2 and angle3. More...

static double averageAngle (double x1, double y1, double x2, double y2, double x3, double y3)
Calculates the average angle (in radians) between the two linear segments from (x1, y1) to (x2, y2) and (x2, y2) to (x3, y3). More...

static double averageAngle (double a1, double a2)
Averages two angles, correctly handling negative angles and ensuring the result is between 0 and 2 pi. More...

static double ccwAngle (double dy, double dx)
Returns the counter clockwise angle between a line with components dx, dy and the line with dx > 0 and dy = 0. More...

static bool circleAngleBetween (double angle, double angle1, double angle2, bool clockwise)
Returns true if, in a circle, angle is between angle1 and angle2. More...

static void circleCenterRadius (const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double &radius, double &centerX, double &centerY)
Returns radius and center of the circle through pt1, pt2, pt3. More...

static int circleCircleIntersections (QgsPointXY center1, double radius1, QgsPointXY center2, double radius2, QgsPointXY &intersection1, QgsPointXY &intersection2)
Calculates the intersections points between the circle with center center1 and radius radius1 and the circle with center center2 and radius radius2. More...

static int circleCircleOuterTangents (const QgsPointXY &center1, double radius1, const QgsPointXY &center2, double radius2, QgsPointXY &line1P1, QgsPointXY &line1P2, QgsPointXY &line2P1, QgsPointXY &line2P2)
Calculates the outer tangent points for two circles, centered at center1 and center2 and with radii of radius1 and radius2 respectively. More...

static bool circleClockwise (double angle1, double angle2, double angle3)
Returns true if the circle defined by three angles is ordered clockwise. More...

static double circleLength (double x1, double y1, double x2, double y2, double x3, double y3)
Length of a circular string segment defined by pt1, pt2, pt3. More...

static double circleTangentDirection (const QgsPoint &tangentPoint, const QgsPoint &cp1, const QgsPoint &cp2, const QgsPoint &cp3)
Calculates the direction angle of a circle tangent (clockwise from north in radians) More...

static QgsPoint closestPoint (const QgsAbstractGeometry &geometry, const QgsPoint &point)
Returns the nearest point on a segment of a geometry for the specified point. More...

template<class T >
static double closestSegmentFromComponents (T &container, ComponentType ctype, const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon)

static QgsPoint closestVertex (const QgsAbstractGeometry &geom, const QgsPoint &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point. More...

static void coefficients (const QgsPoint &pt1, const QgsPoint &pt2, double &a, double &b, double &c)
Returns the coefficients (a, b, c for equation "ax + by + c = 0") of a line defined by points pt1 and pt2. More...

static double distanceToVertex (const QgsAbstractGeometry &geom, QgsVertexId id)
Returns the distance along a geometry from its first vertex to the specified vertex. More...

static QVector< QgsLineString * > extractLineStrings (const QgsAbstractGeometry *geom)
Returns list of linestrings extracted from the passed geometry. More...

static double gradient (const QgsPoint &pt1, const QgsPoint &pt2)
Returns the gradient of a line defined by points pt1 and pt2. More...

static double interpolateArcValue (double angle, double a1, double a2, double a3, double zm1, double zm2, double zm3)
Interpolate a value at given angle on circular arc given values (zm1, zm2, zm3) at three different angles (a1, a2, a3). More...

static QgsPoint interpolatePointOnArc (const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double distance)
Interpolates a point on an arc defined by three points, pt1, pt2 and pt3. More...

static QgsPointXY interpolatePointOnLine (double x1, double y1, double x2, double y2, double fraction)
Interpolates the position of a point a fraction of the way along the line from (x1, y1) to (x2, y2). More...

static QgsPoint interpolatePointOnLine (const QgsPoint &p1, const QgsPoint &p2, double fraction)
Interpolates the position of a point a fraction of the way along the line from p1 to p2. More...

static QgsPointXY interpolatePointOnLineByValue (double x1, double y1, double v1, double x2, double y2, double v2, double value)
Interpolates the position of a point along the line from (x1, y1) to (x2, y2). More...

static int leftOfLine (double x, double y, double x1, double y1, double x2, double y2)
Returns a value < 0 if the point (x, y) is left of the line from (x1, y1) -> ( x2, y2). More...

static double lineAngle (double x1, double y1, double x2, double y2)
Calculates the direction of line joining two points in radians, clockwise from the north direction. More...

static bool lineCircleIntersection (const QgsPointXY &center, double radius, const QgsPointXY &linePoint1, const QgsPointXY &linePoint2, QgsPointXY &intersection)
Compute the intersection of a line and a circle. More...

static bool lineIntersection (const QgsPoint &p1, QgsVector v1, const QgsPoint &p2, QgsVector v2, QgsPoint &intersection)
Computes the intersection between two lines. More...

static double linePerpendicularAngle (double x1, double y1, double x2, double y2)
Calculates the perpendicular angle to a line joining two points. More...

static bool linesIntersection3D (const QgsVector3D &La1, const QgsVector3D &La2, const QgsVector3D &Lb1, const QgsVector3D &Lb2, QgsVector3D &intersection)
An algorithm to calculate an (approximate) intersection of two lines in 3D. More...

static QgsPoint midpoint (const QgsPoint &pt1, const QgsPoint &pt2)
Returns a middle point between points pt1 and pt2. More...

static double normalizedAngle (double angle)
Ensures that an angle is in the range 0 <= angle < 2 pi. More...

static QgsLineString perpendicularSegment (const QgsPoint &p, const QgsPoint &s1, const QgsPoint &s2)
Create a perpendicular line segment from p to segment [s1, s2]. More...

static QgsPoint pointOnLineWithDistance (const QgsPoint &startPoint, const QgsPoint &directionPoint, double distance)
Returns a point a specified distance toward a second point. More...

static void pointOnLineWithDistance (double x1, double y1, double x2, double y2, double distance, double &x, double &y, double *z1=nullptr, double *z2=nullptr, double *z=nullptr, double *m1=nullptr, double *m2=nullptr, double *m=nullptr)
Calculates the point a specified distance from (x1, y1) toward a second point (x2, y2). More...

static QgsPointSequence pointsFromWKT (const QString &wktCoordinateList, bool is3D, bool isMeasure)
Returns a list of points contained in a WKT string. More...

static QDomElement pointsToGML2 (const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY)
Returns a gml::coordinates DOM element. More...

static QDomElement pointsToGML3 (const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, bool is3D, QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY)
Returns a gml::posList DOM element. More...

static QString pointsToJSON (const QgsPointSequence &points, int precision)
Returns a geoJSON coordinates string. More...

static void pointsToWKB (QgsWkbPtr &wkb, const QgsPointSequence &points, bool is3D, bool isMeasure)
Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }. More...

static QString pointsToWKT (const QgsPointSequence &points, int precision, bool is3D, bool isMeasure)
Returns a WKT coordinate list. More...

static QgsPoint projectPointOnSegment (const QgsPoint &p, const QgsPoint &s1, const QgsPoint &s2)
Project the point on a segment. More...

static bool segmentIntersection (const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint, bool &isIntersection, double tolerance=1e-8, bool acceptImproperIntersection=false)
Compute the intersection between two segments. More...

static void segmentizeArc (const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, QgsPointSequence &points, double tolerance=M_PI_2/90, QgsAbstractGeometry::SegmentationToleranceType toleranceType=QgsAbstractGeometry::MaximumAngle, bool hasZ=false, bool hasM=false)
Convert circular arc defined by p1, p2, p3 (p1/p3 being start resp. More...

static bool segmentMidPoint (const QgsPoint &p1, const QgsPoint &p2, QgsPoint &result, double radius, const QgsPoint &mousePos)
Calculates midpoint on circle passing through p1 and p2, closest to the given coordinate mousePos. More...

static QgsPoint segmentMidPointFromCenter (const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &center, bool useShortestArc=true)
Calculates the midpoint on the circle passing through p1 and p2, with the specified center coordinate. More...

static int segmentSide (const QgsPoint &pt1, const QgsPoint &pt3, const QgsPoint &pt2)
For line defined by points pt1 and pt3, find out on which side of the line is point pt3. More...

static QVector< SelfIntersectionselfIntersections (const QgsAbstractGeometry *geom, int part, int ring, double tolerance)
Find self intersections in a polyline. More...

static bool setZValueFromPoints (const QgsPointSequence &points, QgsPoint &point)
A Z dimension is added to point if one of the point in the list points is in 3D. More...

static double skewLinesDistance (const QgsVector3D &P1, const QgsVector3D &P12, const QgsVector3D &P2, const QgsVector3D &P22)
An algorithm to calculate the shortest distance between two skew lines. More...

static bool skewLinesProjection (const QgsVector3D &P1, const QgsVector3D &P12, const QgsVector3D &P2, const QgsVector3D &P22, QgsVector3D &X1, double epsilon=0.0001)
A method to project one skew line onto another. More...

static double sqrDistance2D (const QgsPoint &pt1, const QgsPoint &pt2)
Returns the squared 2D distance between two points. More...

static double sqrDistToLine (double ptX, double ptY, double x1, double y1, double x2, double y2, double &minDistX, double &minDistY, double epsilon)
Returns the squared distance between a point and a line. More...

static double sweepAngle (double centerX, double centerY, double x1, double y1, double x2, double y2, double x3, double y3)
Calculates angle of a circular string part defined by pt1, pt2, pt3. More...

static bool tangentPointAndCircle (const QgsPointXY &center, double radius, const QgsPointXY &p, QgsPointXY &pt1, QgsPointXY &pt2)
Calculates the tangent points between the circle with the specified center and radius and the point p. More...

static bool verticesAtDistance (const QgsAbstractGeometry &geometry, double distance, QgsVertexId &previousVertex, QgsVertexId &nextVertex)
Retrieves the vertices which are before and after the interpolated point at a specified distance along a linestring (or polygon boundary). More...

static QStringList wktGetChildBlocks (const QString &wkt, const QString &defaultType=QString())
Parses a WKT string and returns of list of blocks contained in the WKT. More...

static QPair< QgsWkbTypes::Type, QString > wktReadBlock (const QString &wkt)
Parses a WKT block of the format "TYPE( contents )" and returns a pair of geometry type to contents ("Pair(wkbType, "contents")") More...

## Detailed Description

Contains various geometry utility functions.

Since
QGIS 2.10

Definition at line 36 of file qgsgeometryutils.h.

## Member Enumeration Documentation

Note
not available in Python bindings
Enumerator
Vertex
Ring
Part

Definition at line 638 of file qgsgeometryutils.h.

## Member Function Documentation

 double QgsGeometryUtils::angleBetweenThreePoints ( double x1, double y1, double x2, double y2, double x3, double y3 )
static

Calculates the angle between the lines AB and BC, where AB and BC described by points a, b and b, c.

Parameters
 x1 x-coordinate of point a y1 y-coordinate of point a x2 x-coordinate of point b y2 y-coordinate of point b x3 x-coordinate of point c y3 y-coordinate of point c
Returns
angle between lines in radians. Returned value is undefined if two or more points are equal.

Definition at line 1344 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::angleOnCircle ( double angle, double angle1, double angle2, double angle3 )
static

Returns true if an angle is between angle1 and angle3 on a circle described by angle1, angle2 and angle3.

Definition at line 694 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::averageAngle ( double x1, double y1, double x2, double y2, double x3, double y3 )
static

Calculates the average angle (in radians) between the two linear segments from (x1, y1) to (x2, y2) and (x2, y2) to (x3, y3).

Definition at line 1358 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::averageAngle ( double a1, double a2 )
static

Averages two angles, correctly handling negative angles and ensuring the result is between 0 and 2 pi.

Parameters
Returns

Definition at line 1366 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::ccwAngle ( double dy, double dx )
static

Returns the counter clockwise angle between a line with components dx, dy and the line with dx > 0 and dy = 0.

Definition at line 604 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::circleAngleBetween ( double angle, double angle1, double angle2, bool clockwise )
static

Returns true if, in a circle, angle is between angle1 and angle2.

Definition at line 668 of file qgsgeometryutils.cpp.

 void QgsGeometryUtils::circleCenterRadius ( const QgsPoint & pt1, const QgsPoint & pt2, const QgsPoint & pt3, double & radius, double & centerX, double & centerY )
static

Returns radius and center of the circle through pt1, pt2, pt3.

Definition at line 618 of file qgsgeometryutils.cpp.

 int QgsGeometryUtils::circleCircleIntersections ( QgsPointXY center1, double radius1, QgsPointXY center2, double radius2, QgsPointXY & intersection1, QgsPointXY & intersection2 )
static

If found, the intersection points will be stored in intersection1 and intersection2.

Returns
number of intersection points found.
Since
QGIS 3.2

Definition at line 371 of file qgsgeometryutils.cpp.

 int QgsGeometryUtils::circleCircleOuterTangents ( const QgsPointXY & center1, double radius1, const QgsPointXY & center2, double radius2, QgsPointXY & line1P1, QgsPointXY & line1P2, QgsPointXY & line2P1, QgsPointXY & line2P2 )
static

Calculates the outer tangent points for two circles, centered at center1 and center2 and with radii of radius1 and radius2 respectively.

The outer tangent points correspond to the points at which the two lines which are drawn so that they are tangential to both circles touch the circles.

The first tangent line is described by the points stored in line1P1 and line1P2, and the second line is described by the points stored in line2P1 and line2P2.

Returns the number of tangents (either 0 or 2).

Since
QGIS 3.2

Definition at line 459 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::circleClockwise ( double angle1, double angle2, double angle3 )
static

Returns true if the circle defined by three angles is ordered clockwise.

The angles are defined counter-clockwise from the origin, i.e. using Euclidean angles as opposed to geographic "North up" angles.

Definition at line 656 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::circleLength ( double x1, double y1, double x2, double y2, double x3, double y3 )
static

Length of a circular string segment defined by pt1, pt2, pt3.

Definition at line 700 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::circleTangentDirection ( const QgsPoint & tangentPoint, const QgsPoint & cp1, const QgsPoint & cp2, const QgsPoint & cp3 )
static

Calculates the direction angle of a circle tangent (clockwise from north in radians)

Definition at line 798 of file qgsgeometryutils.cpp.

 QgsPoint QgsGeometryUtils::closestPoint ( const QgsAbstractGeometry & geometry, const QgsPoint & point )
static

Returns the nearest point on a segment of a geometry for the specified point.

The z and m values will be linearly interpolated between the two neighbouring vertices.

Definition at line 97 of file qgsgeometryutils.cpp.

template<class T >
 static double QgsGeometryUtils::closestSegmentFromComponents ( T & container, ComponentType ctype, const QgsPoint & pt, QgsPoint & segmentPt, QgsVertexId & vertexAfter, int * leftOf, double epsilon )
inlinestatic
Note
not available in Python bindings

Definition at line 646 of file qgsgeometryutils.h.

 QgsPoint QgsGeometryUtils::closestVertex ( const QgsAbstractGeometry & geom, const QgsPoint & pt, QgsVertexId & id )
static

Returns the closest vertex to a geometry for a specified point.

On error null point will be returned and "id" argument will be invalid.

Definition at line 66 of file qgsgeometryutils.cpp.

 void QgsGeometryUtils::coefficients ( const QgsPoint & pt1, const QgsPoint & pt2, double & a, double & b, double & c )
static

Returns the coefficients (a, b, c for equation "ax + by + c = 0") of a line defined by points pt1 and pt2.

Parameters
 pt1 first point. pt2 second point. a Output parameter, a coefficient of the equation. b Output parameter, b coefficient of the equation. c Output parameter, c coefficient of the equation.
Since
QGIS 3.0

Definition at line 1276 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::distanceToVertex ( const QgsAbstractGeometry & geom, QgsVertexId id )
static

Returns the distance along a geometry from its first vertex to the specified vertex.

Parameters
 geom geometry id vertex id to find distance to
Returns
distance to vertex (following geometry)
Since
QGIS 2.16

Definition at line 130 of file qgsgeometryutils.cpp.

 QVector< QgsLineString * > QgsGeometryUtils::extractLineStrings ( const QgsAbstractGeometry * geom )
static

Returns list of linestrings extracted from the passed geometry.

The returned objects have to be deleted by the caller.

Definition at line 30 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::gradient ( const QgsPoint & pt1, const QgsPoint & pt2 )
static

Returns the gradient of a line defined by points pt1 and pt2.

Parameters
 pt1 first point. pt2 second point.
Returns
The gradient of this linear entity, or infinity if vertical
Since
QGIS 3.0

Definition at line 1264 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::interpolateArcValue ( double angle, double a1, double a2, double a3, double zm1, double zm2, double zm3 )
static

Interpolate a value at given angle on circular arc given values (zm1, zm2, zm3) at three different angles (a1, a2, a3).

Since
3.0

Definition at line 964 of file qgsgeometryutils.cpp.

 QgsPoint QgsGeometryUtils::interpolatePointOnArc ( const QgsPoint & pt1, const QgsPoint & pt2, const QgsPoint & pt3, double distance )
static

Interpolates a point on an arc defined by three points, pt1, pt2 and pt3.

The arc will be interpolated by the specified distance from pt1.

Any z or m values present in the points will also be linearly interpolated in the output.

Since
QGIS 3.4

Definition at line 579 of file qgsgeometryutils.cpp.

 QgsPointXY QgsGeometryUtils::interpolatePointOnLine ( double x1, double y1, double x2, double y2, double fraction )
static

Interpolates the position of a point a fraction of the way along the line from (x1, y1) to (x2, y2).

Usually the fraction should be between 0 and 1, where 0 represents the point at the start of the line (x1, y1) and 1 represents the end of the line (x2, y2). However, it is possible to use a fraction < 0 or > 1, in which case the returned point is extrapolated from the supplied line.

interpolatePointOnLineByValue()
Since
QGIS 3.0.2

Definition at line 1248 of file qgsgeometryutils.cpp.

 QgsPoint QgsGeometryUtils::interpolatePointOnLine ( const QgsPoint & p1, const QgsPoint & p2, double fraction )
static

Interpolates the position of a point a fraction of the way along the line from p1 to p2.

Usually the fraction should be between 0 and 1, where 0 represents the point at the start of the line (p1) and 1 represents the end of the line (p2). However, it is possible to use a fraction < 0 or > 1, in which case the returned point is extrapolated from the supplied line.

Any Z or M values present in the input points will also be interpolated and present in the returned point.

interpolatePointOnLineByValue()
Since
QGIS 3.0.2

Definition at line 1238 of file qgsgeometryutils.cpp.

 QgsPointXY QgsGeometryUtils::interpolatePointOnLineByValue ( double x1, double y1, double v1, double x2, double y2, double v2, double value )
static

Interpolates the position of a point along the line from (x1, y1) to (x2, y2).

The position is interpolated using a supplied target value and the value at the start of the line (v1) and end of the line (v2). The returned point will be linearly interpolated to match position corresponding to the target value.

interpolatePointOnLine()
Since
QGIS 3.0.2

Definition at line 1255 of file qgsgeometryutils.cpp.

 int QgsGeometryUtils::leftOfLine ( double x, double y, double x1, double y1, double x2, double y2 )
static

Returns a value < 0 if the point (x, y) is left of the line from (x1, y1) -> ( x2, y2).

A positive return value indicates the point is to the right of the line.

If the return value is 0, then the test was unsuccessful (e.g. due to testing a point exactly on the line, or exactly in line with the segment) and the result is undefined.

Definition at line 534 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::lineAngle ( double x1, double y1, double x2, double y2 )
static

Calculates the direction of line joining two points in radians, clockwise from the north direction.

Parameters
 x1 x-coordinate of line start y1 y-coordinate of line start x2 x-coordinate of line end y2 y-coordinate of line end
Returns
angle in radians. Returned value is undefined if start and end point are the same.

Definition at line 1337 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::lineCircleIntersection ( const QgsPointXY & center, double radius, const QgsPointXY & linePoint1, const QgsPointXY & linePoint2, QgsPointXY & intersection )
static

Compute the intersection of a line and a circle.

If the intersection has two solutions (points), the closest point to the initial intersection point is returned.

Parameters
 center the center of the circle radius the radius of the circle linePoint1 a first point on the line linePoint2 a second point on the line intersection the initial point and the returned intersection point
Returns
true if an intersection has been found

Definition at line 317 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::lineIntersection ( const QgsPoint & p1, QgsVector v1, const QgsPoint & p2, QgsVector v2, QgsPoint & intersection )
static

Computes the intersection between two lines.

Z dimension is supported and is retrieved from the first 3D point amongst p1 and p2.

Parameters
 p1 Point on the first line v1 Direction vector of the first line p2 Point on the second line v2 Direction vector of the second line intersection Output parameter, the intersection point
Returns
Whether the lines intersect

Definition at line 238 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::linePerpendicularAngle ( double x1, double y1, double x2, double y2 )
static

Calculates the perpendicular angle to a line joining two points.

Returned angle is in radians, clockwise from the north direction.

Parameters
 x1 x-coordinate of line start y1 y-coordinate of line start x2 x-coordinate of line end y2 y-coordinate of line end
Returns
angle in radians. Returned value is undefined if start and end point are the same.

Definition at line 1351 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::linesIntersection3D ( const QgsVector3D & La1, const QgsVector3D & La2, const QgsVector3D & Lb1, const QgsVector3D & Lb2, QgsVector3D & intersection )
static

An algorithm to calculate an (approximate) intersection of two lines in 3D.

Parameters
 La1 is the first point on the first line, La2 is the second point on the first line, Lb1 is the first point on the second line, Lb2 is the second point on the second line, intersection is the result intersection, of it can be found.
Returns
true if the intersection can be found, false - otherwise. example:
2 # (True, PyQt5.QtGui.QgsVector3D(2.0, 0.0, 0.0))
4 # (True, PyQt5.QtGui.QgsVector3D(2.0, 0.0, 0.0))
6 # (True, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
8 # (True, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
10 # (False, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
12 # (False, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
14 # (True, PyQt5.QtGui.QgsVector3D(3.0, 3.0, 0.0))
16 # (True, PyQt5.QtGui.QgsVector3D(3.0, 3.0, 0.0))
18 # (True, PyQt5.QtGui.QgsVector3D(2.5, 2.5, 2.5))
20 # (True, PyQt5.QtGui.QgsVector3D(2.5, 2.5, 2.5))
22 # (True, PyQt5.QtGui.QgsVector3D(0.0, 5.0, 5.0))

Definition at line 1447 of file qgsgeometryutils.cpp.

 QgsPoint QgsGeometryUtils::midpoint ( const QgsPoint & pt1, const QgsPoint & pt2 )
static

Returns a middle point between points pt1 and pt2.

Z value is computed if one of this point have Z. M value is computed if one of this point have M.

Parameters
 pt1 first point. pt2 second point.
Returns
New point at middle between points pt1 and pt2.
• Example:
1 p = QgsPoint( 4, 6 ) # 2D point
2 pr = midpoint ( p, QgsPoint( 2, 2 ) )
3 # pr is a 2D point: 'Point (3 4)'
4 pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointZ, 2, 2, 2 ) )
5 # pr is a 3D point: 'PointZ (3 4 1)'
6 pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointM, 2, 2, 0, 2 ) )
7 # pr is a 3D point: 'PointM (3 4 1)'
8 pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointZM, 2, 2, 2, 2 ) )
9 # pr is a 3D point: 'PointZM (3 4 1 1)'
Since
QGIS 3.0

Definition at line 1213 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::normalizedAngle ( double angle )
static

Ensures that an angle is in the range 0 <= angle < 2 pi.

Parameters
Returns
equivalent angle within the range [0, 2 pi)

Definition at line 1152 of file qgsgeometryutils.cpp.

 QgsLineString QgsGeometryUtils::perpendicularSegment ( const QgsPoint & p, const QgsPoint & s1, const QgsPoint & s2 )
static

Create a perpendicular line segment from p to segment [s1, s2].

Parameters
 p The point s1 The segment start point s2 The segment end point
Returns
A line (segment) from p to perpendicular point on segment [s1, s2]

Definition at line 1299 of file qgsgeometryutils.cpp.

 QgsPoint QgsGeometryUtils::pointOnLineWithDistance ( const QgsPoint & startPoint, const QgsPoint & directionPoint, double distance )
static

Returns a point a specified distance toward a second point.

Definition at line 545 of file qgsgeometryutils.cpp.

 void QgsGeometryUtils::pointOnLineWithDistance ( double x1, double y1, double x2, double y2, double distance, double & x, double & y, double * z1 = `nullptr`, double * z2 = `nullptr`, double * z = `nullptr`, double * m1 = `nullptr`, double * m2 = `nullptr`, double * m = `nullptr` )
static

Calculates the point a specified distance from (x1, y1) toward a second point (x2, y2).

Optionally, interpolated z and m values can be obtained by specifying the z1, z2 and z arguments and/or the m1, m2, m arguments.

Note
Not available in Python bindings
Since
QGIS 3.4

Definition at line 552 of file qgsgeometryutils.cpp.

 QgsPointSequence QgsGeometryUtils::pointsFromWKT ( const QString & wktCoordinateList, bool is3D, bool isMeasure )
static

Returns a list of points contained in a WKT string.

Note
not available in Python bindings

Definition at line 984 of file qgsgeometryutils.cpp.

 QDomElement QgsGeometryUtils::pointsToGML2 ( const QgsPointSequence & points, QDomDocument & doc, int precision, const QString & ns, QgsAbstractGeometry::AxisOrder axisOrder = `QgsAbstractGeometry::AxisOrder::XY` )
static

Returns a gml::coordinates DOM element.

Note
not available in Python bindings

Definition at line 1088 of file qgsgeometryutils.cpp.

 QDomElement QgsGeometryUtils::pointsToGML3 ( const QgsPointSequence & points, QDomDocument & doc, int precision, const QString & ns, bool is3D, QgsAbstractGeometry::AxisOrder axisOrder = `QgsAbstractGeometry::AxisOrder::XY` )
static

Returns a gml::posList DOM element.

Note
not available in Python bindings

Definition at line 1115 of file qgsgeometryutils.cpp.

 QString QgsGeometryUtils::pointsToJSON ( const QgsPointSequence & points, int precision )
static

Returns a geoJSON coordinates string.

Note
not available in Python bindings

Definition at line 1137 of file qgsgeometryutils.cpp.

 void QgsGeometryUtils::pointsToWKB ( QgsWkbPtr & wkb, const QgsPointSequence & points, bool is3D, bool isMeasure )
static

Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }.

Note
not available in Python bindings

Definition at line 1052 of file qgsgeometryutils.cpp.

 QString QgsGeometryUtils::pointsToWKT ( const QgsPointSequence & points, int precision, bool is3D, bool isMeasure )
static

Returns a WKT coordinate list.

Note
not available in Python bindings

Definition at line 1069 of file qgsgeometryutils.cpp.

 static QgsPoint QgsGeometryUtils::projectPointOnSegment ( const QgsPoint & p, const QgsPoint & s1, const QgsPoint & s2 )
inlinestatic

Project the point on a segment.

Parameters
 p The point s1 The segment start point s2 The segment end point
Returns
The projection of the point on the segment

Definition at line 212 of file qgsgeometryutils.h.

 bool QgsGeometryUtils::segmentIntersection ( const QgsPoint & p1, const QgsPoint & p2, const QgsPoint & q1, const QgsPoint & q2, QgsPoint & intersectionPoint, bool & isIntersection, double tolerance = `1e-8`, bool acceptImproperIntersection = `false` )
static

Compute the intersection between two segments.

Parameters
 p1 First segment start point p2 First segment end point q1 Second segment start point q2 Second segment end point intersectionPoint Output parameter, the intersection point isIntersection Output parameter, return true if an intersection is found tolerance The tolerance to use acceptImproperIntersection By default, this method returns true only if segments have proper intersection. If set true, returns also true if segments have improper intersection (end of one segment on other segment ; continuous segments).
Returns
Whether the segments intersect

Definition at line 257 of file qgsgeometryutils.cpp.

 void QgsGeometryUtils::segmentizeArc ( const QgsPoint & p1, const QgsPoint & p2, const QgsPoint & p3, QgsPointSequence & points, double tolerance = `M_PI_2 / 90`, QgsAbstractGeometry::SegmentationToleranceType toleranceType = `QgsAbstractGeometry::MaximumAngle`, bool hasZ = `false`, bool hasM = `false` )
static

Convert circular arc defined by p1, p2, p3 (p1/p3 being start resp.

end point, p2 lies on the arc) into a sequence of points.

Since
3.0

Definition at line 822 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::segmentMidPoint ( const QgsPoint & p1, const QgsPoint & p2, QgsPoint & result, double radius, const QgsPoint & mousePos )
static

Calculates midpoint on circle passing through p1 and p2, closest to the given coordinate mousePos.

Z dimension is supported and is retrieved from the first 3D point amongst p1 and p2.

segmentMidPointFromCenter()

Definition at line 742 of file qgsgeometryutils.cpp.

 QgsPoint QgsGeometryUtils::segmentMidPointFromCenter ( const QgsPoint & p1, const QgsPoint & p2, const QgsPoint & center, bool useShortestArc = `true` )
static

Calculates the midpoint on the circle passing through p1 and p2, with the specified center coordinate.

If useShortestArc is true, then the midpoint returned will be that corresponding to the shorter arc from p1 to p2. If it is false, the longer arc from p1 to p2 will be used (i.e. winding the other way around the circle).

segmentMidPoint()
Since
QGIS 3.2

Definition at line 789 of file qgsgeometryutils.cpp.

 int QgsGeometryUtils::segmentSide ( const QgsPoint & pt1, const QgsPoint & pt3, const QgsPoint & pt2 )
static

For line defined by points pt1 and pt3, find out on which side of the line is point pt3.

Returns -1 if pt3 on the left side, 1 if pt3 is on the right side or 0 if pt3 lies on the line.

Since
3.0

Definition at line 943 of file qgsgeometryutils.cpp.

 QVector< QgsGeometryUtils::SelfIntersection > QgsGeometryUtils::selfIntersections ( const QgsAbstractGeometry * geom, int part, int ring, double tolerance )
static

Find self intersections in a polyline.

Parameters
 geom The geometry to check part The part of the geometry to check ring The ring of the geometry part to check tolerance The tolerance to use
Returns
The list of self intersections
Note
not available in Python bindings
Since
QGIS 2.12

Definition at line 494 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::setZValueFromPoints ( const QgsPointSequence & points, QgsPoint & point )
static

A Z dimension is added to point if one of the point in the list points is in 3D.

Moreover, the Z value of point is updated with.

Parameters
 points List of points in which a 3D point is searched. point The point to update with Z dimension and value.
Returns
true if the point is updated, false otherwise
Since
QGIS 3.0

Definition at line 1516 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::skewLinesDistance ( const QgsVector3D & P1, const QgsVector3D & P12, const QgsVector3D & P2, const QgsVector3D & P22 )
static

An algorithm to calculate the shortest distance between two skew lines.

Parameters
 P1 is the first point of the first line, P12 is the second point on the first line, P2 is the first point on the second line, P22 is the second point on the second line.
Returns
the shortest distance

Definition at line 1393 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::skewLinesProjection ( const QgsVector3D & P1, const QgsVector3D & P12, const QgsVector3D & P2, const QgsVector3D & P22, QgsVector3D & X1, double epsilon = `0.0001` )
static

A method to project one skew line onto another.

Parameters
 P1 is a first point that belonds to first skew line, P12 is the second point that belongs to first skew line, P2 is the first point that belongs to second skew line, P22 is the second point that belongs to second skew line, X1 is the result projection point of line P2P22 onto line P1P12, epsilon the tolerance to use.
Returns
true if such point exists, false - otherwise.

Definition at line 1405 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::sqrDistance2D ( const QgsPoint & pt1, const QgsPoint & pt2 )
static

Returns the squared 2D distance between two points.

Definition at line 194 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::sqrDistToLine ( double ptX, double ptY, double x1, double y1, double x2, double y2, double & minDistX, double & minDistY, double epsilon )
static

Returns the squared distance between a point and a line.

Definition at line 199 of file qgsgeometryutils.cpp.

 double QgsGeometryUtils::sweepAngle ( double centerX, double centerY, double x1, double y1, double x2, double y2, double x3, double y3 )
static

Calculates angle of a circular string part defined by pt1, pt2, pt3.

Definition at line 712 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::tangentPointAndCircle ( const QgsPointXY & center, double radius, const QgsPointXY & p, QgsPointXY & pt1, QgsPointXY & pt2 )
static

Calculates the tangent points between the circle with the specified center and radius and the point p.

If found, the tangent points will be stored in pt1 and pt2.

Since
QGIS 3.2

Definition at line 435 of file qgsgeometryutils.cpp.

 bool QgsGeometryUtils::verticesAtDistance ( const QgsAbstractGeometry & geometry, double distance, QgsVertexId & previousVertex, QgsVertexId & nextVertex )
static

Retrieves the vertices which are before and after the interpolated point at a specified distance along a linestring (or polygon boundary).

Parameters
 geometry line or polygon geometry distance distance to traverse along geometry previousVertex will be set to previous vertex ID nextVertex will be set to next vertex ID
Returns
true if vertices were successfully retrieved
Note
if the distance coincides exactly with a vertex, then both previousVertex and nextVertex will be set to this vertex
Since
QGIS 3.0

Definition at line 149 of file qgsgeometryutils.cpp.

 QStringList QgsGeometryUtils::wktGetChildBlocks ( const QString & wkt, const QString & defaultType = `QString()` )
static

Parses a WKT string and returns of list of blocks contained in the WKT.

Parameters
 wkt WKT string in the format "TYPE1 (contents1), TYPE2 (TYPE3 (contents3), TYPE4 (contents4))" defaultType default geometry type for children
Returns
list of WKT child block strings, e.g., List("TYPE1 (contents1)", "TYPE2 (TYPE3 (contents3), TYPE4 (contents4))")
Note
not available in Python bindings

Definition at line 1177 of file qgsgeometryutils.cpp.

 QPair< QgsWkbTypes::Type, QString > QgsGeometryUtils::wktReadBlock ( const QString & wkt )
static

Parses a WKT block of the format "TYPE( contents )" and returns a pair of geometry type to contents ("Pair(wkbType, "contents")")

Note
not available in Python bindings

Definition at line 1166 of file qgsgeometryutils.cpp.

The documentation for this class was generated from the following files: