82 if ( !PySequence_Check( a0 ) )
84 PyErr_SetString( PyExc_TypeError, u
"A sequence of QgsPoint, QgsPointXY or array of floats is expected"_s.toUtf8().constData() );
90 const int size = PySequence_Size( a0 );
103 for (
int i = 0; i < size; ++i )
105 PyObject *value = PySequence_GetItem( a0, i );
108 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
113 if ( PySequence_Check( value ) )
115 const int elementSize = PySequence_Size( value );
116 if ( elementSize < 2 || elementSize > 4 )
119 PyErr_SetString( PyExc_TypeError, u
"Invalid sequence size at index %1. Expected an array of 2-4 float values, got %2."_s.arg( i ).arg( elementSize ).toUtf8().constData() );
126 for (
int j = 0; j < elementSize; ++j )
128 PyObject *element = PySequence_GetItem( value, j );
131 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
137 double d = PyFloat_AsDouble( element );
138 if ( PyErr_Occurred() )
149 if ( i == 0 && j == 2 )
155 else if ( i > 0 && j == 2 && hasZ )
160 if ( i == 0 && j == 3 )
166 else if ( i > 0 && j == 3 && hasM )
171 Py_DECREF( element );
174 if ( hasZ && elementSize < 3 )
175 zl.append( std::numeric_limits< double >::quiet_NaN() );
176 if ( hasM && elementSize < 4 )
177 ml.append( std::numeric_limits< double >::quiet_NaN() );
188 if ( sipCanConvertToType( value, sipType_QgsPointXY, SIP_NOT_NONE ) )
191 QgsPointXY *p =
reinterpret_cast<QgsPointXY *
>( sipConvertToType( value, sipType_QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
197 sipReleaseType( p, sipType_QgsPointXY, state );
199 else if ( sipCanConvertToType( value, sipType_QgsPoint, SIP_NOT_NONE ) )
202 QgsPoint *p =
reinterpret_cast<QgsPoint *
>( sipConvertToType( value, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
208 if ( i == 0 && p->
is3D() )
214 else if ( i > 0 && hasZ )
225 else if ( i > 0 && hasM )
233 sipReleaseType( p, sipType_QgsPoint, state );
245 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1. Expected QgsPoint, QgsPointXY or array of floats."_s.arg( i ) .toUtf8().constData() );
251 sipCpp =
new sipQgsLineString(
QgsLineString( xl, yl, zl, ml, is25D ) );
279 QgsLineString(
const QVector<double> &x,
const QVector<double> &y,
280 const QVector<double> &z = QVector<double>(),
281 const QVector<double> &m = QVector<double>(),
bool is25DType =
false )
SIP_HOLDGIL;
306 static std::unique_ptr< QgsLineString >
fromQPolygonF(
const QPolygonF &polygon );
309 bool fuzzyHelper(
double epsilon,
313 std::function<
bool(
double,
double,
double,
double,
double,
double,
double,
double,
double )> comparator3DMeasure,
314 std::function<
bool(
double,
double,
double,
double,
double,
double,
double )> comparator3D,
315 std::function<
bool(
double,
double,
double,
double,
double,
double,
double )> comparatorMeasure,
316 std::function<
bool(
double,
double,
double,
double,
double )> comparator2D )
const
325 const int size = mX.count();
326 if ( size != otherLine->mX.count() )
330 const double *
xData = mX.constData();
331 const double *
yData = mY.constData();
332 const double *
zData = is3DFlag ? mZ.constData() :
nullptr;
333 const double *
mData = isMeasureFlag ? mM.constData() :
nullptr;
334 const double *otherXData = otherLine->mX.constData();
335 const double *otherYData = otherLine->mY.constData();
336 const double *otherZData = is3DFlag ? otherLine->mZ.constData() :
nullptr;
337 const double *otherMData = isMeasureFlag ? otherLine->mM.constData() :
nullptr;
338 for (
int i = 0; i < size; ++i )
340 if ( is3DFlag && isMeasureFlag )
343 *otherXData++, *otherYData++, *otherZData++, *otherMData++ );
348 *otherXData++, *otherYData++, *otherZData++ );
350 else if ( isMeasureFlag )
353 *otherXData++, *otherYData++, *otherMData++ );
357 result &= comparator2D( epsilon, *
xData++, *
yData++,
358 *otherXData++, *otherYData++ );
378 [](
double epsilon,
double x1,
double y1,
double z1,
double m1,
379 double x2,
double y2,
double z2,
double m2 )
383 [](
double epsilon,
double x1,
double y1,
double z1,
384 double x2,
double y2,
double z2 )
388 [](
double epsilon,
double x1,
double y1,
double m1,
389 double x2,
double y2,
double m2 )
393 [](
double epsilon,
double x1,
double y1,
394 double x2,
double y2 )
407 [](
double epsilon,
double x1,
double y1,
double z1,
double m1,
408 double x2,
double y2,
double z2,
double m2 )
412 [](
double epsilon,
double x1,
double y1,
double z1,
413 double x2,
double y2,
double z2 )
417 [](
double epsilon,
double x1,
double y1,
double m1,
418 double x2,
double y2,
double m2 )
422 [](
double epsilon,
double x1,
double y1,
423 double x2,
double y2 )
454 const int count = sipCpp->numPoints();
455 if ( a0 < -count || a0 >= count )
457 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
462 std::unique_ptr< QgsPoint > p;
464 p = std::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
466 p = std::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
467 sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
473 double xAt(
int index )
const override;
484 double xAt(
int index )
const override;
486 const int count = sipCpp->numPoints();
487 if ( a0 < -count || a0 >= count )
489 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
495 return PyFloat_FromDouble( sipCpp->xAt( a0 ) );
497 return PyFloat_FromDouble( sipCpp->xAt( count + a0 ) );
503 double yAt(
int index )
const override;
514 double yAt(
int index )
const override;
516 const int count = sipCpp->numPoints();
517 if ( a0 < -count || a0 >= count )
519 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
525 return PyFloat_FromDouble( sipCpp->yAt( a0 ) );
527 return PyFloat_FromDouble( sipCpp->yAt( count + a0 ) );
540 return mX.constData();
551 return mY.constData();
567 return mZ.constData();
583 return mM.constData();
636 double zAt(
int index )
const override
638 if ( index >= 0 && index < mZ.size() )
639 return mZ.at( index );
641 return std::numeric_limits<double>::quiet_NaN();
655 double zAt(
int index )
const override;
657 const int count = sipCpp->numPoints();
658 if ( a0 < -count || a0 >= count )
660 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
666 return PyFloat_FromDouble( sipCpp->zAt( a0 ) );
668 return PyFloat_FromDouble( sipCpp->zAt( count + a0 ) );
682 double mAt(
int index )
const override
684 if ( index >= 0 && index < mM.size() )
685 return mM.at( index );
687 return std::numeric_limits<double>::quiet_NaN();
701 double mAt(
int index )
const override;
703 const int count = sipCpp->numPoints();
704 if ( a0 < -count || a0 >= count )
706 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
712 return PyFloat_FromDouble( sipCpp->mAt( a0 ) );
714 return PyFloat_FromDouble( sipCpp->mAt( count + a0 ) );
728 void setXAt(
int index,
double x );
742 void setXAt(
int index,
double x );
744 const int count = sipCpp->numPoints();
745 if ( a0 < -count || a0 >= count )
747 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
753 sipCpp->setXAt( a0, a1 );
755 sipCpp->setXAt( count + a0, a1 );
769 void setYAt(
int index,
double y );
783 void setYAt(
int index,
double y );
785 const int count = sipCpp->numPoints();
786 if ( a0 < -count || a0 >= count )
788 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
794 sipCpp->setYAt( a0, a1 );
796 sipCpp->setYAt( count + a0, a1 );
812 if ( index >= 0 && index < mZ.size() )
827 void setZAt(
int index,
double z );
829 const int count = sipCpp->numPoints();
830 if ( a0 < -count || a0 >= count )
832 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
838 sipCpp->setZAt( a0, a1 );
840 sipCpp->setZAt( count + a0, a1 );
856 if ( index >= 0 && index < mM.size() )
871 void setMAt(
int index,
double m );
873 const int count = sipCpp->numPoints();
874 if ( a0 < -count || a0 >= count )
876 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
882 sipCpp->setMAt( a0, a1 );
884 sipCpp->setMAt( count + a0, a1 );
902 void setPoints(
size_t size,
const double *x,
const double *y,
const double *z =
nullptr,
const double *m =
nullptr )
SIP_SKIP;
915 void append( const QgsLineString *line );
921 void addVertex( const QgsPoint &pt );
930 QgsCompoundCurve *toCurveType() const override
SIP_FACTORY;
937 void extend(
double startDistance,
double endDistance );
947 double startSegmentX,
double startSegmentY,
double startSegmentZ,
double startSegmentM,
948 double endSegmentX,
double endSegmentY,
double endSegmentZ,
double endSegmentM
949 ) > &visitPoint )
const;
956 void clear() override;
958 int indexOf( const QgsPoint &point ) const final;
959 bool isValid( QString &error
SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
960 QgsLineString *snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0,
bool removeRedundantPoints = false ) const override
SIP_FACTORY;
961 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false ) override;
964 bool boundingBoxIntersects( const QgsRectangle &rectangle ) const override
SIP_HOLDGIL;
965 bool boundingBoxIntersects( const QgsBox3D &box3d ) const override
SIP_HOLDGIL;
974 QVector< QgsVertexId > collectDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false ) const;
976 QPolygonF asQPolygonF() const override;
978 QgsLineString *simplifyByDistance(
double tolerance ) const override
SIP_FACTORY;
979 bool fromWkb( QgsConstWkbPtr &wkb ) override;
980 bool fromWkt( const QString &wkt ) override;
982 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
983 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
984 QString asWkt(
int precision = 17 ) const override;
985 QDomElement asGml2( QDomDocument &doc,
int precision = 17, const QString &ns =
"gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
986 QDomElement asGml3( QDomDocument &doc,
int precision = 17, const QString &ns =
"gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
987 json asJsonObject(
int precision = 17 ) const override
SIP_SKIP;
988 QString asKml(
int precision = 17 ) const override;
994 std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > >
splitCurveAtVertex(
int index )
const final;
1005 QVector<QgsLineString *> splitToDisjointXYParts() const
SIP_FACTORY;
1023 QgsLineString *curveToLine(
double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override
SIP_FACTORY;
1029 void draw( QPainter &p ) const override;
1031 void transform( const QgsCoordinateTransform &ct, Qgis::TransformDirection d = Qgis::TransformDirection::Forward,
bool transformZ = false ) override
SIP_THROW( QgsCsException );
1032 void transform( const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 ) override;
1034 void addToPainterPath( QPainterPath &path ) const override;
1035 void drawAsPolygon( QPainter &p ) const override;
1037 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
1038 bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
1039 bool deleteVertex( QgsVertexId position ) override;
1041 QgsLineString *reversed() const override
SIP_FACTORY;
1042 QgsPoint *interpolatePoint(
double distance ) const override
SIP_FACTORY;
1043 QgsLineString *curveSubstring(
double startDistance,
double endDistance ) const override
SIP_FACTORY;
1045 double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt
SIP_OUT, QgsVertexId &vertexAfter
SIP_OUT,
int *leftOf
SIP_OUT =
nullptr,
double epsilon = 4 * std::numeric_limits<
double>::epsilon() ) const override;
1046 bool pointAt(
int node, QgsPoint &point, Qgis::VertexType &type ) const override;
1048 QgsPoint centroid() const override;
1060 void sumUpArea(
double &sum
SIP_OUT ) const override;
1072 void sumUpArea3D(
double &sum
SIP_OUT ) const override;
1074 double vertexAngle( QgsVertexId vertex ) const override;
1075 double segmentLength( QgsVertexId startVertex ) const override;
1076 double distanceBetweenVertices( QgsVertexId fromVertex, QgsVertexId toVertex ) const override;
1077 bool addZValue(
double zValue = 0 ) override;
1078 bool addMValue(
double mValue = 0 ) override;
1080 bool dropZValue() override;
1081 bool dropMValue() override;
1082 void swapXy() override;
1084 bool convertTo( Qgis::WkbType type ) override;
1086 bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback =
nullptr ) override;
1087 void scroll(
int firstVertexIndex ) final;
1090 void filterVertices(
const std::function<
bool(
const QgsPoint & ) > &filter )
override;
1091 void transformVertices(
const std::function< QgsPoint(
const QgsPoint & ) > &transform )
override;
1127 SIP_PYOBJECT __repr__();
1129 QString wkt = sipCpp->asWkt();
1130 if ( wkt.length() > 1000 )
1131 wkt = wkt.left( 1000 ) + u
"..."_s;
1132 QString str = u
"<QgsLineString: %1>"_s.arg( wkt );
1133 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1147 const int count = sipCpp->numPoints();
1148 if ( a0 < -count || a0 >= count )
1150 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
1155 std::unique_ptr< QgsPoint > p;
1157 p = std::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
1159 p = std::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
1160 sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
1173 void __setitem__(
int index,
const QgsPoint &point );
1175 const int count = sipCpp->numPoints();
1176 if ( a0 < -count || a0 >= count )
1178 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
1185 sipCpp->setXAt( a0, a1->x() );
1186 sipCpp->setYAt( a0, a1->y() );
1187 if ( sipCpp->isMeasure() )
1188 sipCpp->setMAt( a0, a1->m() );
1189 if ( sipCpp->is3D() )
1190 sipCpp->setZAt( a0, a1->z() );
1204 void __delitem__(
int index );
1206 const int count = sipCpp->numPoints();
1207 if ( a0 >= 0 && a0 < count )
1208 sipCpp->deleteVertex( QgsVertexId( -1, -1, a0 ) );
1209 else if ( a0 < 0 && a0 >= -count )
1210 sipCpp->deleteVertex( QgsVertexId( -1, -1, count + a0 ) );
1213 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
1226 Q_DECL_DEPRECATED QgsBox3D calculateBoundingBox3d() const
SIP_DEPRECATED;
1233 QgsBox3D calculateBoundingBox3D() const override;
1241 std::unique_ptr< QgsLineString > measuredLine(
double start,
double end ) const;
1256 std::unique_ptr< QgsLineString > interpolateM(
bool use3DDistance = true ) const;
1282 bool lineLocatePointByM(
double m,
double &x
SIP_OUT,
double &y
SIP_OUT,
double &z
SIP_OUT,
double &distanceFromStart
SIP_OUT,
bool use3DDistance = true ) const;
1286 int compareToSameClass( const QgsAbstractGeometry *other ) const final;
1294 void importVerticesFromWkb( const QgsConstWkbPtr &wkb );
1301 void fromWkbPoints( Qgis::WkbType type, const QgsConstWkbPtr &wkb )
1304 importVerticesFromWkb( wkb );
1307 bool lineLocatePointByMPrivate(
double m,
double &x,
double &y,
double &z,
double &distanceFromStart,
bool use3DDistance,
bool haveInterpolatedM )
const;