Subgroup: Line

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] = []) 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()

New in version 3.0.

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(QgsLineString)

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

New in version 2.10: 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
asJson
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
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
isEmpty
length
mAt Returns the m value of the specified node in the line string.
moveVertex
nCoordinates
numPoints
pointAt
pointN Returns the specified point from inside the line string.
points
removeDuplicateNodes
reversed
segmentLength
setMAt Sets the m value 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
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
yAt
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 = '') → QDomElement
asGml3(self, doc: QDomDocument, precision: int = 17, ns: str = '') → QDomElement
asJson(self, precision: int = 17) → str
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
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
isEmpty(self) → bool
length(self) → float
mAt(self, index: int) → float

Returns the m value of the specified node in the line string.

Parameters:index – index of node, where the first node in the line is 0
Returns:m value of node, or nan if index is out of bounds or the line

does not have m values

See also

setMAt()

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 specified point from inside the line string.

Parameters:i – index of point, starting at 0 for the first point
points(self) → object
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 value of the specified node in the line string.

Parameters:index – index of node, where the first node in the line is 0. Corresponding

node must already exist in line string, and the line string must have m values. :param m: m value of node

See also

mAt()

setPoints(self, points: object)

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.

Parameters:index – index of node, where the first node in the line is 0. Corresponding

node must already exist in line string. :param x: x-coordinate of node

See also

xAt()

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

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

Parameters:index – index of node, where the first node in the line is 0. Corresponding

node must already exist in line string. :param y: y-coordinate of node

See also

yAt()

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

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

Parameters:index – index of node, where the first node in the line is 0. Corresponding

node must already exist in line string, and the line string must have z-dimension. :param z: z-coordinate of node

See also

zAt()

setZMTypeFromSubGeometry()
snappedToGrid(self, hSpacing: float, vSpacing: float, dSpacing: float = 0, mSpacing: float = 0) → QgsLineString
startPoint(self) → QgsPoint
sumUpArea(self) → float
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
yAt(self, index: int) → float
zAt(self, index: int) → float

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

Parameters:index – index of node, where the first node in the line is 0
Returns:z-coordinate of node, or nan if index is out of bounds or the line

does not have a z dimension

See also

setZAt()