Class: QgsCurve¶
- class qgis.core.QgsCurve¶
Bases:
QgsAbstractGeometry
Abstract base class for curved geometry type
New in version 2.10.
QgsCurve() Constructor for QgsCurve.
QgsCurve(
QgsCurve
)Enums
alias of
AngularDirection
Methods
Adds a curve to a painter path.
- param vertex:
- param precision:
- rtype:
QPainterPath
Returns a QPolygonF representing the points.
- rtype:
QgsAbstractGeometry
- rtype:
QgsRectangle
- rtype:
QgsCurve
- rtype:
object
Returns a new curve representing a substring of this curve.
Returns a new line string geometry corresponding to a segmentized approximation of the curve.
Draws the curve as a polygon on the specified QPainter.
Returns the end point of the curve.
Checks whether this curve exactly equals another curve.
Returns the index of the first vertex matching the given
point
, or -1 if a matching vertex is not found.Returns an interpolated point on the curve at the specified
distance
.Returns
True
if the curve is closed.Returns true if the curve is closed.
Returns
True
if the curve is a ring.- param flags:
- param id:
Returns the number of points in the curve.
Returns the curve's orientation, e.g.
- rtype:
int
Returns the point and vertex id of a point within the curve.
Returns a list of points within the curve.
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
- param part:
Scrolls the curve vertices so that they start with the vertex at the given index.
Returns a geometry without curves.
Returns the curve sinuosity, which is the ratio of the curve
length()
to curvestraightDistance2d()
.Returns the starting point of the curve.
Returns the straight distance of the curve, i.e. the direct/euclidean distance between the first and last vertex of the curve.
Sums up the area of the curve by iterating over the vertices (shoelace formula).
- rtype:
QgsCurve
- param id:
- param part:
- param id:
Returns the x-coordinate of the specified node in the line string.
Returns the y-coordinate of the specified node in the line string.
- Orientation¶
alias of
AngularDirection
- addToPainterPath(self, path: QPainterPath)¶
Adds a curve to a painter path.
- Parameters:
path (QPainterPath) –
- adjacentVertices(self, vertex: QgsVertexId) Tuple[QgsVertexId, QgsVertexId] ¶
- Parameters:
vertex (QgsVertexId) –
- Return type:
Tuple[
QgsVertexId
, QgsVertexId]
- asKml(self, precision: int = 17) str ¶
- Parameters:
precision (int = 17) –
- Return type:
str
- asQPainterPath(self) QPainterPath ¶
- Return type:
QPainterPath
- asQPolygonF(self) QPolygonF ¶
Returns a QPolygonF representing the points.
- Return type:
QPolygonF
- boundary(self) QgsAbstractGeometry ¶
- Return type:
- boundingBox(self) QgsRectangle ¶
- Return type:
- coordinateSequence(self) object ¶
- Return type:
object
- curveSubstring(self, startDistance: float, endDistance: float) QgsCurve ¶
Returns a new curve representing a substring of this curve.
The
startDistance
andendDistance
arguments specify the length along the curve which the substring should start and end at. If theendDistance
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.
New in version 3.4.
- Parameters:
startDistance (float) –
endDistance (float) –
- Return type:
- 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 (float = M_PI_2/90) – segmentation tolerance
toleranceType (QgsAbstractGeometry.SegmentationToleranceType = QgsAbstractGeometry.MaximumAngle) – maximum segmentation angle or maximum difference between approximation and curve
Uses a MaximumAngle tolerance of 1 degrees by default (360 segments in a full circle)
- Return type:
- drawAsPolygon(self, p: QPainter)¶
Draws the curve as a polygon on the specified QPainter.
- Parameters:
p (QPainter) – destination QPainter
- equals(self, other: QgsCurve) bool ¶
Checks whether this curve exactly equals another curve.
New in version 3.0.
- Parameters:
other (QgsCurve) –
- Return type:
bool
- indexOf(self, point: QgsPoint) int ¶
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.Note
This method only matches against segment vertices, not curve vertices.
New in version 3.20.
- Parameters:
point (QgsPoint) –
- Return type:
int
- interpolatePoint(self, distance: float) QgsPoint ¶
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,
None
will be returned.New in version 3.4.
- Parameters:
distance (float) –
- Return type:
- isClosed(self) bool ¶
Returns
True
if the curve is closed.See also
- Return type:
bool
- isClosed2D(self) bool ¶
Returns true if the curve is closed.
Unlike isClosed. It looks only for XY coordinates.
See also
New in version 3.20.
- Return type:
bool
- isRing(self) bool ¶
Returns
True
if the curve is a ring.- Return type:
bool
- isValid(self, flags: Qgis.GeometryValidityFlags | Qgis.GeometryValidityFlag = Qgis.GeometryValidityFlags()) Tuple[bool, str] ¶
- Parameters:
flags (Union[Qgis.GeometryValidityFlags) –
- Return type:
Tuple[bool, str]
- nextVertex(self, id: QgsVertexId) Tuple[bool, QgsPoint] ¶
- Parameters:
id (QgsVertexId) –
- Return type:
Tuple[bool, QgsPoint]
- normalize(self)¶
- numPoints(self) int ¶
Returns the number of points in the curve.
- Return type:
int
- orientation(self) Qgis.AngularDirection ¶
Returns the curve’s orientation, e.g. clockwise or counter-clockwise.
Warning
The result is not predictable for non-closed curves.
New in version 3.6.
- Return type:
- partCount(self) int ¶
- Return type:
int
- pointAt(self, node: int) Tuple[bool, QgsPoint, Qgis.VertexType] ¶
Returns the point and vertex id of a point within the curve.
- Parameters:
node (int) – node number, where the first node is 0
- Return type:
Tuple[bool,
QgsPoint
, Qgis.VertexType]- Returns:
True
if node exists within the curvepoint: will be set to point at corresponding node in the curve
type: will be set to the vertex type of the node
- points(self) List[QgsPoint] ¶
Returns a list of points within the curve.
- Return type:
List[QgsPoint]
- reversed(self) QgsCurve ¶
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
New in version 2.14.
- Return type:
- ringCount(self, part: int = 0) int ¶
- Parameters:
part (int = 0) –
- Return type:
int
- scroll(self, firstVertexIndex: int)¶
Scrolls the curve vertices so that they start with the vertex at the given index.
Warning
This should only be called on closed curves, or the shape of the curve will be altered and the result is undefined.
Warning
The
firstVertexIndex
must correspond to a segment vertex and not a curve point or the result is undefined.New in version 3.20.
- Parameters:
firstVertexIndex (int) –
- segmentize(self, tolerance: float = M_PI_2 / 90, toleranceType: QgsAbstractGeometry.SegmentationToleranceType = QgsAbstractGeometry.MaximumAngle) QgsCurve ¶
Returns a geometry without curves. Caller takes ownership
- Parameters:
tolerance (float = M_PI_2/90) – segmentation tolerance
toleranceType (QgsAbstractGeometry.SegmentationToleranceType = QgsAbstractGeometry.MaximumAngle) – maximum segmentation angle or maximum difference between approximation and curve
- Return type:
- sinuosity(self) float ¶
Returns the curve sinuosity, which is the ratio of the curve
length()
to curvestraightDistance2d()
. Larger numbers indicate a more “sinuous” curve (i.e. more “bendy”). The minimum value returned of 1.0 indicates a perfectly straight curve.If a curve
isClosed()
, it has infinite sinuosity and will return NaN.New in version 3.2.
- Return type:
float
- straightDistance2d(self) float ¶
Returns the straight distance of the curve, i.e. the direct/euclidean distance between the first and last vertex of the curve. (Also known as “as the crow flies” distance).
New in version 3.2.
- Return type:
float
- sumUpArea(self) float ¶
Sums up the area of the curve by iterating over the vertices (shoelace formula).
- Return type:
float
- vertexAt(self, id: QgsVertexId) QgsPoint ¶
- Parameters:
id (QgsVertexId) –
- Return type:
- vertexCount(self, part: int = 0, ring: int = 0) int ¶
- Parameters:
part (int = 0) –
ring (int = 0) –
- Return type:
int
- vertexNumberFromVertexId(self, id: QgsVertexId) int ¶
- Parameters:
id (QgsVertexId) –
- Return type:
int
- xAt(self, index: int) float ¶
Returns the x-coordinate of the specified node in the line string.
- Parameters:
index (int) – index of node, where the first node in the line is 0
- Return type:
float
- Returns:
x-coordinate of node, or 0.0 if index is out of bounds
- yAt(self, index: int) float ¶
Returns the y-coordinate of the specified node in the line string.
- Parameters:
index (int) – index of node, where the first node in the line is 0
- Return type:
float
- Returns:
y-coordinate of node, or 0.0 if index is out of bounds