QgsCurve class

Abstract base class for curved geometry type.

Base classes

class QgsAbstractGeometry
Abstract base class for all geometries.

Derived classes

class QgsCircularString
Circular string geometry type.
class QgsCompoundCurve
Compound curve geometry type.
class QgsLineString
Line string geometry type, with support for z-dimension and m-values.

Public types

enum Orientation { Clockwise, CounterClockwise }
Curve orientation.

Constructors, destructors, conversion operators

QgsCurve() defaulted
Constructor for QgsCurve.

Public functions

void addToPainterPath(QPainterPath& path) const pure virtual
Adds a curve to a painter path.
void adjacentVertices(QgsVertexId vertex, QgsVertexId& previousVertex, QgsVertexId& nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
auto asQPolygonF() const -> QPolygonF virtual
Returns a QPolygonF representing the points.
auto boundary() const -> QgsAbstractGeometry* override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the geometry).
auto boundingBox() const -> QgsRectangle override
Returns the minimal bounding box for the geometry.
auto cast(const QgsAbstractGeometry* geom) const -> const QgsCurve*
Cast the geom to a QgsCurve.
auto clone() const -> QgsCurve* override
Clones the geometry by performing a deep copy.
auto coordinateSequence() const -> QgsCoordinateSequence override
Retrieves the sequence of geometries, rings and nodes.
auto curveSubstring(double startDistance, double endDistance) const -> QgsCurve* pure virtual
Returns a new curve representing a substring of this curve.
auto curveToLine(double tolerance = M_PI_2/90, SegmentationToleranceType toleranceType = MaximumAngle) const -> QgsLineString* pure virtual
Returns a new line string geometry corresponding to a segmentized approximation of the curve.
void drawAsPolygon(QPainter& p) const pure virtual
Draws the curve as a polygon on the specified QPainter.
auto endPoint() const -> QgsPoint pure virtual
Returns the end point of the curve.
auto equals(const QgsCurve& other) const -> bool pure virtual
Checks whether this curve exactly equals another curve.
auto interpolatePoint(double distance) const -> QgsPoint* pure virtual
Returns an interpolated point on the curve at the specified distance.
auto isClosed() const -> bool virtual
Returns true if the curve is closed.
auto isRing() const -> bool virtual
Returns true if the curve is a ring.
auto nextVertex(QgsVertexId& id, QgsPoint& vertex) const -> bool override
Returns next vertex id and coordinates.
auto numPoints() const -> int pure virtual
Returns the number of points in the curve.
auto orientation() const -> Orientation
Returns the curve's orientation, e.g.
auto partCount() const -> int override
Returns count of parts contained in the geometry.
auto pointAt(int node, QgsPoint& point, QgsVertexId::VertexType& type) const -> bool pure virtual
Returns the point and vertex id of a point within the curve.
void points(QgsPointSequence& pt) const pure virtual
Returns a list of points within the curve.
auto reversed() const -> QgsCurve* pure virtual
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
auto ringCount(int part = 0) const -> int override
Returns the number of rings of which this geometry is built.
auto segmentize(double tolerance = M_PI_2/90, SegmentationToleranceType toleranceType = MaximumAngle) const -> QgsCurve* override
Returns a geometry without curves.
auto sinuosity() const -> double
Returns the curve sinuosity, which is the ratio of the curve length() to curve straightDistance2d().
auto startPoint() const -> QgsPoint pure virtual
Returns the starting point of the curve.
auto straightDistance2d() const -> double
Returns the straight distance of the curve, i.e.
void sumUpArea(double& sum) const pure virtual
Sums up the area of the curve by iterating over the vertices (shoelace formula).
auto toCurveType() const -> QgsCurve* override
Returns the geometry converted to the more generic curve type.
auto vertexAt(QgsVertexId id) const -> QgsPoint override
Returns the point corresponding to a specified vertex id.
auto vertexCount(int part = 0, int ring = 0) const -> int override
Returns the number of vertices of which this geometry is built.
auto vertexNumberFromVertexId(QgsVertexId id) const -> int override
Returns the vertex number corresponding to a vertex id.
auto xAt(int index) const -> double pure virtual
Returns the x-coordinate of the specified node in the line string.
auto yAt(int index) const -> double pure virtual
Returns the y-coordinate of the specified node in the line string.

Protected functions

auto childCount() const -> int override
Returns number of child geometries (for geometries with child geometries) or child points (for geometries without child geometries - i.e.
auto childPoint(int index) const -> QgsPoint 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.
auto 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) const -> bool
Helper function for QgsCurve subclasses to snap to grids.

Enum documentation

enum QgsCurve::Orientation

Curve orientation.

Enumerators
Clockwise

Clockwise orientation.

CounterClockwise

Counter-clockwise orientation.

Function documentation

void QgsCurve::adjacentVertices(QgsVertexId vertex, QgsVertexId& previousVertex, QgsVertexId& nextVertex) const override

Returns the vertices adjacent to a specified vertex within a geometry.

QgsAbstractGeometry* QgsCurve::boundary() const override

Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the geometry).

Returns boundary for geometry. May be null for some geometry types.

For instance, a polygon geometry will have a boundary consisting of the linestrings for each ring in the polygon.

const QgsCurve* QgsCurve::cast(const QgsAbstractGeometry* geom) const

Cast the geom to a QgsCurve.

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

QgsCoordinateSequence QgsCurve::coordinateSequence() const override

Retrieves the sequence of geometries, rings and nodes.

Returns coordinate sequence

QgsCurve* QgsCurve::curveSubstring(double startDistance, double endDistance) const pure virtual

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.

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

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

Uses a MaximumAngle tolerance of 1 degrees by default (360 segments in a full circle)

void QgsCurve::drawAsPolygon(QPainter& p) const pure virtual

Draws the curve as a polygon on the specified QPainter.

Parameters
p destination QPainter

QgsPoint QgsCurve::endPoint() const pure virtual

Returns the end point of the curve.

bool QgsCurve::equals(const QgsCurve& other) const pure virtual

Checks whether this curve exactly equals another curve.

QgsPoint* QgsCurve::interpolatePoint(double distance) const pure virtual

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, a nullptr will be returned.

bool QgsCurve::nextVertex(QgsVertexId& id, QgsPoint& vertex) const override

Returns next vertex id and coordinates.

Parameters
id initial value should be the starting vertex id. The next vertex id will be stored in this variable if found.
vertex container for found node
Returns false if at end

Orientation QgsCurve::orientation() const

Returns the curve's orientation, e.g.

clockwise or counter-clockwise.

int QgsCurve::partCount() const override

Returns count of parts contained in the geometry.

bool QgsCurve::pointAt(int node, QgsPoint& point, QgsVertexId::VertexType& type) const pure virtual

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

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

QgsCurve* QgsCurve::reversed() const pure virtual

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

QgsCurve* QgsCurve::segmentize(double tolerance = M_PI_2/90, SegmentationToleranceType toleranceType = MaximumAngle) const override

Returns a geometry without curves.

Parameters
tolerance segmentation tolerance
toleranceType maximum segmentation angle or maximum difference between approximation and curve

Caller takes ownership

double QgsCurve::sinuosity() const

Returns the curve sinuosity, which is the ratio of the curve length() to curve straightDistance2d().

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.

QgsPoint QgsCurve::startPoint() const pure virtual

Returns the starting point of the curve.

double QgsCurve::straightDistance2d() const

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).

QgsCurve* QgsCurve::toCurveType() const override

Returns the geometry converted to the more generic curve type.

Returns the converted geometry. Caller takes ownership

E.g. QgsLineString -> QgsCompoundCurve, QgsPolygon -> QgsCurvePolygon, QgsMultiLineString -> QgsMultiCurve, QgsMultiPolygon -> QgsMultiSurface

int QgsCurve::vertexNumberFromVertexId(QgsVertexId id) const override

Returns the vertex number corresponding to a vertex id.

The vertex numbers start at 0, so a return value of 0 corresponds to the first vertex.

Returns -1 if a corresponding vertex could not be found.

double QgsCurve::xAt(int index) const pure virtual

Returns 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
Returns x-coordinate of node, or 0.0 if index is out of bounds

double QgsCurve::yAt(int index) const pure virtual

Returns 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
Returns y-coordinate of node, or 0.0 if index is out of bounds

int QgsCurve::childCount() const override protected

Returns number of child geometries (for geometries with child geometries) or child points (for geometries without child geometries - i.e.

curve / point)

QgsPoint QgsCurve::childPoint(int index) const override protected

Returns point at index (for geometries without child geometries - i.e.

curve / point)

bool QgsCurve::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) const protected

Helper function for QgsCurve subclasses to snap to grids.