Class: QgsLineString

class qgis.core.QgsLineString

Bases: qgis._core.QgsCurve

QgsLineString(points: Iterable[QgsPoint]) 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.

New in version 3.0.

QgsLineString(x: Iterable[float], y: Iterable[float], z: Iterable[float] = [], m: Iterable[float] = [], is25DType: bool = 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.

New in version 3.0.

QgsLineString(p1: QgsPoint, p2: QgsPoint) Constructs a linestring with a single segment from p1 to p2.

New in version 3.2.

QgsLineString(points: Iterable[QgsPointXY]) Construct a linestring from list of points. This constructor is more efficient then calling setPoints() or repeatedly calling addVertex()

New in version 3.0.

QgsLineString(segment: QgsLineSegment2D) Construct a linestring from a single 2d line segment.

New in version 3.2.

QgsLineString(QgsLineString)

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

New in version 2.10: Enums

Methods

addMValue

addToPainterPath

addVertex

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

addZValue

append

Appends the contents of another line string to the end of this line string.

asGml2

asGml3

asQPolygonF

asWkb

asWkt

calculateBoundingBox

centroid

childCount

childGeometry

childPoint

clear

clearCache

clone

close

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

closestSegment

convertTo

createEmptyWithSameType

curveSubstring

curveToLine

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

deleteVertex

dimension

draw

drawAsPolygon

dropMValue

dropZValue

endPoint

equals

extend

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

fromWkb

fromWkt

geometryType

hasChildGeometries

insertVertex

interpolatePoint

isEmpty

length

mAt

Returns the m-coordinate of the specified node in the line string.

moveVertex

nCoordinates

numPoints

pointAt

pointN

Returns the point at the specified index.

points

removeDuplicateNodes

reversed

segmentLength

setMAt

Sets the m-coordinate of the specified node in the line string.

setPoints

Resets the line string to match the specified list of points.

setXAt

Sets the x-coordinate of the specified node in the line string.

setYAt

Sets the y-coordinate of the specified node in the line string.

setZAt

Sets the z-coordinate of the specified node in the line string.

setZMTypeFromSubGeometry

snappedToGrid

startPoint

sumUpArea

swapXy

toCurveType

Returns the geometry converted to the more generic curve type QgsCompoundCurve

transform

transform(self, t: QTransform, zTranslate: float = 0, zScale: float = 1, mTranslate: float = 0, mScale: float = 1)

vertexAngle

xAt

Returns the x-coordinate of the specified node in the line string.

yAt

Returns the y-coordinate of the specified node in the line string.

zAt

Returns the z-coordinate of the specified node in the line string.

Signals

Attributes

addMValue(self, mValue: float = 0) → bool
addToPainterPath(self, path: QPainterPath)
addVertex(self, pt: QgsPoint)

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

Parameters

pt – vertex to add

addZValue(self, zValue: float = 0) → bool
append(self, line: QgsLineString)

Appends the contents of another line string to the end of this line string.

Parameters

line – line to append. Ownership is not transferred.

asGml2(self, doc: QDomDocument, precision: int = 17, ns: str = '', axisOrder: QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) → QDomElement
asGml3(self, doc: QDomDocument, precision: int = 17, ns: str = '', axisOrder: QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) → QDomElement
asQPolygonF(self) → QPolygonF
asWkb(self) → QByteArray
asWkt(self, precision: int = 17) → str
calculateBoundingBox(self) → QgsRectangle
centroid(self) → QgsPoint
childCount()
childGeometry()
childPoint()
clear(self)
clearCache()
clone(self) → QgsLineString
close(self)

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

closestSegment(self, pt: QgsPoint, epsilon: float = 4*DBL_EPSILON) → Tuple[float, QgsPoint, QgsVertexId, int]
convertTo(self, type: QgsWkbTypes.Type) → bool
createEmptyWithSameType(self) → QgsLineString
curveSubstring(self, startDistance: float, endDistance: float) → QgsLineString
curveToLine(self, tolerance: float = M_PI_2/90, toleranceType: QgsAbstractGeometry.SegmentationToleranceType = QgsAbstractGeometry.MaximumAngle) → QgsLineString

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

Parameters
  • tolerance – segmentation tolerance

  • toleranceType – maximum segmentation angle or maximum difference between approximation and curve*

deleteVertex(self, position: QgsVertexId) → bool
dimension(self) → int
draw(self, p: QPainter)
drawAsPolygon(self, p: QPainter)
dropMValue(self) → bool
dropZValue(self) → bool
endPoint(self) → QgsPoint
equals(self, other: QgsCurve) → bool
extend(self, startDistance: float, endDistance: float)

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.

New in version 3.0.

fromWkb(self, wkb: QgsConstWkbPtr) → bool
fromWkt(self, wkt: str) → bool
geometryType(self) → str
hasChildGeometries()
insertVertex(self, position: QgsVertexId, vertex: QgsPoint) → bool
interpolatePoint(self, distance: float) → QgsPoint
isEmpty(self) → bool
length(self) → float
mAt(self, index: int) → float

Returns the m-coordinate of the specified node in the line string.

An IndexError will be raised if no point with the specified index exists.

If the LineString does not have a m-dimension then nan will be returned.

Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1 corresponds to the last point in the line.

moveVertex(self, position: QgsVertexId, newPos: QgsPoint) → bool
nCoordinates(self) → int
numPoints(self) → int
pointAt(self, node: int, point: QgsPoint) → Tuple[bool, QgsVertexId.VertexType]
pointN(self, i: int) → QgsPoint

Returns the point at the specified index. An IndexError will be raised if no point with the specified index exists.

Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1 corresponds to the last point in the line.

points(self) → List[QgsPoint]
removeDuplicateNodes(self, epsilon: float = 4*DBL_EPSILON, useZValues: bool = False) → bool
reversed(self) → QgsLineString
segmentLength(self, startVertex: QgsVertexId) → float
setMAt(self, index: int, m: float)

Sets the m-coordinate of the specified node in the line string. The corresponding node must already exist in line string and the line string must have m-dimension.

An IndexError will be raised if no point with the specified index exists.

Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1 corresponds to the last point in the line.

See also

mAt()

setPoints(self, points: Iterable[QgsPoint])

Resets the line string to match the specified list of points. The line string will inherit the dimensionality of the first point in the list.

Parameters

points – new points for line string. If empty, line string will be cleared.

setXAt(self, index: int, x: float)

Sets the x-coordinate of the specified node in the line string. The corresponding node must already exist in line string.

An IndexError will be raised if no point with the specified index exists.

Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1 corresponds to the last point in the line.

See also

xAt()

setYAt(self, index: int, y: float)

Sets the y-coordinate of the specified node in the line string. The corresponding node must already exist in line string.

An IndexError will be raised if no point with the specified index exists.

Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1 corresponds to the last point in the line.

See also

yAt()

setZAt(self, index: int, z: float)

Sets the z-coordinate of the specified node in the line string. The corresponding node must already exist in line string and the line string must have z-dimension.

An IndexError will be raised if no point with the specified index exists.

Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1 corresponds to the last point in the line.

See also

zAt()

setZMTypeFromSubGeometry()
snappedToGrid(self, hSpacing: float, vSpacing: float, dSpacing: float = 0, mSpacing: float = 0) → QgsLineString
startPoint(self) → QgsPoint
sumUpArea(self) → float
swapXy(self)
toCurveType(self) → QgsCompoundCurve

Returns the geometry converted to the more generic curve type QgsCompoundCurve

Returns

the converted geometry. Caller takes ownership*

transform(self, ct: QgsCoordinateTransform, d: QgsCoordinateTransform.TransformDirection = QgsCoordinateTransform.ForwardTransform, transformZ: bool = False)

transform(self, t: QTransform, zTranslate: float = 0, zScale: float = 1, mTranslate: float = 0, mScale: float = 1)

vertexAngle(self, vertex: QgsVertexId) → float
xAt(self, index: int) → float

Returns the x-coordinate of the specified node in the line string.

An IndexError will be raised if no point with the specified index exists.

Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1 corresponds to the last point in the line.

yAt(self, index: int) → float

Returns the y-coordinate of the specified node in the line string.

An IndexError will be raised if no point with the specified index exists.

Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1 corresponds to the last point in the line.

zAt(self, index: int) → float

Returns the z-coordinate of the specified node in the line string.

An IndexError will be raised if no point with the specified index exists.

If the LineString does not have a z-dimension then nan will be returned.

Indexes can be less than 0, in which case they correspond to positions from the end of the line. E.g. an index of -1 corresponds to the last point in the line.