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] = [], 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: 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
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 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
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
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 = '', axisOrder: QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) → QDomElement
asGml3(self, doc: QDomDocument, precision: int = 17, ns: str = '', axisOrder: QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) → QDomElement
asJson(self, precision: int = 17) → str
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 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.
  • 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.
  • 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.
  • 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.
  • 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
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
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()