QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
27 #include <nlohmann/json.hpp>
32 #include <QDomDocument>
33 #include <QJsonObject>
56 mX.resize(
points.count() );
57 mY.resize(
points.count() );
58 double *x = mX.data();
59 double *y = mY.data();
64 mZ.resize(
points.count() );
69 mM.resize(
points.count() );
84 QgsLineString::QgsLineString(
const QVector<double> &x,
const QVector<double> &y,
const QVector<double> &z,
const QVector<double> &m,
bool is25DType )
87 int pointCount = std::min( x.size(), y.size() );
88 if ( x.size() == pointCount )
94 mX = x.mid( 0, pointCount );
96 if ( y.size() == pointCount )
102 mY = y.mid( 0, pointCount );
104 if ( !z.isEmpty() && z.count() >= pointCount )
107 if ( z.size() == pointCount )
113 mZ = z.mid( 0, pointCount );
116 if ( !m.isEmpty() && m.count() >= pointCount )
119 if ( m.size() == pointCount )
125 mM = m.mid( 0, pointCount );
158 mX.reserve(
points.size() );
159 mY.reserve(
points.size() );
173 mX[1] = segment.
endX();
175 mY[1] = segment.
endY();
178 static double cubicInterpolate(
double a,
double b,
179 double A,
double B,
double C,
double D )
181 return A * b * b * b + 3 * B * b * b * a + 3 * C * b * a * a + D * a * a * a;
190 x.resize( segments + 1 );
192 y.resize( segments + 1 );
194 double *
zData =
nullptr;
195 if ( start.
is3D() && end.
is3D() && controlPoint1.
is3D() && controlPoint2.
is3D() )
197 z.resize( segments + 1 );
201 double *
mData =
nullptr;
204 m.resize( segments + 1 );
208 double *
xData = x.data();
209 double *
yData = y.data();
210 const double step = 1.0 / segments;
213 for (
int i = 0; i < segments; i++, a += step, b -= step )
226 *
xData++ = cubicInterpolate( a, b, start.
x(), controlPoint1.
x(), controlPoint2.
x(), end.
x() );
227 *
yData++ = cubicInterpolate( a, b, start.
y(), controlPoint1.
y(), controlPoint2.
y(), end.
y() );
229 *
zData++ = cubicInterpolate( a, b, start.
z(), controlPoint1.
z(), controlPoint2.
z(), end.
z() );
231 *
mData++ = cubicInterpolate( a, b, start.
m(), controlPoint1.
m(), controlPoint2.
m(), end.
m() );
249 x.resize( polygon.count() );
250 y.resize( polygon.count() );
251 double *
xData = x.data();
252 double *
yData = y.data();
254 const QPointF *src = polygon.data();
255 for (
int i = 0 ; i < polygon.size(); ++ i )
267 const QgsLineString *otherLine = qgsgeometry_cast< const QgsLineString * >( &other );
274 if ( mX.count() != otherLine->mX.count() )
277 for (
int i = 0; i < mX.count(); ++i )
318 bool res =
snapToGridPrivate( hSpacing, vSpacing, dSpacing, mSpacing, mX, mY, mZ, mM,
319 result->mX, result->mY, result->mZ, result->mM );
321 return result.release();
328 if ( mX.count() <= 2 )
331 double prevX = mX.at( 0 );
332 double prevY = mY.at( 0 );
334 bool useZ = hasZ && useZValues;
335 double prevZ = useZ ? mZ.at( 0 ) : 0;
337 int remaining = mX.count();
338 while ( i < remaining )
340 double currentX = mX.at( i );
341 double currentY = mY.at( i );
342 double currentZ = useZ ? mZ.at( i ) : 0;
368 QVector< QgsVertexId > res;
369 if ( mX.count() <= 1 )
372 const double *x = mX.constData();
373 const double *y = mY.constData();
375 bool useZ = hasZ && useZValues;
376 const double *z = useZ ? mZ.constData() :
nullptr;
380 double prevZ = z ? *z++ : 0;
383 for (
int i = 1; i < mX.count(); ++i )
385 double currentX = *x++;
386 double currentY = *y++;
387 double currentZ = useZ ? *z++ : 0;
407 const int nb = mX.size();
410 const double *x = mX.constData();
411 const double *y = mY.constData();
412 QPointF *dest =
points.data();
413 for (
int i = 0; i < nb; ++i )
415 *dest++ = QPointF( *x++, *y++ );
433 importVerticesFromWkb( wkbPtr );
439 double xmin = std::numeric_limits<double>::max();
440 double ymin = std::numeric_limits<double>::max();
441 double xmax = -std::numeric_limits<double>::max();
442 double ymax = -std::numeric_limits<double>::max();
444 for (
double x : mX )
451 for (
double y : mY )
476 QString secondWithoutParentheses =
parts.second;
477 secondWithoutParentheses = secondWithoutParentheses.remove(
'(' ).remove(
')' ).simplified().remove(
' ' );
478 parts.second =
parts.second.remove(
'(' ).remove(
')' );
479 if ( (
parts.second.compare( QLatin1String(
"EMPTY" ), Qt::CaseInsensitive ) == 0 ) ||
480 secondWithoutParentheses.isEmpty() )
495 int binarySize =
sizeof( char ) +
sizeof( quint32 ) +
sizeof( quint32 );
506 wkb << static_cast<quint32>(
wkbType() );
524 wkt += QLatin1String(
"EMPTY" );
539 QDomElement elemLineString = doc.createElementNS( ns, QStringLiteral(
"LineString" ) );
542 return elemLineString;
546 return elemLineString;
554 QDomElement elemLineString = doc.createElementNS( ns, QStringLiteral(
"LineString" ) );
557 return elemLineString;
560 return elemLineString;
569 {
"type",
"LineString" },
579 kml.append( QLatin1String(
"<LinearRing>" ) );
583 kml.append( QLatin1String(
"<LineString>" ) );
586 kml.append( QLatin1String(
"<altitudeMode>" ) );
589 kml.append( QLatin1String(
"absolute" ) );
593 kml.append( QLatin1String(
"clampToGround" ) );
595 kml.append( QLatin1String(
"</altitudeMode>" ) );
596 kml.append( QLatin1String(
"<coordinates>" ) );
598 int nPoints = mX.size();
599 for (
int i = 0; i < nPoints; ++i )
603 kml.append( QLatin1String(
" " ) );
606 kml.append( QLatin1String(
"," ) );
610 kml.append( QLatin1String(
"," ) );
615 kml.append( QLatin1String(
",0" ) );
618 kml.append( QLatin1String(
"</coordinates>" ) );
621 kml.append( QLatin1String(
"</LinearRing>" ) );
625 kml.append( QLatin1String(
"</LineString>" ) );
639 int size = mX.size();
641 for (
int i = 1; i < size; ++i )
643 dx = mX.at( i ) - mX.at( i - 1 );
644 dy = mY.at( i ) - mY.at( i - 1 );
645 length += std::sqrt( dx * dx + dy * dy );
655 int size = mX.size();
657 for (
int i = 1; i < size; ++i )
659 dx = mX.at( i ) - mX.at( i - 1 );
660 dy = mY.at( i ) - mY.at( i - 1 );
661 dz = mZ.at( i ) - mZ.at( i - 1 );
662 length += std::sqrt( dx * dx + dy * dy + dz * dz );
698 Q_UNUSED( tolerance )
699 Q_UNUSED( toleranceType )
715 if ( i < 0 || i >= mX.size() )
720 double x = mX.at( i );
721 double y = mY.at( i );
722 double z = std::numeric_limits<double>::quiet_NaN();
723 double m = std::numeric_limits<double>::quiet_NaN();
741 else if ( hasZ && hasM )
764 if ( index >= 0 && index < mX.size() )
765 return mX.at( index );
772 if ( index >= 0 && index < mY.size() )
773 return mY.at( index );
780 if ( index >= 0 && index < mX.size() )
787 if ( index >= 0 && index < mY.size() )
802 pts.reserve( nPoints );
803 for (
int i = 0; i < nPoints; ++i )
805 pts.push_back(
pointN( i ) );
821 bool hasZ = firstPt.
is3D();
826 mX.resize(
points.size() );
827 mY.resize(
points.size() );
830 mZ.resize(
points.size() );
838 mM.resize(
points.size() );
845 for (
int i = 0; i <
points.size(); ++i )
847 mX[i] =
points.at( i ).x();
848 mY[i] =
points.at( i ).y();
851 double z =
points.at( i ).z();
852 mZ[i] = std::isnan( z ) ? 0 : z;
856 double m =
points.at( i ).m();
857 mM[i] = std::isnan( m ) ? 0 : m;
910 mZ.insert( mZ.count(), mX.size() - mZ.size(), std::numeric_limits<double>::quiet_NaN() );
923 mM.insert( mM.count(), mX.size() - mM.size(), std::numeric_limits<double>::quiet_NaN() );
933 std::reverse( copy->mX.begin(), copy->mX.end() );
934 std::reverse( copy->mY.begin(), copy->mY.end() );
937 std::reverse( copy->mZ.begin(), copy->mZ.end() );
941 std::reverse( copy->mM.begin(), copy->mM.end() );
946 void QgsLineString::visitPointsByRegularDistance(
const double distance,
const std::function<
bool (
double,
double,
double,
double,
double,
double,
double,
double,
double,
double,
double,
double )> &visitPoint )
const
951 double distanceTraversed = 0;
953 if ( totalPoints == 0 )
956 const double *x = mX.constData();
957 const double *y = mY.constData();
958 const double *z =
is3D() ? mZ.constData() :
nullptr;
959 const double *m =
isMeasure() ? mM.constData() :
nullptr;
963 double prevZ = z ? *z++ : 0.0;
964 double prevM = m ? *m++ : 0.0;
968 visitPoint( prevX, prevY, prevZ, prevM, prevX, prevY, prevZ, prevM, prevX, prevY, prevZ, prevM );
972 double pZ = std::numeric_limits<double>::quiet_NaN();
973 double pM = std::numeric_limits<double>::quiet_NaN();
974 double nextPointDistance = distance;
975 for (
int i = 1; i < totalPoints; ++i )
979 double thisZ = z ? *z++ : 0.0;
980 double thisM = m ? *m++ : 0.0;
982 const double segmentLength = std::sqrt( ( thisX - prevX ) * ( thisX - prevX ) + ( thisY - prevY ) * ( thisY - prevY ) );
986 const double distanceToPoint = std::min( nextPointDistance - distanceTraversed,
segmentLength );
989 z ? &prevZ :
nullptr, z ? &thisZ :
nullptr, z ? &pZ :
nullptr,
990 m ? &prevM :
nullptr, m ? &thisM :
nullptr, m ? &pM :
nullptr );
992 if ( !visitPoint( pX, pY, pZ, pM, prevX, prevY, prevZ, prevM, thisX, thisY, thisZ, thisM ) )
995 nextPointDistance += distance;
1017 std::unique_ptr< QgsPoint > res;
1018 visitPointsByRegularDistance( distance, [ & ](
double x,
double y,
double z,
double m,
double,
double,
double,
double,
double,
double,
double,
double )->
bool
1020 res = qgis::make_unique< QgsPoint >( pointType, x, y, z, m );
1023 return res.release();
1028 if ( startDistance < 0 && endDistance < 0 )
1031 endDistance = std::max( startDistance, endDistance );
1033 double distanceTraversed = 0;
1035 if ( totalPoints == 0 )
1038 QVector< QgsPoint > substringPoints;
1046 const double *x = mX.constData();
1047 const double *y = mY.constData();
1048 const double *z =
is3D() ? mZ.constData() :
nullptr;
1049 const double *m =
isMeasure() ? mM.constData() :
nullptr;
1051 double prevX = *x++;
1052 double prevY = *y++;
1053 double prevZ = z ? *z++ : 0.0;
1054 double prevM = m ? *m++ : 0.0;
1055 bool foundStart =
false;
1057 if (
qgsDoubleNear( startDistance, 0.0 ) || startDistance < 0 )
1059 substringPoints <<
QgsPoint( pointType, prevX, prevY, prevZ, prevM );
1063 substringPoints.reserve( totalPoints );
1065 for (
int i = 1; i < totalPoints; ++i )
1067 double thisX = *x++;
1068 double thisY = *y++;
1069 double thisZ = z ? *z++ : 0.0;
1070 double thisM = m ? *m++ : 0.0;
1072 const double segmentLength = std::sqrt( ( thisX - prevX ) * ( thisX - prevX ) + ( thisY - prevY ) * ( thisY - prevY ) );
1073 if ( distanceTraversed < startDistance && distanceTraversed + segmentLength > startDistance )
1076 const double distanceToStart = startDistance - distanceTraversed;
1077 double startX, startY;
1081 z ? &prevZ :
nullptr, z ? &thisZ :
nullptr, z ? &startZ :
nullptr,
1082 m ? &prevM :
nullptr, m ? &thisM :
nullptr, m ? &startM :
nullptr );
1083 substringPoints <<
QgsPoint( pointType, startX, startY, startZ, startM );
1086 if ( foundStart && ( distanceTraversed +
segmentLength > endDistance ) )
1089 const double distanceToEnd = endDistance - distanceTraversed;
1094 z ? &prevZ :
nullptr, z ? &thisZ :
nullptr, z ? &endZ :
nullptr,
1095 m ? &prevM :
nullptr, m ? &thisM :
nullptr, m ? &endM :
nullptr );
1096 substringPoints <<
QgsPoint( pointType, endX, endY, endZ, endM );
1098 else if ( foundStart )
1100 substringPoints <<
QgsPoint( pointType, thisX, thisY, thisZ, thisM );
1104 if ( distanceTraversed > endDistance )
1135 if ( path.isEmpty() || path.currentPosition() != QPointF( mX.at( 0 ), mY.at( 0 ) ) )
1137 path.moveTo( mX.at( 0 ), mY.at( 0 ) );
1140 for (
int i = 1; i < nPoints; ++i )
1142 path.lineTo( mX.at( i ), mY.at( i ) );
1155 return compoundCurve;
1160 if ( mX.size() < 2 || mY.size() < 2 )
1164 if ( startDistance > 0 )
1166 double currentLen = std::sqrt( std::pow( mX.at( 0 ) - mX.at( 1 ), 2 ) +
1167 std::pow( mY.at( 0 ) - mY.at( 1 ), 2 ) );
1168 double newLen = currentLen + startDistance;
1169 mX[ 0 ] = mX.at( 1 ) + ( mX.at( 0 ) - mX.at( 1 ) ) / currentLen * newLen;
1170 mY[ 0 ] = mY.at( 1 ) + ( mY.at( 0 ) - mY.at( 1 ) ) / currentLen * newLen;
1173 if ( endDistance > 0 )
1175 int last = mX.size() - 1;
1176 double currentLen = std::sqrt( std::pow( mX.at( last ) - mX.at( last - 1 ), 2 ) +
1177 std::pow( mY.at( last ) - mY.at( last - 1 ), 2 ) );
1178 double newLen = currentLen + endDistance;
1179 mX[ last ] = mX.at( last - 1 ) + ( mX.at( last ) - mX.at( last - 1 ) ) / currentLen * newLen;
1180 mY[ last ] = mY.at( last - 1 ) + ( mY.at( last ) - mY.at( last - 1 ) ) / currentLen * newLen;
1186 auto result = qgis::make_unique< QgsLineString >();
1188 return result.release();
1193 return QStringLiteral(
"LineString" );
1209 double *zArray =
nullptr;
1215 std::unique_ptr< double[] > dummyZ;
1216 if ( !hasZ || !transformZ )
1218 dummyZ.reset(
new double[nPoints]() );
1219 zArray = dummyZ.get();
1234 double *x = mX.data();
1235 double *y = mY.data();
1236 double *z = hasZ ? mZ.data() :
nullptr;
1237 double *m = hasM ? mM.data() :
nullptr;
1238 for (
int i = 0; i < nPoints; ++i )
1241 t.map( *x, *y, &xOut, &yOut );
1246 *z = *z * zScale + zTranslate;
1251 *m = *m * mScale + mTranslate;
1266 if ( position.
vertex < 0 || position.
vertex > mX.size() )
1276 mX.insert( position.
vertex, vertex.
x() );
1277 mY.insert( position.
vertex, vertex.
y() );
1280 mZ.insert( position.
vertex, vertex.
z() );
1284 mM.insert( position.
vertex, vertex.
m() );
1292 if ( position.
vertex < 0 || position.
vertex >= mX.size() )
1296 mX[position.
vertex] = newPos.
x();
1297 mY[position.
vertex] = newPos.
y();
1300 mZ[position.
vertex] = newPos.
z();
1304 mM[position.
vertex] = newPos.
m();
1312 if ( position.
vertex >= mX.size() || position.
vertex < 0 )
1317 mX.remove( position.
vertex );
1318 mY.remove( position.
vertex );
1321 mZ.remove( position.
vertex );
1325 mM.remove( position.
vertex );
1350 mX.append( pt.
x() );
1351 mY.append( pt.
y() );
1354 mZ.append( pt.
z() );
1358 mM.append( pt.
m() );
1365 double sqrDist = std::numeric_limits<double>::max();
1366 double leftOfDist = std::numeric_limits<double>::max();
1368 double prevLeftOfX = 0.0;
1369 double prevLeftOfY = 0.0;
1370 double testDist = 0;
1371 double segmentPtX, segmentPtY;
1376 int size = mX.size();
1377 if ( size == 0 || size == 1 )
1382 for (
int i = 1; i < size; ++i )
1384 double prevX = mX.at( i - 1 );
1385 double prevY = mY.at( i - 1 );
1386 double currentX = mX.at( i );
1387 double currentY = mY.at( i );
1389 if ( testDist < sqrDist )
1392 segmentPt.
setX( segmentPtX );
1393 segmentPt.
setY( segmentPtY );
1394 vertexAfter.
part = 0;
1395 vertexAfter.
ring = 0;
1406 if (
qgsDoubleNear( testDist, leftOfDist ) && left != prevLeftOf && prevLeftOf != 0 )
1419 leftOfDist = testDist;
1420 prevLeftOfX = prevX;
1421 prevLeftOfY = prevY;
1423 else if ( testDist < leftOfDist )
1426 leftOfDist = testDist;
1458 return QgsPoint( mX.at( 0 ), mY.at( 0 ) );
1460 double totalLineLength = 0.0;
1461 double prevX = mX.at( 0 );
1462 double prevY = mY.at( 0 );
1468 double currentX = mX.at( i );
1469 double currentY = mY.at( i );
1470 double segmentLength = std::sqrt( std::pow( currentX - prevX, 2.0 ) +
1471 std::pow( currentY - prevY, 2.0 ) );
1483 return QgsPoint( mX.at( 0 ), mY.at( 0 ) );
1485 return QgsPoint( sumX / totalLineLength, sumY / totalLineLength );
1499 for (
int i = 0; i < maxIndex; ++i )
1501 sum += 0.5 * ( mX.at( i ) * mY.at( i + 1 ) - mY.at( i ) * mX.at( i + 1 ) );
1505 void QgsLineString::importVerticesFromWkb(
const QgsConstWkbPtr &wkb )
1511 mX.resize( nVertices );
1512 mY.resize( nVertices );
1513 hasZ ? mZ.resize( nVertices ) : mZ.clear();
1514 hasM ? mM.resize( nVertices ) : mM.clear();
1515 double *x = mX.data();
1516 double *y = mY.data();
1517 double *m = hasM ? mM.data() :
nullptr;
1518 double *z = hasZ ? mZ.data() :
nullptr;
1519 for (
int i = 0; i < nVertices; ++i )
1552 if ( mX.count() < 2 )
1562 double previousX = mX.at(
numPoints() - 2 );
1563 double previousY = mY.at(
numPoints() - 2 );
1564 double currentX = mX.at( 0 );
1565 double currentY = mY.at( 0 );
1566 double afterX = mX.at( 1 );
1567 double afterY = mY.at( 1 );
1570 else if ( vertex.
vertex == 0 )
1583 double previousX = mX.at( vertex.
vertex - 1 );
1584 double previousY = mY.at( vertex.
vertex - 1 );
1585 double currentX = mX.at( vertex.
vertex );
1586 double currentY = mY.at( vertex.
vertex );
1587 double afterX = mX.at( vertex.
vertex + 1 );
1588 double afterY = mY.at( vertex.
vertex + 1 );
1595 if ( startVertex.
vertex < 0 || startVertex.
vertex >= mX.count() - 1 )
1598 double dx = mX.at( startVertex.
vertex + 1 ) - mX.at( startVertex.
vertex );
1599 double dy = mY.at( startVertex.
vertex + 1 ) - mY.at( startVertex.
vertex );
1600 return std::sqrt( dx * dx + dy * dy );
1625 mZ.reserve( nPoints );
1626 for (
int i = 0; i < nPoints; ++i )
1656 mM.reserve( nPoints );
1657 for (
int i = 0; i < nPoints; ++i )
1688 std::swap( mX, mY );
1702 addZValue( std::numeric_limits<double>::quiet_NaN() );
1716 int size = mX.size();
1718 double *srcX = mX.data();
1719 double *srcY = mY.data();
1720 double *srcM = hasM ? mM.data() :
nullptr;
1721 double *srcZ = hasZ ? mZ.data() :
nullptr;
1723 double *destX = srcX;
1724 double *destY = srcY;
1725 double *destM = srcM;
1726 double *destZ = srcZ;
1728 int filteredPoints = 0;
1729 for (
int i = 0; i < size; ++i )
1733 double z = hasZ ? *srcZ++ : std::numeric_limits<double>::quiet_NaN();
1734 double m = hasM ? *srcM++ : std::numeric_limits<double>::quiet_NaN();
1736 if ( filter(
QgsPoint( x, y, z, m ) ) )
1748 mX.resize( filteredPoints );
1749 mY.resize( filteredPoints );
1751 mZ.resize( filteredPoints );
1753 mM.resize( filteredPoints );
1762 int size = mX.size();
1764 double *srcX = mX.data();
1765 double *srcY = mY.data();
1766 double *srcM = hasM ? mM.data() :
nullptr;
1767 double *srcZ = hasZ ? mZ.data() :
nullptr;
1769 for (
int i = 0; i < size; ++i )
1773 double z = hasZ ? *srcZ : std::numeric_limits<double>::quiet_NaN();
1774 double m = hasM ? *srcM : std::numeric_limits<double>::quiet_NaN();
Abstract base class for curved geometry type.
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) override SIP_THROW(QgsCsException)
Transforms the geometry using a coordinate transform.
QgsPoint pointN(int i) const
Returns the specified point from inside the line string.
void setYAt(int index, double y)
Sets the y-coordinate of the specified node in the line string.
double xAt(int index) const override
Returns the x-coordinate of the specified node in the line string.
const double * zData() const
Returns a const pointer to the z vertex data, or nullptr if the linestring does not have z values.
virtual bool isRing() const SIP_HOLDGIL
Returns true if the curve is a ring.
static Type dropM(Type type) SIP_HOLDGIL
Drops the m dimension (if present) for a WKB type and returns the new type.
void setPoints(const QgsPointSequence &points)
Resets the line string to match the specified list of points.
static json pointsToJson(const QgsPointSequence &points, int precision)
Returns coordinates as json object.
QgsPoint endPoint() const override SIP_HOLDGIL
Returns the end point of the curve.
@ SegmentVertex
The actual start or end point of a segment.
Represents a single 2D line segment, consisting of a 2D start and end vertex only.
double length() const override SIP_HOLDGIL
Returns the planar, 2-dimensional length of the geometry.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
Point geometry type, with support for z-dimension and m-values.
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 addToPainterPath(QPainterPath &path) const override
Adds a curve to a painter path.
double yAt(int index) const override
Returns the y-coordinate of the specified node in the line string.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
QgsGeometryConstPartIterator parts() const
Returns Java-style iterator for traversal of parts of the geometry.
QgsPoint centroid() const override
Returns the centroid of the geometry.
void addCurve(QgsCurve *c)
Adds a curve to the geometry (takes ownership)
static double sqrDistToLine(double ptX, double ptY, double x1, double y1, double x2, double y2, double &minDistX, double &minDistY, double epsilon) SIP_HOLDGIL
Returns the squared distance between a point and a line.
double endX() const SIP_HOLDGIL
Returns the segment's end x-coordinate.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
QgsLineString * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const override
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
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.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
static double lineAngle(double x1, double y1, double x2, double y2) SIP_HOLDGIL
Calculates the direction of line joining two points in radians, clockwise from the north direction.
void drawAsPolygon(QPainter &p) const override
Draws the curve as a polygon on the specified QPainter.
const double * yData() const
Returns a const pointer to the y vertex data.
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
double startX() const SIP_HOLDGIL
Returns the segment's start x-coordinate.
void setXAt(int index, double x)
Sets the x-coordinate of the specified node in the line string.
Type
The WKB type describes the number of dimensions a geometry has.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
QgsWkbTypes::Type mWkbType
static int leftOfLine(const double x, const double y, const double x1, const double y1, const double x2, const double y2) SIP_HOLDGIL
Returns a value < 0 if the point (x, y) is left of the line from (x1, y1) -> (x2, y2).
Line string geometry type, with support for z-dimension and m-values.
double endY() const SIP_HOLDGIL
Returns the segment's end y-coordinate.
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
QgsCompoundCurve * toCurveType() const override
Returns the geometry converted to the more generic curve type QgsCompoundCurve.
static QgsPointSequence pointsFromWKT(const QString &wktCoordinateList, bool is3D, bool isMeasure)
Returns a list of points contained in a WKT string.
A rectangle specified with double values.
const double * xData() const
Returns a const pointer to the x vertex data.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
bool isEmpty() const override SIP_HOLDGIL
Returns true if the geometry is empty.
int nCoordinates() const override SIP_HOLDGIL
Returns the number of nodes contained in the geometry.
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
QVector< QgsVertexId > collectDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false) const
Returns a list of any duplicate nodes contained in the geometry, within the specified tolerance.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
static QgsLineString * fromBezierCurve(const QgsPoint &start, const QgsPoint &controlPoint1, const QgsPoint &controlPoint2, const QgsPoint &end, int segments=30)
Returns a new linestring created by segmentizing the bezier curve between start and end,...
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 ...
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
QgsLineString * clone() const override
Clones the geometry by performing a deep copy.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
QString asKml(int precision=17) const override
Returns a KML representation of the geometry.
bool pointAt(int node, QgsPoint &point, QgsVertexId::VertexType &type) const override
Returns the point and vertex id of a point within the curve.
AxisOrder
Axis order for GML generation.
bool convertTo(QgsWkbTypes::Type type) override
Converts the geometry to a specified type.
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
static void pointsToWKB(QgsWkbPtr &wkb, const QgsPointSequence &points, bool is3D, bool isMeasure)
Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform) override
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
QPolygonF asQPolygonF() const override
Returns a QPolygonF representing the points.
QgsLineString() SIP_HOLDGIL
Constructor for an empty linestring geometry.
QByteArray asWkb(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
static double averageAngle(double x1, double y1, double x2, double y2, double x3, double y3) SIP_HOLDGIL
Calculates the average angle (in radians) between the two linear segments from (x1,...
static QgsPoint pointOnLineWithDistance(const QgsPoint &startPoint, const QgsPoint &directionPoint, double distance) SIP_HOLDGIL
Returns a point a specified distance toward a second point.
static QgsLineString * fromQPolygonF(const QPolygonF &polygon)
Returns a new linestring from a QPolygonF polygon input.
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 setX(double x) SIP_HOLDGIL
Sets the point's x-coordinate.
static bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
double length3D() const SIP_HOLDGIL
Returns the length in 3D world of the line string.
static endian_t endian()
Returns whether this machine uses big or little endian.
static Type zmType(Type type, bool hasZ, bool hasM) SIP_HOLDGIL
Returns the modified input geometry type according to hasZ / hasM.
void clear() override
Clears the geometry, ie reset it to a null geometry.
static Type dropZ(Type type) SIP_HOLDGIL
Drops the z dimension (if present) for a WKB type and returns the new type.
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) const
Helper function for QgsCurve subclasses to snap to grids.
const double * mData() const
Returns a const pointer to the m vertex data, or nullptr if the linestring does not have m values.
void sumUpArea(double &sum) const override
Sums up the area of the curve by iterating over the vertices (shoelace formula).
QgsPoint * interpolatePoint(double distance) const override
Returns an interpolated point on the curve at the specified distance.
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
QgsLineString * curveSubstring(double startDistance, double endDistance) const override
Returns a new curve representing a substring of this curve.
void extend(double startDistance, double endDistance)
Extends the line geometry by extrapolating out the start or end of the line by a specified distance.
A class to represent a 2D point.
bool dropMValue() override
Drops any measure values which exist in the geometry.
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.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
int dimension() const override SIP_HOLDGIL
Returns the inherent dimension of the geometry.
void append(const QgsLineString *line)
Appends the contents of another line string to the end of this line string.
void swapXy() override
Swaps the x and y coordinates from the geometry.
QVector< QgsPoint > QgsPointSequence
int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns the length of the QByteArray returned by asWkb()
void close()
Closes the line string by appending the first point to the end of the line, if it is not already clos...
void addVertex(const QgsPoint &pt)
Adds a new vertex to the end of the line string.
static QString pointsToWKT(const QgsPointSequence &points, int precision, bool is3D, bool isMeasure)
Returns a WKT coordinate list.
double startY() const SIP_HOLDGIL
Returns the segment's start y-coordinate.
void filterVertices(const std::function< bool(const QgsPoint &) > &filter) override
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
Utility class for identifying a unique vertex within a geometry.
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.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
VertexType
Type of vertex.
QString geometryType() const override SIP_HOLDGIL
Returns a unique string representing the geometry type.
QgsRectangle calculateBoundingBox() const override
Default calculator for the minimal bounding box for the geometry.
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
virtual bool convertTo(QgsWkbTypes::Type type)
Converts the geometry to a specified type.
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
bool equals(const QgsCurve &other) const override
Checks whether this curve exactly equals another curve.
QgsWkbTypes::Type readHeader() const
readHeader
void setY(double y) SIP_HOLDGIL
Sets the point's y-coordinate.
QgsLineString * reversed() const override
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
static QPair< QgsWkbTypes::Type, QString > wktReadBlock(const QString &wkt)
Parses a WKT block of the format "TYPE( contents )" and returns a pair of geometry type to contents (...
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, QgsWkbTypes::Type baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
virtual bool isClosed() const SIP_HOLDGIL
Returns true if the curve is closed.
int numPoints() const override SIP_HOLDGIL
Returns the number of points in the curve.
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.
void points(QgsPointSequence &pt) const override
Returns a list of points within the curve.
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...
QgsLineString * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
QgsPoint startPoint() const override SIP_HOLDGIL
Returns the starting point of the curve.
double vertexAngle(QgsVertexId vertex) const override
Returns approximate angle at a vertex.
Compound curve geometry type.
void visitPointsByRegularDistance(double distance, const std::function< bool(double x, double y, double z, double m, double startSegmentX, double startSegmentY, double startSegmentZ, double startSegmentM, double endSegmentX, double endSegmentY, double endSegmentZ, double endSegmentM) > &visitPoint) const
Visits regular points along the linestring, spaced by distance.
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.