27#include <QRegularExpression>
28#include <nlohmann/json.hpp>
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;
86 if ( currentDist <= minDist )
88 minDist = currentDist;
89 minDistPoint = vertex;
90 id.part = vertexId.
part;
91 id.ring = vertexId.
ring;
92 id.vertex = vertexId.
vertex;
93 id.type = vertexId.
type;
108 if ( vertexAfter.
vertex > 0 )
113 const double length = pointBefore.
distance( pointAfter );
135 double currentDist = 0;
140 if ( vertexId ==
id )
154 double currentDist = 0;
169 nextVertex = previousVertex;
174 while ( currentDist < distance && geometry.
nextVertex( nextVertex, point ) )
176 if ( !first && nextVertex.
part == previousVertex.
part && nextVertex.
ring == previousVertex.
ring )
184 previousVertex = nextVertex;
188 if ( currentDist > distance )
193 previousVertex = nextVertex;
194 previousPoint = point;
204 const double area = std::abs(
205 ( linePoint1.
x() - linePoint2.
x() ) * ( point.
y() - linePoint2.
y() ) -
206 ( linePoint1.
y() - linePoint2.
y() ) * ( point.
x() - linePoint2.
x() )
209 const double length = std::sqrt(
210 std::pow( linePoint1.
x() - linePoint2.
x(), 2 ) +
211 std::pow( linePoint1.
y() - linePoint2.
y(), 2 )
214 const double distance = area / length;
215 return qgsDoubleNear( distance, 0.0, epsilon ) ? 0.0 : distance;
224 const double x1 = linePoint1.
x() - center.
x();
225 const double y1 = linePoint1.
y() - center.
y();
226 const double x2 = linePoint2.
x() - center.
x();
227 const double y2 = linePoint2.
y() - center.
y();
228 const double dx = x2 - x1;
229 const double dy = y2 - y1;
231 const double dr2 = std::pow( dx, 2 ) + std::pow( dy, 2 );
232 const double d = x1 * y2 - x2 * y1;
234 const double disc = std::pow( radius, 2 ) * dr2 - std::pow( d, 2 );
244 const int sgnDy = dy < 0 ? -1 : 1;
246 const double sqrDisc = std::sqrt( disc );
248 const double ax = center.
x() + ( d * dy + sgnDy * dx * sqrDisc ) / dr2;
249 const double ay = center.
y() + ( -d * dx + std::fabs( dy ) * sqrDisc ) / dr2;
252 const double bx = center.
x() + ( d * dy - sgnDy * dx * sqrDisc ) / dr2;
253 const double by = center.
y() + ( -d * dx - std::fabs( dy ) * sqrDisc ) / dr2;
260 intersection.
set( p1.
x(), p1.
y() );
264 intersection.
set( p2.
x(), p2.
y() );
275 const double d = center1.
distance( center2 );
279 const bool singleSolutionInt =
qgsDoubleNear( d, std::fabs( r1 - r2 ) );
282 if ( !singleSolutionExt && d > ( r1 + r2 ) )
287 else if ( !singleSolutionInt && d < std::fabs( r1 - r2 ) )
307 const double a = singleSolutionExt ? r1 : ( singleSolutionInt ? ( r1 > r2 ? r1 : -r1 ) : ( ( r1 * r1 ) - ( r2 * r2 ) + ( d * d ) ) / ( 2.0 * d ) );
312 const double dx = center2.
x() - center1.
x();
313 const double dy = center2.
y() - center1.
y();
316 const double x2 = center1.
x() + ( dx * a / d );
317 const double y2 = center1.
y() + ( dy * a / d );
320 if ( singleSolutionExt || singleSolutionInt )
333 const double h = std::sqrt( ( r1 * r1 ) - ( a * a ) );
338 const double rx = dy * ( h / d );
339 const double ry = dx * ( h / d );
342 intersection1 =
QgsPointXY( x2 + rx, y2 - ry );
343 intersection2 =
QgsPointXY( x2 - rx, y2 + ry );
353 const double dx = center.
x() - p.
x();
354 const double dy = center.
y() - p.
y();
355 const double distanceSquared = dx * dx + dy * dy;
356 const double radiusSquared = radius * radius;
357 if ( distanceSquared < radiusSquared )
364 const double distanceToTangent = std::sqrt( distanceSquared - radiusSquared );
376 if ( radius1 > radius2 )
379 const double radius2a = radius2 - radius1;
388 QgsVector v1( -( line1P2.
y() - center1.
y() ), line1P2.
x() - center1.
x() );
389 const double v1Length = v1.
length();
390 v1 = v1 * ( radius1 / v1Length );
393 line1P1 = center1 + v1;
394 line1P2 = line1P2 + v1;
398 QgsVector v2( line2P2.
y() - center1.
y(), -( line2P2.
x() - center1.
x() ) );
399 const double v2Length = v2.
length();
400 v2 = v2 * ( radius1 / v2Length );
403 line2P1 = center1 + v2;
404 line2P2 = line2P2 + v2;
412 if ( radius1 > radius2 )
416 const double d = center1.
distance( center2 );
417 const double radius1a = radius1 + radius2;
434 QgsVector v1( ( line1P2.
y() - center2.
y() ), -( line1P2.
x() - center2.
x() ) );
435 const double v1Length = v1.
length();
436 v1 = v1 * ( radius2 / v1Length );
439 line1P1 = center2 + v1;
440 line1P2 = line1P2 + v1;
444 QgsVector v2( -( line2P2.
y() - center2.
y() ), line2P2.
x() - center2.
x() );
445 const double v2Length = v2.
length();
446 v2 = v2 * ( radius2 / v2Length );
449 line2P1 = center2 + v2;
450 line2P2 = line2P2 + v2;
457 QVector<SelfIntersection> intersections;
463 for (
int i = 0, j = 1; j < n; i = j++ )
470 const int start = j + 1;
471 const int end = i == 0 && isClosed ? n - 1 : n;
472 for (
int k = start, l = start + 1; l < end; k = l++ )
478 bool intersection =
false;
489 intersections.append( s );
492 return intersections;
510 double centerX, centerY, radius;
513 const double theta = distance / radius;
514 const double anglePt1 = std::atan2( pt1.
y() - centerY, pt1.
x() - centerX );
515 const double anglePt2 = std::atan2( pt2.
y() - centerY, pt2.
x() - centerX );
516 const double anglePt3 = std::atan2( pt3.
y() - centerY, pt3.
x() - centerX );
518 const double angleDest = anglePt1 + (
isClockwise ? -theta : theta );
520 const double x = centerX + radius * ( std::cos( angleDest ) );
521 const double y = centerY + radius * ( std::sin( angleDest ) );
523 const double z = pt1.
is3D() ?
535 const QgsPoint midPoint( ( p1.
x() + p2.
x() ) / 2.0, ( p1.
y() + p2.
y() ) / 2.0 );
536 const double midDist = std::sqrt(
sqrDistance2D( p1, midPoint ) );
537 if ( radius < midDist )
541 const double centerMidDist = std::sqrt( radius * radius - midDist * midDist );
542 const double dist = radius - centerMidDist;
544 const double midDx = midPoint.
x() - p1.
x();
545 const double midDy = midPoint.
y() - p1.
y();
548 QVector<QgsPoint> possibleMidPoints;
555 double minDist = std::numeric_limits<double>::max();
556 int minDistIndex = -1;
557 for (
int i = 0; i < possibleMidPoints.size(); ++i )
559 const double currentDist =
sqrDistance2D( mousePos, possibleMidPoints.at( i ) );
560 if ( currentDist < minDist )
563 minDist = currentDist;
567 if ( minDistIndex == -1 )
572 result = possibleMidPoints.at( minDistIndex );
584 if ( !useShortestArc )
585 midPointAngle += M_PI;
586 return center.
project( center.
distance( p1 ), midPointAngle * 180 / M_PI );
593 double mX, mY, radius;
626 const double bDistance = std::sqrt( ( b.
x() - centerX ) * ( b.
x() - centerX ) +
627 ( b.
y() - centerY ) * ( b.
y() - centerY ) );
629 double diff = std::fabs( radius - bDistance );
633 const double abX = b.
x() - a.
x();
634 const double abY = b.
y() - a.
y();
636 const double cbX = b.
x() -
c.x();
637 const double cbY = b.
y() -
c.y();
639 const double dot = ( abX * cbX + abY * cbY );
640 const double cross = ( abX * cbY - abY * cbX );
642 const double alpha = std::atan2( cross, dot );
648 if ( diff < distanceTolerance )
650 const double angle1 = arcAngle( a1, a2, a3 );
651 const double angle2 = arcAngle( a2, a3, b );
656 diff = std::fabs( angle1 - angle2 );
657 if ( diff > pointSpacingAngleTolerance )
667 if ( bSide != a2Side )
675 bool reversed =
false;
699 circleCenterRadius( circlePoint1, circlePoint2, circlePoint3, radius, centerX, centerY );
701 if ( circlePoint1 != circlePoint3 && ( radius < 0 ||
qgsDoubleNear( segSide, 0.0 ) ) )
709 double increment = tolerance;
713 tolerance = std::min( tolerance, radius * 2 );
714 const double halfAngle = std::acos( -tolerance / radius + 1 );
715 increment = 2 * halfAngle;
719 const double a1 = std::atan2( circlePoint1.
y() - centerY, circlePoint1.
x() - centerX );
720 double a2 = std::atan2( circlePoint2.
y() - centerY, circlePoint2.
x() - centerX );
721 double a3 = std::atan2( circlePoint3.
y() - centerY, circlePoint3.
x() - centerX );
724 const bool symmetric =
true;
727 double angle = a3 - a1;
729 if ( angle <= 0 ) angle += M_PI * 2;
732 const int segs = ceil( angle / increment );
734 increment = angle / segs;
748 QVector<QgsPoint> stringPoints;
749 stringPoints.insert( 0, circlePoint1 );
750 if ( circlePoint2 != circlePoint3 && circlePoint1 != circlePoint2 )
764 const double tolError = increment / 100;
765 const double stopAngle = a3 - tolError;
766 for (
double angle = a1 + increment; angle < stopAngle; angle += increment )
768 x = centerX + radius * std::cos( angle );
769 y = centerY + radius * std::sin( angle );
780 stringPoints.insert( stringPoints.size(),
QgsPoint( pointWkbType, x, y, z, m ) );
783 stringPoints.insert( stringPoints.size(), circlePoint3 );
788 std::reverse( stringPoints.begin(), stringPoints.end() );
790 if ( ! points.empty() && stringPoints.front() == points.back() ) stringPoints.pop_front();
791 points.append( stringPoints );
796 const double side = ( ( pt2.
x() - pt1.
x() ) * ( pt3.
y() - pt1.
y() ) - ( pt3.
x() - pt1.
x() ) * ( pt2.
y() - pt1.
y() ) );
817 const int dim = 2 + is3D + isMeasure;
820 const QStringList coordList = wktCoordinateList.split(
',', Qt::SkipEmptyParts );
825 const thread_local QRegularExpression rx( QStringLiteral(
"\\s" ) );
826 const thread_local QRegularExpression rxIsNumber( QStringLiteral(
"^[+-]?(\\d\\.?\\d*[Ee][+\\-]?\\d+|(\\d+\\.\\d*|\\d*\\.\\d+)|\\d+)$" ) );
827 for (
const QString &pointCoordinates : coordList )
829 const QStringList coordinates = pointCoordinates.split( rx, Qt::SkipEmptyParts );
832 if ( coordinates.filter( rxIsNumber ).size() != coordinates.size() )
835 if ( coordinates.size() == 3 && !foundZ && !foundM && !is3D && !isMeasure )
841 else if ( coordinates.size() >= 4 && ( !( is3D || foundZ ) || !( isMeasure || foundM ) ) )
850 for (
const QString &pointCoordinates : coordList )
852 QStringList coordinates = pointCoordinates.split( rx, Qt::SkipEmptyParts );
853 if ( coordinates.size() < dim )
857 const double x = coordinates[idx++].toDouble();
858 const double y = coordinates[idx++].toDouble();
861 if ( ( is3D || foundZ ) && coordinates.length() > idx )
862 z = coordinates[idx++].toDouble();
865 if ( ( isMeasure || foundM ) && coordinates.length() > idx )
866 m = coordinates[idx++].toDouble();
869 if ( is3D || foundZ )
871 if ( isMeasure || foundM )
878 if ( isMeasure || foundM )
884 points.append(
QgsPoint( t, x, y, z, m ) );
892 wkb << static_cast<quint32>( points.size() );
893 for (
const QgsPoint &point : points )
895 wkb << point.x() << point.y();
898 double z = point.z();
901 z = -std::numeric_limits<double>::max();
907 double m = point.m();
910 m = -std::numeric_limits<double>::max();
919 QString wkt = QStringLiteral(
"(" );
928 wkt += QLatin1String(
", " );
930 if ( wkt.endsWith( QLatin1String(
", " ) ) )
938 QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral(
"coordinates" ) );
941 const QString cs = QStringLiteral(
"," );
943 const QString ts = QStringLiteral(
" " );
945 elemCoordinates.setAttribute( QStringLiteral(
"cs" ), cs );
946 elemCoordinates.setAttribute( QStringLiteral(
"ts" ), ts );
948 QString strCoordinates;
956 if ( strCoordinates.endsWith( ts ) )
957 strCoordinates.chop( 1 );
959 elemCoordinates.appendChild( doc.createTextNode( strCoordinates ) );
960 return elemCoordinates;
965 QDomElement elemPosList = doc.createElementNS( ns, QStringLiteral(
"posList" ) );
966 elemPosList.setAttribute( QStringLiteral(
"srsDimension" ), is3D ? 3 : 2 );
968 QString strCoordinates;
978 if ( strCoordinates.endsWith(
' ' ) )
979 strCoordinates.chop( 1 );
981 elemPosList.appendChild( doc.createTextNode( strCoordinates ) );
987 QString json = QStringLiteral(
"[ " );
992 if ( json.endsWith( QLatin1String(
", " ) ) )
1003 json coordinates( json::array() );
1020 QString wktParsed = wkt;
1022 const QLatin1String empty {
"EMPTY" };
1023 if ( wkt.contains( empty, Qt::CaseInsensitive ) )
1025 const thread_local QRegularExpression whiteSpaces(
"\\s" );
1026 wktParsed.remove( whiteSpaces );
1027 const int index = wktParsed.indexOf( empty, 0, Qt::CaseInsensitive );
1029 if ( index == wktParsed.length() - empty.size() )
1033 wktParsed = wktParsed.left( index );
1039 const int openedParenthesisCount = wktParsed.count(
'(' );
1040 const int closedParenthesisCount = wktParsed.count(
')' );
1042 for (
int i = 0 ; i < openedParenthesisCount - closedParenthesisCount; ++i )
1043 wktParsed.push_back(
')' );
1045 wktParsed.truncate( wktParsed.size() - ( closedParenthesisCount - openedParenthesisCount ) );
1047 const thread_local QRegularExpression cooRegEx( QStringLiteral(
"^[^\\(]*\\((.*)\\)[^\\)]*$" ), QRegularExpression::DotMatchesEverythingOption );
1048 const QRegularExpressionMatch match = cooRegEx.match( wktParsed );
1049 contents = match.hasMatch() ? match.captured( 1 ) : QString();
1052 return qMakePair( wkbType, contents );
1059 block.reserve( wkt.size() );
1062 const QChar *wktData = wkt.data();
1063 const int wktLength = wkt.length();
1064 for (
int i = 0, n = wktLength; i < n; ++i, ++wktData )
1066 if ( ( wktData->isSpace() || *wktData ==
'\n' || *wktData ==
'\t' ) && level == 0 )
1069 if ( *wktData ==
',' && level == 0 )
1071 if ( !block.isEmpty() )
1073 if ( block.startsWith(
'(' ) && !defaultType.isEmpty() )
1074 block.prepend( defaultType +
' ' );
1075 blocks.append( block );
1080 if ( *wktData ==
'(' )
1082 else if ( *wktData ==
')' )
1086 if ( !block.isEmpty() )
1088 if ( block.startsWith(
'(' ) && !defaultType.isEmpty() )
1089 block.prepend( defaultType +
' ' );
1090 blocks.append( block );
1100 const double x = ( pt1.
x() + pt2.
x() ) / 2.0;
1101 const double y = ( pt1.
y() + pt2.
y() ) / 2.0;
1102 double z = std::numeric_limits<double>::quiet_NaN();
1103 double m = std::numeric_limits<double>::quiet_NaN();
1108 z = ( pt1.
z() + pt2.
z() ) / 2.0;
1114 m = ( pt1.
m() + pt2.
m() ) / 2.0;
1117 return QgsPoint( pType, x, y, z, m );
1122 const double _fraction = 1 - fraction;
1124 p1.
x() * _fraction + p2.
x() * fraction,
1125 p1.
y() * _fraction + p2.
y() * fraction,
1126 p1.
is3D() ? p1.
z() * _fraction + p2.
z() * fraction : std::numeric_limits<double>::quiet_NaN(),
1127 p1.
isMeasure() ? p1.
m() * _fraction + p2.
m() * fraction : std::numeric_limits<double>::quiet_NaN() );
1132 const double deltaX = ( x2 - x1 ) * fraction;
1133 const double deltaY = ( y2 - y1 ) * fraction;
1134 return QgsPointXY( x1 + deltaX, y1 + deltaY );
1142 const double fraction = ( value - v1 ) / ( v2 - v1 );
1148 const double delta_x = pt2.
x() - pt1.
x();
1149 const double delta_y = pt2.
y() - pt1.
y();
1155 return delta_y / delta_x;
1174 a = pt1.
y() - pt2.
y();
1175 b = pt2.
x() - pt1.
x();
1176 c = pt1.
x() * pt2.
y() - pt1.
y() * pt2.
x();
1186 if ( ( p == s1 ) || ( p == s2 ) )
1204 const double y = ( -
c - a * p.
x() ) / b;
1205 const double m =
gradient( s1, s2 );
1206 const double d2 = 1 + m * m;
1207 const double H = p.
y() - y;
1208 const double dx = m * H / d2;
1209 const double dy = m * dx;
1223 for (
const QgsPoint &pt : points )
1225 if ( pt.isMeasure() )
1228 point.
setM( pt.m() );
1241 for (
const QgsPoint &pt : points )
1246 point.
setZ( pt.z() );
WkbType
The WKB type describes the number of dimensions a geometry has.
Abstract base class for all geometries.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
@ MaximumDifference
Maximum distance between an arbitrary point on the original curve and closest point on its approximat...
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
bool isMeasure() const
Returns true if the geometry contains m values.
QFlags< WkbFlag > WkbFlags
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
AxisOrder
Axis order for GML generation.
@ XY
X comes before Y (or lon before lat)
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual bool isEmpty() const
Returns true if the geometry is empty.
@ FlagExportNanAsDoubleMin
Use -DOUBLE_MAX to represent NaN.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
virtual double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const =0
Searches for the closest segment of the geometry to a given point.
Curve polygon geometry type.
Abstract base class for curved geometry type.
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,...
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 circleClockwise(double angle1, double angle2, double angle3)
Returns true if the circle defined by three angles is ordered clockwise.
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.
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,...
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 int leftOfLine(const double x, const double y, const double x1, const double y1, const double x2, const double y2)
Returns a value < 0 if the point (x, y) is left of the line from (x1, y1) -> (x2, y2).
static int circleCircleIntersections(const QgsPointXY ¢er1, double radius1, const QgsPointXY ¢er2, double radius2, QgsPointXY &intersection1, QgsPointXY &intersection2)
Calculates the intersections points between the circle with center center1 and radius radius1 and the...
static QString pointsToJSON(const QgsPointSequence &points, int precision)
Returns a geoJSON coordinates string.
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,...
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 int leftOfLine(const QgsPoint &point, const QgsPoint &p1, const QgsPoint &p2)
Returns a value < 0 if the point point is left of the line from p1 -> p2.
static QgsPoint pointOnLineWithDistance(const QgsPoint &startPoint, const QgsPoint &directionPoint, double distance)
Returns a point a specified distance toward a second point.
static double gradient(const QgsPoint &pt1, const QgsPoint &pt2)
Returns the gradient of a line defined by points pt1 and pt2.
static json pointsToJson(const QgsPointSequence &points, int precision)
Returns coordinates as json object.
static QVector< QgsLineString * > extractLineStrings(const QgsAbstractGeometry *geom)
Returns list of linestrings extracted from the passed geometry.
static QVector< SelfIntersection > selfIntersections(const QgsAbstractGeometry *geom, int part, int ring, double tolerance)
Find self intersections in a polyline.
static bool transferFirstZValueToPoint(const QgsPointSequence &points, QgsPoint &point)
A Z dimension is added to point if one of the point in the list points is in 3D.
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.
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).
static QgsPoint closestPoint(const QgsAbstractGeometry &geometry, const QgsPoint &point)
Returns the nearest point on a segment of a geometry for the specified point.
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 QStringList wktGetChildBlocks(const QString &wkt, const QString &defaultType=QString())
Parses a WKT string and returns of list of blocks contained in the WKT.
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.
static QgsLineString perpendicularSegment(const QgsPoint &p, const QgsPoint &s1, const QgsPoint &s2)
Create a perpendicular line segment from p to segment [s1, s2].
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 pt2.
static void pointsToWKB(QgsWkbPtr &wkb, const QgsPointSequence &points, bool is3D, bool isMeasure, QgsAbstractGeometry::WkbFlags flags)
Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }.
static double distanceToVertex(const QgsAbstractGeometry &geom, QgsVertexId id)
Returns the distance along a geometry from its first vertex to the specified vertex.
static QPair< Qgis::WkbType, QString > wktReadBlock(const QString &wkt)
Parses a WKT block of the format "TYPE( contents )" and returns a pair of geometry type to contents (...
static bool lineCircleIntersection(const QgsPointXY ¢er, double radius, const QgsPointXY &linePoint1, const QgsPointXY &linePoint2, QgsPointXY &intersection)
Compute the intersection of a line and a circle.
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.
static double distToInfiniteLine(const QgsPoint &point, const QgsPoint &linePoint1, const QgsPoint &linePoint2, double epsilon=1e-7)
Returns the distance between a point and an infinite line.
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...
static bool transferFirstMValueToPoint(const QgsPointSequence &points, QgsPoint &point)
A M dimension is added to point if one of the points in the list points contains an M value.
static QgsPoint midpoint(const QgsPoint &pt1, const QgsPoint &pt2)
Returns a middle point between points pt1 and pt2.
static QgsPoint closestVertex(const QgsAbstractGeometry &geom, const QgsPoint &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point.
static bool pointContinuesArc(const QgsPoint &a1, const QgsPoint &a2, const QgsPoint &a3, const QgsPoint &b, double distanceTolerance, double pointSpacingAngleTolerance)
Returns true if point b is on the arc formed by points a1, a2, and a3, but not within that arc portio...
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.
static bool tangentPointAndCircle(const QgsPointXY ¢er, 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...
static int circleCircleOuterTangents(const QgsPointXY ¢er1, double radius1, const QgsPointXY ¢er2, 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 o...
static QgsPointSequence pointsFromWKT(const QString &wktCoordinateList, bool is3D, bool isMeasure)
Returns a list of points contained in a WKT string.
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 Q_DECL_DEPRECATED double sqrDistance2D(double x1, double y1, double x2, double y2)
Returns the squared 2D distance between (x1, y1) and (x2, y2).
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.
static bool transferFirstZOrMValueToPoint(Iterator verticesBegin, Iterator verticesEnd, QgsPoint &point)
A Z or M dimension is added to point if one of the points in the list points contains Z or M value.
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.
static int circleCircleInnerTangents(const QgsPointXY ¢er1, double radius1, const QgsPointXY ¢er2, double radius2, QgsPointXY &line1P1, QgsPointXY &line1P2, QgsPointXY &line2P1, QgsPointXY &line2P2)
Calculates the inner tangent points for two circles, centered at center1 and center2 and with radii o...
static QString pointsToWKT(const QgsPointSequence &points, int precision, bool is3D, bool isMeasure)
Returns a WKT coordinate list.
static QgsPoint segmentMidPointFromCenter(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint ¢er, bool useShortestArc=true)
Calculates the midpoint on the circle passing through p1 and p2, with the specified center coordinate...
Line string geometry type, with support for z-dimension and m-values.
void addVertex(const QgsPoint &pt)
Adds a new vertex to the end of the line string.
A class to represent a 2D point.
double sqrDist(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
void set(double x, double y)
Sets the x and y value of the point.
Point geometry type, with support for z-dimension and m-values.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
void setM(double m)
Sets the point's m-value.
bool convertTo(Qgis::WkbType type) override
Converts the geometry to a specified type.
bool isEmpty() const override
Returns true if the geometry is empty.
double distance(double x, double y) const
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
void setZ(double z)
Sets the point's z-coordinate.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const
Returns a new point which corresponds to this point projected by a specified distance with specified ...
A class to represent a vector.
double length() const
Returns the length of the vector.
static Qgis::WkbType parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
static bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
QVector< QgsPoint > QgsPointSequence
bool isClockwise(std::array< Direction, 4 > dirs)
Checks whether the 4 directions in dirs make up a clockwise rectangle.
Utility class for identifying a unique vertex within a geometry.
bool isValid() const
Returns true if the vertex id is valid.
Qgis::VertexType type
Vertex type.