18 #ifndef QGSLINESTRING_H
19 #define QGSLINESTRING_H
24 #include "qgis_core.h"
75 QgsLineString(
const QVector<double> &x,
const QVector<double> &y,
76 const QVector<double> &z = QVector<double>(),
77 const QVector<double> &m = QVector<double>(),
bool is25DType =
false )
SIP_HOLDGIL;
137 const int count = sipCpp->numPoints();
138 if ( a0 < -count || a0 >= count )
140 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
145 std::unique_ptr< QgsPoint > p;
147 p = qgis::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
149 p = qgis::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
150 sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
156 double xAt(
int index )
const override;
167 double xAt(
int index )
const override;
169 const int count = sipCpp->numPoints();
170 if ( a0 < -count || a0 >= count )
172 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
178 return PyFloat_FromDouble( sipCpp->xAt( a0 ) );
180 return PyFloat_FromDouble( sipCpp->xAt( count + a0 ) );
186 double yAt(
int index )
const override;
197 double yAt(
int index )
const override;
199 const int count = sipCpp->numPoints();
200 if ( a0 < -count || a0 >= count )
202 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
208 return PyFloat_FromDouble( sipCpp->yAt( a0 ) );
210 return PyFloat_FromDouble( sipCpp->yAt( count + a0 ) );
223 return mX.constData();
234 return mY.constData();
250 return mZ.constData();
266 return mM.constData();
278 double zAt(
int index )
const
280 if ( index >= 0 && index < mZ.size() )
281 return mZ.at( index );
283 return std::numeric_limits<double>::quiet_NaN();
297 double zAt(
int index )
const;
299 const int count = sipCpp->numPoints();
300 if ( a0 < -count || a0 >= count )
302 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
308 return PyFloat_FromDouble( sipCpp->zAt( a0 ) );
310 return PyFloat_FromDouble( sipCpp->zAt( count + a0 ) );
324 double mAt(
int index )
const
326 if ( index >= 0 && index < mM.size() )
327 return mM.at( index );
329 return std::numeric_limits<double>::quiet_NaN();
343 double mAt(
int index )
const;
345 const int count = sipCpp->numPoints();
346 if ( a0 < -count || a0 >= count )
348 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
354 return PyFloat_FromDouble( sipCpp->mAt( a0 ) );
356 return PyFloat_FromDouble( sipCpp->mAt( count + a0 ) );
370 void setXAt(
int index,
double x );
384 void setXAt(
int index,
double x );
386 const int count = sipCpp->numPoints();
387 if ( a0 < -count || a0 >= count )
389 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
395 sipCpp->setXAt( a0, a1 );
397 sipCpp->setXAt( count + a0, a1 );
411 void setYAt(
int index,
double y );
425 void setYAt(
int index,
double y );
427 const int count = sipCpp->numPoints();
428 if ( a0 < -count || a0 >= count )
430 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
436 sipCpp->setYAt( a0, a1 );
438 sipCpp->setYAt( count + a0, a1 );
454 if ( index >= 0 && index < mZ.size() )
470 void setZAt(
int index,
double z );
472 const int count = sipCpp->numPoints();
473 if ( a0 < -count || a0 >= count )
475 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
481 sipCpp->setZAt( a0, a1 );
483 sipCpp->setZAt( count + a0, a1 );
499 if ( index >= 0 && index < mM.size() )
515 void setMAt(
int index,
double m );
517 const int count = sipCpp->numPoints();
518 if ( a0 < -count || a0 >= count )
520 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
526 sipCpp->setMAt( a0, a1 );
528 sipCpp->setMAt( count + a0, a1 );
550 void addVertex(
const QgsPoint &pt );
567 void extend(
double startDistance,
double endDistance );
576 void visitPointsByRegularDistance(
double distance,
const std::function<
bool(
double x,
double y,
double z,
double m,
577 double startSegmentX,
double startSegmentY,
double startSegmentZ,
double startSegmentM,
578 double endSegmentX,
double endSegmentY,
double endSegmentZ,
double endSegmentM
579 ) > &visitPoint )
const;
587 void clear() override;
589 bool isValid( QString &error
SIP_OUT,
int flags = 0 ) const override;
590 QgsLineString *snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0 ) const override
SIP_FACTORY;
591 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false ) override;
600 QVector<
QgsVertexId > collectDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false ) const;
602 QPolygonF asQPolygonF() const override;
605 bool fromWkt( const QString &wkt ) override;
609 QString asWkt(
int precision = 17 ) const override;
613 QString asKml(
int precision = 17 ) const override;
634 QgsLineString *curveToLine(
double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override
SIP_FACTORY;
640 void draw( QPainter &p ) const override;
643 void transform( const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 ) override;
645 void addToPainterPath( QPainterPath &path ) const override;
646 void drawAsPolygon( QPainter &p ) const override;
650 bool deleteVertex(
QgsVertexId position ) override;
661 void sumUpArea(
double &sum
SIP_OUT ) const override;
662 double vertexAngle(
QgsVertexId vertex ) const override;
663 double segmentLength(
QgsVertexId startVertex ) const override;
664 bool addZValue(
double zValue = 0 ) override;
665 bool addMValue(
double mValue = 0 ) override;
667 bool dropZValue() override;
668 bool dropMValue() override;
669 void swapXy() override;
697 SIP_PYOBJECT __repr__();
699 QString wkt = sipCpp->asWkt();
700 if ( wkt.length() > 1000 )
701 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
702 QString str = QStringLiteral(
"<QgsLineString: %1>" ).arg( wkt );
703 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
716 const int count = sipCpp->numPoints();
717 if ( a0 < -count || a0 >= count )
719 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
724 std::unique_ptr< QgsPoint > p;
726 p = qgis::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
728 p = qgis::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
729 sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
741 void __setitem__(
int index,
const QgsPoint &point );
743 const int count = sipCpp->numPoints();
744 if ( a0 < -count || a0 >= count )
746 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
753 sipCpp->setXAt( a0, a1->x() );
754 sipCpp->setYAt( a0, a1->y() );
755 if ( sipCpp->isMeasure() )
756 sipCpp->setMAt( a0, a1->m() );
757 if ( sipCpp->is3D() )
758 sipCpp->setZAt( a0, a1->z() );
771 void __delitem__(
int index );
773 const int count = sipCpp->numPoints();
774 if ( a0 >= 0 && a0 < count )
776 else if ( a0 < 0 && a0 >= -count )
777 sipCpp->deleteVertex(
QgsVertexId( -1, -1, count + a0 ) );
780 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
807 importVerticesFromWkb( wkb );
Abstract base class for all geometries.
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
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.
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.
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...
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
Compound curve geometry type.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
QgsCurve * toCurveType() const override
Returns the geometry converted to the more generic curve type.
virtual double xAt(int index) const =0
Returns the x-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.
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.
static const QgsLineString * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsLineString.
const double * mData() const
Returns a const pointer to the m vertex data, or nullptr if the linestring does not have m values.
void setZAt(int index, double z)
Sets the z-coordinate of the specified node in the line string.
double mAt(int index) const
Returns the m value of the specified node in the line string.
double zAt(int index) const
Returns the z-coordinate of the specified node in the line string.
void setMAt(int index, double m)
Sets the m value of the specified node in the line string.
const double * xData() const
Returns a const pointer to the x vertex data.
const double * zData() const
Returns a const pointer to the z vertex data, or nullptr if the linestring does not have z values.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
Handles storage of information regarding WKB types and their properties.
Type
The WKB type describes the number of dimensions a geometry has.
static Type flatType(Type type) SIP_HOLDGIL
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 ...
#define SIP_TYPEHINT(type)
QVector< QgsPoint > QgsPointSequence
double closestSegment(const QgsPolylineXY &pl, const QgsPointXY &pt, int &vertexAfter, double epsilon)
Utility class for identifying a unique vertex within a geometry.