18#ifndef QGSLINESTRING_H
19#define QGSLINESTRING_H
77 QgsLineString( SIP_PYOBJECT points
SIP_TYPEHINT( Sequence[Union[
QgsPoint,
QgsPointXY, Sequence[
float]]] ) )
SIP_HOLDGIL [(
const QVector<double> &x,
const QVector<double> &y,
const QVector<double> &z = QVector<double>(),
const QVector<double> &m = QVector<double>(),
bool is25DType = false )];
79 if ( !PySequence_Check( a0 ) )
81 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"A sequence of QgsPoint, QgsPointXY or array of floats is expected" ).toUtf8().constData() );
87 const int size = PySequence_Size( a0 );
100 for (
int i = 0; i < size; ++i )
102 PyObject *value = PySequence_GetItem( a0, i );
105 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
110 if ( PySequence_Check( value ) )
112 const int elementSize = PySequence_Size( value );
113 if ( elementSize < 2 || elementSize > 4 )
116 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid sequence size at index %1. Expected an array of 2-4 float values, got %2." ).arg( i ).arg( elementSize ).toUtf8().constData() );
123 for (
int j = 0; j < elementSize; ++j )
125 PyObject *element = PySequence_GetItem( value, j );
128 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
134 double d = PyFloat_AsDouble( element );
135 if ( PyErr_Occurred() )
146 if ( i == 0 && j == 2 )
152 else if ( i > 0 && j == 2 && hasZ )
157 if ( i == 0 && j == 3 )
163 else if ( i > 0 && j == 3 && hasM )
168 Py_DECREF( element );
171 if ( hasZ && elementSize < 3 )
172 zl.append( std::numeric_limits< double >::quiet_NaN() );
173 if ( hasM && elementSize < 4 )
174 ml.append( std::numeric_limits< double >::quiet_NaN() );
185 if ( sipCanConvertToType( value, sipType_QgsPointXY, SIP_NOT_NONE ) )
188 QgsPointXY *p =
reinterpret_cast<QgsPointXY *
>( sipConvertToType( value, sipType_QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
194 sipReleaseType( p, sipType_QgsPointXY, state );
196 else if ( sipCanConvertToType( value, sipType_QgsPoint, SIP_NOT_NONE ) )
199 QgsPoint *p =
reinterpret_cast<QgsPoint *
>( sipConvertToType( value, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
205 if ( i == 0 && p->
is3D() )
211 else if ( i > 0 && hasZ )
222 else if ( i > 0 && hasM )
230 sipReleaseType( p, sipType_QgsPoint, state );
242 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1. Expected QgsPoint, QgsPointXY or array of floats." ).arg( i ) .toUtf8().constData() );
248 sipCpp =
new sipQgsLineString(
QgsLineString( xl, yl, zl, ml, is25D ) );
276 QgsLineString(
const QVector<double> &x,
const QVector<double> &y,
277 const QVector<double> &z = QVector<double>(),
278 const QVector<double> &m = QVector<double>(),
bool is25DType =
false )
SIP_HOLDGIL;
306 bool fuzzyHelper(
double epsilon,
310 std::function<
bool(
double,
double,
double,
double,
double,
double,
double,
double,
double )> comparator3DMeasure,
311 std::function<
bool(
double,
double,
double,
double,
double,
double,
double )> comparator3D,
312 std::function<
bool(
double,
double,
double,
double,
double,
double,
double )> comparatorMeasure,
313 std::function<
bool(
double,
double,
double,
double,
double )> comparator2D )
const
315 const QgsLineString *otherLine = qgsgeometry_cast< const QgsLineString * >( &other );
319 if ( mWkbType != otherLine->
mWkbType )
322 const int size = mX.count();
323 if ( size != otherLine->mX.count() )
327 const double *xData = mX.constData();
328 const double *yData = mY.constData();
329 const double *zData = is3DFlag ? mZ.constData() :
nullptr;
330 const double *mData = isMeasureFlag ? mM.constData() :
nullptr;
331 const double *otherXData = otherLine->mX.constData();
332 const double *otherYData = otherLine->mY.constData();
333 const double *otherZData = is3DFlag ? otherLine->mZ.constData() :
nullptr;
334 const double *otherMData = isMeasureFlag ? otherLine->mM.constData() :
nullptr;
335 for (
int i = 0; i < size; ++i )
337 if ( is3DFlag && isMeasureFlag )
339 result &= comparator3DMeasure( epsilon, *xData++, *yData++, *zData++, *mData++,
340 *otherXData++, *otherYData++, *otherZData++, *otherMData++ );
344 result &= comparator3D( epsilon, *xData++, *yData++, *zData++,
345 *otherXData++, *otherYData++, *otherZData++ );
347 else if ( isMeasureFlag )
349 result &= comparatorMeasure( epsilon, *xData++, *yData++, *mData++,
350 *otherXData++, *otherYData++, *otherMData++ );
354 result &= comparator2D( epsilon, *xData++, *yData++,
355 *otherXData++, *otherYData++ );
375 [](
double epsilon,
double x1,
double y1,
double z1,
double m1,
376 double x2,
double y2,
double z2,
double m2 )
380 [](
double epsilon,
double x1,
double y1,
double z1,
381 double x2,
double y2,
double z2 )
385 [](
double epsilon,
double x1,
double y1,
double m1,
386 double x2,
double y2,
double m2 )
390 [](
double epsilon,
double x1,
double y1,
391 double x2,
double y2 )
404 [](
double epsilon,
double x1,
double y1,
double z1,
double m1,
405 double x2,
double y2,
double z2,
double m2 )
409 [](
double epsilon,
double x1,
double y1,
double z1,
410 double x2,
double y2,
double z2 )
414 [](
double epsilon,
double x1,
double y1,
double m1,
415 double x2,
double y2,
double m2 )
419 [](
double epsilon,
double x1,
double y1,
420 double x2,
double y2 )
451 const int count = sipCpp->numPoints();
452 if ( a0 < -count || a0 >= count )
454 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
459 std::unique_ptr< QgsPoint > p;
461 p = std::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
463 p = std::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
464 sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
470 double xAt(
int index )
const override;
481 double xAt(
int index )
const override;
483 const int count = sipCpp->numPoints();
484 if ( a0 < -count || a0 >= count )
486 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
492 return PyFloat_FromDouble( sipCpp->xAt( a0 ) );
494 return PyFloat_FromDouble( sipCpp->xAt( count + a0 ) );
500 double yAt(
int index )
const override;
511 double yAt(
int index )
const override;
513 const int count = sipCpp->numPoints();
514 if ( a0 < -count || a0 >= count )
516 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
522 return PyFloat_FromDouble( sipCpp->yAt( a0 ) );
524 return PyFloat_FromDouble( sipCpp->yAt( count + a0 ) );
537 return mX.constData();
548 return mY.constData();
564 return mZ.constData();
580 return mM.constData();
633 double zAt(
int index )
const override
635 if ( index >= 0 && index < mZ.size() )
636 return mZ.at( index );
638 return std::numeric_limits<double>::quiet_NaN();
652 double zAt(
int index )
const override;
654 const int count = sipCpp->numPoints();
655 if ( a0 < -count || a0 >= count )
657 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
663 return PyFloat_FromDouble( sipCpp->zAt( a0 ) );
665 return PyFloat_FromDouble( sipCpp->zAt( count + a0 ) );
679 double mAt(
int index )
const override
681 if ( index >= 0 && index < mM.size() )
682 return mM.at( index );
684 return std::numeric_limits<double>::quiet_NaN();
698 double mAt(
int index )
const override;
700 const int count = sipCpp->numPoints();
701 if ( a0 < -count || a0 >= count )
703 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
709 return PyFloat_FromDouble( sipCpp->mAt( a0 ) );
711 return PyFloat_FromDouble( sipCpp->mAt( count + a0 ) );
725 void setXAt(
int index,
double x );
739 void setXAt(
int index,
double x );
741 const int count = sipCpp->numPoints();
742 if ( a0 < -count || a0 >= count )
744 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
750 sipCpp->setXAt( a0, a1 );
752 sipCpp->setXAt( count + a0, a1 );
766 void setYAt(
int index,
double y );
780 void setYAt(
int index,
double y );
782 const int count = sipCpp->numPoints();
783 if ( a0 < -count || a0 >= count )
785 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
791 sipCpp->setYAt( a0, a1 );
793 sipCpp->setYAt( count + a0, a1 );
809 if ( index >= 0 && index < mZ.size() )
824 void setZAt(
int index,
double z );
826 const int count = sipCpp->numPoints();
827 if ( a0 < -count || a0 >= count )
829 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
835 sipCpp->setZAt( a0, a1 );
837 sipCpp->setZAt( count + a0, a1 );
853 if ( index >= 0 && index < mM.size() )
868 void setMAt(
int index,
double m );
870 const int count = sipCpp->numPoints();
871 if ( a0 < -count || a0 >= count )
873 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
879 sipCpp->setMAt( a0, a1 );
881 sipCpp->setMAt( count + a0, a1 );
899 void setPoints(
size_t size,
const double *x,
const double *y,
const double *z =
nullptr,
const double *m =
nullptr )
SIP_SKIP;
918 void addVertex( const
QgsPoint &pt );
934 void extend(
double startDistance,
double endDistance );
943 void visitPointsByRegularDistance(
double distance,
const std::function<
bool(
double x,
double y,
double z,
double m,
944 double startSegmentX,
double startSegmentY,
double startSegmentZ,
double startSegmentM,
945 double endSegmentX,
double endSegmentY,
double endSegmentZ,
double endSegmentM
946 ) > &visitPoint )
const;
953 void clear() override;
955 int indexOf( const
QgsPoint &point ) const final;
956 bool isValid( QString &error
SIP_OUT,
Qgis::GeometryValidityFlags flags =
Qgis::GeometryValidityFlags() ) const override;
957 QgsLineString *snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0 ) const override
SIP_FACTORY;
958 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false ) override;
971 QVector<
QgsVertexId > collectDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false ) const;
973 QPolygonF asQPolygonF() const override;
976 bool fromWkt( const QString &wkt ) override;
980 QString asWkt(
int precision = 17 ) const override;
984 QString asKml(
int precision = 17 ) const override;
990 std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > >
splitCurveAtVertex(
int index )
const final;
1009 QgsLineString *curveToLine(
double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override
SIP_FACTORY;
1015 void draw( QPainter &p ) const override;
1018 void transform( const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 ) override;
1020 void addToPainterPath( QPainterPath &path ) const override;
1021 void drawAsPolygon( QPainter &p ) const override;
1025 bool deleteVertex(
QgsVertexId position ) override;
1032 bool pointAt(
int node,
QgsPoint &point,
Qgis::VertexType &type ) const override;
1044 void sumUpArea(
double &sum
SIP_OUT ) const override;
1046 double vertexAngle(
QgsVertexId vertex ) const override;
1047 double segmentLength(
QgsVertexId startVertex ) const override;
1048 bool addZValue(
double zValue = 0 ) override;
1049 bool addMValue(
double mValue = 0 ) override;
1051 bool dropZValue() override;
1052 bool dropMValue() override;
1053 void swapXy() override;
1055 bool convertTo(
Qgis::WkbType type ) override;
1058 void scroll(
int firstVertexIndex ) final;
1081 SIP_PYOBJECT __repr__();
1083 QString wkt = sipCpp->asWkt();
1084 if ( wkt.length() > 1000 )
1085 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
1086 QString
str = QStringLiteral(
"<QgsLineString: %1>" ).arg( wkt );
1087 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
1101 const int count = sipCpp->numPoints();
1102 if ( a0 < -count || a0 >= count )
1104 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
1109 std::unique_ptr< QgsPoint > p;
1111 p = std::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
1113 p = std::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
1114 sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
1127 void __setitem__(
int index,
const QgsPoint &point );
1129 const int count = sipCpp->numPoints();
1130 if ( a0 < -count || a0 >= count )
1132 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
1139 sipCpp->setXAt( a0, a1->x() );
1140 sipCpp->setYAt( a0, a1->y() );
1141 if ( sipCpp->isMeasure() )
1142 sipCpp->setMAt( a0, a1->m() );
1143 if ( sipCpp->is3D() )
1144 sipCpp->setZAt( a0, a1->z() );
1158 void __delitem__(
int index );
1160 const int count = sipCpp->numPoints();
1161 if ( a0 >= 0 && a0 < count )
1162 sipCpp->deleteVertex(
QgsVertexId( -1, -1, a0 ) );
1163 else if ( a0 < 0 && a0 >= -count )
1164 sipCpp->deleteVertex(
QgsVertexId( -1, -1, count + a0 ) );
1167 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
1188 QgsBox3D calculateBoundingBox3D() const override;
1219 importVerticesFromWkb( wkb );
1224 friend class TestQgsGeometry;
The Qgis class provides global constants for use throughout the application.
Abstract base class for all geometries.
bool isMeasure() const
Returns true if the geometry contains m values.
virtual void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform)
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual bool fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const =0
Performs fuzzy comparison between this geometry and other using an epsilon.
virtual void filterVertices(const std::function< bool(const QgsPoint &) > &filter)
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
A 3-dimensional box composed of x, y, z coordinates.
Compound curve geometry type.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
virtual double xAt(int index) const =0
Returns the x-coordinate of the specified node in the line string.
virtual std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex(int index) const =0
Splits the curve at the specified vertex index, returning two curves which represent the portion of t...
virtual double zAt(int index) const =0
Returns the z-coordinate of the specified node in the line string.
virtual double mAt(int index) const =0
Returns the m-coordinate of the specified node in the line string.
virtual double yAt(int index) const =0
Returns the y-coordinate of the specified node in the line string.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
static bool fuzzyEqual(T epsilon, const Args &... args) noexcept
Performs fuzzy comparison between pairs of values within a specified epsilon.
static bool fuzzyDistanceEqual(T epsilon, const Args &... args) noexcept
Compare equality between multiple pairs of values with a specified epsilon.
Represents a single 2D line segment, consisting of a 2D start and end vertex only.
Line string geometry type, with support for z-dimension and m-values.
const double * yData() const
Returns a const pointer to the y vertex data.
bool equals(const QgsCurve &other) const override
Checks whether this curve exactly equals another curve.
const double * xData() const
Returns a const pointer to the x vertex data.
bool fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy comparison between this geometry and other using an epsilon.
QVector< double > xVector() const
Returns the x vertex values as a vector.
const double * zData() const
Returns a const pointer to the z vertex data, or nullptr if the linestring does not have z values.
QVector< double > yVector() const
Returns the y vertex values as a vector.
bool fuzzyDistanceEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy distance comparison between this geometry and other using an epsilon.
static const QgsLineString * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsLineString.
void setZAt(int index, double z)
Sets the z-coordinate of the specified node in the line string.
double mAt(int index) const override
Returns the m value of the specified node in the line string.
QVector< double > zVector() const
Returns the z vertex values as a vector.
const double * mData() const
Returns a const pointer to the m vertex data, or nullptr if the linestring does not have m values.
QVector< double > mVector() const
Returns the m vertex values as a vector.
void setMAt(int index, double m)
Sets the m value of the specified node in the line string.
double zAt(int index) const override
Returns the z-coordinate of the specified node in the line string.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB 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 ...
CORE_EXPORT QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
#define SIP_TYPEHINT(type)
#define SIP_THROW(name,...)
QVector< QgsPoint > QgsPointSequence
QLineF segment(int index, QRectF rect, double radius)
double closestSegment(const QgsPolylineXY &pl, const QgsPointXY &pt, int &vertexAfter, double epsilon)
Utility class for identifying a unique vertex within a geometry.