21#include <nlohmann/json.hpp>
34#include <QPainterPath>
37using namespace Qt::StringLiterals;
47 bool hasZ = p1.
is3D();
80 int pointCount = std::min( x.size(), y.size() );
81 if ( x.size() == pointCount )
87 mX = x.mid( 0, pointCount );
89 if ( y.size() == pointCount )
95 mY = y.mid( 0, pointCount );
97 if ( !z.isEmpty() && z.count() >= pointCount )
100 if ( z.size() == pointCount )
106 mZ = z.mid( 0, pointCount );
109 if ( !m.isEmpty() && m.count() >= pointCount )
112 if ( m.size() == pointCount )
118 mM = m.mid( 0, pointCount );
131 auto result = std::make_unique< QgsCircularString >();
133 return result.release();
138 return u
"CircularString"_s;
156 for (
int i = 0; i < ( nPoints - 2 ); i += 2 )
159 double zMin = std::numeric_limits<double>::quiet_NaN();
160 double zMax = std::numeric_limits<double>::quiet_NaN();
163 zMin = *std::min_element(
mZ.begin() + i,
mZ.begin() + i + 3 );
164 zMax = *std::max_element(
mZ.begin() + i,
mZ.begin() + i + 3 );
168 bbox =
QgsBox3D( box2d, zMin, zMax );
176 if ( nPoints > 0 && nPoints % 2 == 0 )
178 double z = std::numeric_limits<double>::quiet_NaN();
198 double centerX, centerY, radius;
207 bbox.combineExtentWith( pt3.
x(), pt3.
y() );
209 QgsPointSequence compassPoints = compassPointsOnSegment( p1Angle, p2Angle, p3Angle, centerX, centerY, radius );
210 QgsPointSequence::const_iterator cpIt = compassPoints.constBegin();
211 for ( ; cpIt != compassPoints.constEnd(); ++cpIt )
213 bbox.combineExtentWith( cpIt->x(), cpIt->y() );
218QgsPointSequence QgsCircularString::compassPointsOnSegment(
double p1Angle,
double p2Angle,
double p3Angle,
double centerX,
double centerY,
double radius )
222 QgsPoint nPoint( centerX, centerY + radius );
223 QgsPoint ePoint( centerX + radius, centerY );
224 QgsPoint sPoint( centerX, centerY - radius );
225 QgsPoint wPoint( centerX - radius, centerY );
227 if ( p3Angle >= p1Angle )
229 if ( p2Angle > p1Angle && p2Angle < p3Angle )
231 if ( p1Angle <= 90 && p3Angle >= 90 )
233 pointList.append( nPoint );
235 if ( p1Angle <= 180 && p3Angle >= 180 )
237 pointList.append( wPoint );
239 if ( p1Angle <= 270 && p3Angle >= 270 )
241 pointList.append( sPoint );
246 pointList.append( ePoint );
247 if ( p1Angle >= 90 || p3Angle <= 90 )
249 pointList.append( nPoint );
251 if ( p1Angle >= 180 || p3Angle <= 180 )
253 pointList.append( wPoint );
255 if ( p1Angle >= 270 || p3Angle <= 270 )
257 pointList.append( sPoint );
263 if ( p2Angle < p1Angle && p2Angle > p3Angle )
265 if ( p1Angle >= 270 && p3Angle <= 270 )
267 pointList.append( sPoint );
269 if ( p1Angle >= 180 && p3Angle <= 180 )
271 pointList.append( wPoint );
273 if ( p1Angle >= 90 && p3Angle <= 90 )
275 pointList.append( nPoint );
280 pointList.append( ePoint );
281 if ( p1Angle <= 270 || p3Angle >= 270 )
283 pointList.append( sPoint );
285 if ( p1Angle <= 180 || p3Angle >= 180 )
287 pointList.append( wPoint );
289 if ( p1Angle <= 90 || p3Angle >= 90 )
291 pointList.append( nPoint );
301 std::unique_ptr< QgsLineString > line(
curveToLine() );
302 QDomElement gml = line->asGml2( doc, precision, ns, axisOrder );
311 QDomElement elemCurve = doc.createElementNS( ns, u
"Curve"_s );
316 QDomElement elemSegments = doc.createElementNS( ns, u
"segments"_s );
317 QDomElement elemArcString = doc.createElementNS( ns, u
"ArcString"_s );
319 elemSegments.appendChild( elemArcString );
320 elemCurve.appendChild( elemSegments );
332 std::unique_ptr< QgsLineString > line(
curveToLine() );
333 return line->asJsonObject( precision, profile );
341 constexpr int MAX_POINT = 11;
342 if ( pts.size() > MAX_POINT )
344 json geometries = json::array();
345 json subCs = { {
"type",
"CircularString" } };
346 subCs[
"coordinates"] = json::array();
347 for (
int i = 0; i < pts.size(); i++ )
349 const json pointCoords = pts[i].asJsonObject( precision, profile )[
"coordinates"];
350 subCs[
"coordinates"].push_back( pointCoords );
351 if ( subCs[
"coordinates"].size() == MAX_POINT )
353 geometries.push_back( subCs );
355 subCs[
"coordinates"] = json::array();
356 subCs[
"coordinates"].push_back( pointCoords );
360 if ( subCs[
"coordinates"].size() > 1 )
362 geometries.push_back( subCs );
364 return { {
"type",
"CompoundCurve" }, {
"geometries", geometries } };
379 error = QObject::tr(
"CircularString has less than 3 points and is not empty." );
390 for (
int i = 0; i < ( nPoints - 2 ); i += 2 )
403 for (
int i = 0; i < ( nPoints - 2 ); i += 2 )
418 bool res =
snapToGridPrivate( hSpacing, vSpacing, dSpacing, mSpacing,
mX,
mY,
mZ,
mM, result->mX, result->mY, result->mZ, result->mM,
false );
420 return result.release();
427 std::unique_ptr< QgsLineString > line(
curveToLine() );
428 return line->simplifyByDistance( tolerance );
433 if (
mX.count() <= 3 )
436 double prevX =
mX.at( 0 );
437 double prevY =
mY.at( 0 );
439 bool useZ = hasZ && useZValues;
440 double prevZ = useZ ?
mZ.at( 0 ) : 0;
442 int remaining =
mX.count();
445 while ( i + 1 < remaining )
447 double currentCurveX =
mX.at( i );
448 double currentCurveY =
mY.at( i );
449 double currentX =
mX.at( i + 1 );
450 double currentY =
mY.at( i + 1 );
451 double currentZ = useZ ?
mZ.at( i + 1 ) : 0;
484 const int size =
mX.size();
488 const double *x =
mX.constData();
489 const double *y =
mY.constData();
490 const bool useZ =
is3D();
492 const double *z = useZ ?
mZ.constData() :
nullptr;
493 const double *m = useM ?
mM.constData() :
nullptr;
495 for (
int i = 0; i < size; i += 2 )
521 QVector< double > x1, y1, z1, m1;
522 QVector< double > x2, y2, z2, m2;
525 std::unique_ptr< QgsCircularString > first;
526 if ( x1.isEmpty() || ( x1.size() < 2 && x2.size() >= 2 ) )
527 first = std::make_unique< QgsCircularString >();
529 first = std::make_unique< QgsCircularString >( x1, y1, z1, m1 );
531 std::unique_ptr< QgsCircularString > second;
532 if ( x2.isEmpty() || x2.size() < 2 )
533 second = std::make_unique< QgsCircularString >();
535 second = std::make_unique< QgsCircularString >( x2, y2, z2, m2 );
537 return std::make_tuple( std::move( first ), std::move( second ) );
547void arcTo( QPainterPath &path, QPointF pt1, QPointF pt2, QPointF pt3 )
549 double centerX, centerY, radius;
555 double diameter = 2 * radius;
556 path.arcTo( centerX - radius, centerY - radius, diameter, diameter, -p1Angle, -sweepAngle );
567 if ( path.isEmpty() || path.currentPosition() != QPointF(
mX[0],
mY[0] ) )
569 path.moveTo( QPointF(
mX[0],
mY[0] ) );
572 for (
int i = 0; i < ( nPoints - 2 ); i += 2 )
574 arcTo( path, QPointF(
mX[i],
mY[i] ), QPointF(
mX[i + 1],
mY[i + 1] ), QPointF(
mX[i + 2],
mY[i + 2] ) );
578 if ( nPoints % 2 == 0 )
580 path.lineTo(
mX[nPoints - 1],
mY[nPoints - 1] );
596 mX.insert( position.
vertex, vertex.
x() );
597 mY.insert( position.
vertex, vertex.
y() );
600 mZ.insert( position.
vertex, vertex.
z() );
604 mM.insert( position.
vertex, vertex.
m() );
607 bool vertexNrEven = ( position.
vertex % 2 == 0 );
620void QgsCircularString::removeVertexAt(
int i )
637 if ( positions.empty() )
652 QList<QgsVertexId>
vertices( positions.begin(), positions.end() );
657 for (
size_t i =
vertices.size() - 1; i >= 1; i-- )
660 int prevVertexNr =
vertices[i - 1].vertex;
662 if ( vertexNr - 1 == prevVertexNr )
664 if ( vertexNr < nVertices - 2 )
681 if ( nVertices -
vertices.size() * 2 < 3 )
687 QListIterator<QgsVertexId> positionsIt(
vertices );
688 positionsIt.toBack();
689 while ( positionsIt.hasPrevious() )
691 int currentVertexNr = positionsIt.previous().vertex;
693 if ( currentVertexNr < nVertices - 2 )
695 removeVertexAt( currentVertexNr + 1 );
696 removeVertexAt( currentVertexNr );
700 removeVertexAt( currentVertexNr );
701 removeVertexAt( currentVertexNr - 1 );
711 double minDist = std::numeric_limits<double>::max();
714 int minDistLeftOf = 0;
716 double currentDist = 0.0;
719 for (
int i = 0; i < ( nPoints - 2 ); i += 2 )
721 currentDist = closestPointOnArc(
mX[i],
mY[i],
mX[i + 1],
mY[i + 1],
mX[i + 2],
mY[i + 2], pt, segmentPt, vertexAfter, leftOf, epsilon );
722 if ( currentDist < minDist )
724 minDist = currentDist;
725 minDistSegmentPoint = segmentPt;
729 minDistLeftOf = *leftOf;
734 if ( minDist == std::numeric_limits<double>::max() )
737 segmentPt = minDistSegmentPoint;
738 vertexAfter = minDistVertexAfter;
739 vertexAfter.
part = 0;
740 vertexAfter.
ring = 0;
769 for (
int i = 0; i < maxIndex; i += 2 )
786 double midPointX = ( p1.
x() + p3.
x() ) / 2.0;
787 double midPointY = ( p1.
y() + p3.
y() ) / 2.0;
789 double radius, centerX, centerY;
793 double r2 = radius * radius;
804 double cov = 0.5 - d * std::sqrt( r2 - d * d ) / ( M_PI * r2 ) - M_1_PI * std::asin( d / radius );
805 double circleChordArea = 0;
806 if ( circlePointLeftOfLine == centerPointLeftOfLine )
808 circleChordArea = M_PI * r2 * ( 1 - cov );
812 circleChordArea = M_PI * r2 * cov;
815 if ( !circlePointLeftOfLine )
868 double normalSign = 1.0;
888 QVector<double> projX;
889 QVector<double> projY;
890 projX.reserve( nrPoints );
891 projY.reserve( nrPoints );
892 for (
int i = 0; i < nrPoints; i++ )
894 const double vecAX =
mX[i] - ptA.
x();
895 const double vecAY =
mY[i] - ptA.
y();
896 const double vecAZ =
mZ[i] - ptA.
z();
898 projX.push_back( vecAX * ux.
x() + vecAY * ux.
y() + vecAZ * ux.
z() );
899 projY.push_back( vecAX * uy.
x() + vecAY * uy.
y() + vecAZ * uy.
z() );
916double QgsCircularString::closestPointOnArc(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
const QgsPoint &pt,
QgsPoint &segmentPt,
QgsVertexId &vertexAfter,
int *leftOf,
double epsilon )
918 double radius, centerX, centerY;
943 segmentPt = ( distPtPt1 <= distPtPt3 ) ? pt1 : pt3;
944 vertexAfter.
vertex = ( distPtPt1 <= distPtPt3 ) ? 1 : 2;
951 segmentPt.
setX( pt.
x() );
952 segmentPt.
setY( pt.
y() );
958 double sqrDistancePointToCenter = pt.
distanceSquared( centerX, centerY );
959 *
leftOf = clockwise ? ( sqrDistancePointToCenter > radius * radius ? -1 : 1 ) : ( sqrDistancePointToCenter < radius * radius ? -1 : 1 );
965void QgsCircularString::insertVertexBetween(
int after,
int before,
int pointOnCircle )
967 double xAfter =
mX.at( after );
968 double yAfter =
mY.at( after );
969 double xBefore =
mX.at( before );
970 double yBefore =
mY.at( before );
971 double xOnCircle =
mX.at( pointOnCircle );
972 double yOnCircle =
mY.at( pointOnCircle );
974 double radius, centerX, centerY;
977 double x = ( xAfter + xBefore ) / 2.0;
978 double y = ( yAfter + yBefore ) / 2.0;
981 mX.insert( before, newVertex.
x() );
982 mY.insert( before, newVertex.
y() );
986 mZ.insert( before, (
mZ[after] +
mZ[before] ) / 2.0 );
990 mM.insert( before, (
mM[after] +
mM[before] ) / 2.0 );
1003 int before = vId.
vertex - 1;
1005 int after = vId.
vertex + 1;
1007 if ( vId.
vertex % 2 != 0 )
1034 int vertex1 = vId.
vertex - 2;
1035 int vertex2 = vId.
vertex - 1;
1036 int vertex3 = vId.
vertex;
1039 int vertex4 = vId.
vertex + 1;
1040 int vertex5 = vId.
vertex + 2;
1051 if ( startVertex.
vertex % 2 == 1 )
1054 if ( startVertex.
vertex < 0 || startVertex.
vertex >=
mX.count() - 2 )
1057 double x1 =
mX.at( startVertex.
vertex );
1058 double y1 =
mY.at( startVertex.
vertex );
1059 double x2 =
mX.at( startVertex.
vertex + 1 );
1060 double y2 =
mY.at( startVertex.
vertex + 1 );
1061 double x3 =
mX.at( startVertex.
vertex + 2 );
1062 double y3 =
mY.at( startVertex.
vertex + 2 );
1075 if ( fromVertex.
part != 0 || fromVertex.
ring != 0 || toVertex.
part != 0 || toVertex.
ring != 0 )
1078 const int fromVertexNumber = fromVertex.
vertex;
1079 const int toVertexNumber = toVertex.
vertex;
1082 if ( fromVertexNumber < 0 || fromVertexNumber >= nPoints || toVertexNumber < 0 || toVertexNumber >= nPoints )
1085 if ( fromVertexNumber == toVertexNumber )
1088 const double *
xData =
mX.constData();
1089 const double *
yData =
mY.constData();
1090 double totalDistance = 0.0;
1094 const int startArc = ( fromVertexNumber / 2 ) * 2;
1097 for (
int i = startArc; i < nPoints - 2; i += 2 )
1100 double x1 =
xData[i];
1101 double y1 =
yData[i];
1102 double x2 =
xData[i + 1];
1103 double y2 =
yData[i + 1];
1104 double x3 =
xData[i + 2];
1105 double y3 =
yData[i + 2];
1108 if ( fromVertexNumber >= i && toVertexNumber <= i + 2 )
1110 if ( fromVertexNumber == i && toVertexNumber == i + 2 )
1115 else if ( fromVertexNumber == i && toVertexNumber == i + 1 )
1118 double centerX, centerY, radius;
1121 return QgsGeometryUtilsBase::calculateArcLength( centerX, centerY, radius, x1, y1, x2, y2, x3, y3, 0, 1 );
1123 else if ( fromVertexNumber == i + 1 && toVertexNumber == i + 2 )
1126 double centerX, centerY, radius;
1129 return QgsGeometryUtilsBase::calculateArcLength( centerX, centerY, radius, x1, y1, x2, y2, x3, y3, 1, 2 );
1131 else if ( fromVertexNumber == i + 1 && toVertexNumber == i + 1 )
1138 bool startInThisSegment = ( fromVertexNumber >= i && fromVertexNumber <= i + 2 );
1139 bool endInThisSegment = ( toVertexNumber >= i && toVertexNumber <= i + 2 );
1140 bool segmentInRange = ( fromVertexNumber < i && toVertexNumber > i + 2 );
1142 if ( startInThisSegment && !endInThisSegment )
1145 if ( fromVertexNumber == i )
1147 else if ( fromVertexNumber == i + 1 )
1150 double centerX, centerY, radius;
1152 totalDistance +=
QgsGeometryUtilsBase::calculateArcLength( centerX, centerY, radius, x1, y1, x2, y2, x3, y3, 1, 2 );
1155 else if ( !startInThisSegment && endInThisSegment )
1158 if ( toVertexNumber == i + 1 )
1161 double centerX, centerY, radius;
1163 totalDistance +=
QgsGeometryUtilsBase::calculateArcLength( centerX, centerY, radius, x1, y1, x2, y2, x3, y3, 0, 1 );
1165 else if ( toVertexNumber == i + 2 )
1169 else if ( segmentInRange )
1176 return totalDistance;
1190 double distanceTraversed = 0;
1192 if ( totalPoints == 0 )
1201 const double *x =
mX.constData();
1202 const double *y =
mY.constData();
1203 const double *z =
is3D() ?
mZ.constData() :
nullptr;
1204 const double *m =
isMeasure() ?
mM.constData() :
nullptr;
1206 double prevX = *x++;
1207 double prevY = *y++;
1208 double prevZ = z ? *z++ : 0.0;
1209 double prevM = m ? *m++ : 0.0;
1213 return new QgsPoint( pointType, prevX, prevY, prevZ, prevM );
1216 for (
int i = 0; i < ( totalPoints - 2 ); i += 2 )
1225 double z2 = z ? *z++ : 0.0;
1226 double m2 = m ? *m++ : 0.0;
1230 double z3 = z ? *z++ : 0.0;
1231 double m3 = m ? *m++ : 0.0;
1237 const double distanceToPoint = std::min( distance - distanceTraversed,
segmentLength );
1238 return new QgsPoint(
QgsGeometryUtils::interpolatePointOnArc(
QgsPoint( pointType, x1, y1, z1, m1 ),
QgsPoint( pointType, x2, y2, z2, m2 ),
QgsPoint( pointType, x3, y3, z3, m3 ), distanceToPoint ) );
1254 if ( startDistance < 0 && endDistance < 0 )
1257 endDistance = std::max( startDistance, endDistance );
1260 if ( totalPoints == 0 )
1263 QVector< QgsPoint > substringPoints;
1264 substringPoints.reserve( totalPoints );
1272 const double *x =
mX.constData();
1273 const double *y =
mY.constData();
1274 const double *z =
is3D() ?
mZ.constData() :
nullptr;
1275 const double *m =
isMeasure() ?
mM.constData() :
nullptr;
1277 double distanceTraversed = 0;
1278 double prevX = *x++;
1279 double prevY = *y++;
1280 double prevZ = z ? *z++ : 0.0;
1281 double prevM = m ? *m++ : 0.0;
1282 bool foundStart =
false;
1284 if ( startDistance < 0 )
1287 for (
int i = 0; i < ( totalPoints - 2 ); i += 2 )
1296 double z2 = z ? *z++ : 0.0;
1297 double m2 = m ? *m++ : 0.0;
1301 double z3 = z ? *z++ : 0.0;
1302 double m3 = m ? *m++ : 0.0;
1304 bool addedSegmentEnd =
false;
1306 if ( distanceTraversed <= startDistance && startDistance < distanceTraversed +
segmentLength )
1309 const double distanceToStart = startDistance - distanceTraversed;
1311 =
QgsGeometryUtils::interpolatePointOnArc(
QgsPoint( pointType, x1, y1, z1, m1 ),
QgsPoint( pointType, x2, y2, z2, m2 ),
QgsPoint( pointType, x3, y3, z3, m3 ), distanceToStart );
1314 const bool endPointOnSegment = distanceTraversed +
segmentLength > endDistance;
1315 if ( endPointOnSegment )
1317 const double distanceToEnd = endDistance - distanceTraversed;
1318 const double midPointDistance = ( distanceToEnd - distanceToStart ) * 0.5 + distanceToStart;
1321 <<
QgsGeometryUtils::interpolatePointOnArc(
QgsPoint( pointType, x1, y1, z1, m1 ),
QgsPoint( pointType, x2, y2, z2, m2 ),
QgsPoint( pointType, x3, y3, z3, m3 ), midPointDistance )
1322 <<
QgsGeometryUtils::interpolatePointOnArc(
QgsPoint( pointType, x1, y1, z1, m1 ),
QgsPoint( pointType, x2, y2, z2, m2 ),
QgsPoint( pointType, x3, y3, z3, m3 ), distanceToEnd );
1323 addedSegmentEnd =
true;
1327 const double midPointDistance = (
segmentLength - distanceToStart ) * 0.5 + distanceToStart;
1330 <<
QgsGeometryUtils::interpolatePointOnArc(
QgsPoint( pointType, x1, y1, z1, m1 ),
QgsPoint( pointType, x2, y2, z2, m2 ),
QgsPoint( pointType, x3, y3, z3, m3 ), midPointDistance )
1331 <<
QgsPoint( pointType, x3, y3, z3, m3 );
1332 addedSegmentEnd =
true;
1336 if ( !addedSegmentEnd && foundStart && ( distanceTraversed +
segmentLength > endDistance ) )
1339 const double distanceToEnd = endDistance - distanceTraversed;
1342 <<
QgsGeometryUtils::interpolatePointOnArc(
QgsPoint( pointType, x1, y1, z1, m1 ),
QgsPoint( pointType, x2, y2, z2, m2 ),
QgsPoint( pointType, x3, y3, z3, m3 ), distanceToEnd / 2.0 )
1344 <<
QgsGeometryUtils::interpolatePointOnArc(
QgsPoint( pointType, x1, y1, z1, m1 ),
QgsPoint( pointType, x2, y2, z2, m2 ),
QgsPoint( pointType, x3, y3, z3, m3 ), distanceToEnd );
1346 else if ( !addedSegmentEnd && foundStart )
1348 substringPoints <<
QgsPoint( pointType, x2, y2, z2, m2 ) <<
QgsPoint( pointType, x3, y3, z3, m3 );
1356 if ( distanceTraversed >= endDistance )
1361 if ( !foundStart &&
qgsDoubleNear( distanceTraversed, startDistance ) )
1363 substringPoints <<
QgsPoint( pointType, prevX, prevY, prevZ, prevM ) <<
QgsPoint( pointType, prevX, prevY, prevZ, prevM ) <<
QgsPoint( pointType, prevX, prevY, prevZ, prevM );
1366 auto result = std::make_unique< QgsCircularString >();
1367 result->setPoints( substringPoints );
1368 return result.release();
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
VertexType
Types of vertex.
@ Curve
An intermediate point on a segment defining the curvature of the segment.
@ Segment
The actual start or end point of a segment.
GeoJsonProfile
GeoJson export Profile according to OGC Features and Geometries JSON - Part 1: Core https://docs....
@ Legacy
Legacy GeoJson profile used in QGIS prior to 4.2, which included some non-standard extensions and dev...
@ Rfc7946
GeoJson profile compliant with RFC7946 standard "http://www.opengis.net/def/profile/OGC/0/rfc7946".
@ JsonFg
GeoJson profile from OGC Features and Geometries JSON Part 1: core "http://www.opengis....
@ JsonFgPlus
GeoJson profile from OGC Features and Geometries JSON Part 1: core "http://www.opengis....
WkbType
The WKB type describes the number of dimensions a geometry has.
@ CircularString
CircularString.
@ CircularStringZ
CircularStringZ.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
QgsVertexIterator vertices() const
Returns a read-only, Java-style iterator for traversal of vertices of all the geometry,...
bool isMeasure() const
Returns true if the geometry contains m values.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
AxisOrder
Axis order for GML generation.
QgsAbstractGeometry()=default
A 3-dimensional box composed of x, y, z coordinates.
void combineWith(const QgsBox3D &box)
Expands the bbox so that it covers both the original rectangle and the given rectangle.
QgsCircularString * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0, bool removeRedundantPoints=false) const override
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
double length() const override
Returns the planar, 2-dimensional length of the geometry.
QString geometryType() const override
Returns a unique string representing the geometry type.
QgsCircularString * clone() const override
Clones the geometry by performing a deep copy.
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
QgsCircularString * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const override
Searches for the closest segment of the geometry to a given point.
double distanceBetweenVertices(QgsVertexId fromVertex, QgsVertexId toVertex) const override
Returns the distance along the curve between two vertices.
static QgsCircularString fromTwoPointsAndCenter(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint ¢er, bool useShortestArc=true)
Creates a circular string with a single arc representing the curve from p1 to p2 with the specified c...
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
bool removeDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false) override
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML2 representation of the geometry.
void sumUpArea(double &sum) const override
Sums up the area of the curve by iterating over the vertices (shoelace formula).
QgsCircularString * reversed() const override
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
QgsBox3D calculateBoundingBox3D() const override
Calculates the minimal 3D bounding box for the geometry.
bool pointAt(int node, QgsPoint &point, Qgis::VertexType &type) const override
Returns the point and vertex type of a point within the curve.
int indexOf(const QgsPoint &point) const final
Returns the index of the first vertex matching the given point, or -1 if a matching vertex is not fou...
void addToPainterPath(QPainterPath &path) const override
Adds a curve to a painter path.
QgsCircularString * curveSubstring(double startDistance, double endDistance) const override
Returns a new curve representing a substring of this curve.
json asJsonObject(int precision=17, Qgis::GeoJsonProfile profile=Qgis::GeoJsonProfile::Legacy) const override
Returns a json object representation of the geometry with the given precision and profile.
void drawAsPolygon(QPainter &p) const override
Draws the curve as a polygon on the specified QPainter.
bool deleteVertices(const QSet< QgsVertexId > &positions) override
Deletes vertices within the geometry.
QgsLineString * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a new line string geometry corresponding to a segmentized approximation of the curve.
void sumUpArea3D(double &sum) const override
Sums up the 3d area of the curve by iterating over the vertices (shoelace formula).
double vertexAngle(QgsVertexId vertex) const override
Returns approximate angle at a vertex.
QgsAbstractGeometry * simplifyByDistance(double tolerance) const override
Simplifies the geometry by applying the Douglas Peucker simplification by distance algorithm.
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML3 representation of the geometry.
void clear() override
Clears the geometry, ie reset it to a null geometry.
bool hasCurvedSegments() const override
Returns true if the geometry contains curved segments.
QgsPoint * interpolatePoint(double distance) const override
Returns an interpolated point on the curve at the specified distance.
bool isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const override
Checks validity of the geometry, and returns true if the geometry is valid.
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
QgsCircularString()
Constructs an empty circular string.
std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex(int index) const final
Splits the curve at the specified vertex index, returning two curves which represent the portion of t...
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
bool mHasCachedSummedUpArea
bool mHasCachedSummedUpArea3D
bool isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const override
Checks validity of the geometry, and returns true if the geometry is valid.
bool snapToGridPrivate(double hSpacing, double vSpacing, double dSpacing, double mSpacing, const QVector< double > &srcX, const QVector< double > &srcY, const QVector< double > &srcZ, const QVector< double > &srcM, QVector< double > &outX, QVector< double > &outY, QVector< double > &outZ, QVector< double > &outM, bool removeRedundantPoints) const
Helper function for QgsCurve subclasses to snap to grids.
bool hasVertex(QgsVertexId position) const override
Returns true if the geometry contains a vertex matching the given position.
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 calculateArcLength(double centerX, double centerY, double radius, double x1, double y1, double x2, double y2, double x3, double y3, int fromVertex, int toVertex)
Calculates the precise arc length between two vertices on a circular arc.
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 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 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 circleAngleBetween(double angle, double angle1, double angle2, bool clockwise)
Returns true if, in a circle, angle is between angle1 and angle2.
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 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 void circleCenterRadius(double x1, double y1, double x2, double y2, double x3, double y3, double &radius, double ¢erX, double ¢erY)
Returns radius and center of the circle through (x1 y1), (x2 y2), (x3 y3).
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 QgsPoint pointOnLineWithDistance(const QgsPoint &startPoint, const QgsPoint &directionPoint, double distance)
Returns a point a specified distance toward a second point.
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 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 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 bool checkWeaklyFor3DPlane(const QgsAbstractGeometry *geom, QgsPoint &pt1, QgsPoint &pt2, QgsPoint &pt3, double epsilon=std::numeric_limits< double >::epsilon())
Checks if a 3D geometry has a plane defined by at least 3 non-collinear points.
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 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...
static json pointsToJson(const QgsPointSequence &points, int precision, Qgis::GeoJsonProfile profile)
Returns coordinates as json object.
Line string geometry type, with support for z-dimension and m-values.
void setPoints(size_t size, const double *x, const double *y, const double *z=nullptr, const double *m=nullptr)
Resets the line string to match the specified point data.
Point geometry type, with support for z-dimension and m-values.
void setY(double y)
Sets the point's y-coordinate.
void setX(double x)
Sets the point's x-coordinate.
double distanceSquared(double x, double y) const
Returns the Cartesian 2D squared distance between this point a specified x, y coordinate.
A rectangle specified with double values.
int numPoints() const override
Returns the number of points in the curve.
bool isEmpty() const override
Returns true if the geometry is empty.
void splitCurveAtVertexProtected(int index, QVector< double > &x1, QVector< double > &y1, QVector< double > &z1, QVector< double > &m1, QVector< double > &x2, QVector< double > &y2, QVector< double > &z2, QVector< double > &m2) const
Returns coordinate vectors for the split curves.
void points(QgsPointSequence &pts) const override
Returns a list of points within the curve.
void clear() override
Clears the geometry, ie reset it to a null geometry.
const double * yData() const
Returns a const pointer to the y vertex data.
QgsPoint startPoint() const override
Returns the starting point of the curve.
QgsPoint pointN(int i) const
Returns the specified point from inside the simple curve.
QgsSimpleCurve * reversed() const override
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
const double * xData() const
Returns a const pointer to the x vertex data.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
double y() const
Returns Y coordinate.
double z() const
Returns Z coordinate.
double x() const
Returns X coordinate.
void normalize()
Normalizes the current vector in place.
static QgsVector3D crossProduct(const QgsVector3D &v1, const QgsVector3D &v2)
Returns the cross product of two vectors.
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.
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negative values mean left ...
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 BUILTIN_UNREACHABLE
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
QVector< QgsPoint > QgsPointSequence
void arcTo(QPainterPath &path, QPointF pt1, QPointF pt2, QPointF pt3)
Utility class for identifying a unique vertex within a geometry.