18 #ifndef QGSLINESTRING_H
19 #define QGSLINESTRING_H
24 #include "qgis_core.h"
76 QgsLineString(
const QVector<double> &x,
const QVector<double> &y,
77 const QVector<double> &z = QVector<double>(),
78 const QVector<double> &m = QVector<double>(),
bool is25DType =
false )
SIP_HOLDGIL;
138 const int count = sipCpp->numPoints();
139 if ( a0 < -count || a0 >= count )
141 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
146 std::unique_ptr< QgsPoint > p;
148 p = std::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
150 p = std::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
151 sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
157 double xAt(
int index )
const override;
168 double xAt(
int index )
const override;
170 const int count = sipCpp->numPoints();
171 if ( a0 < -count || a0 >= count )
173 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
179 return PyFloat_FromDouble( sipCpp->xAt( a0 ) );
181 return PyFloat_FromDouble( sipCpp->xAt( count + a0 ) );
187 double yAt(
int index )
const override;
198 double yAt(
int index )
const override;
200 const int count = sipCpp->numPoints();
201 if ( a0 < -count || a0 >= count )
203 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
209 return PyFloat_FromDouble( sipCpp->yAt( a0 ) );
211 return PyFloat_FromDouble( sipCpp->yAt( count + a0 ) );
224 return mX.constData();
235 return mY.constData();
251 return mZ.constData();
267 return mM.constData();
279 double zAt(
int index )
const
281 if ( index >= 0 && index < mZ.size() )
282 return mZ.at( index );
284 return std::numeric_limits<double>::quiet_NaN();
298 double zAt(
int index )
const;
300 const int count = sipCpp->numPoints();
301 if ( a0 < -count || a0 >= count )
303 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
309 return PyFloat_FromDouble( sipCpp->zAt( a0 ) );
311 return PyFloat_FromDouble( sipCpp->zAt( count + a0 ) );
325 double mAt(
int index )
const
327 if ( index >= 0 && index < mM.size() )
328 return mM.at( index );
330 return std::numeric_limits<double>::quiet_NaN();
344 double mAt(
int index )
const;
346 const int count = sipCpp->numPoints();
347 if ( a0 < -count || a0 >= count )
349 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
355 return PyFloat_FromDouble( sipCpp->mAt( a0 ) );
357 return PyFloat_FromDouble( sipCpp->mAt( count + a0 ) );
371 void setXAt(
int index,
double x );
385 void setXAt(
int index,
double x );
387 const int count = sipCpp->numPoints();
388 if ( a0 < -count || a0 >= count )
390 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
396 sipCpp->setXAt( a0, a1 );
398 sipCpp->setXAt( count + a0, a1 );
412 void setYAt(
int index,
double y );
426 void setYAt(
int index,
double y );
428 const int count = sipCpp->numPoints();
429 if ( a0 < -count || a0 >= count )
431 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
437 sipCpp->setYAt( a0, a1 );
439 sipCpp->setYAt( count + a0, a1 );
455 if ( index >= 0 && index < mZ.size() )
471 void setZAt(
int index,
double z );
473 const int count = sipCpp->numPoints();
474 if ( a0 < -count || a0 >= count )
476 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
482 sipCpp->setZAt( a0, a1 );
484 sipCpp->setZAt( count + a0, a1 );
500 if ( index >= 0 && index < mM.size() )
516 void setMAt(
int index,
double m );
518 const int count = sipCpp->numPoints();
519 if ( a0 < -count || a0 >= count )
521 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
527 sipCpp->setMAt( a0, a1 );
529 sipCpp->setMAt( count + a0, a1 );
551 void addVertex(
const QgsPoint &pt );
568 void extend(
double startDistance,
double endDistance );
577 void visitPointsByRegularDistance(
double distance,
const std::function<
bool(
double x,
double y,
double z,
double m,
578 double startSegmentX,
double startSegmentY,
double startSegmentZ,
double startSegmentM,
579 double endSegmentX,
double endSegmentY,
double endSegmentZ,
double endSegmentM
580 ) > &visitPoint )
const;
588 void clear() override;
590 bool isValid( QString &error
SIP_OUT,
int flags = 0 ) const override;
591 QgsLineString *snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0 ) const override
SIP_FACTORY;
592 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false ) override;
603 QVector<
QgsVertexId > collectDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false ) const;
605 QPolygonF asQPolygonF() const override;
608 bool fromWkt( const QString &wkt ) override;
612 QString asWkt(
int precision = 17 ) const override;
616 QString asKml(
int precision = 17 ) const override;
637 QgsLineString *curveToLine(
double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override
SIP_FACTORY;
643 void draw( QPainter &p ) const override;
646 void transform( const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 ) override;
648 void addToPainterPath( QPainterPath &path ) const override;
649 void drawAsPolygon( QPainter &p ) const override;
653 bool deleteVertex(
QgsVertexId position ) override;
664 void sumUpArea(
double &sum
SIP_OUT ) const override;
665 double vertexAngle(
QgsVertexId vertex ) const override;
666 double segmentLength(
QgsVertexId startVertex ) const override;
667 bool addZValue(
double zValue = 0 ) override;
668 bool addMValue(
double mValue = 0 ) override;
670 bool dropZValue() override;
671 bool dropMValue() override;
672 void swapXy() override;
700 SIP_PYOBJECT __repr__();
702 QString wkt = sipCpp->asWkt();
703 if ( wkt.length() > 1000 )
704 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
705 QString str = QStringLiteral(
"<QgsLineString: %1>" ).arg( wkt );
706 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
719 const int count = sipCpp->numPoints();
720 if ( a0 < -count || a0 >= count )
722 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
727 std::unique_ptr< QgsPoint > p;
729 p = std::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
731 p = std::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
732 sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
744 void __setitem__(
int index,
const QgsPoint &point );
746 const int count = sipCpp->numPoints();
747 if ( a0 < -count || a0 >= count )
749 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
756 sipCpp->setXAt( a0, a1->x() );
757 sipCpp->setYAt( a0, a1->y() );
758 if ( sipCpp->isMeasure() )
759 sipCpp->setMAt( a0, a1->m() );
760 if ( sipCpp->is3D() )
761 sipCpp->setZAt( a0, a1->z() );
774 void __delitem__(
int index );
776 const int count = sipCpp->numPoints();
777 if ( a0 >= 0 && a0 < count )
779 else if ( a0 < 0 && a0 >= -count )
780 sipCpp->deleteVertex(
QgsVertexId( -1, -1, count + a0 ) );
783 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
810 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
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.