18 #ifndef QGSLINESTRING_H 19 #define QGSLINESTRING_H 24 #include "qgis_core.h" 71 QgsLineString(
const QVector<double> &x,
const QVector<double> &y,
72 const QVector<double> &z = QVector<double>(),
73 const QVector<double> &m = QVector<double>(),
bool is25DType =
false );
133 const int count = sipCpp->numPoints();
134 if ( a0 < -count || a0 >= count )
136 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
141 std::unique_ptr< QgsPoint > p;
143 p = qgis::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
145 p = qgis::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
146 sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
152 double xAt(
int index )
const override;
163 double xAt(
int index )
const override;
165 const int count = sipCpp->numPoints();
166 if ( a0 < -count || a0 >= count )
168 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
174 return PyFloat_FromDouble( sipCpp->xAt( a0 ) );
176 return PyFloat_FromDouble( sipCpp->xAt( count + a0 ) );
182 double yAt(
int index )
const override;
193 double yAt(
int index )
const override;
195 const int count = sipCpp->numPoints();
196 if ( a0 < -count || a0 >= count )
198 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
204 return PyFloat_FromDouble( sipCpp->yAt( a0 ) );
206 return PyFloat_FromDouble( sipCpp->yAt( count + a0 ) );
219 return mX.constData();
230 return mY.constData();
246 return mZ.constData();
262 return mM.constData();
274 double zAt(
int index )
const 276 if ( index >= 0 && index < mZ.size() )
277 return mZ.at( index );
279 return std::numeric_limits<double>::quiet_NaN();
293 double zAt(
int index )
const;
295 const int count = sipCpp->numPoints();
296 if ( a0 < -count || a0 >= count )
298 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
304 return PyFloat_FromDouble( sipCpp->zAt( a0 ) );
306 return PyFloat_FromDouble( sipCpp->zAt( count + a0 ) );
320 double mAt(
int index )
const 322 if ( index >= 0 && index < mM.size() )
323 return mM.at( index );
325 return std::numeric_limits<double>::quiet_NaN();
339 double mAt(
int index )
const;
341 const int count = sipCpp->numPoints();
342 if ( a0 < -count || a0 >= count )
344 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
350 return PyFloat_FromDouble( sipCpp->mAt( a0 ) );
352 return PyFloat_FromDouble( sipCpp->mAt( count + a0 ) );
366 void setXAt(
int index,
double x );
380 void setXAt(
int index,
double x );
382 const int count = sipCpp->numPoints();
383 if ( a0 < -count || a0 >= count )
385 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
391 sipCpp->setXAt( a0, a1 );
393 sipCpp->setXAt( count + a0, a1 );
407 void setYAt(
int index,
double y );
421 void setYAt(
int index,
double y );
423 const int count = sipCpp->numPoints();
424 if ( a0 < -count || a0 >= count )
426 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
432 sipCpp->setYAt( a0, a1 );
434 sipCpp->setYAt( count + a0, a1 );
450 if ( index >= 0 && index < mZ.size() )
466 void setZAt(
int index,
double z );
468 const int count = sipCpp->numPoints();
469 if ( a0 < -count || a0 >= count )
471 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
477 sipCpp->setZAt( a0, a1 );
479 sipCpp->setZAt( count + a0, a1 );
495 if ( index >= 0 && index < mM.size() )
511 void setMAt(
int index,
double m );
513 const int count = sipCpp->numPoints();
514 if ( a0 < -count || a0 >= count )
516 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
522 sipCpp->setMAt( a0, a1 );
524 sipCpp->setMAt( count + a0, a1 );
546 void addVertex(
const QgsPoint &pt );
562 void extend(
double startDistance,
double endDistance );
569 void clear()
override;
572 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<double>::epsilon(),
bool useZValues =
false )
override;
576 bool fromWkt(
const QString &wkt )
override;
578 QByteArray
asWkb()
const override;
585 double length()
const override;
593 double length3D()
const;
608 void draw( QPainter &p )
const override;
611 void transform(
const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 )
override;
629 void sumUpArea(
double &sum SIP_OUT )
const override;
632 bool addZValue(
double zValue = 0 )
override;
633 bool addMValue(
double mValue = 0 )
override;
663 SIP_PYOBJECT __repr__();
665 QString wkt = sipCpp->asWkt();
666 if ( wkt.length() > 1000 )
667 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
668 QString str = QStringLiteral(
"<QgsLineString: %1>" ).arg( wkt );
669 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
682 const int count = sipCpp->numPoints();
683 if ( a0 < -count || a0 >= count )
685 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
690 std::unique_ptr< QgsPoint > p;
692 p = qgis::make_unique< QgsPoint >( sipCpp->pointN( a0 ) );
694 p = qgis::make_unique< QgsPoint >( sipCpp->pointN( count + a0 ) );
695 sipRes = sipConvertFromType( p.release(), sipType_QgsPoint, Py_None );
707 void __setitem__(
int index,
const QgsPoint &point );
709 const int count = sipCpp->numPoints();
710 if ( a0 < -count || a0 >= count )
712 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
719 sipCpp->setXAt( a0, a1->x() );
720 sipCpp->setYAt( a0, a1->y() );
721 if ( sipCpp->isMeasure() )
722 sipCpp->setMAt( a0, a1->m() );
723 if ( sipCpp->is3D() )
724 sipCpp->setZAt( a0, a1->z() );
737 void __delitem__(
int index );
739 const int count = sipCpp->numPoints();
740 if ( a0 >= 0 && a0 < count )
742 else if ( a0 < 0 && a0 >= -count )
743 sipCpp->deleteVertex(
QgsVertexId( -1, -1, count + a0 ) );
746 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
773 importVerticesFromWkb( wkb );
783 #endif // QGSLINESTRING_H
virtual QgsCurve * reversed() const =0
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
A rectangle specified with double values.
virtual QgsAbstractGeometry * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const =0
Makes a new geometry with all the points or vertices snapped to the closest point of the grid...
virtual bool isEmpty() const
Returns true if the geometry is empty.
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 bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
virtual QgsPoint * interpolatePoint(double distance) const =0
Returns an interpolated point on the curve at the specified distance.
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)=0
Transforms the geometry using a coordinate transform.
double zAt(int index) const
Returns the z-coordinate of the specified node in the line string.
virtual QByteArray asWkb() const =0
Returns a WKB representation of the geometry.
const double * mData() const
Returns a const pointer to the m vertex data, or nullptr if the linestring does not have m values...
virtual bool insertVertex(QgsVertexId position, const QgsPoint &vertex)=0
Inserts a vertex into the geometry.
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
virtual void sumUpArea(double &sum) const =0
Sums up the area of the curve by iterating over the vertices (shoelace formula).
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership...
virtual QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const =0
Returns a GML2 representation of the geometry.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
virtual bool pointAt(int node, QgsPoint &point, QgsVertexId::VertexType &type) const =0
Returns the point and vertex id of a point within the curve.
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
#define SIP_TYPEHINT(type)
virtual QgsPoint centroid() const
Returns the centroid of the geometry.
virtual QgsPoint endPoint() const =0
Returns the end point of the curve.
const double * xData() const
Returns a const pointer to the x vertex data.
virtual QPolygonF asQPolygonF() const
Returns a QPolygonF representing the points.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
Type
The WKB type describes the number of dimensions a geometry has.
virtual double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const =0
Searches for the closest segment of the geometry to a given point.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
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...
virtual QgsCurve * curveSubstring(double startDistance, double endDistance) const =0
Returns a new curve representing a substring of this curve.
Utility class for identifying a unique vertex within a geometry.
double mAt(int index) const
Returns the m value of the specified node in the line string.
virtual double xAt(int index) const =0
Returns the x-coordinate of the specified node in the line string.
Abstract base class for curved geometry type.
Abstract base class for all geometries.
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
void setZAt(int index, double z)
Sets the z-coordinate of the specified node in the line string.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Point geometry type, with support for z-dimension and m-values.
const double * yData() const
Returns a const pointer to the y vertex data.
AxisOrder
Axis order for GML generation.
Represents a single 2D line segment, consisting of a 2D start and end vertex only.
const double * zData() const
Returns a const pointer to the z vertex data, or nullptr if the linestring does not have z values...
void setMAt(int index, double m)
Sets the m value of the specified node in the line string.
QVector< QgsPoint > QgsPointSequence
virtual void addToPainterPath(QPainterPath &path) const =0
Adds a curve to a painter path.
QgsCurve * toCurveType() const override
Returns the geometry converted to the more generic curve type.
virtual void clear()=0
Clears the geometry, ie reset it to a null geometry.
virtual bool moveVertex(QgsVertexId position, const QgsPoint &newPos)=0
Moves a vertex within the geometry.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
const QgsLineString * cast(const QgsAbstractGeometry *geom) const
Cast the geom to a QgsLineString.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
Line string geometry type, with support for z-dimension and m-values.
virtual QgsLineString * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
virtual double yAt(int index) const =0
Returns the y-coordinate of the specified node in the line string.
virtual bool convertTo(QgsWkbTypes::Type type)
Converts the geometry to a specified type.
Compound curve geometry type.
virtual bool removeDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false)=0
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
Custom exception class for Coordinate Reference System related exceptions.
virtual void drawAsPolygon(QPainter &p) const =0
Draws the curve as a polygon on the specified QPainter.
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
virtual bool fromWkt(const QString &wkt)=0
Sets the geometry from a WKT string.
virtual QgsPoint startPoint() const =0
Returns the starting point of the curve.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
static Type flatType(Type type)
Returns the flat type for a WKB type.
virtual void swapXy()=0
Swaps the x and y coordinates from the geometry.
virtual int numPoints() const =0
Returns the number of points in the curve.
virtual json asJsonObject(int precision=17) const
Returns a json object representation of the geometry.
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'. Negativ values mean left a...
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
virtual void points(QgsPointSequence &pt) const =0
Returns a list of points within the curve.
virtual QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const =0
Returns a GML3 representation of the geometry.
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
virtual bool fromWkb(QgsConstWkbPtr &wkb)=0
Sets the geometry from a WKB string.