QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Classes | Public Types | Static Public Member Functions | List of all members
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 void adjacentVertices (const QgsAbstractGeometryV2 &geom, QgsVertexId atVertex, QgsVertexId &beforeVertex, QgsVertexId &afterVertex)
 Returns vertices adjacent to a specified vertex within a geometry. 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)
 Angle between two linear segments. 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 QgsPointV2 &pt1, const QgsPointV2 &pt2, const QgsPointV2 &pt3, double &radius, double &centerX, double &centerY)
 Returns radius and center of the circle through pt1, pt2, pt3. More...
 
static bool circleClockwise (double angle1, double angle2, double angle3)
 Returns true if circle 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 QgsPointV2 &tangentPoint, const QgsPointV2 &cp1, const QgsPointV2 &cp2, const QgsPointV2 &cp3)
 Calculates the direction angle of a circle tangent (clockwise from north in radians) More...
 
template<class T >
static double closestSegmentFromComponents (T &container, componentType ctype, const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon)
 
static QgsPointV2 closestVertex (const QgsAbstractGeometryV2 &geom, const QgsPointV2 &pt, QgsVertexId &id)
 Returns the closest vertex to a geometry for a specified point. More...
 
static double distanceToVertex (const QgsAbstractGeometryV2 &geom, const QgsVertexId &id)
 Returns the distance along a geometry from its first vertex to the specified vertex. More...
 
static QList< QgsLineStringV2 * > extractLineStrings (const QgsAbstractGeometryV2 *geom)
 Returns list of linestrings extracted from the passed geometry. More...
 
static QList< SelfIntersectiongetSelfIntersections (const QgsAbstractGeometryV2 *geom, int part, int ring, double tolerance)
 Find self intersections in a polyline. More...
 
static double leftOfLine (double x, double y, double x1, double y1, double x2, double y2)
 Returns < 0 if point(x/y) is left of the line 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 lineIntersection (const QgsPointV2 &p1, QgsVector v, const QgsPointV2 &q1, QgsVector w, QgsPointV2 &inter)
 Compute 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 double normalizedAngle (double angle)
 Ensures that an angle is in the range 0 <= angle < 2 pi. More...
 
static QgsPointV2 pointOnLineWithDistance (const QgsPointV2 &startPoint, const QgsPointV2 &directionPoint, double distance)
 Returns a point a specified distance toward a second point. More...
 
static QgsPointSequenceV2 pointsFromWKT (const QString &wktCoordinateList, bool is3D, bool isMeasure)
 Returns a list of points contained in a WKT string. More...
 
static QDomElement pointsToGML2 (const QgsPointSequenceV2 &points, QDomDocument &doc, int precision, const QString &ns)
 Returns a gml::coordinates DOM element. More...
 
static QDomElement pointsToGML3 (const QgsPointSequenceV2 &points, QDomDocument &doc, int precision, const QString &ns, bool is3D)
 Returns a gml::posList DOM element. More...
 
static QString pointsToJSON (const QgsPointSequenceV2 &points, int precision)
 Returns a geoJSON coordinates string. More...
 
static void pointsToWKB (QgsWkbPtr &wkb, const QgsPointSequenceV2 &points, bool is3D, bool isMeasure)
 Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }. More...
 
static QString pointsToWKT (const QgsPointSequenceV2 &points, int precision, bool is3D, bool isMeasure)
 Returns a WKT coordinate list. More...
 
static QgsPointV2 projPointOnSegment (const QgsPointV2 &p, const QgsPointV2 &s1, const QgsPointV2 &s2)
 Project the point on a segment. More...
 
static bool segmentIntersection (const QgsPointV2 &p1, const QgsPointV2 &p2, const QgsPointV2 &q1, const QgsPointV2 &q2, QgsPointV2 &inter, double tolerance)
 Compute the intersection between two segments. More...
 
static bool segmentMidPoint (const QgsPointV2 &p1, const QgsPointV2 &p2, QgsPointV2 &result, double radius, const QgsPointV2 &mousePos)
 Calculates midpoint on circle passing through p1 and p2, closest to given coordinate. More...
 
static double sqrDistance2D (const QgsPointV2 &pt1, const QgsPointV2 &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 verticesAtDistance (const QgsAbstractGeometryV2 &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="")
 Parses a WKT string and returns of list of blocks contained in the WKT. More...
 
static QPair< QgsWKBTypes::Type, QStringwktReadBlock (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.

Note
added in QGIS 2.10
this API is not considered stable and may change for 2.12
not available in Python bindings

Definition at line 31 of file qgsgeometryutils.h.

Member Enumeration Documentation

◆ componentType

Enumerator
VERTEX 
RING 
PART 

Definition at line 233 of file qgsgeometryutils.h.

Member Function Documentation

◆ adjacentVertices()

void QgsGeometryUtils::adjacentVertices ( const QgsAbstractGeometryV2 geom,
QgsVertexId  atVertex,
QgsVertexId beforeVertex,
QgsVertexId afterVertex 
)
static

Returns vertices adjacent to a specified vertex within a geometry.

Definition at line 168 of file qgsgeometryutils.cpp.

◆ angleOnCircle()

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 499 of file qgsgeometryutils.cpp.

◆ averageAngle() [1/2]

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

Angle between two linear segments.

Definition at line 844 of file qgsgeometryutils.cpp.

◆ averageAngle() [2/2]

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
a1first angle (in radians)
a2second angle (in radians)
Returns
average angle (in radians)

Definition at line 852 of file qgsgeometryutils.cpp.

◆ ccwAngle()

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 395 of file qgsgeometryutils.cpp.

◆ circleAngleBetween()

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 473 of file qgsgeometryutils.cpp.

◆ circleCenterRadius()

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

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

Definition at line 409 of file qgsgeometryutils.cpp.

◆ circleClockwise()

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

Returns true if circle is ordered clockwise.

Definition at line 447 of file qgsgeometryutils.cpp.

◆ circleLength()

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 505 of file qgsgeometryutils.cpp.

◆ circleTangentDirection()

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

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

Definition at line 590 of file qgsgeometryutils.cpp.

◆ closestSegmentFromComponents()

template<class T >
static double QgsGeometryUtils::closestSegmentFromComponents ( T &  container,
componentType  ctype,
const QgsPointV2 pt,
QgsPointV2 segmentPt,
QgsVertexId vertexAfter,
bool *  leftOf,
double  epsilon 
)
inlinestatic

Definition at line 240 of file qgsgeometryutils.h.

◆ closestVertex()

QgsPointV2 QgsGeometryUtils::closestVertex ( const QgsAbstractGeometryV2 geom,
const QgsPointV2 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 63 of file qgsgeometryutils.cpp.

◆ distanceToVertex()

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

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

Parameters
geomgeometry
idvertex id to find distance to
Returns
distance to vertex (following geometry)
Note
added in QGIS 2.16

Definition at line 94 of file qgsgeometryutils.cpp.

◆ extractLineStrings()

QList< QgsLineStringV2 * > QgsGeometryUtils::extractLineStrings ( const QgsAbstractGeometryV2 geom)
static

Returns list of linestrings extracted from the passed geometry.

The returned objects have to be deleted by the caller.

Definition at line 27 of file qgsgeometryutils.cpp.

◆ getSelfIntersections()

QList< QgsGeometryUtils::SelfIntersection > QgsGeometryUtils::getSelfIntersections ( const QgsAbstractGeometryV2 geom,
int  part,
int  ring,
double  tolerance 
)
static

Find self intersections in a polyline.

Parameters
geomThe geometry to check
partThe part of the geometry to check
ringThe ring of the geometry part to check
toleranceThe tolerance to use
Returns
The list of self intersections
Note
added in QGIS 2.12

Definition at line 332 of file qgsgeometryutils.cpp.

◆ leftOfLine()

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

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

Definition at line 371 of file qgsgeometryutils.cpp.

◆ lineAngle()

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
x1x-coordinate of line start
y1y-coordinate of line start
x2x-coordinate of line end
y2y-coordinate of line end
Returns
angle in radians. Returned value is undefined if start and end point are the same.

Definition at line 830 of file qgsgeometryutils.cpp.

◆ lineIntersection()

bool QgsGeometryUtils::lineIntersection ( const QgsPointV2 p1,
QgsVector  v,
const QgsPointV2 q1,
QgsVector  w,
QgsPointV2 inter 
)
static

Compute the intersection between two lines.

Parameters
p1Point on the first line
vDirection vector of the first line
q1Point on the second line
wDirection vector of the second line
interOutput parameter, the intersection point
Returns
Whether the lines intersect

Definition at line 288 of file qgsgeometryutils.cpp.

◆ linePerpendicularAngle()

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
x1x-coordinate of line start
y1y-coordinate of line start
x2x-coordinate of line end
y2y-coordinate of line end
Returns
angle in radians. Returned value is undefined if start and end point are the same.

Definition at line 837 of file qgsgeometryutils.cpp.

◆ normalizedAngle()

double QgsGeometryUtils::normalizedAngle ( double  angle)
static

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

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

Definition at line 771 of file qgsgeometryutils.cpp.

◆ pointOnLineWithDistance()

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

Returns a point a specified distance toward a second point.

Definition at line 380 of file qgsgeometryutils.cpp.

◆ pointsFromWKT()

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

Returns a list of points contained in a WKT string.

Definition at line 610 of file qgsgeometryutils.cpp.

◆ pointsToGML2()

QDomElement QgsGeometryUtils::pointsToGML2 ( const QgsPointSequenceV2 points,
QDomDocument doc,
int  precision,
const QString ns 
)
static

Returns a gml::coordinates DOM element.

Definition at line 713 of file qgsgeometryutils.cpp.

◆ pointsToGML3()

QDomElement QgsGeometryUtils::pointsToGML3 ( const QgsPointSequenceV2 points,
QDomDocument doc,
int  precision,
const QString ns,
bool  is3D 
)
static

Returns a gml::posList DOM element.

Definition at line 737 of file qgsgeometryutils.cpp.

◆ pointsToJSON()

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

Returns a geoJSON coordinates string.

Definition at line 756 of file qgsgeometryutils.cpp.

◆ pointsToWKB()

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

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

Definition at line 677 of file qgsgeometryutils.cpp.

◆ pointsToWKT()

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

Returns a WKT coordinate list.

Definition at line 694 of file qgsgeometryutils.cpp.

◆ projPointOnSegment()

static QgsPointV2 QgsGeometryUtils::projPointOnSegment ( const QgsPointV2 p,
const QgsPointV2 s1,
const QgsPointV2 s2 
)
inlinestatic

Project the point on a segment.

Parameters
pThe point
s1The segment start point
s2The segment end point
Returns
The projection of the point on the segment

Definition at line 110 of file qgsgeometryutils.h.

◆ segmentIntersection()

bool QgsGeometryUtils::segmentIntersection ( const QgsPointV2 p1,
const QgsPointV2 p2,
const QgsPointV2 q1,
const QgsPointV2 q2,
QgsPointV2 inter,
double  tolerance 
)
static

Compute the intersection between two segments.

Parameters
p1First segment start point
p2First segment end point
q1Second segment start point
q2Second segment end point
interOutput parameter, the intersection point
toleranceThe tolerance to use
Returns
Whether the segments intersect

Definition at line 304 of file qgsgeometryutils.cpp.

◆ segmentMidPoint()

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

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

Definition at line 547 of file qgsgeometryutils.cpp.

◆ sqrDistance2D()

double QgsGeometryUtils::sqrDistance2D ( const QgsPointV2 pt1,
const QgsPointV2 pt2 
)
static

Returns the squared 2D distance between two points.

Definition at line 244 of file qgsgeometryutils.cpp.

◆ sqrDistToLine()

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 249 of file qgsgeometryutils.cpp.

◆ sweepAngle()

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 517 of file qgsgeometryutils.cpp.

◆ verticesAtDistance()

bool QgsGeometryUtils::verticesAtDistance ( const QgsAbstractGeometryV2 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
geometryline or polygon geometry
distancedistance to traverse along geometry
previousVertexwill be set to previous vertex ID
nextVertexwill be set to next vertex ID
Note
if the distance coincides exactly with a vertex, then both previousVertex and nextVertex will be set to this vertex
Returns
true if vertices were successfully retrieved
Note
added in QGIS 2.18

Definition at line 123 of file qgsgeometryutils.cpp.

◆ wktGetChildBlocks()

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

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

Parameters
wktWKT string in the format "TYPE1 (contents1), TYPE2 (TYPE3 (contents3), TYPE4 (contents4))"
defaultTypedefault geometry type for childen
Returns
list of WKT child block strings, eg List("TYPE1 (contents1)", "TYPE2 (TYPE3 (contents3), TYPE4 (contents4))")

Definition at line 794 of file qgsgeometryutils.cpp.

◆ wktReadBlock()

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")")

Definition at line 785 of file qgsgeometryutils.cpp.


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