26 #include <QStringList> 28 #include <QRegularExpression> 32 QVector< QgsLineString * > linestrings;
36 QVector< const QgsAbstractGeometry * > geometries;
38 while ( ! geometries.isEmpty() )
41 if (
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( g ) )
43 linestrings << static_cast< QgsLineString * >( curve->segmentize() );
45 else if (
const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( g ) )
47 for (
int i = 0; i < collection->numGeometries(); ++i )
49 geometries.append( collection->geometryN( i ) );
52 else if (
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( g ) )
54 if ( curvePolygon->exteriorRing() )
55 linestrings << static_cast< QgsLineString * >( curvePolygon->exteriorRing()->segmentize() );
57 for (
int i = 0; i < curvePolygon->numInteriorRings(); ++i )
59 linestrings << static_cast< QgsLineString * >( curvePolygon->interiorRing( i )->segmentize() );
68 double minDist = std::numeric_limits<double>::max();
69 double currentDist = 0;
83 if ( currentDist <= minDist )
85 minDist = currentDist;
86 minDistPoint = vertex;
87 id.part = vertexId.
part;
88 id.ring = vertexId.
ring;
89 id.vertex = vertexId.
vertex;
90 id.type = vertexId.
type;
105 if ( vertexAfter.
vertex > 0 )
111 double distance = pointBefore.
distance( closestPoint );
114 closestPoint = pointBefore;
116 closestPoint = pointAfter;
120 closestPoint.
addZValue( pointBefore.
z() + ( pointAfter.
z() - pointBefore.
z() ) * distance / length );
122 closestPoint.
addMValue( pointBefore.
m() + ( pointAfter.
m() - pointBefore.
m() ) * distance / length );
132 double currentDist = 0;
137 if ( vertexId ==
id )
151 double currentDist = 0;
161 nextVertex = previousVertex;
166 while ( currentDist < distance && geometry.
nextVertex( nextVertex, point ) )
180 if ( currentDist > distance )
186 previousPoint = point;
196 return ( pt1.
x() - pt2.
x() ) * ( pt1.
x() - pt2.
x() ) + ( pt1.
y() - pt2.
y() ) * ( pt1.
y() - pt2.
y() );
209 double t = ( ( ptX - x1 ) * dx + ( ptY - y1 ) * dy ) / ( dx * dx + dy * dy );
225 double dist = dx * dx + dy * dy;
240 double d = v1.
y() * v2.
x() - v1.
x() * v2.
y();
245 double dx = p2.
x() - p1.
x();
246 double dy = p2.
y() - p1.
y();
247 double k = ( dy * v2.
x() - dx * v2.
y() ) / d;
249 intersection =
QgsPoint( p1.
x() + v1.
x() * k, p1.
y() + v1.
y() * k );
259 isIntersection =
false;
264 double wl = w.length();
278 isIntersection =
true;
279 if ( acceptImproperIntersection )
281 if ( ( p1 == q1 ) || ( p1 == q2 ) )
283 intersectionPoint = p1;
286 else if ( ( p2 == q1 ) || ( p2 == q2 ) )
288 intersectionPoint = p2;
295 qgsDoubleNear(
QgsGeometryUtils::sqrDistToLine( p1.
x(), p1.
y(), q1.
x(), q1.
y(), q2.
x(), q2.
y(), x, y, tolerance ), 0.0, tolerance ) ||
297 qgsDoubleNear(
QgsGeometryUtils::sqrDistToLine( p2.
x(), p2.
y(), q1.
x(), q1.
y(), q2.
x(), q2.
y(), x, y, tolerance ), 0.0, tolerance ) ||
299 qgsDoubleNear(
QgsGeometryUtils::sqrDistToLine( q1.
x(), q1.
y(), p1.
x(), p1.
y(), p2.
x(), p2.
y(), x, y, tolerance ), 0.0, tolerance ) ||
301 qgsDoubleNear(
QgsGeometryUtils::sqrDistToLine( q2.
x(), q2.
y(), p1.
x(), p1.
y(), p2.
x(), p2.
y(), x, y, tolerance ), 0.0, tolerance )
308 double lambdav =
QgsVector( intersectionPoint.
x() - p1.
x(), intersectionPoint.
y() - p1.
y() ) * v;
309 if ( lambdav < 0. + tolerance || lambdav > vl - tolerance )
312 double lambdaw =
QgsVector( intersectionPoint.
x() - q1.
x(), intersectionPoint.
y() - q1.
y() ) * w;
313 return !( lambdaw < 0. + tolerance || lambdaw >= wl - tolerance );
322 const double x1 = linePoint1.
x() - center.
x();
323 const double y1 = linePoint1.
y() - center.
y();
324 const double x2 = linePoint2.
x() - center.
x();
325 const double y2 = linePoint2.
y() - center.
y();
326 const double dx = x2 - x1;
327 const double dy = y2 - y1;
329 const double dr = std::sqrt( std::pow( dx, 2 ) + std::pow( dy, 2 ) );
330 const double d = x1 * y2 - x2 * y1;
332 const double disc = std::pow( radius, 2 ) * std::pow( dr, 2 ) - std::pow( d, 2 );
342 const int sgnDy = dy < 0 ? -1 : 1;
344 const double ax = center.
x() + ( d * dy + sgnDy * dx * std::sqrt( std::pow( radius, 2 ) * std::pow( dr, 2 ) - std::pow( d, 2 ) ) ) / ( std::pow( dr, 2 ) );
345 const double ay = center.
y() + ( -d * dx + std::fabs( dy ) * std::sqrt( std::pow( radius, 2 ) * std::pow( dr, 2 ) - std::pow( d, 2 ) ) ) / ( std::pow( dr, 2 ) );
348 const double bx = center.
x() + ( d * dy - sgnDy * dx * std::sqrt( std::pow( radius, 2 ) * std::pow( dr, 2 ) - std::pow( d, 2 ) ) ) / ( std::pow( dr, 2 ) );
349 const double by = center.
y() + ( -d * dx - std::fabs( dy ) * std::sqrt( std::pow( radius, 2 ) * std::pow( dr, 2 ) - std::pow( d, 2 ) ) ) / ( std::pow( dr, 2 ) );
356 intersection.
set( p1.
x(), p1.
y() );
360 intersection.
set( p2.
x(), p2.
y() );
368 QVector<SelfIntersection> intersections;
374 for (
int i = 0, j = 1; j < n; i = j++ )
382 int end = i == 0 && isClosed ? n - 1 : n;
383 for (
int k = start, l = start + 1; l <
end; k = l++ )
389 bool intersection =
false;
400 intersections.append( s );
403 return intersections;
412 double test = ( f1 * f2 - f3 * f4 );
414 return qgsDoubleNear( test, 0.0 ) ? 0 : ( test < 0 ? -1 : 1 );
419 double dx = directionPoint.
x() - startPoint.
x();
420 double dy = directionPoint.
y() - startPoint.
y();
421 double length = std::sqrt( dx * dx + dy * dy );
428 double scaleFactor = distance /
length;
429 return QgsPoint( startPoint.
x() + dx * scaleFactor, startPoint.
y() + dy * scaleFactor );
434 double angle = std::atan2( dy, dx ) * 180 / M_PI;
439 else if ( angle > 360 )
448 double dx21, dy21, dx31, dy31, h21, h31, d;
453 centerX = ( pt1.
x() + pt2.
x() ) / 2.0;
454 centerY = ( pt1.
y() + pt2.
y() ) / 2.0;
455 radius = std::sqrt( std::pow( centerX - pt1.
x(), 2.0 ) + std::pow( centerY - pt1.
y(), 2.0 ) );
460 dx21 = pt2.
x() - pt1.
x();
461 dy21 = pt2.
y() - pt1.
y();
462 dx31 = pt3.
x() - pt1.
x();
463 dy31 = pt3.
y() - pt1.
y();
465 h21 = std::pow( dx21, 2.0 ) + std::pow( dy21, 2.0 );
466 h31 = std::pow( dx31, 2.0 ) + std::pow( dy31, 2.0 );
469 d = 2 * ( dx21 * dy31 - dx31 * dy21 );
479 centerX = pt1.
x() + ( h21 * dy31 - h31 * dy21 ) / d;
480 centerY = pt1.
y() - ( h21 * dx31 - h31 * dx21 ) / d;
481 radius = std::sqrt( std::pow( centerX - pt1.
x(), 2.0 ) + std::pow( centerY - pt1.
y(), 2.0 ) );
486 if ( angle3 >= angle1 )
488 return !( angle2 > angle1 && angle2 < angle3 );
492 return !( angle2 > angle1 || angle2 < angle3 );
500 if ( angle2 < angle1 )
502 return ( angle <= angle1 && angle >= angle2 );
506 return ( angle <= angle1 || angle >= angle2 );
511 if ( angle2 > angle1 )
513 return ( angle >= angle1 && angle <= angle2 );
517 return ( angle >= angle1 || angle <= angle2 );
530 double centerX, centerY, radius;
532 double length = M_PI / 180.0 * radius *
sweepAngle( centerX, centerY, x1, y1, x2, y2, x3, y3 );
546 if ( p3Angle >= p1Angle )
548 if ( p2Angle > p1Angle && p2Angle < p3Angle )
550 return ( p3Angle - p1Angle );
554 return ( - ( p1Angle + ( 360 - p3Angle ) ) );
559 if ( p2Angle < p1Angle && p2Angle > p3Angle )
561 return ( -( p1Angle - p3Angle ) );
565 return ( p3Angle + ( 360 - p1Angle ) );
572 QgsPoint midPoint( ( p1.
x() + p2.
x() ) / 2.0, ( p1.
y() + p2.
y() ) / 2.0 );
574 if ( radius < midDist )
578 double centerMidDist = std::sqrt( radius * radius - midDist * midDist );
579 double dist = radius - centerMidDist;
581 double midDx = midPoint.
x() - p1.
x();
582 double midDy = midPoint.
y() - p1.
y();
585 QVector<QgsPoint> possibleMidPoints;
592 double minDist = std::numeric_limits<double>::max();
593 int minDistIndex = -1;
594 for (
int i = 0; i < possibleMidPoints.size(); ++i )
596 double currentDist =
sqrDistance2D( mousePos, possibleMidPoints.at( i ) );
597 if ( currentDist < minDist )
600 minDist = currentDist;
604 if ( minDistIndex == -1 )
609 result = possibleMidPoints.at( minDistIndex );
621 double mX, mY, radius;
630 angle =
lineAngle( tangentPoint.
x(), tangentPoint.
y(), mX, mY ) - M_PI_2;
634 angle =
lineAngle( mX, mY, tangentPoint.
x(), tangentPoint.
y() ) - M_PI_2;
643 bool reversed =
false;
667 circleCenterRadius( circlePoint1, circlePoint2, circlePoint3, radius, centerX, centerY );
669 if ( circlePoint1 != circlePoint3 && ( radius < 0 ||
qgsDoubleNear( segSide, 0.0 ) ) )
677 double increment = tolerance;
680 double halfAngle = std::acos( -tolerance / radius + 1 );
681 increment = 2 * halfAngle;
685 double a1 = std::atan2( circlePoint1.
y() - centerY, circlePoint1.
x() - centerX );
686 double a2 = std::atan2( circlePoint2.
y() - centerY, circlePoint2.
x() - centerX );
687 double a3 = std::atan2( circlePoint3.
y() - centerY, circlePoint3.
x() - centerX );
690 const bool symmetric =
true;
693 double angle = a3 - a1;
694 if ( angle < 0 ) angle += M_PI * 2;
697 int segs = ceil( angle / increment );
699 increment = angle / segs;
712 QVector<QgsPoint> stringPoints;
713 stringPoints.insert( 0, circlePoint1 );
714 if ( circlePoint2 != circlePoint3 && circlePoint1 != circlePoint2 )
728 double tolError = increment / 100;
729 double stopAngle = a3 - tolError;
730 for (
double angle = a1 + increment;
angle < stopAngle;
angle += increment )
732 x = centerX + radius * std::cos(
angle );
733 y = centerY + radius * std::sin(
angle );
744 stringPoints.insert( stringPoints.size(),
QgsPoint( pointWkbType, x, y, z, m ) );
747 stringPoints.insert( stringPoints.size(), circlePoint3 );
752 std::reverse( stringPoints.begin(), stringPoints.end() );
754 if ( ! points.empty() && stringPoints.front() == points.back() ) stringPoints.pop_front();
755 points.append( stringPoints );
760 double side = ( ( pt2.
x() - pt1.
x() ) * ( pt3.
y() - pt1.
y() ) - ( pt3.
x() - pt1.
x() ) * ( pt2.
y() - pt1.
y() ) );
785 return zm1 + ( zm2 - zm1 ) * ( angle - a1 ) / ( a2 - a1 );
787 return zm2 + ( zm3 - zm2 ) * ( angle - a2 ) / ( a3 - a2 );
793 return zm1 + ( zm2 - zm1 ) * ( a1 - angle ) / ( a1 - a2 );
795 return zm2 + ( zm3 - zm2 ) * ( a2 - angle ) / ( a2 - a3 );
803 const QStringList coordList = wktCoordinateList.split(
',', QString::SkipEmptyParts );
808 QRegularExpression rx( QStringLiteral(
"\\s" ) );
809 for (
const QString &pointCoordinates : coordList )
811 QStringList coordinates = pointCoordinates.split( rx, QString::SkipEmptyParts );
812 if ( coordinates.size() == 3 && !foundZ && !foundM && !is3D && !
isMeasure )
818 else if ( coordinates.size() >= 4 && ( !( is3D || foundZ ) || !( isMeasure || foundM ) ) )
827 for (
const QString &pointCoordinates : coordList )
829 QStringList coordinates = pointCoordinates.split( rx, QString::SkipEmptyParts );
830 if ( coordinates.size() < dim )
834 double x = coordinates[idx++].toDouble();
835 double y = coordinates[idx++].toDouble();
838 if ( ( is3D || foundZ ) && coordinates.length() > idx )
839 z = coordinates[idx++].toDouble();
842 if ( ( isMeasure || foundM ) && coordinates.length() > idx )
843 m = coordinates[idx++].toDouble();
846 if ( is3D || foundZ )
848 if ( isMeasure || foundM )
855 if ( isMeasure || foundM )
861 points.append(
QgsPoint( t, x, y, z, m ) );
869 wkb << static_cast<quint32>( points.size() );
870 for (
const QgsPoint &point : points )
872 wkb << point.x() << point.y();
886 QString wkt = QStringLiteral(
"(" );
895 wkt += QLatin1String(
", " );
897 if ( wkt.endsWith( QLatin1String(
", " ) ) )
905 QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral(
"coordinates" ) );
908 QString cs = QStringLiteral(
"," );
910 QString ts = QStringLiteral(
" " );
912 elemCoordinates.setAttribute( QStringLiteral(
"cs" ), cs );
913 elemCoordinates.setAttribute( QStringLiteral(
"ts" ), ts );
915 QString strCoordinates;
920 if ( strCoordinates.endsWith( ts ) )
921 strCoordinates.chop( 1 );
923 elemCoordinates.appendChild( doc.createTextNode( strCoordinates ) );
924 return elemCoordinates;
929 QDomElement elemPosList = doc.createElementNS( ns, QStringLiteral(
"posList" ) );
930 elemPosList.setAttribute( QStringLiteral(
"srsDimension" ), is3D ? 3 : 2 );
932 QString strCoordinates;
939 if ( strCoordinates.endsWith(
' ' ) )
940 strCoordinates.chop( 1 );
942 elemPosList.appendChild( doc.createTextNode( strCoordinates ) );
948 QString json = QStringLiteral(
"[ " );
953 if ( json.endsWith( QLatin1String(
", " ) ) )
963 double clippedAngle =
angle;
964 if ( clippedAngle >= M_PI * 2 || clippedAngle <= -2 * M_PI )
966 clippedAngle = std::fmod( clippedAngle, 2 * M_PI );
968 if ( clippedAngle < 0.0 )
970 clippedAngle += 2 * M_PI;
979 QRegularExpression cooRegEx( QStringLiteral(
"^[^\\(]*\\((.*)\\)[^\\)]*$" ) );
980 cooRegEx.setPatternOptions( QRegularExpression::DotMatchesEverythingOption );
981 QRegularExpressionMatch match = cooRegEx.match( wkt );
982 QString contents = match.hasMatch() ? match.captured( 1 ) : QString();
983 return qMakePair( wkbType, contents );
991 for (
int i = 0, n = wkt.length(); i < n; ++i )
993 if ( ( wkt[i].isSpace() || wkt[i] ==
'\n' || wkt[i] ==
'\t' ) && level == 0 )
996 if ( wkt[i] ==
',' && level == 0 )
998 if ( !block.isEmpty() )
1000 if ( block.startsWith(
'(' ) && !defaultType.isEmpty() )
1001 block.prepend( defaultType +
' ' );
1002 blocks.append( block );
1007 if ( wkt[i] ==
'(' )
1009 else if ( wkt[i] ==
')' )
1013 if ( !block.isEmpty() )
1015 if ( block.startsWith(
'(' ) && !defaultType.isEmpty() )
1016 block.prepend( defaultType +
' ' );
1017 blocks.append( block );
1027 double x = ( pt1.
x() + pt2.
x() ) / 2.0;
1028 double y = ( pt1.
y() + pt2.
y() ) / 2.0;
1029 double z = std::numeric_limits<double>::quiet_NaN();
1030 double m = std::numeric_limits<double>::quiet_NaN();
1035 z = ( pt1.
z() + pt2.
z() ) / 2.0;
1041 m = ( pt1.
m() + pt2.
m() ) / 2.0;
1044 return QgsPoint( pType, x, y, z, m );
1049 const double _fraction = 1 - fraction;
1051 p1.
x() * _fraction + p2.
x() * fraction,
1052 p1.
y() * _fraction + p2.
y() * fraction,
1053 p1.
is3D() ? p1.
z() * _fraction + p2.
z() * fraction : std::numeric_limits<double>::quiet_NaN(),
1054 p1.
isMeasure() ? p1.
m() * _fraction + p2.
m() * fraction : std::numeric_limits<double>::quiet_NaN() );
1059 const double deltaX = ( x2 - x1 ) * fraction;
1060 const double deltaY = ( y2 - y1 ) * fraction;
1061 return QgsPointXY( x1 + deltaX, y1 + deltaY );
1069 const double fraction = ( value - v1 ) / ( v2 - v1 );
1075 double delta_x = pt2.
x() - pt1.
x();
1076 double delta_y = pt2.
y() - pt1.
y();
1082 return delta_y / delta_x;
1101 a = pt1.
y() - pt2.
y();
1102 b = pt2.
x() - pt1.
x();
1103 c = pt1.
x() * pt2.
y() - pt1.
y() * pt2.
x();
1113 if ( ( p == s1 ) || ( p == s2 ) )
1131 double y = ( -c - a * p.
x() ) / b;
1133 double d2 = 1 + m * m;
1134 double H = p.
y() - y;
1135 double dx = m * H / d2;
1148 double at = std::atan2( y2 - y1, x2 - x1 );
1149 double a = -at + M_PI_2;
1155 double angle1 = std::atan2( y1 - y2, x1 - x2 );
1156 double angle2 = std::atan2( y3 - y2, x3 - x2 );
1170 double a1 =
lineAngle( x1, y1, x2, y2 );
1171 double a2 =
lineAngle( x2, y2, x3, y3 );
1179 double clockwiseDiff = 0.0;
1182 clockwiseDiff = a2 - a1;
1186 clockwiseDiff = a2 + ( 2 * M_PI - a1 );
1188 double counterClockwiseDiff = 2 * M_PI - clockwiseDiff;
1190 double resultAngle = 0;
1191 if ( clockwiseDiff <= counterClockwiseDiff )
1193 resultAngle = a1 + clockwiseDiff / 2.0;
1197 resultAngle = a1 - counterClockwiseDiff / 2.0;
1206 for (
const QgsPoint &pt : points )
1211 point.
setZ( pt.z() );
bool isMeasure() const
Returns true if the geometry contains m values.
Maximum distance between an arbitrary point on the original curve and closest point on its approximat...
static QString pointsToJSON(const QgsPointSequence &points, int precision)
Returns a geoJSON coordinates string.
void set(double x, double y)
Sets the x and y value of the point.
static bool segmentIntersection(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint, bool &isIntersection, const double tolerance=1e-8, bool acceptImproperIntersection=false)
Compute the intersection between two segments.
static bool circleAngleBetween(double angle, double angle1, double angle2, bool clockwise)
Returns true if, in a circle, angle is between angle1 and angle2.
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 an...
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 an...
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 alon...
static QVector< SelfIntersection > selfIntersections(const QgsAbstractGeometry *geom, int part, int ring, double tolerance)
Find self intersections in a polyline.
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...
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
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...
bool isValid() const
Returns true if the vertex id is valid.
void setZ(double z)
Sets the point's z-coordinate.
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 (...
static double averageAngle(double x1, double y1, double x2, double y2, double x3, double y3)
Angle between two linear segments.
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...
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
static double gradient(const QgsPoint &pt1, const QgsPoint &pt2)
Return the gradient of a line defined by points pt1 and pt2.
A class to represent a 2D point.
Curve polygon geometry type.
static double linePerpendicularAngle(double x1, double y1, double x2, double y2)
Calculates the perpendicular angle to a line joining two points.
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
virtual double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *DBL_EPSILON) const =0
Searches for the closest segment of the geometry to a given point.
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 given coordinate.
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.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
static QgsPoint closestVertex(const QgsAbstractGeometry &geom, const QgsPoint &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point.
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
static QStringList wktGetChildBlocks(const QString &wkt, const QString &defaultType=QString())
Parses a WKT string and returns of list of blocks contained in the WKT.
double sqrDist(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
virtual double length() const
Returns the length of the geometry.
static bool circleClockwise(double angle1, double angle2, double angle3)
Returns true if circle is ordered clockwise.
static QString pointsToWKT(const QgsPointSequence &points, int precision, bool is3D, bool isMeasure)
Returns a WKT coordinate list.
Type
The WKB type describes the number of dimensions a geometry has.
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.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
void addVertex(const QgsPoint &pt)
Adds a new vertex to the end of the line string.
static QDomElement pointsToGML2(const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns)
Returns a gml::coordinates DOM element.
Utility class for identifying a unique vertex within a geometry.
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
static QgsPoint midpoint(const QgsPoint &pt1, const QgsPoint &pt2)
Returns a middle point between points pt1 and pt2.
static QDomElement pointsToGML3(const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, bool is3D)
Returns a gml::posList DOM element.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
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) ...
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.
Abstract base class for curved geometry type.
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).
Abstract base class for all geometries.
static QVector< QgsLineString * > extractLineStrings(const QgsAbstractGeometry *geom)
Returns list of linestrings extracted from the passed geometry.
static double normalizedAngle(double angle)
Ensures that an angle is in the range 0 <= angle < 2 pi.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Point geometry type, with support for z-dimension and m-values.
double length() const
Returns the length of the vector.
static bool lineIntersection(const QgsPoint &p1, QgsVector v1, const QgsPoint &p2, QgsVector v2, QgsPoint &intersection)
Computes the intersection between two lines.
A class to represent a vector.
QVector< QgsPoint > QgsPointSequence
static QgsPoint pointOnLineWithDistance(const QgsPoint &startPoint, const QgsPoint &directionPoint, double distance)
Returns a point a specified distance toward a second point.
static double sqrDistance2D(const QgsPoint &pt1, const QgsPoint &pt2)
Returns the squared 2D distance between two points.
static bool lineCircleIntersection(const QgsPointXY ¢er, const double radius, const QgsPointXY &linePoint1, const QgsPointXY &linePoint2, QgsPointXY &intersection)
Compute the intersection of a line and a circle.
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.
static QgsLineString perpendicularSegment(const QgsPoint &p, const QgsPoint &s1, const QgsPoint &s2)
Create a perpendicular line segment from p to segment [s1, s2].
static QgsPointSequence pointsFromWKT(const QString &wktCoordinateList, bool is3D, bool isMeasure)
Returns a list of points contained in a WKT string.
Line string geometry type, with support for z-dimension and m-values.
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
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).
static void circleCenterRadius(const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double &radius, double ¢erX, double ¢erY)
Returns radius and center of the circle through pt1, pt2, pt3.
bool convertTo(QgsWkbTypes::Type type) override
Converts the geometry to a specified type.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
static void pointsToWKB(QgsWkbPtr &wkb, const QgsPointSequence &points, bool is3D, bool isMeasure)
Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }.
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.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
double x() const
Returns the vector's x-component.
static QgsPoint closestPoint(const QgsAbstractGeometry &geometry, const QgsPoint &point)
Returns the nearest point on a segment of a geometry for the specified point.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
double y() const
Returns the vector's y-component.
static double distanceToVertex(const QgsAbstractGeometry &geom, QgsVertexId id)
Returns the distance along a geometry from its first vertex to the specified vertex.
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).
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
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.
static void coefficients(const QgsPoint &pt1, const QgsPoint &pt2, double &a, double &b, double &c)
Return the coefficients (a, b, c for equation "ax + by + c = 0") of a line defined by points pt1 and ...