QGIS API Documentation 4.1.0-Master (3fcefe620d1)
Loading...
Searching...
No Matches
QgsLineString Class Reference

Line string geometry type, with support for z-dimension and m-values. More...

#include <qgslinestring.h>

Inheritance diagram for QgsLineString:

Public Member Functions

 QgsLineString ()
 Constructor for an empty linestring geometry.
 QgsLineString (const QgsLineSegment2D &segment)
 Construct a linestring from a single 2d line segment.
 QgsLineString (const QgsPoint &p1, const QgsPoint &p2)
 Constructs a linestring with a single segment from p1 to p2.
 QgsLineString (const QVector< double > &x, const QVector< double > &y, const QVector< double > &z=QVector< double >(), const QVector< double > &m=QVector< double >(), bool is25DType=false)
 Construct a linestring from arrays of coordinates.
 QgsLineString (const QVector< QgsPoint > &points)
 Construct a linestring from a vector of points.
 QgsLineString (const QVector< QgsPointXY > &points)
 Construct a linestring from list of points.
void addToPainterPath (QPainterPath &path) const override
 Adds a curve to a painter path.
void addVertex (const QgsPoint &pt)
 Adds a new vertex to the end of the line string.
QDomElement asGml2 (QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
 Returns a GML2 representation of the geometry.
QDomElement asGml3 (QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
 Returns a GML3 representation of the geometry.
json asJsonObject (int precision=17) const override
 Returns a json object representation of the geometry.
QString asKml (int precision=17) const override
 Returns a KML representation of the geometry.
QPolygonF asQPolygonF () const override
 Returns a QPolygonF representing the points.
bool boundingBoxIntersects (const QgsBox3D &box3d) const override
 Returns true if the bounding box of this geometry intersects with a box3d.
bool boundingBoxIntersects (const QgsRectangle &rectangle) const override
 Returns true if the bounding box of this geometry intersects with a rectangle.
QgsBox3D calculateBoundingBox3D () const override
 Calculates the minimal 3D bounding box for the geometry.
Q_DECL_DEPRECATED QgsBox3D calculateBoundingBox3d () const
 Calculates the minimal 3D bounding box for the geometry.
QgsPoint centroid () const override
 Returns the centroid of the geometry.
void clear () override
 Clears the geometry, ie reset it to a null geometry.
QgsLineStringclone () const override
 Clones the geometry by performing a deep copy.
void close ()
 Closes the line string by appending the first point to the end of the line, if it is not already closed.
double closestSegment (const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const override
 Searches for the closest segment of the geometry to a given point.
QVector< QgsVertexIdcollectDuplicateNodes (double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false) const
 Returns a list of any duplicate nodes contained in the geometry, within the specified tolerance.
bool convertTo (Qgis::WkbType type) override
 Converts the geometry to a specified type.
QgsLineStringcreateEmptyWithSameType () const override
 Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
QgsLineStringcurveSubstring (double startDistance, double endDistance) const override
 Returns a new curve representing a substring of this curve.
QgsLineStringcurveToLine (double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
 Returns a new line string geometry corresponding to a segmentized approximation of the curve.
bool deleteVertex (QgsVertexId position) override
 Deletes a vertex within the geometry.
bool deleteVertices (const QSet< QgsVertexId > &positions) override
 Deletes vertices within the geometry.
double distanceBetweenVertices (QgsVertexId fromVertex, QgsVertexId toVertex) const override
 Returns the distance along the curve between two vertices.
void draw (QPainter &p) const override
 Draws the geometry using the specified QPainter.
void drawAsPolygon (QPainter &p) const override
 Draws the curve as a polygon on the specified QPainter.
void extend (double startDistance, double endDistance)
 Extends the line geometry by extrapolating out the start or end of the line by a specified distance.
QString geometryType () const override
 Returns a unique string representing the geometry type.
int indexOf (const QgsPoint &point) const final
 Returns the index of the first vertex matching the given point, or -1 if a matching vertex is not found.
bool insertVertex (QgsVertexId position, const QgsPoint &vertex) override
 Inserts a vertex into the geometry.
std::unique_ptr< QgsLineStringinterpolateM (bool use3DDistance=true) const
 Returns a copy of this line with all missing (NaN) m values interpolated from m values of surrounding vertices.
QgsPointinterpolatePoint (double distance) const override
 Returns an interpolated point on the curve at the specified distance.
bool isClosed () const override
 Returns true if the curve is closed.
bool isClosed2D () const override
 Returns true if the curve is closed.
bool isValid (QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const override
 Checks validity of the geometry, and returns true if the geometry is valid.
double length () const override
 Returns the planar, 2-dimensional length of the geometry.
double length3D () const
 Returns the length in 3D world of the line string.
bool lineLocatePointByM (double m, double &x, double &y, double &z, double &distanceFromStart, bool use3DDistance=true) const
 Attempts to locate a point on the linestring by m value.
std::unique_ptr< QgsLineStringmeasuredLine (double start, double end) const
 Re-write the measure ordinate (or add one, if it isn't already there) interpolating the measure between the supplied start and end values.
bool pointAt (int node, QgsPoint &point, Qgis::VertexType &type) const override
 Returns the point and vertex type of a point within the curve.
bool removeDuplicateNodes (double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false) override
 Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerate geometry.
QgsLineStringreversed () const override
 Returns a reversed copy of the curve, where the direction of the curve has been flipped.
double segmentLength (QgsVertexId startVertex) const override
 Returns the length of the segment of the geometry which begins at startVertex.
void setPoints (const QgsPointSequence &points)
 Resets the simple curve to match the specified list of points.
void setPoints (size_t size, const double *x, const double *y, const double *z=nullptr, const double *m=nullptr)
 Resets the line string to match the specified point data.
QgsLineStringsimplifyByDistance (double tolerance) const override
 Simplifies the geometry by applying the Douglas Peucker simplification by distance algorithm.
QgsLineStringsnappedToGrid (double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0, bool removeRedundantPoints=false) const override
 Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > splitCurveAtVertex (int index) const final
 Splits the curve at the specified vertex index, returning two curves which represent the portion of the curve up to including the vertex at index, and the portion of the curve from the vertex at index (inclusive) to the end of the curve.
QVector< QgsLineString * > splitToDisjointXYParts () const
 Divides the linestring into parts that don't share any points or lines.
void sumUpArea (double &sum) const override
 Calculates the shoelace/triangle formula sum for the points in the linestring.
void sumUpArea3D (double &sum) const override
 Calculates the shoelace/triangle formula sum for the points in the linestring.
QgsCompoundCurvetoCurveType () const override
 Returns the geometry converted to the more generic curve type QgsCompoundCurve.
double vertexAngle (QgsVertexId vertex) const override
 Returns approximate angle at a vertex.
void visitPointsByRegularDistance (double distance, const std::function< bool(double x, double y, double z, double m, double startSegmentX, double startSegmentY, double startSegmentZ, double startSegmentM, double endSegmentX, double endSegmentY, double endSegmentZ, double endSegmentM) > &visitPoint) const
 Visits regular points along the linestring, spaced by distance.
Public Member Functions inherited from QgsSimpleCurve
bool addMValue (double mValue=0) override
 Adds a measure to the geometry, initialized to a preset value.
bool addZValue (double zValue=0) override
 Adds a z-dimension to the geometry, initialized to a preset value.
void append (const QgsSimpleCurve *curve)
 Appends the contents of another simple curve to the end of this simple curve.
QByteArray asWkb (QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
 Returns a WKB representation of the geometry.
QString asWkt (int precision=17) const override
 Returns a WKT representation of the geometry.
void clear () override
 Clears the geometry, ie reset it to a null geometry.
int dimension () const override
 Returns the inherent dimension of the geometry.
bool dropMValue () override
 Drops any measure values which exist in the geometry.
bool dropZValue () override
 Drops any z-dimensions which exist in the geometry.
QgsPoint endPoint () const override
 Returns the end point of the curve.
bool equals (const QgsCurve &other) const override
 Checks whether this curve exactly equals another curve.
void filterVertices (const std::function< bool(const QgsPoint &) > &filter) override
 Filters the vertices from the geometry in place, removing any which do not return true for the filter function check.
bool fromWkb (QgsConstWkbPtr &wkb) override
 Sets the geometry from a WKB string.
bool fromWkt (const QString &wkt) override
 Sets the geometry from a WKT string.
bool fuzzyDistanceEqual (const QgsAbstractGeometry &other, double epsilon=1e-8) const override
 Performs fuzzy distance comparison between this geometry and other using an epsilon.
bool fuzzyEqual (const QgsAbstractGeometry &other, double epsilon=1e-8) const override
 Performs fuzzy comparison between this geometry and other using an epsilon.
bool isEmpty () const override
 Returns true if the geometry is empty.
double mAt (int index) const override
 Returns the m value of the specified node in the simple curve.
const double * mData () const
 Returns a const pointer to the m vertex data, or nullptr if the simple curve does not have m values.
bool moveVertex (QgsVertexId position, const QgsPoint &newPos) override
 Moves a vertex within the geometry.
QVector< double > mVector () const
 Returns the m vertex values as a vector.
int nCoordinates () const override
 Returns the number of nodes contained in the geometry.
int numPoints () const override
 Returns the number of points in the curve.
QgsPoint pointN (int i) const
 Returns the specified point from inside the simple curve.
void points (QgsPointSequence &pts) const override
 Returns a list of points within the curve.
QgsSimpleCurvereversed () const override
 Returns a reversed copy of the curve, where the direction of the curve has been flipped.
void scroll (int firstVertexIndex) final
 Scrolls the curve vertices so that they start with the vertex at the given index.
void setMAt (int index, double m)
 Sets the m value of the specified node in the simple curve.
void setPoints (const QgsPointSequence &points)
 Resets the simple curve to match the specified list of points.
void setXAt (int index, double x)
 Sets the x-coordinate of the specified node in the simple curve.
void setYAt (int index, double y)
 Sets the y-coordinate of the specified node in the simple curve.
void setZAt (int index, double z)
 Sets the z-coordinate of the specified node in the simple curve.
QgsPoint startPoint () const override
 Returns the starting point of the curve.
void swapXy () override
 Swaps the x and y coordinates from the geometry.
void transform (const QgsCoordinateTransform &ct, Qgis::TransformDirection d=Qgis::TransformDirection::Forward, bool transformZ=false) override
 Transforms the geometry using a coordinate transform.
void transform (const QTransform &t, double zTranslate=0.0, double zScale=1.0, double mTranslate=0.0, double mScale=1.0) override
 Transforms the x and y components of the geometry using a QTransform object t.
bool transform (QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback=nullptr) override
 Transforms the vertices from the geometry in place, using the specified geometry transformer object.
void transformVertices (const std::function< QgsPoint(const QgsPoint &) > &transform) override
 Transforms the vertices from the geometry in place, applying the transform function to every vertex.
int wkbSize (QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
 Returns the length of the QByteArray returned by asWkb().
double xAt (int index) const override
 Returns the x-coordinate of the specified node in the line string.
const double * xData () const
 Returns a const pointer to the x vertex data.
QVector< double > xVector () const
 Returns the x vertex values as a vector.
double yAt (int index) const override
 Returns the y-coordinate of the specified node in the line string.
const double * yData () const
 Returns a const pointer to the y vertex data.
QVector< double > yVector () const
 Returns the y vertex values as a vector.
double zAt (int index) const override
 Returns the z-coordinate of the specified node in the simple curve.
const double * zData () const
 Returns a const pointer to the z vertex data, or nullptr if the simple curve does not have z values.
QVector< double > zVector () const
 Returns the z vertex values as a vector.
Public Member Functions inherited from QgsCurve
 QgsCurve ()=default
void adjacentVertices (QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
 Returns the vertices adjacent to a specified vertex within a geometry.
QPainterPath asQPainterPath () const override
 Returns the geometry represented as a QPainterPath.
QgsAbstractGeometryboundary () const override
 Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the geometry).
QgsBox3D boundingBox3D () const override
 Returns the 3D bounding box for the geometry.
QgsCoordinateSequence coordinateSequence () const override
 Retrieves the sequence of geometries, rings and nodes.
bool hasVertex (QgsVertexId position) const override
 Returns true if the geometry contains a vertex matching the given position.
virtual bool isRing () const
 Returns true if the curve is a ring.
bool nextVertex (QgsVertexId &id, QgsPoint &vertex) const override
 Returns next vertex id and coordinates.
void normalize () final
 Reorganizes the geometry into a normalized form (or "canonical" form).
bool operator!= (const QgsAbstractGeometry &other) const override
bool operator== (const QgsAbstractGeometry &other) const override
Qgis::AngularDirection orientation () const
 Returns the curve's orientation, e.g.
int partCount () const override
 Returns count of parts contained in the geometry.
int ringCount (int part=0) const override
 Returns the number of rings of which this geometry is built.
QgsCurvesegmentize (double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
 Returns a geometry without curves.
double sinuosity () const
 Returns the curve sinuosity, which is the ratio of the curve length() to curve straightDistance2d().
double straightDistance2d () const
 Returns the straight distance of the curve, i.e.
QgsPoint vertexAt (QgsVertexId id) const override
 Returns the point corresponding to a specified vertex id.
int vertexCount (int part=0, int ring=0) const override
 Returns the number of vertices of which this geometry is built.
int vertexNumberFromVertexId (QgsVertexId id) const override
 Returns the vertex number corresponding to a vertex id.
Public Member Functions inherited from QgsAbstractGeometry
 QgsAbstractGeometry ()=default
 QgsAbstractGeometry (const QgsAbstractGeometry &geom)
virtual ~QgsAbstractGeometry ()=default
virtual double area () const
 Returns the planar, 2-dimensional area of the geometry.
virtual double area3D () const
 Returns the 3-dimensional surface area of the geometry.
QString asJson (int precision=17)
 Returns a GeoJSON representation of the geometry as a QString.
virtual QgsRectangle boundingBox () const
 Returns the minimal bounding box for the geometry.
virtual int compareTo (const QgsAbstractGeometry *other) const
 Comparator for sorting of geometry.
const_part_iterator const_parts_begin () const
 Returns STL-style iterator pointing to the const first part of the geometry.
const_part_iterator const_parts_end () const
 Returns STL-style iterator pointing to the imaginary const part after the last part of the geometry.
virtual bool hasCurvedSegments () const
 Returns true if the geometry contains curved segments.
bool is3D () const
 Returns true if the geometry is 3D and contains a z-value.
bool isMeasure () const
 Returns true if the geometry contains m values.
QgsAbstractGeometryoperator= (const QgsAbstractGeometry &geom)
QgsGeometryPartIterator parts ()
 Returns Java-style iterator for traversal of parts of the geometry.
QgsGeometryConstPartIterator parts () const
 Returns Java-style iterator for traversal of parts of the geometry.
part_iterator parts_begin ()
 Returns STL-style iterator pointing to the first part of the geometry.
part_iterator parts_end ()
 Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
virtual double perimeter () const
 Returns the planar, 2-dimensional perimeter of the geometry.
virtual const QgsAbstractGeometrysimplifiedTypeRef () const
 Returns a reference to the simplest lossless representation of this geometry, e.g.
QgsVertexIterator vertices () const
 Returns a read-only, Java-style iterator for traversal of vertices of all the geometry, including all geometry parts and rings.
vertex_iterator vertices_begin () const
 Returns STL-style iterator pointing to the first vertex of the geometry.
vertex_iterator vertices_end () const
 Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
Qgis::WkbType wkbType () const
 Returns the WKB type of the geometry.
QString wktTypeStr () const
 Returns the WKT type string of the geometry.

Static Public Member Functions

static const QgsLineStringcast (const QgsAbstractGeometry *geom)
 Cast the geom to a QgsLineString.
static QgsLineStringcast (QgsAbstractGeometry *geom)
 Cast the geom to a QgsLineString.
static std::unique_ptr< QgsLineStringfromBezierCurve (const QgsPoint &start, const QgsPoint &controlPoint1, const QgsPoint &controlPoint2, const QgsPoint &end, int segments=30)
 Returns a new linestring created by segmentizing the bezier curve between start and end, with the specified control points.
static std::unique_ptr< QgsLineStringfromQPolygonF (const QPolygonF &polygon)
 Returns a new linestring from a QPolygonF polygon input.
Static Public Member Functions inherited from QgsSimpleCurve
static const QgsSimpleCurvecast (const QgsAbstractGeometry *geom)
 Cast the geom to a QgsSimpleCurve.
static QgsSimpleCurvecast (QgsAbstractGeometry *geom)
 Cast the geom to a QgsSimpleCurve.
Static Public Member Functions inherited from QgsCurve
static const QgsCurvecast (const QgsAbstractGeometry *geom)
 Cast the geom to a QgsCurve.
static QgsCurvecast (QgsAbstractGeometry *geom)
 Cast the geom to a QgsCurve.

Friends

class QgsPolygon
class QgsTriangle
class TestQgsGeometry

Additional Inherited Members

Public Types inherited from QgsAbstractGeometry
enum  AxisOrder { XY = 0 , YX }
 Axis order for GML generation. More...
enum  SegmentationToleranceType { MaximumAngle = 0 , MaximumDifference }
 Segmentation tolerance as maximum angle or maximum difference between approximation and circle. More...
enum  WkbFlag { FlagExportTrianglesAsPolygons = 1 << 0 , FlagExportNanAsDoubleMin = 1 << 1 }
 WKB export flags. More...
typedef QFlags< WkbFlagWkbFlags
Protected Member Functions inherited from QgsSimpleCurve
 QgsSimpleCurve ()=default
int compareToSameClass (const QgsAbstractGeometry *other) const final
 Compares to an other geometry of the same class, and returns a integer for sorting of the two geometries.
void importVerticesFromWkb (const QgsConstWkbPtr &wkb)
 Imports vertices from wkb geometry representation.
void splitCurveAtVertexProtected (int index, QVector< double > &x1, QVector< double > &y1, QVector< double > &z1, QVector< double > &m1, QVector< double > &x2, QVector< double > &y2, QVector< double > &z2, QVector< double > &m2) const
 Returns coordinate vectors for the split curves.
Protected Member Functions inherited from QgsCurve
int childCount () const override
 Returns number of child geometries (for geometries with child geometries) or child points (for geometries without child geometries - i.e.
QgsPoint childPoint (int index) const override
 Returns point at index (for geometries without child geometries - i.e.
void clearCache () const override
 Clears any cached parameters associated with the geometry, e.g., bounding boxes.
bool snapToGridPrivate (double hSpacing, double vSpacing, double dSpacing, double mSpacing, const QVector< double > &srcX, const QVector< double > &srcY, const QVector< double > &srcZ, const QVector< double > &srcM, QVector< double > &outX, QVector< double > &outY, QVector< double > &outZ, QVector< double > &outM, bool removeRedundantPoints) const
 Helper function for QgsCurve subclasses to snap to grids.
Protected Member Functions inherited from QgsAbstractGeometry
virtual QgsRectangle calculateBoundingBox () const
 Default calculator for the minimal bounding box for the geometry.
virtual QgsAbstractGeometrychildGeometry (int index) const
 Returns pointer to child geometry (for geometries with child geometries - i.e.
virtual bool hasChildGeometries () const
 Returns whether the geometry has any child geometries (false for point / curve, true otherwise).
void setZMTypeFromSubGeometry (const QgsAbstractGeometry *subggeom, Qgis::WkbType baseGeomType)
 Updates the geometry type based on whether sub geometries contain z or m values.
int sortIndex () const
 Returns the sort index for the geometry, used in the compareTo() method to compare geometries of different types.
Protected Attributes inherited from QgsSimpleCurve
QVector< double > mM
QVector< double > mX
QVector< double > mY
QVector< double > mZ
Protected Attributes inherited from QgsCurve
QgsBox3D mBoundingBox
 Cached bounding box.
bool mHasCachedSummedUpArea = false
bool mHasCachedSummedUpArea3D = false
double mSummedUpArea = 0
double mSummedUpArea3D = 0
Protected Attributes inherited from QgsAbstractGeometry
Qgis::WkbType mWkbType = Qgis::WkbType::Unknown

Detailed Description

Line string geometry type, with support for z-dimension and m-values.

Definition at line 48 of file qgslinestring.h.

Constructor & Destructor Documentation

◆ QgsLineString() [1/6]

QgsLineString::QgsLineString ( )

Constructor for an empty linestring geometry.

Definition at line 46 of file qgslinestring.cpp.

◆ QgsLineString() [2/6]

QgsLineString::QgsLineString ( const QVector< QgsPoint > & points)

Construct a linestring from a vector of points.

Z and M type will be set based on the type of the first point in the vector.

Definition at line 51 of file qgslinestring.cpp.

◆ QgsLineString() [3/6]

QgsLineString::QgsLineString ( const QVector< QgsPointXY > & points)

Construct a linestring from list of points.

This constructor is more efficient then calling setPoints() or repeatedly calling addVertex()

Definition at line 159 of file qgslinestring.cpp.

◆ QgsLineString() [4/6]

QgsLineString::QgsLineString ( const QgsLineSegment2D & segment)
explicit

Construct a linestring from a single 2d line segment.

Since
QGIS 3.2

Definition at line 171 of file qgslinestring.cpp.

◆ QgsLineString() [5/6]

QgsLineString::QgsLineString ( const QVector< double > & x,
const QVector< double > & y,
const QVector< double > & z = QVector<double>(),
const QVector< double > & m = QVector<double>(),
bool is25DType = false )

Construct a linestring from arrays of coordinates.

If the z or m arrays are non-empty then the resultant linestring will have z and m types accordingly. This constructor is more efficient then calling setPoints() or repeatedly calling addVertex()

If the z vector is filled, then the geometry type will either be a LineStringZ(M) or LineString25D depending on the is25DType argument. If is25DType is true (and the m vector is unfilled) then the created Linestring will be a LineString25D type. Otherwise, the LineString will be LineStringZ (or LineStringZM) type.

If the sizes of x and y are non-equal then the resultant linestring will be created using the minimum size of these arrays.

Definition at line 88 of file qgslinestring.cpp.

◆ QgsLineString() [6/6]

QgsLineString::QgsLineString ( const QgsPoint & p1,
const QgsPoint & p2 )

Constructs a linestring with a single segment from p1 to p2.

Since
QGIS 3.2

Definition at line 134 of file qgslinestring.cpp.

Member Function Documentation

◆ addToPainterPath()

void QgsLineString::addToPainterPath ( QPainterPath & path) const
overridevirtual

Adds a curve to a painter path.

Implements QgsCurve.

Definition at line 1369 of file qgslinestring.cpp.

◆ addVertex()

void QgsLineString::addVertex ( const QgsPoint & pt)

Adds a new vertex to the end of the line string.

Parameters
ptvertex to add

Definition at line 1550 of file qgslinestring.cpp.

◆ asGml2()

QDomElement QgsLineString::asGml2 ( QDomDocument & doc,
int precision = 17,
const QString & ns = "gml",
QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const
overridevirtual

Returns a GML2 representation of the geometry.

Parameters
docDOM document
precisionnumber of decimal places for coordinates
nsXML namespace
axisOrderAxis order for generated GML
See also
asWkb()
asWkt()
asGml3()
asJson()

Implements QgsAbstractGeometry.

Definition at line 774 of file qgslinestring.cpp.

◆ asGml3()

QDomElement QgsLineString::asGml3 ( QDomDocument & doc,
int precision = 17,
const QString & ns = "gml",
QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const
overridevirtual

Returns a GML3 representation of the geometry.

Parameters
docDOM document
precisionnumber of decimal places for coordinates
nsXML namespace
axisOrderAxis order for generated GML
See also
asWkb()
asWkt()
asGml2()
asJson()

Implements QgsAbstractGeometry.

Definition at line 789 of file qgslinestring.cpp.

◆ asJsonObject()

json QgsLineString::asJsonObject ( int precision = 17) const
overridevirtual

Returns a json object representation of the geometry.

See also
asWkb()
asWkt()
asGml2()
asGml3()
asJson()
Note
not available in Python bindings
Since
QGIS 3.10

Reimplemented from QgsAbstractGeometry.

Definition at line 803 of file qgslinestring.cpp.

◆ asKml()

QString QgsLineString::asKml ( int precision = 17) const
overridevirtual

Returns a KML representation of the geometry.

Since
QGIS 3.12

Reimplemented from QgsCurve.

Definition at line 810 of file qgslinestring.cpp.

◆ asQPolygonF()

QPolygonF QgsLineString::asQPolygonF ( ) const
overridevirtual

Returns a QPolygonF representing the points.

Reimplemented from QgsCurve.

Definition at line 607 of file qgslinestring.cpp.

◆ boundingBoxIntersects() [1/2]

bool QgsLineString::boundingBoxIntersects ( const QgsBox3D & box3d) const
overridevirtual

Returns true if the bounding box of this geometry intersects with a box3d.

Since this test only considers the bounding box of the geometry, is is very fast to calculate and handles invalid geometries.

Since
QGIS 3.34

Reimplemented from QgsAbstractGeometry.

Definition at line 483 of file qgslinestring.cpp.

◆ boundingBoxIntersects() [2/2]

bool QgsLineString::boundingBoxIntersects ( const QgsRectangle & rectangle) const
overridevirtual

Returns true if the bounding box of this geometry intersects with a rectangle.

Since this test only considers the bounding box of the geometry, is is very fast to calculate and handles invalid geometries.

Since
QGIS 3.20

Reimplemented from QgsAbstractGeometry.

Definition at line 394 of file qgslinestring.cpp.

◆ calculateBoundingBox3D()

QgsBox3D QgsLineString::calculateBoundingBox3D ( ) const
overridevirtual

Calculates the minimal 3D bounding box for the geometry.

See also
calculateBoundingBox()
Since
QGIS 3.34

Reimplemented from QgsAbstractGeometry.

Definition at line 737 of file qgslinestring.cpp.

◆ calculateBoundingBox3d()

QgsBox3D QgsLineString::calculateBoundingBox3d ( ) const

Calculates the minimal 3D bounding box for the geometry.

See also
calculateBoundingBox()
Since
QGIS 3.26
Deprecated
QGIS 3.34. Use calculateBoundingBox3D() instead.

Definition at line 764 of file qgslinestring.cpp.

◆ cast() [1/2]

const QgsLineString * QgsLineString::cast ( const QgsAbstractGeometry * geom)
inlinestatic

Cast the geom to a QgsLineString.

Should be used by qgsgeometry_cast<QgsLineString *>( geometry ).

Objects will be automatically converted to the appropriate target type.

Note
Not available in Python.

Definition at line 487 of file qgslinestring.h.

◆ cast() [2/2]

QgsLineString * QgsLineString::cast ( QgsAbstractGeometry * geom)
inlinestatic

Cast the geom to a QgsLineString.

Should be used by qgsgeometry_cast<QgsLineString *>( geometry ).

Objects will be automatically converted to the appropriate target type.

Note
Not available in Python.

Definition at line 502 of file qgslinestring.h.

◆ centroid()

QgsPoint QgsLineString::centroid ( ) const
overridevirtual

Returns the centroid of the geometry.

Reimplemented from QgsAbstractGeometry.

Definition at line 1661 of file qgslinestring.cpp.

◆ clear()

void QgsLineString::clear ( )
overridevirtual

Clears the geometry, ie reset it to a null geometry.

Implements QgsAbstractGeometry.

Definition at line 281 of file qgslinestring.cpp.

◆ clone()

QgsLineString * QgsLineString::clone ( ) const
overridevirtual

Clones the geometry by performing a deep copy.

Implements QgsCurve.

Definition at line 276 of file qgslinestring.cpp.

◆ close()

void QgsLineString::close ( )

Closes the line string by appending the first point to the end of the line, if it is not already closed.

Definition at line 1827 of file qgslinestring.cpp.

◆ closestSegment()

double QgsLineString::closestSegment ( const QgsPoint & pt,
QgsPoint & segmentPt,
QgsVertexId & vertexAfter,
int * leftOf = nullptr,
double epsilon = 4 *std::numeric_limits< double >::epsilon() ) const
overridevirtual

Searches for the closest segment of the geometry to a given point.

Parameters
ptspecifies the point to find closest segment to
segmentPtstorage for the closest point within the geometry
vertexAfterstorage for the ID of the vertex at the end of the closest segment
leftOfindicates whether the point lies on the left side of the geometry (-1 if point is to the left of the geometry, +1 if the point is to the right of the geometry, or 0 for cases where left/right could not be determined, e.g. point exactly on a line) false if point is to right of segment)
epsilonepsilon for segment snapping
Returns
squared distance to closest segment or negative value on error

Implements QgsAbstractGeometry.

Definition at line 1570 of file qgslinestring.cpp.

◆ collectDuplicateNodes()

QVector< QgsVertexId > QgsLineString::collectDuplicateNodes ( double epsilon = 4 * std::numeric_limits<double>::epsilon(),
bool useZValues = false ) const

Returns a list of any duplicate nodes contained in the geometry, within the specified tolerance.

If useZValues is true then z values will also be considered when testing for duplicates.

Since
QGIS 3.16

Definition at line 570 of file qgslinestring.cpp.

◆ convertTo()

bool QgsLineString::convertTo ( Qgis::WkbType type)
overridevirtual

Converts the geometry to a specified type.

Returns
true if conversion was successful

Reimplemented from QgsAbstractGeometry.

Definition at line 1895 of file qgslinestring.cpp.

◆ createEmptyWithSameType()

QgsLineString * QgsLineString::createEmptyWithSameType ( ) const
overridevirtual

Creates a new geometry with the same class and same WKB type as the original and transfers ownership.

To create it, the geometry is default constructed and then the WKB is changed.

See also
clone()

Implements QgsAbstractGeometry.

Definition at line 1430 of file qgslinestring.cpp.

◆ curveSubstring()

QgsLineString * QgsLineString::curveSubstring ( double startDistance,
double endDistance ) const
overridevirtual

Returns a new curve representing a substring of this curve.

The startDistance and endDistance arguments specify the length along the curve which the substring should start and end at. If the endDistance is greater than the total length of the curve then any "extra" length will be ignored.

If z or m values are present, the output z and m will be interpolated using the existing vertices' z or m values.

Since
QGIS 3.4

Implements QgsCurve.

Definition at line 1268 of file qgslinestring.cpp.

◆ curveToLine()

QgsLineString * QgsLineString::curveToLine ( double tolerance = M_PI_2 / 90,
SegmentationToleranceType toleranceType = MaximumAngle ) const
overridevirtual

Returns a new line string geometry corresponding to a segmentized approximation of the curve.

Parameters
tolerancesegmentation tolerance
toleranceTypemaximum segmentation angle or maximum difference between approximation and curve

Implements QgsCurve.

Definition at line 996 of file qgslinestring.cpp.

◆ deleteVertex()

bool QgsLineString::deleteVertex ( QgsVertexId position)
overridevirtual

Deletes a vertex within the geometry.

Parameters
positionvertex id for vertex to delete
Returns
true if delete was successful
See also
insertVertex
moveVertex

Implements QgsAbstractGeometry.

Definition at line 1474 of file qgslinestring.cpp.

◆ deleteVertices()

bool QgsLineString::deleteVertices ( const QSet< QgsVertexId > & positions)
overridevirtual

Deletes vertices within the geometry.

If positions contains vertices not belonging to the geometry, false is returned and the geometry is not modified. If a vertex cannot be deleted, the method returns false and the geometry may be left in a partially modified and invalid state.

Parameters
positionsset of vertex ids to delete
Returns
true if all requested vertices were deleted, false if at least one vertex could not be deleted
See also
deleteVertex
Since
QGIS 4.2

Implements QgsAbstractGeometry.

Definition at line 1501 of file qgslinestring.cpp.

◆ distanceBetweenVertices()

double QgsLineString::distanceBetweenVertices ( QgsVertexId fromVertex,
QgsVertexId toVertex ) const
overridevirtual

Returns the distance along the curve between two vertices.

This method calculates the accumulated distance along the curve from one vertex to another. For circular strings, this includes following the arc path precisely.

Note
For 3D geometries, the distance calculation includes the Z coordinate component.
Parameters
fromVertexthe starting vertex ID
toVertexthe ending vertex ID
Returns
distance along the curve between the vertices, or -1 if either vertex is invalid
Since
QGIS 4.00

Implements QgsCurve.

Definition at line 2121 of file qgslinestring.cpp.

◆ draw()

void QgsLineString::draw ( QPainter & p) const
overridevirtual

Draws the geometry using the specified QPainter.

Parameters
pdestination QPainter

Implements QgsAbstractGeometry.

Definition at line 1364 of file qgslinestring.cpp.

◆ drawAsPolygon()

void QgsLineString::drawAsPolygon ( QPainter & p) const
overridevirtual

Draws the curve as a polygon on the specified QPainter.

Parameters
pdestination QPainter

Implements QgsCurve.

Definition at line 1388 of file qgslinestring.cpp.

◆ extend()

void QgsLineString::extend ( double startDistance,
double endDistance )

Extends the line geometry by extrapolating out the start or end of the line by a specified distance.

Lines are extended using the bearing of the first or last segment in the line.

Definition at line 1400 of file qgslinestring.cpp.

◆ fromBezierCurve()

std::unique_ptr< QgsLineString > QgsLineString::fromBezierCurve ( const QgsPoint & start,
const QgsPoint & controlPoint1,
const QgsPoint & controlPoint2,
const QgsPoint & end,
int segments = 30 )
static

Returns a new linestring created by segmentizing the bezier curve between start and end, with the specified control points.

The segments parameter controls how many line segments will be present in the returned linestring.

Any z or m values present in the input coordinates will be interpolated along with the x and y values.

Since
QGIS 3.10

Definition at line 182 of file qgslinestring.cpp.

◆ fromQPolygonF()

std::unique_ptr< QgsLineString > QgsLineString::fromQPolygonF ( const QPolygonF & polygon)
static

Returns a new linestring from a QPolygonF polygon input.

Since
QGIS 3.10

Definition at line 256 of file qgslinestring.cpp.

◆ geometryType()

QString QgsLineString::geometryType ( ) const
overridevirtual

Returns a unique string representing the geometry type.

See also
wkbType
wktTypeStr

Implements QgsAbstractGeometry.

Definition at line 1437 of file qgslinestring.cpp.

◆ indexOf()

int QgsLineString::indexOf ( const QgsPoint & point) const
finalvirtual

Returns the index of the first vertex matching the given point, or -1 if a matching vertex is not found.

Note
If the curve has m or z values then the search point must have exactly matching m and z values in order to be matched against the curve's vertices.
This method only matches against segment vertices, not curve vertices.
Since
QGIS 3.20

Implements QgsCurve.

Definition at line 287 of file qgslinestring.cpp.

◆ insertVertex()

bool QgsLineString::insertVertex ( QgsVertexId position,
const QgsPoint & vertex )
overridevirtual

Inserts a vertex into the geometry.

Parameters
positionvertex id for position of inserted vertex
vertexvertex to insert
Returns
true if insert was successful
See also
moveVertex
deleteVertex

Implements QgsAbstractGeometry.

Definition at line 1448 of file qgslinestring.cpp.

◆ interpolateM()

std::unique_ptr< QgsLineString > QgsLineString::interpolateM ( bool use3DDistance = true) const

Returns a copy of this line with all missing (NaN) m values interpolated from m values of surrounding vertices.

If the line does not contain m values, nullptr is returned.

The use3DDistance controls whether 2D or 3D distances between vertices should be used during interpolation. This option is only considered for lines with z values.

See also
lineLocatePointByM()
Since
QGIS 3.38

Definition at line 1951 of file qgslinestring.cpp.

◆ interpolatePoint()

QgsPoint * QgsLineString::interpolatePoint ( double distance) const
overridevirtual

Returns an interpolated point on the curve at the specified distance.

If z or m values are present, the output z and m will be interpolated using the existing vertices' z or m values.

If distance is negative, or is greater than the length of the curve, nullptr will be returned.

Since
QGIS 3.4

Implements QgsCurve.

Definition at line 1152 of file qgslinestring.cpp.

◆ isClosed()

bool QgsLineString::isClosed ( ) const
overridevirtual

Returns true if the curve is closed.

See also
isClosed2D()

Reimplemented from QgsCurve.

Definition at line 383 of file qgslinestring.cpp.

◆ isClosed2D()

bool QgsLineString::isClosed2D ( ) const
overridevirtual

Returns true if the curve is closed.

Unlike isClosed. It looks only for XY coordinates.

See also
isClosed()
Since
QGIS 3.20

Reimplemented from QgsCurve.

Definition at line 375 of file qgslinestring.cpp.

◆ isValid()

bool QgsLineString::isValid ( QString & error,
Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const
overridevirtual

Checks validity of the geometry, and returns true if the geometry is valid.

Parameters
errorwill be set to the validity error message
flagsindicates optional flags which control the type of validity checking performed (corresponding to Qgis::GeometryValidityFlags).
Returns
true if geometry is valid
Since
QGIS 3.8

Reimplemented from QgsCurve.

Definition at line 315 of file qgslinestring.cpp.

◆ length()

double QgsLineString::length ( ) const
overridevirtual

Returns the planar, 2-dimensional length of the geometry.

Warning
QgsAbstractGeometry objects are inherently Cartesian/planar geometries, and the length returned by this method is calculated using strictly Cartesian mathematics. In contrast, the QgsDistanceArea class exposes methods for calculating the lengths of geometries using geodesic calculations which account for the curvature of the Earth (or any other celestial body).
See also
area()
perimeter()

Reimplemented from QgsAbstractGeometry.

Definition at line 872 of file qgslinestring.cpp.

◆ length3D()

double QgsLineString::length3D ( ) const

Returns the length in 3D world of the line string.

If it is not a 3D line string, return its 2D length.

See also
length()
Since
QGIS 3.10

Definition at line 953 of file qgslinestring.cpp.

◆ lineLocatePointByM()

bool QgsLineString::lineLocatePointByM ( double m,
double & x,
double & y,
double & z,
double & distanceFromStart,
bool use3DDistance = true ) const

Attempts to locate a point on the linestring by m value.

This method will linearly interpolate along line segments to find the point which corresponds to the specified m value.

If the linestring contains sections with constant m values matching m, then the interpolated point will be located at the center of these sections.

Any missing (NaN) values in the linestring will be linearly interpolated from the m values of surrounding vertices (see interpolateM()).

Parameters
mtarget m value
xinterpolated x coordinate
yinterpolated y coordinate
zinterpolated z coordinate (for 3D lines only)
distanceFromStartcalculated distance from the start of the linestring to the located point
use3DDistancecontrols whether 2D or 3D distances between vertices should be used during interpolation. This option is only considered for lines with z values.
Returns
true if a matching point was found, or false if it could not be found
See also
interpolateM()
Since
QGIS 3.40

Definition at line 1171 of file qgslinestring.cpp.

◆ measuredLine()

std::unique_ptr< QgsLineString > QgsLineString::measuredLine ( double start,
double end ) const

Re-write the measure ordinate (or add one, if it isn't already there) interpolating the measure between the supplied start and end values.

Since
QGIS 3.36

Definition at line 1915 of file qgslinestring.cpp.

◆ pointAt()

bool QgsLineString::pointAt ( int node,
QgsPoint & point,
Qgis::VertexType & type ) const
overridevirtual

Returns the point and vertex type of a point within the curve.

Parameters
nodenode number, where the first node is 0
pointwill be set to point at corresponding node in the curve
typewill be set to the vertex type of the node
Returns
true if node exists within the curve

Implements QgsCurve.

Definition at line 1650 of file qgslinestring.cpp.

◆ removeDuplicateNodes()

bool QgsLineString::removeDuplicateNodes ( double epsilon = 4 *std::numeric_limits< double >::epsilon(),
bool useZValues = false )
overridevirtual

Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerate geometry.

The epsilon parameter specifies the tolerance for coordinates when determining that vertices are identical.

By default, z values are not considered when detecting duplicate nodes. E.g. two nodes with the same x and y coordinate but different z values will still be considered duplicate and one will be removed. If useZValues is true, then the z values are also tested and nodes with the same x and y but different z will be maintained.

Note that duplicate nodes are not tested between different parts of a multipart geometry. E.g. a multipoint geometry with overlapping points will not be changed by this method.

The function will return true if nodes were removed, or false if no duplicate nodes were found.

Implements QgsAbstractGeometry.

Definition at line 337 of file qgslinestring.cpp.

◆ reversed()

QgsLineString * QgsLineString::reversed ( ) const
overridevirtual

Returns a reversed copy of the curve, where the direction of the curve has been flipped.

Implements QgsCurve.

Definition at line 1085 of file qgslinestring.cpp.

◆ segmentLength()

double QgsLineString::segmentLength ( QgsVertexId startVertex) const
overridevirtual

Returns the length of the segment of the geometry which begins at startVertex.

Warning
QgsAbstractGeometry objects are inherently Cartesian/planar geometries, and the lengths returned by this method are calculated using strictly Cartesian mathematics.

Implements QgsAbstractGeometry.

Definition at line 1879 of file qgslinestring.cpp.

◆ setPoints() [1/2]

Resets the simple curve to match the specified list of points.

The simple curve will inherit the dimensionality of the first point in the list.

Parameters
pointsnew points for simple curve. If empty, simple curve will be cleared.

Definition at line 127 of file qgssimplecurve.cpp.

◆ setPoints() [2/2]

void QgsLineString::setPoints ( size_t size,
const double * x,
const double * y,
const double * z = nullptr,
const double * m = nullptr )

Resets the line string to match the specified point data.

The line string dimensionality will be based on whether z or m arrays are specified.

Parameters
sizepoint count.
xarray of x data
yarray of y data
zarray of z data, can be nullptr
marray of m data, can be nullptr
Note
Not available from Python bindings
Since
QGIS 3.26

Definition at line 1009 of file qgslinestring.cpp.

◆ simplifyByDistance()

QgsLineString * QgsLineString::simplifyByDistance ( double tolerance) const
overridevirtual

Simplifies the geometry by applying the Douglas Peucker simplification by distance algorithm.

The caller takes ownership of the returned geometry. Curved geometries will be segmentized prior to simplification.

If a simplified geometry cannot be calculated nullptr will be returned.

The returned geometry may be invalid and contain self-intersecting rings.

Since
QGIS 3.38

Implements QgsAbstractGeometry.

Definition at line 659 of file qgslinestring.cpp.

◆ snappedToGrid()

QgsLineString * QgsLineString::snappedToGrid ( double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0,
bool removeRedundantPoints = false ) const
overridevirtual

Makes a new geometry with all the points or vertices snapped to the closest point of the grid.

Ownership is transferred to the caller.

If the gridified geometry could not be calculated nullptr will be returned. It may generate an invalid geometry (in some corner cases). It can also be thought as rounding the edges and it may be useful for removing errors.

Example:

geometry.snappedToGrid(1, 1)

In this case we use a 2D grid of 1x1 to gridify. In this case, it can be thought like rounding the x and y of all the points/vertices to full units (remove all decimals).

Parameters
hSpacingHorizontal spacing of the grid (x axis). 0 to disable.
vSpacingVertical spacing of the grid (y axis). 0 to disable.
dSpacingDepth spacing of the grid (z axis). 0 (default) to disable.
mSpacingCustom dimension spacing of the grid (m axis). 0 (default) to disable.
removeRedundantPointsif true, then points which are redundant (e.g. they represent mid points on a straight line segment) will be skipped (since QGIS 3.38)

Implements QgsAbstractGeometry.

Definition at line 325 of file qgslinestring.cpp.

◆ splitCurveAtVertex()

std::tuple< std::unique_ptr< QgsCurve >, std::unique_ptr< QgsCurve > > QgsLineString::splitCurveAtVertex ( int index) const
finalvirtual

Splits the curve at the specified vertex index, returning two curves which represent the portion of the curve up to including the vertex at index, and the portion of the curve from the vertex at index (inclusive) to the end of the curve.

Note
The vertex index must correspond to a segment vertex, not a curve vertex.
Not available in Python bindings.
Since
QGIS 3.20

Implements QgsCurve.

Definition at line 898 of file qgslinestring.cpp.

◆ splitToDisjointXYParts()

QVector< QgsLineString * > QgsLineString::splitToDisjointXYParts ( ) const

Divides the linestring into parts that don't share any points or lines.

This method throws away Z and M coordinates.

The ownership of returned pointers is transferred to the caller.

Since
QGIS 3.40

Definition at line 919 of file qgslinestring.cpp.

◆ sumUpArea()

void QgsLineString::sumUpArea ( double & sum) const
overridevirtual

Calculates the shoelace/triangle formula sum for the points in the linestring.

2D version.

If the linestring is closed (i.e. a polygon) then the polygon area is equal to the absolute value of the sum. Please note that the sum will be negative if the points are defined in clockwise order. Therefore, if you want to use the sum as an area (as the method name indicates) then you probably should use the absolute value, since otherwise a bug can be introduced (such as the bug fixed for github issue 49578)

See also
https://en.wikipedia.org/wiki/Shoelace_formula#Triangle_formula

Implements QgsCurve.

Definition at line 1705 of file qgslinestring.cpp.

◆ sumUpArea3D()

void QgsLineString::sumUpArea3D ( double & sum) const
overridevirtual

Calculates the shoelace/triangle formula sum for the points in the linestring.

3D version.

If the linestring is closed (i.e. a polygon) then the polygon area is equal to the value of the sum.

Note
If the geometry is 2D, the method falls back to the 2D computation.
Since
QGIS 4.0

Implements QgsCurve.

Definition at line 1737 of file qgslinestring.cpp.

◆ toCurveType()

QgsCompoundCurve * QgsLineString::toCurveType ( ) const
overridevirtual

Returns the geometry converted to the more generic curve type QgsCompoundCurve.

Returns
the converted geometry. Caller takes ownership

Reimplemented from QgsCurve.

Definition at line 1393 of file qgslinestring.cpp.

◆ vertexAngle()

double QgsLineString::vertexAngle ( QgsVertexId vertex) const
overridevirtual

Returns approximate angle at a vertex.

This is usually the average angle between adjacent segments, and can be pictured as the orientation of a line following the curvature of the geometry at the specified vertex.

Parameters
vertexthe vertex id
Returns
rotation in radians, clockwise from north

Implements QgsAbstractGeometry.

Definition at line 1836 of file qgslinestring.cpp.

◆ visitPointsByRegularDistance()

void QgsLineString::visitPointsByRegularDistance ( double distance,
const std::function< bool(double x, double y, double z, double m, double startSegmentX, double startSegmentY, double startSegmentZ, double startSegmentM, double endSegmentX, double endSegmentY, double endSegmentZ, double endSegmentM) > & visitPoint ) const

Visits regular points along the linestring, spaced by distance.

The visitPoint function should return false to abort further traversal.

Definition at line 1090 of file qgslinestring.cpp.

◆ QgsPolygon

friend class QgsPolygon
friend

Definition at line 686 of file qgslinestring.h.

◆ QgsTriangle

friend class QgsTriangle
friend

Definition at line 687 of file qgslinestring.h.

◆ TestQgsGeometry

friend class TestQgsGeometry
friend

Definition at line 688 of file qgslinestring.h.


The documentation for this class was generated from the following files: