QgsCurvePolygon class
Curve polygon geometry type.
Contents
Derived classes
- class QgsPolygon
- Polygon geometry type.
Public functions
- void addInteriorRing(QgsCurve* ring) virtual
- Adds an interior ring to the geometry (takes ownership)
- auto addMValue(double mValue = 0) -> bool override
- Adds a measure to the geometry, initialized to a preset value.
- auto addZValue(double zValue = 0) -> bool override
- Adds a z-dimension to the geometry, initialized to a preset value.
- void adjacentVertices(QgsVertexId vertex, QgsVertexId& previousVertex, QgsVertexId& nextVertex) const override
- Returns the vertices adjacent to a specified vertex within a geometry.
- auto area() const -> double override
- Returns the area of the geometry.
-
auto asGml2(QDomDocument& doc,
int precision = 17,
const QString& ns = "gml",
QgsAbstractGeometry::
AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY) const -> QDomElement override - Returns a GML2 representation of the geometry.
-
auto asGml3(QDomDocument& doc,
int precision = 17,
const QString& ns = "gml",
QgsAbstractGeometry::
AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY) const -> QDomElement override - Returns a GML3 representation of the geometry.
- auto asJson(int precision = 17) const -> QString override
- Returns a GeoJSON representation of the geometry.
- auto asWkb() const -> QByteArray override
- Returns a WKB representation of the geometry.
- auto asWkt(int precision = 17) const -> QString override
- Returns a WKT representation of the geometry.
- auto boundary() const -> QgsAbstractGeometry* override
- Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the geometry).
- auto cast(const QgsAbstractGeometry* geom) const -> const QgsCurvePolygon*
- Cast the geom to a QgsCurvePolygon.
- void clear() override
- Clears the geometry, ie reset it to a null geometry.
- auto clone() const -> QgsCurvePolygon* override
- Clones the geometry by performing a deep copy.
- auto closestSegment(const QgsPoint& pt, QgsPoint& segmentPt, QgsVertexId& vertexAfter, int* leftOf = nullptr, double epsilon = 4*std::numeric_limits<double>::epsilon()) const -> double override
- Searches for the closest segment of the geometry to a given point.
- auto coordinateSequence() const -> QgsCoordinateSequence override
- Retrieves the sequence of geometries, rings and nodes.
- auto createEmptyWithSameType() const -> QgsCurvePolygon* override
- Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
- auto deleteVertex(QgsVertexId position) -> bool override
- Deletes a vertex within the geometry.
- auto dimension() const -> int override
- Returns the inherent dimension of the geometry.
- void draw(QPainter& p) const override
- Draws the geometry using the specified QPainter.
- auto dropMValue() -> bool override
- Drops any measure values which exist in the geometry.
- auto dropZValue() -> bool override
- Drops any z-dimensions which exist in the geometry.
- auto exteriorRing() const -> const QgsCurve*
- Returns the curve polygon's exterior ring.
- void filterVertices(const std::function<bool(const QgsPoint&)>& filter) override
- Filters the vertices from the geometry in place, removing any which do not return true for the filter function check.
- void forceRHR()
- Forces the geometry to respect the Right-Hand-Rule, in which the area that is bounded by the polygon is to the right of the boundary.
- auto fromWkb(QgsConstWkbPtr& wkb) -> bool override
- Sets the geometry from a WKB string.
- auto fromWkt(const QString& wkt) -> bool override
- Sets the geometry from a WKT string.
- auto geometryType() const -> QString override
- Returns a unique string representing the geometry type.
- auto hasCurvedSegments() const -> bool override
- Returns true if the geometry contains curved segments.
- auto insertVertex(QgsVertexId position, const QgsPoint& vertex) -> bool override
- Inserts a vertex into the geometry.
- auto interiorRing(int i) const -> const QgsCurve*
- Retrieves an interior ring from the curve polygon.
- auto isEmpty() const -> bool override
- Returns true if the geometry is empty.
- auto moveVertex(QgsVertexId position, const QgsPoint& newPos) -> bool override
- Moves a vertex within the geometry.
- auto nCoordinates() const -> int override
- Returns the number of nodes contained in the geometry.
- auto nextVertex(QgsVertexId& id, QgsPoint& vertex) const -> bool override
- Returns next vertex id and coordinates.
- auto numInteriorRings() const -> int
- Returns the number of interior rings contained with the curve polygon.
- auto partCount() const -> int override
- Returns count of parts contained in the geometry.
- auto perimeter() const -> double override
- Returns the perimeter of the geometry.
- auto removeDuplicateNodes(double epsilon = 4*std::numeric_limits<double>::epsilon(), bool useZValues = false) -> bool override
- Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerate geometry.
- auto removeInteriorRing(int ringIndex) -> bool
- Removes an interior ring from the polygon.
- void removeInteriorRings(double minimumAllowedArea = -1)
- Removes the interior rings from the polygon.
- void removeInvalidRings()
- Removes any interior rings which are not valid from the polygon.
- 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 -> QgsAbstractGeometry* override
- Returns a geometry without curves.
- auto segmentLength(QgsVertexId startVertex) const -> double override
- Returns the length of the segment of the geometry which begins at startVertex.
- void setExteriorRing(QgsCurve* ring) virtual
- Sets the exterior ring of the polygon.
- void setInteriorRings(const QVector<QgsCurve*>& rings)
- Sets all interior rings (takes ownership)
- auto snappedToGrid(double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0) const -> QgsCurvePolygon* override
- Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
- auto surfaceToPolygon() const -> QgsPolygon* override
- Gets a polygon representation of this surface.
- void swapXy() override
- Swaps the x and y coordinates from the geometry.
- auto toCurveType() const -> QgsCurvePolygon* override
- Returns the geometry converted to the more generic curve type.
- auto toPolygon(double tolerance = M_PI_2/90, SegmentationToleranceType toleranceType = MaximumAngle) const -> QgsPolygon* virtual
- Returns a new polygon geometry corresponding to a segmentized approximation of the curve.
-
void transform(const QgsCoordinateTransform& ct,
QgsCoordinateTransform::
TransformDirection d = QgsCoordinateTransform:: ForwardTransform, bool transformZ = false) virtual - Transforms the geometry using a coordinate transform.
- void transform(const QTransform& t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0) override
- Transforms the x and y components of the geometry using a QTransform object t.
- void transformVertices(const std::function<QgsPoint(const QgsPoint&)>& transform) override
- Transforms the vertices from the geometry in place, applying the transform function to every vertex.
- auto vertexAngle(QgsVertexId vertex) const -> double override
- Returns approximate rotation angle for a vertex.
- 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.
Protected functions
- auto calculateBoundingBox() const -> QgsRectangle override
- Default calculator for the minimal bounding box for the geometry.
- 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 childGeometry(int index) const -> QgsAbstractGeometry* override
- Returns pointer to child geometry (for geometries with child geometries - i.e.
Function documentation
bool QgsCurvePolygon:: addMValue(double mValue = 0) override
Adds a measure to the geometry, initialized to a preset value.
| Parameters | |
|---|---|
| mValue | initial m-value for all nodes |
| Returns | true on success |
bool QgsCurvePolygon:: addZValue(double zValue = 0) override
Adds a z-dimension to the geometry, initialized to a preset value.
| Parameters | |
|---|---|
| zValue | initial z-value for all nodes |
| Returns | true on success |
void QgsCurvePolygon:: adjacentVertices(QgsVertexId vertex,
QgsVertexId& previousVertex,
QgsVertexId& nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
double QgsCurvePolygon:: area() const override
Returns the area of the geometry.
QDomElement QgsCurvePolygon:: asGml2(QDomDocument& doc,
int precision = 17,
const QString& ns = "gml",
QgsAbstractGeometry:: AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML2 representation of the geometry.
| Parameters | |
|---|---|
| doc | DOM document |
| precision | number of decimal places for coordinates |
| ns | XML namespace |
| axisOrder | Axis order for generated GML |
QDomElement QgsCurvePolygon:: asGml3(QDomDocument& doc,
int precision = 17,
const QString& ns = "gml",
QgsAbstractGeometry:: AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML3 representation of the geometry.
| Parameters | |
|---|---|
| doc | DOM document |
| precision | number of decimal places for coordinates |
| ns | XML namespace |
| axisOrder | Axis order for generated GML |
QString QgsCurvePolygon:: asJson(int precision = 17) const override
Returns a GeoJSON representation of the geometry.
| Parameters | |
|---|---|
| precision | number of decimal places for coordinates |
QByteArray QgsCurvePolygon:: asWkb() const override
Returns a WKB representation of the geometry.
QString QgsCurvePolygon:: asWkt(int precision = 17) const override
Returns a WKT representation of the geometry.
| Parameters | |
|---|---|
| precision | number of decimal places for coordinates |
QgsAbstractGeometry* QgsCurvePolygon:: 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 QgsCurvePolygon* QgsCurvePolygon:: cast(const QgsAbstractGeometry* geom) const
Cast the geom to a QgsCurvePolygon.
Should be used by qgsgeometry_cast<QgsCurvePolygon *>( geometry ).
double QgsCurvePolygon:: closestSegment(const QgsPoint& pt,
QgsPoint& segmentPt,
QgsVertexId& vertexAfter,
int* leftOf = nullptr,
double epsilon = 4*std::numeric_limits<double>::epsilon()) const override
Searches for the closest segment of the geometry to a given point.
| Parameters | |
|---|---|
| pt | specifies the point to find closest segment to |
| segmentPt | storage for the closest point within the geometry |
| vertexAfter | storage for the ID of the vertex at the end of the closest segment |
| leftOf | indicates whether the point lies on the left side of the geometry (-1 if point is to the left of the geometry, +1 if the point is to the right of the geometry, or 0 for cases where left/right could not be determined, e.g. point exactly on a line) false if point is to right of segment) |
| epsilon | epsilon for segment snapping |
| Returns | squared distance to closest segment or negative value on error |
QgsCoordinateSequence QgsCurvePolygon:: coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
| Returns | coordinate sequence |
|---|
QgsCurvePolygon* QgsCurvePolygon:: createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
To create it, the geometry is default constructed and then the WKB is changed.
bool QgsCurvePolygon:: deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
| Parameters | |
|---|---|
| position | vertex id for vertex to delete |
| Returns | true if delete was successful |
int QgsCurvePolygon:: dimension() const override
Returns the inherent dimension of the geometry.
For example, this is 0 for a point geometry, 1 for a linestring and 2 for a polygon.
void QgsCurvePolygon:: draw(QPainter& p) const override
Draws the geometry using the specified QPainter.
| Parameters | |
|---|---|
| p | destination QPainter |
bool QgsCurvePolygon:: dropMValue() override
Drops any measure values which exist in the geometry.
| Returns | true if m-values were present and have been removed |
|---|
bool QgsCurvePolygon:: dropZValue() override
Drops any z-dimensions which exist in the geometry.
| Returns | true if Z values were present and have been removed |
|---|
const QgsCurve* QgsCurvePolygon:: exteriorRing() const
Returns the curve polygon's exterior ring.
void QgsCurvePolygon:: filterVertices(const std::function<bool(const QgsPoint&)>& filter) override
Filters the vertices from the geometry in place, removing any which do not return true for the filter function check.
Has no meaning when called on a single point geometry.
Depending on the filter used, this may result in an invalid geometry.
void QgsCurvePolygon:: forceRHR()
Forces the geometry to respect the Right-Hand-Rule, in which the area that is bounded by the polygon is to the right of the boundary.
In particular, the exterior ring is oriented in a clockwise direction and the interior rings in a counter-clockwise direction.
bool QgsCurvePolygon:: fromWkb(QgsConstWkbPtr& wkb) override
Sets the geometry from a WKB string.
After successful read the wkb argument will be at the position where the reading has stopped.
bool QgsCurvePolygon:: fromWkt(const QString& wkt) override
Sets the geometry from a WKT string.
QString QgsCurvePolygon:: geometryType() const override
Returns a unique string representing the geometry type.
bool QgsCurvePolygon:: insertVertex(QgsVertexId position,
const QgsPoint& vertex) override
Inserts a vertex into the geometry.
| Parameters | |
|---|---|
| position | vertex id for position of inserted vertex |
| vertex | vertex to insert |
| Returns | true if insert was successful |
const QgsCurve* QgsCurvePolygon:: interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
The first interior ring has index 0.
bool QgsCurvePolygon:: moveVertex(QgsVertexId position,
const QgsPoint& newPos) override
Moves a vertex within the geometry.
| Parameters | |
|---|---|
| position | vertex id for vertex to move |
| newPos | new position of vertex |
| Returns | true if move was successful |
bool QgsCurvePolygon:: 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 |
int QgsCurvePolygon:: numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
int QgsCurvePolygon:: partCount() const override
Returns count of parts contained in the geometry.
double QgsCurvePolygon:: perimeter() const override
Returns the perimeter of the geometry.
bool QgsCurvePolygon:: removeDuplicateNodes(double epsilon = 4*std::numeric_limits<double>::epsilon(),
bool useZValues = false) override
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerate geometry.
The epsilon parameter specifies the tolerance for coordinates when determining that vertices are identical.
By default, z values are not considered when detecting duplicate nodes. E.g. two nodes with the same x and y coordinate but different z values will still be considered duplicate and one will be removed. If useZValues is true, then the z values are also tested and nodes with the same x and y but different z will be maintained.
Note that duplicate nodes are not tested between different parts of a multipart geometry. E.g. a multipoint geometry with overlapping points will not be changed by this method.
The function will return true if nodes were removed, or false if no duplicate nodes were found.
bool QgsCurvePolygon:: removeInteriorRing(int ringIndex)
Removes an interior ring from the polygon.
The first interior ring has index 0. The corresponding ring is removed from the polygon and deleted. If a ring was successfully removed the function will return true. It is not possible to remove the exterior ring using this method.
void QgsCurvePolygon:: removeInteriorRings(double minimumAllowedArea = -1)
Removes the interior rings from the polygon.
If the minimumAllowedArea parameter is specified then only rings smaller than this minimum area will be removed.
void QgsCurvePolygon:: removeInvalidRings()
Removes any interior rings which are not valid from the polygon.
For example, this removes unclosed rings and rings with less than 4 vertices.
QgsAbstractGeometry* QgsCurvePolygon:: 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 QgsCurvePolygon:: segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
void QgsCurvePolygon:: setExteriorRing(QgsCurve* ring) virtual
Sets the exterior ring of the polygon.
| Parameters | |
|---|---|
| ring | new exterior ring. Ownership is transferred to the CurvePolygon. |
The CurvePolygon type will be updated to match the dimensionality of the exterior ring. For instance, setting a 2D exterior ring on a 3D CurvePolygon will drop the z dimension from the CurvePolygon and all interior rings.
QgsCurvePolygon* QgsCurvePolygon:: snappedToGrid(double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0) const override
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
| Parameters | |
|---|---|
| hSpacing | Horizontal spacing of the grid (x axis). 0 to disable. |
| vSpacing | Vertical spacing of the grid (y axis). 0 to disable. |
| dSpacing | Depth spacing of the grid (z axis). 0 (default) to disable. |
| mSpacing | Custom dimension spacing of the grid (m axis). 0 (default) to disable. |
Ownership is transferred to the caller.
If the gridified geometry could not be calculated a nullptr will be returned. It may generate an invalid geometry (in some corner cases). It can also be thought as rounding the edges and it may be useful for removing errors. Example: geometry->snappedToGrid(1, 1); In this case we use a 2D grid of 1x1 to gridify. In this case, it can be thought like rounding the x and y of all the points/vertices to full units (remove all decimals).
QgsPolygon* QgsCurvePolygon:: surfaceToPolygon() const override
Gets a polygon representation of this surface.
Ownership is transferred to the caller.
void QgsCurvePolygon:: swapXy() override
Swaps the x and y coordinates from the geometry.
This can be used to repair geometries which have accidentally had their latitude and longitude coordinates reversed.
QgsCurvePolygon* QgsCurvePolygon:: 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
QgsPolygon* QgsCurvePolygon:: toPolygon(double tolerance = M_PI_2/90,
SegmentationToleranceType toleranceType = MaximumAngle) const virtual
Returns a new polygon geometry corresponding to a segmentized approximation of the curve.
| Parameters | |
|---|---|
| tolerance | segmentation tolerance |
| toleranceType | maximum segmentation angle or maximum difference between approximation and curve |
void QgsCurvePolygon:: transform(const QgsCoordinateTransform& ct,
QgsCoordinateTransform:: TransformDirection d = QgsCoordinateTransform:: ForwardTransform,
bool transformZ = false) virtual
Transforms the geometry using a coordinate transform.
| Parameters | |
|---|---|
| ct | coordinate transform |
| d | transformation direction |
| transformZ | set to true to also transform z coordinates. This requires that the z coordinates in the geometry represent height relative to the vertical datum of the source CRS (generally ellipsoidal heights) and are expressed in its vertical units (generally meters). If false, then z coordinates will not be changed by the transform. |
void QgsCurvePolygon:: transform(const QTransform& t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0) override
Transforms the x and y components of the geometry using a QTransform object t.
Optionally, the geometry's z values can be scaled via zScale and translated via zTranslate. Similarly, m-values can be scaled via mScale and translated via mTranslate.
void QgsCurvePolygon:: transformVertices(const std::function<QgsPoint(const QgsPoint&)>& transform) override
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
Depending on the transform used, this may result in an invalid geometry.
Transform functions are not permitted to alter the dimensionality of vertices. If a transform which adds (or removes) z/m values is desired, first call the corresponding addZValue() or addMValue() function to change the geometry's dimensionality and then transform.
double QgsCurvePolygon:: vertexAngle(QgsVertexId vertex) const override
Returns approximate rotation angle for a vertex.
| Parameters | |
|---|---|
| vertex | the vertex id |
| Returns | rotation in radians, clockwise from north |
Usually average angle between adjacent segments.
int QgsCurvePolygon:: 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.
QgsRectangle QgsCurvePolygon:: calculateBoundingBox() const override protected
Default calculator for the minimal bounding box for the geometry.
Derived classes should override this method if a more efficient bounding box calculation is available.
int QgsCurvePolygon:: 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)
QgsAbstractGeometry* QgsCurvePolygon:: childGeometry(int index) const override protected
Returns pointer to child geometry (for geometries with child geometries - i.e.
geom. collection / polygon)