QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
qgsgeometryutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometryutils.h
3 -------------------------------------------------------------------
4Date : 21 Nov 2014
5Copyright : (C) 2014 by Marco Hugentobler
6email : marco.hugentobler at sourcepole dot com
7***************************************************************************
8* *
9* This program is free software; you can redistribute it and/or modify *
10* it under the terms of the GNU General Public License as published by *
11* the Free Software Foundation; either version 2 of the License, or *
12* (at your option) any later version. *
13* *
14***************************************************************************/
15
16#pragma once
17
18#include <limits>
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
22#include "qgspoint.h"
23#include "qgsvertexid.h"
24#include "qgsgeometry.h"
26#include "qgsvector3d.h"
27
28#include <QJsonArray>
29
30class QgsLineString;
31
37class CORE_EXPORT QgsGeometryUtils
38{
39 public:
40
45 static QVector<QgsLineString *> extractLineStrings( const QgsAbstractGeometry *geom ) SIP_FACTORY;
46
51 static QgsPoint closestVertex( const QgsAbstractGeometry &geom, const QgsPoint &pt, QgsVertexId &id SIP_OUT );
52
58 static QgsPoint closestPoint( const QgsAbstractGeometry &geometry, const QgsPoint &point );
59
66 static double distanceToVertex( const QgsAbstractGeometry &geom, QgsVertexId id );
67
78 static bool verticesAtDistance( const QgsAbstractGeometry &geometry,
79 double distance,
80 QgsVertexId &previousVertex SIP_OUT,
81 QgsVertexId &nextVertex SIP_OUT );
82
91 static double distToInfiniteLine( const QgsPoint &point, const QgsPoint &linePoint1, const QgsPoint &linePoint2, double epsilon = 1e-7 );
92
104 static bool lineCircleIntersection( const QgsPointXY &center, double radius,
105 const QgsPointXY &linePoint1, const QgsPointXY &linePoint2,
106 QgsPointXY &intersection SIP_INOUT ) SIP_HOLDGIL;
107
118 static int circleCircleIntersections( const QgsPointXY &center1, double radius1,
119 const QgsPointXY &center2, double radius2,
120 QgsPointXY &intersection1 SIP_OUT, QgsPointXY &intersection2 SIP_OUT ) SIP_HOLDGIL;
121
130 static bool tangentPointAndCircle( const QgsPointXY &center, double radius,
132
150 static int circleCircleOuterTangents(
151 const QgsPointXY &center1, double radius1, const QgsPointXY &center2, double radius2,
152 QgsPointXY &line1P1 SIP_OUT, QgsPointXY &line1P2 SIP_OUT,
153 QgsPointXY &line2P1 SIP_OUT, QgsPointXY &line2P2 SIP_OUT ) SIP_HOLDGIL;
154
173 static int circleCircleInnerTangents(
174 const QgsPointXY &center1, double radius1, const QgsPointXY &center2, double radius2,
175 QgsPointXY &line1P1 SIP_OUT, QgsPointXY &line1P2 SIP_OUT,
176 QgsPointXY &line2P1 SIP_OUT, QgsPointXY &line2P2 SIP_OUT ) SIP_HOLDGIL;
177
185 static QgsPoint projectPointOnSegment( const QgsPoint &p, const QgsPoint &s1, const QgsPoint &s2 ) SIP_HOLDGIL
186 {
187 const double nx = s2.y() - s1.y();
188 const double ny = -( s2.x() - s1.x() );
189 const double t = ( p.x() * ny - p.y() * nx - s1.x() * ny + s1.y() * nx ) / ( ( s2.x() - s1.x() ) * ny - ( s2.y() - s1.y() ) * nx );
190 return t < 0. ? s1 : t > 1. ? s2 : QgsPoint( s1.x() + ( s2.x() - s1.x() ) * t, s1.y() + ( s2.y() - s1.y() ) * t );
191 }
192
200
210 static QVector<SelfIntersection> selfIntersections( const QgsAbstractGeometry *geom, int part, int ring, double tolerance ) SIP_SKIP;
211
221 static int leftOfLine( const QgsPoint &point, const QgsPoint &p1, const QgsPoint &p2 ) SIP_HOLDGIL;
222
226 static QgsPoint pointOnLineWithDistance( const QgsPoint &startPoint, const QgsPoint &directionPoint, double distance ) SIP_HOLDGIL;
227
236 static QgsPoint interpolatePointOnArc( const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double distance ) SIP_HOLDGIL;
237
244 static bool segmentMidPoint( const QgsPoint &p1, const QgsPoint &p2, QgsPoint &result SIP_OUT, double radius, const QgsPoint &mousePos ) SIP_HOLDGIL;
245
257 static QgsPoint segmentMidPointFromCenter( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &center, bool useShortestArc = true ) SIP_HOLDGIL;
258
260 static double circleTangentDirection( const QgsPoint &tangentPoint, const QgsPoint &cp1, const QgsPoint &cp2, const QgsPoint &cp3 ) SIP_HOLDGIL;
261
265 static void segmentizeArc( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3,
266 QgsPointSequence SIP_PYALTERNATIVETYPE( QVector<QgsPoint> ) &points SIP_OUT, double tolerance = M_PI_2 / 90,
267 QgsAbstractGeometry::SegmentationToleranceType toleranceType = QgsAbstractGeometry::MaximumAngle,
268 bool hasZ = false, bool hasM = false );
269
285 static bool pointContinuesArc( const QgsPoint &a1, const QgsPoint &a2, const QgsPoint &a3, const QgsPoint &b, double distanceTolerance,
286 double pointSpacingAngleTolerance ) SIP_HOLDGIL;
287
292 static int segmentSide( const QgsPoint &pt1, const QgsPoint &pt3, const QgsPoint &pt2 ) SIP_HOLDGIL;
293
298 static QgsPointSequence pointsFromWKT( const QString &wktCoordinateList, bool is3D, bool isMeasure ) SIP_SKIP;
299
304 static void pointsToWKB( QgsWkbPtr &wkb, const QgsPointSequence &points, bool is3D, bool isMeasure, QgsAbstractGeometry::WkbFlags flags ) SIP_SKIP;
305
310 static QString pointsToWKT( const QgsPointSequence &points, int precision, bool is3D, bool isMeasure ) SIP_SKIP;
311
316 static QDomElement pointsToGML2( const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) SIP_SKIP;
317
322 static QDomElement pointsToGML3( const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, bool is3D, QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) SIP_SKIP;
323
328 static QString pointsToJSON( const QgsPointSequence &points, int precision ) SIP_SKIP;
329
334 static json pointsToJson( const QgsPointSequence &points, int precision ) SIP_SKIP;
335
340 static QPair<Qgis::WkbType, QString> wktReadBlock( const QString &wkt ) SIP_SKIP;
341
349 static QStringList wktGetChildBlocks( const QString &wkt, const QString &defaultType = QString() ) SIP_SKIP;
350
373 static QgsPoint midpoint( const QgsPoint &pt1, const QgsPoint &pt2 ) SIP_HOLDGIL;
374
387 static QgsPointXY interpolatePointOnLine( double x1, double y1, double x2, double y2, double fraction ) SIP_HOLDGIL;
388
404 static QgsPoint interpolatePointOnLine( const QgsPoint &p1, const QgsPoint &p2, double fraction ) SIP_HOLDGIL;
405
417 static QgsPointXY interpolatePointOnLineByValue( double x1, double y1, double v1, double x2, double y2, double v2, double value ) SIP_HOLDGIL;
418
425 static double gradient( const QgsPoint &pt1, const QgsPoint &pt2 ) SIP_HOLDGIL;
426
435 static void coefficients( const QgsPoint &pt1, const QgsPoint &pt2,
436 double &a SIP_OUT, double &b SIP_OUT, double &c SIP_OUT ) SIP_HOLDGIL;
437
445 static QgsLineString perpendicularSegment( const QgsPoint &p, const QgsPoint &s1, const QgsPoint &s2 ) SIP_HOLDGIL;
446
462 Q_DECL_DEPRECATED static bool setZValueFromPoints( const QgsPointSequence &points, QgsPoint &point ) SIP_DEPRECATED
463 {
464 return transferFirstZValueToPoint( points, point );
465 }
466
482 static bool transferFirstZValueToPoint( const QgsPointSequence &points, QgsPoint &point );
483
499 static bool transferFirstMValueToPoint( const QgsPointSequence &points, QgsPoint &point );
500
519 template <class Iterator> static bool transferFirstZOrMValueToPoint( Iterator verticesBegin, Iterator verticesEnd, QgsPoint &point ) SIP_SKIP
520 {
521 bool zFound = false;
522 bool mFound = false;
523
524 for ( auto it = verticesBegin ; it != verticesEnd ; ++it )
525 {
526 if ( !mFound && ( *it ).isMeasure() )
527 {
528 point.convertTo( QgsWkbTypes::addM( point.wkbType() ) );
529 point.setM( ( *it ).m() );
530 mFound = true;
531 }
532 if ( !zFound && ( *it ).is3D() )
533 {
534 point.convertTo( QgsWkbTypes::addZ( point.wkbType() ) );
535 point.setZ( ( *it ).z() );
536 zFound = true;
537 }
538 if ( zFound && mFound )
539 break;
540 }
541
542 return zFound || mFound;
543 }
544
561 static bool transferFirstZOrMValueToPoint( const QgsPointSequence &points, QgsPoint &point )
562 {
563 return QgsGeometryUtils::transferFirstZOrMValueToPoint( points.constBegin(), points.constEnd(), point );
564 }
565
582 static bool transferFirstZOrMValueToPoint( const QgsGeometry &geom, QgsPoint &point )
583 {
585 }
586
594
596 template<class T> static double closestSegmentFromComponents( T &container, ComponentType ctype, const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon ) SIP_SKIP
597 {
598 double minDist = std::numeric_limits<double>::max();
599 double minDistSegmentX = 0.0, minDistSegmentY = 0.0;
600 QgsVertexId minDistVertexAfter;
601 int minDistLeftOf = 0;
602 double sqrDist = 0.0;
603 int vertexOffset = 0;
604 int ringOffset = 0;
605 int partOffset = 0;
606
607 for ( int i = 0; i < container.size(); ++i )
608 {
609 sqrDist = container.at( i )->closestSegment( pt, segmentPt, vertexAfter, leftOf, epsilon );
610 if ( sqrDist >= 0 && sqrDist < minDist )
611 {
612 minDist = sqrDist;
613 minDistSegmentX = segmentPt.x();
614 minDistSegmentY = segmentPt.y();
615 minDistVertexAfter = vertexAfter;
616 minDistVertexAfter.vertex = vertexAfter.vertex + vertexOffset;
617 minDistVertexAfter.part = vertexAfter.part + partOffset;
618 minDistVertexAfter.ring = vertexAfter.ring + ringOffset;
619 if ( leftOf )
620 {
621 minDistLeftOf = *leftOf;
622 }
623 }
624
625 if ( ctype == Vertex )
626 {
627 //-1 because compoundcurve counts duplicated vertices of neighbour curves as one node
628 vertexOffset += container.at( i )->nCoordinates() - 1;
629 }
630 else if ( ctype == Ring )
631 {
632 ringOffset += 1;
633 }
634 else if ( ctype == Part )
635 {
636 partOffset += 1;
637 }
638 }
639
640 if ( minDist == std::numeric_limits<double>::max() )
641 return -1; // error: no segments
642
643 segmentPt.setX( minDistSegmentX );
644 segmentPt.setY( minDistSegmentY );
645 vertexAfter = minDistVertexAfter;
646 if ( leftOf )
647 {
648 *leftOf = minDistLeftOf;
649 }
650 return minDist;
651 }
652
653 /******************************/
654 /* From QgsGeometryUtils_Base */
655 /******************************/
656
662 Q_DECL_DEPRECATED static double sqrDistance2D( double x1, double y1, double x2, double y2 ) SIP_DEPRECATED SIP_HOLDGIL {return QgsGeometryUtilsBase::sqrDistance2D( x1, y1, x2, y2 ); }
663
667 static double sqrDistance2D( const QgsPoint &pt1, const QgsPoint &pt2 ) SIP_HOLDGIL
668 {
669 return QgsGeometryUtilsBase::sqrDistance2D( pt1.x(), pt1.y(), pt2.x(), pt2.y() );
670 }
671
678 static double sqrDistance3D( const QgsPoint &pt1, const QgsPoint &pt2 ) SIP_HOLDGIL
679 {
680 return QgsGeometryUtilsBase::sqrDistance3D( pt1.x(), pt1.y(), pt1.z(), pt2.x(), pt2.y(), pt2.z() );
681 }
682
688 Q_DECL_DEPRECATED static double distance2D( double x1, double y1, double x2, double y2 ) SIP_DEPRECATED SIP_HOLDGIL {return QgsGeometryUtilsBase::distance2D( x1, y1, x2, y2 ); }
689
693 static double distance2D( const QgsPoint &pt1, const QgsPoint &pt2 ) SIP_HOLDGIL { return QgsGeometryUtilsBase::distance2D( pt1.x(), pt1.y(), pt2.x(), pt2.y() );}
694
701 static double distance3D( const QgsPoint &pt1, const QgsPoint &pt2 ) SIP_HOLDGIL
702 {
703 return QgsGeometryUtilsBase::distance3D( pt1.x(), pt1.y(), pt1.z(), pt2.x(), pt2.y(), pt2.z() );
704 }
705
706
712 Q_DECL_DEPRECATED static double sqrDistToLine( double ptX, double ptY, double x1, double y1, double x2, double y2, double &minDistX SIP_OUT, double &minDistY SIP_OUT, double epsilon ) SIP_DEPRECATED SIP_HOLDGIL
713 {
714 return QgsGeometryUtilsBase::sqrDistToLine( ptX, ptY, x1, y1, x2, y2, minDistX, minDistY, epsilon );
715 }
716
726 Q_DECL_DEPRECATED static int leftOfLine( const double x, const double y, const double x1, const double y1, const double x2, const double y2 ) SIP_DEPRECATED SIP_HOLDGIL
727 {
728 return QgsGeometryUtilsBase::leftOfLine( x, y, x1, y1, x2, y2 ) ;
729 }
730
741 Q_DECL_DEPRECATED static void pointOnLineWithDistance( double x1, double y1, double x2, double y2, double distance, double &x, double &y,
742 double *z1 = nullptr, double *z2 = nullptr, double *z = nullptr,
743 double *m1 = nullptr, double *m2 = nullptr, double *m = nullptr ) SIP_SKIP
744 {
745 return QgsGeometryUtilsBase::pointOnLineWithDistance( x1, y1, x2, y2, distance, x, y,
746 z1, z2, z,
747 m1, m2, m );
748 }
749
778 Q_DECL_DEPRECATED static void perpendicularOffsetPointAlongSegment( double x1, double y1, double x2, double y2, double proportion, double offset, double *x SIP_OUT, double *y SIP_OUT )
779 {
780 QgsGeometryUtilsBase::perpendicularOffsetPointAlongSegment( x1, y1, x2, y2, proportion, offset, x, y );
781 }
782
783
784
785
791 Q_DECL_DEPRECATED static double ccwAngle( double dy, double dx ) SIP_DEPRECATED SIP_HOLDGIL
792 {
793 return QgsGeometryUtilsBase::ccwAngle( dy, dx );
794 }
795
796
805 Q_DECL_DEPRECATED static bool circleClockwise( double angle1, double angle2, double angle3 ) SIP_DEPRECATED SIP_HOLDGIL
806 {
807 return QgsGeometryUtilsBase::circleClockwise( angle1, angle2, angle3 );
808 }
809
815 Q_DECL_DEPRECATED static bool circleAngleBetween( double angle, double angle1, double angle2, bool clockwise ) SIP_DEPRECATED SIP_HOLDGIL
816 {
817 return QgsGeometryUtilsBase::circleAngleBetween( angle, angle1, angle2, clockwise );
818 }
819
826 Q_DECL_DEPRECATED static bool angleOnCircle( double angle, double angle1, double angle2, double angle3 ) SIP_DEPRECATED SIP_HOLDGIL
827 {
828 return QgsGeometryUtilsBase::angleOnCircle( angle, angle1, angle2, angle3 );
829 }
830
836 Q_DECL_DEPRECATED static double circleLength( double x1, double y1, double x2, double y2, double x3, double y3 ) SIP_DEPRECATED SIP_HOLDGIL
837 {
838 return QgsGeometryUtilsBase::circleLength( x1, y1, x2, y2, x3, y3 );
839 }
840
846 Q_DECL_DEPRECATED static double sweepAngle( double centerX, double centerY, double x1, double y1, double x2, double y2, double x3, double y3 ) SIP_DEPRECATED SIP_HOLDGIL
847 {
848 return QgsGeometryUtilsBase::sweepAngle( centerX, centerY, x1, y1, x2, y2, x3, y3 );
849 }
850
855 Q_DECL_DEPRECATED static double interpolateArcValue( double angle, double a1, double a2, double a3, double zm1, double zm2, double zm3 ) SIP_DEPRECATED SIP_HOLDGIL
856 {
857 return QgsGeometryUtilsBase::interpolateArcValue( angle, a1, a2, a3, zm1, zm2, zm3 );
858 }
859
867 Q_DECL_DEPRECATED static double normalizedAngle( double angle ) SIP_DEPRECATED SIP_HOLDGIL
868 {
870 }
871
882 Q_DECL_DEPRECATED static double lineAngle( double x1, double y1, double x2, double y2 ) SIP_DEPRECATED SIP_HOLDGIL
883 {
884 return QgsGeometryUtilsBase::lineAngle( x1, y1, x2, y2 );
885 }
886
900 Q_DECL_DEPRECATED static double angleBetweenThreePoints( double x1, double y1, double x2, double y2, double x3, double y3 ) SIP_DEPRECATED SIP_HOLDGIL
901 {
902 return QgsGeometryUtilsBase::angleBetweenThreePoints( x1, y1, x2, y2, x3, y3 );
903 }
904
916 Q_DECL_DEPRECATED static double linePerpendicularAngle( double x1, double y1, double x2, double y2 ) SIP_DEPRECATED SIP_HOLDGIL
917 {
918 return QgsGeometryUtilsBase::linePerpendicularAngle( x1, y1, x2, y2 );
919 }
920
927 Q_DECL_DEPRECATED static double averageAngle( double x1, double y1, double x2, double y2, double x3, double y3 ) SIP_DEPRECATED SIP_HOLDGIL
928 {
929 return QgsGeometryUtilsBase::averageAngle( x1, y1, x2, y2, x3, y3 );
930 }
931
940 Q_DECL_DEPRECATED static double averageAngle( double a1, double a2 ) SIP_DEPRECATED SIP_HOLDGIL
941 {
942 return QgsGeometryUtilsBase::averageAngle( a1, a2 );
943 }
944
945
969 Q_DECL_DEPRECATED static int closestSideOfRectangle( double right, double bottom, double left, double top, double x, double y )
970 {
971 return QgsGeometryUtilsBase::closestSideOfRectangle( right, bottom, left, top, x, y );
972 }
973
997 Q_DECL_DEPRECATED static void perpendicularCenterSegment( double centerPointX, double centerPointY,
998 double segmentPoint1x, double segmentPoint1y,
999 double segmentPoint2x, double segmentPoint2y,
1000 double &perpendicularSegmentPoint1x SIP_OUT, double &perpendicularSegmentPoint1y SIP_OUT,
1001 double &perpendicularSegmentPoint2x SIP_OUT, double &perpendicularSegmentPoint2y SIP_OUT,
1002 double segmentLength = 0 ) SIP_HOLDGIL
1003 {
1004 return QgsGeometryUtilsBase::perpendicularCenterSegment( centerPointX, centerPointY, segmentPoint1x, segmentPoint1y, segmentPoint2x, segmentPoint2y, perpendicularSegmentPoint1x, perpendicularSegmentPoint1y, perpendicularSegmentPoint2x, perpendicularSegmentPoint2y, segmentLength );
1005 }
1006
1017 Q_DECL_DEPRECATED static double skewLinesDistance( const QgsVector3D &P1, const QgsVector3D &P12, const QgsVector3D &P2, const QgsVector3D &P22 ) SIP_DEPRECATED SIP_HOLDGIL
1018 {
1019 return QgsGeometryUtilsBase::skewLinesDistance( P1, P12, P2, P22 );
1020 }
1021
1034 Q_DECL_DEPRECATED static bool skewLinesProjection( const QgsVector3D &P1, const QgsVector3D &P12,
1035 const QgsVector3D &P2, const QgsVector3D &P22,
1036 QgsVector3D &X1 SIP_OUT,
1037 double epsilon = 0.0001 ) SIP_HOLDGIL
1038 {
1039 return QgsGeometryUtilsBase::skewLinesProjection( P1, P12, P2, P22, X1, epsilon );
1040 }
1041
1042
1081 Q_DECL_DEPRECATED static bool linesIntersection3D( const QgsVector3D &La1, const QgsVector3D &La2,
1082 const QgsVector3D &Lb1, const QgsVector3D &Lb2,
1083 QgsVector3D &intersection SIP_OUT ) SIP_HOLDGIL
1084 {
1085 return QgsGeometryUtilsBase::linesIntersection3D( La1, La2, Lb1, Lb2, intersection );
1086 }
1087
1095 Q_DECL_DEPRECATED static double triangleArea( double aX, double aY, double bX, double bY, double cX, double cY ) SIP_DEPRECATED SIP_HOLDGIL
1096 {
1097 return QgsGeometryUtilsBase::triangleArea( aX, aY, bX, bY, cX, cY );
1098 }
1099
1109 Q_DECL_DEPRECATED static double pointFractionAlongLine( double x1, double y1, double x2, double y2, double px, double py )
1110 {
1111 return QgsGeometryUtilsBase::pointFractionAlongLine( x1, y1, x2, y2, px, py );
1112 }
1113
1132 Q_DECL_DEPRECATED static void weightedPointInTriangle( double aX, double aY, double bX, double bY, double cX, double cY,
1133 double weightB, double weightC, double &pointX SIP_OUT, double &pointY SIP_OUT ) SIP_HOLDGIL
1134 {
1135 return QgsGeometryUtilsBase::weightedPointInTriangle( aX, aY, bX, bY, cX, cY, weightB, weightC, pointX, pointY );
1136 }
1137
1145 Q_DECL_DEPRECATED static bool pointsAreCollinear( double x1, double y1, double x2, double y2, double x3, double y3, double epsilon )
1146 {
1147 return QgsGeometryUtilsBase::pointsAreCollinear( x1, y1, x2, y2, x3, y3, epsilon );
1148 }
1149
1171 Q_DECL_DEPRECATED static bool angleBisector( double aX, double aY, double bX, double bY, double cX, double cY, double dX, double dY,
1172 double &pointX SIP_OUT, double &pointY SIP_OUT, double &angle SIP_OUT ) SIP_HOLDGIL
1173 {
1174 return QgsGeometryUtilsBase::angleBisector( aX, aY, bX, bY, cX, cY, dX, dY, pointX, pointY, angle );
1175 }
1176
1194 Q_DECL_DEPRECATED static bool bisector( double aX, double aY, double bX, double bY, double cX, double cY,
1195 double &pointX SIP_OUT, double &pointY SIP_OUT ) SIP_HOLDGIL
1196 {
1197 return QgsGeometryUtilsBase::bisector( aX, aY, bX, bY, cX, cY, pointX, pointY );
1198 }
1199
1203 static void circleCenterRadius( const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double &radius SIP_OUT,
1204 double &centerX SIP_OUT, double &centerY SIP_OUT ) SIP_HOLDGIL
1205 {
1206 return QgsGeometryUtilsBase::circleCenterRadius( pt1.x(), pt1.y(), pt2.x(), pt2.y(), pt3.x(), pt3.y(), radius, centerX, centerY );
1207 }
1208
1220 static bool lineIntersection( const QgsPoint &p1, QgsVector v1, const QgsPoint &p2, QgsVector v2, QgsPoint &intersection SIP_OUT ) SIP_HOLDGIL
1221 {
1222 double intersectionX = 0.0, intersectionY = 0.0;
1223 bool result = QgsGeometryUtilsBase::lineIntersection( p1.x(), p1.y(), v1, p2.x(), p2.y(), v2, intersectionX, intersectionY );
1224 intersection = QgsPoint( intersectionX, intersectionY );
1225
1226 // z and m support for intersection point
1228
1229 return result;
1230 }
1231
1268 static bool segmentIntersection( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint SIP_OUT, bool &isIntersection SIP_OUT, double tolerance = 1e-8, bool acceptImproperIntersection = false ) SIP_HOLDGIL
1269 {
1270 double intersectionPointX = 0.0, intersectionPointY = 0.0;
1271 bool result = QgsGeometryUtilsBase::segmentIntersection( p1.x(), p1.y(), p2.x(), p2.y(), q1.x(), q1.y(), q2.x(), q2.y(), intersectionPointX, intersectionPointY, isIntersection, tolerance, acceptImproperIntersection );
1272 intersectionPoint.setX( intersectionPointX );
1273 intersectionPoint.setY( intersectionPointY );
1274 return result;
1275 }
1276
1277
1278};
1279#include "qgsgeometryutils_base.h"
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
Abstract base class for all geometries.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
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.
static double sqrDistance2D(double x1, double y1, double x2, double y2)
Returns the squared 2D distance between (x1, y1) and (x2, y2).
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 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,...
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 distance2D(double x1, double y1, double x2, double y2)
Returns the 2D distance between (x1, y1) and (x2, y2).
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 double linePerpendicularAngle(double x1, double y1, double x2, double y2)
Calculates the perpendicular angle to a line joining two points.
static bool bisector(double aX, double aY, double bX, double bY, double cX, double cY, double &pointX, double &pointY)
Returns the point (pointX, pointY) forming the bisector from point (aX, aY) to the segment (bX,...
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 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.
static int closestSideOfRectangle(double right, double bottom, double left, double top, double x, double y)
Returns a number representing the closest side of a rectangle defined by /a right,...
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 void perpendicularOffsetPointAlongSegment(double x1, double y1, double x2, double y2, double proportion, double offset, double *x, double *y)
Calculates a point a certain proportion of the way along the segment from (x1, y1) to (x2,...
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.
static double pointFractionAlongLine(double x1, double y1, double x2, double y2, double px, double py)
Given the line (x1, y1) to (x2, y2) and a point (px, py) returns the fraction of the line length at w...
static double normalizedAngle(double angle)
Ensures that an angle is in the range 0 <= angle < 2 pi.
static void weightedPointInTriangle(double aX, double aY, double bX, double bY, double cX, double cY, double weightB, double weightC, double &pointX, double &pointY)
Returns a weighted point inside the triangle denoted by the points (aX, aY), (bX, bY) and (cX,...
static void perpendicularCenterSegment(double centerPointX, double centerPointY, double segmentPoint1x, double segmentPoint1y, double segmentPoint2x, double segmentPoint2y, double &perpendicularSegmentPoint1x, double &perpendicularSegmentPoint1y, double &perpendicularSegmentPoint2x, double &perpendicularSegmentPoint2y, double segmentLength=0)
Create a perpendicular line segment to a given segment [segmentPoint1,segmentPoint2] with its center ...
static double distance3D(double x1, double y1, double z1, double x2, double y2, double z2)
Returns the 3D distance between (x1, y1), (x2, y2) and (z2, z2).
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 triangleArea(double aX, double aY, double bX, double bY, double cX, double cY)
Returns the area of the triangle denoted by the points (aX, aY), (bX, bY) and (cX,...
static bool angleBisector(double aX, double aY, double bX, double bY, double cX, double cY, double dX, double dY, double &pointX, double &pointY, double &angle)
Returns the point (pointX, pointY) forming the bisector from segment (aX aY) (bX bY) and segment (bX,...
static double sqrDistance3D(double x1, double y1, double z1, double x2, double y2, double z2)
Returns the squared 3D distance between (x1, y1), (x2, y2) and (z2, z2).
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 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,...
static bool segmentIntersection(double p1x, double p1y, double p2x, double p2y, double q1x, double q1y, double q2x, double q2y, double &intersectionPointX, double &intersectionPointY, bool &isIntersection, double tolerance=1e-8, bool acceptImproperIntersection=false)
Compute the intersection between two segments.
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 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.
static bool pointsAreCollinear(double x1, double y1, double x2, double y2, double x3, double y3, double epsilon)
Given the points (x1, y1), (x2, y2) and (x3, y3) returns true if these points can be considered colli...
static void circleCenterRadius(double x1, double y1, double x2, double y2, double x3, double y3, double &radius, double &centerX, double &centerY)
Returns radius and center of the circle through (x1 y1), (x2 y2), (x3 y3)
static bool lineIntersection(double p1x, double p1y, QgsVector v1, double p2x, double p2y, QgsVector v2, double &intersectionX, double &intersectionY)
Computes the intersection between two lines.
Contains various geometry utility functions.
static Q_DECL_DEPRECATED double linePerpendicularAngle(double x1, double y1, double x2, double y2)
Calculates the perpendicular angle to a line joining two points.
static bool lineIntersection(const QgsPoint &p1, QgsVector v1, const QgsPoint &p2, QgsVector v2, QgsPoint &intersection)
Computes the intersection between two lines.
static Q_DECL_DEPRECATED double triangleArea(double aX, double aY, double bX, double bY, double cX, double cY)
Returns the area of the triangle denoted by the points (aX, aY), (bX, bY) and (cX,...
static Q_DECL_DEPRECATED 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 Q_DECL_DEPRECATED bool circleClockwise(double angle1, double angle2, double angle3)
Returns true if the circle defined by three angles is ordered clockwise.
static Q_DECL_DEPRECATED 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 bool transferFirstZOrMValueToPoint(const QgsPointSequence &points, 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 QgsPoint projectPointOnSegment(const QgsPoint &p, const QgsPoint &s1, const QgsPoint &s2)
Project the point on a segment.
static Q_DECL_DEPRECATED 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 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 Q_DECL_DEPRECATED void perpendicularOffsetPointAlongSegment(double x1, double y1, double x2, double y2, double proportion, double offset, double *x, double *y)
Calculates a point a certain proportion of the way along the segment from (x1, y1) to (x2,...
static Q_DECL_DEPRECATED 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 Q_DECL_DEPRECATED double averageAngle(double a1, double a2)
Averages two angles, correctly handling negative angles and ensuring the result is between 0 and 2 pi...
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.
static Q_DECL_DEPRECATED 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 Q_DECL_DEPRECATED 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 Q_DECL_DEPRECATED double distance2D(double x1, double y1, double x2, double y2)
Returns the 2D distance between (x1, y1) and (x2, y2).
static bool transferFirstZOrMValueToPoint(const QgsGeometry &geom, 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 Q_DECL_DEPRECATED void perpendicularCenterSegment(double centerPointX, double centerPointY, double segmentPoint1x, double segmentPoint1y, double segmentPoint2x, double segmentPoint2y, double &perpendicularSegmentPoint1x, double &perpendicularSegmentPoint1y, double &perpendicularSegmentPoint2x, double &perpendicularSegmentPoint2y, double segmentLength=0)
Create a perpendicular line segment to a given segment [segmentPoint1,segmentPoint2] with its center ...
static Q_DECL_DEPRECATED 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.
static Q_DECL_DEPRECATED 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,...
static Q_DECL_DEPRECATED 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.
static Q_DECL_DEPRECATED bool pointsAreCollinear(double x1, double y1, double x2, double y2, double x3, double y3, double epsilon)
Given the points (x1, y1), (x2, y2) and (x3, y3) returns true if these points can be considered colli...
static double closestSegmentFromComponents(T &container, ComponentType ctype, const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon)
static double distance2D(const QgsPoint &pt1, const QgsPoint &pt2)
Returns the 2D distance between two points.
static double sqrDistance2D(const QgsPoint &pt1, const QgsPoint &pt2)
Returns the squared 2D distance between two points.
static Q_DECL_DEPRECATED bool angleBisector(double aX, double aY, double bX, double bY, double cX, double cY, double dX, double dY, double &pointX, double &pointY, double &angle)
Returns the point (pointX, pointY) forming the bisector from segment (aX aY) (bX bY) and segment (bX,...
static Q_DECL_DEPRECATED double normalizedAngle(double angle)
Ensures that an angle is in the range 0 <= angle < 2 pi.
static Q_DECL_DEPRECATED bool circleAngleBetween(double angle, double angle1, double angle2, bool clockwise)
Returns true if, in a circle, angle is between angle1 and angle2.
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 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 Q_DECL_DEPRECATED 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 Q_DECL_DEPRECATED 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 Q_DECL_DEPRECATED 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.
static double distance3D(const QgsPoint &pt1, const QgsPoint &pt2)
Returns the 3D distance between two points.
static Q_DECL_DEPRECATED int closestSideOfRectangle(double right, double bottom, double left, double top, double x, double y)
Returns a number representing the closest side of a rectangle defined by /a right,...
static Q_DECL_DEPRECATED 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,...
static Q_DECL_DEPRECATED double pointFractionAlongLine(double x1, double y1, double x2, double y2, double px, double py)
Given the line (x1, y1) to (x2, y2) and a point (px, py) returns the fraction of the line length at w...
static Q_DECL_DEPRECATED bool bisector(double aX, double aY, double bX, double bY, double cX, double cY, double &pointX, double &pointY)
Returns the point (pointX, pointY) forming the bisector from point (aX, aY) to the segment (bX,...
static double sqrDistance3D(const QgsPoint &pt1, const QgsPoint &pt2)
Returns the squared 3D distance between two points.
static Q_DECL_DEPRECATED 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.
static Q_DECL_DEPRECATED void weightedPointInTriangle(double aX, double aY, double bX, double bY, double cX, double cY, double weightB, double weightC, double &pointX, double &pointY)
Returns a weighted point inside the triangle denoted by the points (aX, aY), (bX, bY) and (cX,...
A geometry is the spatial representation of a feature.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
Line string geometry type, with support for z-dimension and m-values.
A class to represent a 2D point.
Definition qgspointxy.h:60
double y
Definition qgspointxy.h:64
double x
Definition qgspointxy.h:63
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
double x
Definition qgspoint.h:52
void setM(double m)
Sets the point's m-value.
Definition qgspoint.h:371
bool convertTo(Qgis::WkbType type) override
Converts the geometry to a specified type.
Definition qgspoint.cpp:622
void setZ(double z)
Sets the point's z-coordinate.
Definition qgspoint.h:356
double y
Definition qgspoint.h:53
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
A class to represent a vector.
Definition qgsvector.h:30
WKB pointer handler.
Definition qgswkbptr.h:44
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.
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
#define SIP_PYALTERNATIVETYPE(type)
Definition qgis_sip.h:141
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_HOLDGIL
Definition qgis_sip.h:171
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_INOUT
Definition qgis_sip.h:71
QVector< QgsPoint > QgsPointSequence
int precision
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30
int vertex
Vertex number.
Definition qgsvertexid.h:94
int part
Part number.
Definition qgsvertexid.h:88
int ring
Ring number.
Definition qgsvertexid.h:91