Class: QgsSfcgalGeometry¶
Wraps SFCGAL geometry object.
SfcgalGeometry geometry type.
Added in version 4.0.
List of all members, including inherited members
Methods
Adds a m-dimension to the geometry, initialized to a preset value (existing M values remains unchanged). |
|
Adds a z-dimension to the geometry, initialized to a preset value (existing Z values remains unchanged). |
|
Calculate a 2D approximate medial axis of geom based on its straight skeleton. |
|
Computes the area of geom. |
|
Returns the geometry converted to a QGIS geometry object. |
|
Export the geometry as WKB |
|
Export the geometry as WKT |
|
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the geometry). |
|
Calculate a 2D buffer where all points are at distance from the original geometry. |
|
Calculate a 3D buffer where all points are at distance from the original geometry. |
|
Calculates the centroid of this geometry. |
|
Clears any cached parameters associated with the geometry, e.g., bounding boxes |
|
Clones the geometry by performing a deep copy |
|
Calculate the combination of this and geomList. |
|
Calculate the convex hull (bounding box). |
|
Cover test on 2D or 3D geometries Checks if this covers otherGeom. |
|
Calculate the difference of this and otherGeom. |
|
Returns the inherent dimension of the geometry. |
|
Drops the m coordinate of the geometry |
|
Drops the z coordinate of the geometry |
|
Calculate the envelope (bounding box). |
|
Calculate an extrusion of the original geometry. |
|
Returns true if this == other geometry modulo epsilon distance |
|
Returns type of the geometry as a OGC string in CamelCase |
|
Calculate the intersection of this and otherGeom. |
|
Checks if otherGeom intersects this. |
|
Checks if geom is empty. |
|
Checks this geometry is simple. |
|
Checks if geom is valid. |
|
Computes the max length of geom. |
|
Returns the geom part count. |
|
Converts the current primitive to geometry. |
|
Returns the parameter value according to its name |
|
Returns the list of available parameter description for this primitive. |
|
Updates parameter value |
|
Returns the primitive transform matrix. |
|
2D Rotate this geometry around point center by angle angle |
|
3D Rotate this geometry around axis axisVector by angle angle |
|
Scale this geometry by vector scaleFactor. |
|
Simplifies a geometry using the CGAL algorithm |
|
Swaps the x and y coordinates of the geometry |
|
Converts the geometry to a PolyhedralSurface geometry. |
|
Converts the geometry to a Solid geometry. |
|
Apply 3D matrix transform mat to geometry geom |
|
Translate this geometry by vector translation. |
|
Triangulates this geometry using constraint 2D Delaunay Triangulation (keep Z if defined) |
|
Computes the volume of the primitive prim. |
|
Returns type of the geometry as a WKB type (point / linestring / polygon etc.) |
Static Methods
Create a cube primitive |
|
Creates a new geometry from a WKB byte pointer |
|
Creates a new geometry from a WKT string. |
- class qgis.core.QgsSfcgalGeometry[source]¶
Bases:
object- __init__()
Constructor for an empty SFCGAL geometry geometry.
- __init__(qgsGeom: QgsAbstractGeometry | None)
Constructor with
QgsAbstractGeometrypointer.Will not take ownership.
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- Parameters:
qgsGeom (Optional[QgsAbstractGeometry])
- __init__(qgsGeom: QgsAbstractGeometry)
Constructor with
QgsAbstractGeometryreference.- Raises:
QgsSfcgalException – if an error was encountered during the operation
- Parameters:
qgsGeom (QgsAbstractGeometry)
- __init__(qgsGeom: QgsGeometry)
Constructor with
QgsGeometryreference.- Raises:
QgsSfcgalException – if an error was encountered during the operation
- Parameters:
qgsGeom (QgsGeometry)
- __init__(wkt: str | None)
Constructor from WKT
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- Parameters:
wkt (Optional[str])
- __init__(otherGeom: QgsSfcgalGeometry)
Copy constructor
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- Parameters:
otherGeom (QgsSfcgalGeometry)
- addMValue(self, mValue: float = 0) bool[source]¶
Adds a m-dimension to the geometry, initialized to a preset value (existing M values remains unchanged).
- Parameters:
mValue (float = 0) – m value to use
- Return type:
bool
- Returns:
true if success
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- addZValue(self, zValue: float = 0) bool[source]¶
Adds a z-dimension to the geometry, initialized to a preset value (existing Z values remains unchanged).
- Parameters:
zValue (float = 0) – z value to use
- Return type:
bool
- Returns:
true if success
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- approximateMedialAxis(self) QgsSfcgalGeometry | None¶
Calculate a 2D approximate medial axis of
geombased on its straight skeleton. The approximate medial axis is a simplified representation of a shape’s central skeleton It the geometry is 3D, the approximate medial axis will be calculated from its 2D projection If the operation fails, a null pointer is returned.- Return type:
- Returns:
new geometry as 2D multilinestring
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- area(self, withDiscretization: bool = False) float[source]¶
Computes the area of
geom.- Parameters:
withDiscretization (bool = False) – If true, the area is computed using the real discretization with radial segments. If false, the area is computed for a perfect primitive. Defaults to false.
- Return type:
float
- Returns:
geometry area
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- asQgisGeometry(self) QgsAbstractGeometry | None¶
Returns the geometry converted to a QGIS geometry object. This method is slow to call, as it always involves re-conversion of the underlying SFCGAL geometry object.
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- Return type:
- asWkb(self, flags: QgsAbstractGeometry.WkbFlag = QgsAbstractGeometry.WkbFlags()) QByteArray[source]¶
Export the geometry as WKB
- Parameters:
flags (QgsAbstractGeometry.WkbFlag = QgsAbstractGeometry.WkbFlags()) – argument specifies flags controlling WKB export behavior.
- Return type:
QByteArray
- Returns:
WKB data
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- asWkt(self, precision: int = -1) str[source]¶
Export the geometry as WKT
- Parameters:
precision (int = -1) – Floating point precision for WKT coordinates. Setting to -1 yields rational number WKT (not decimal) f.e. “Point(1/3, 1/6, 1/4)”. Note that this will produce WKT which is not compatible with other QGIS methods or external libraries.
- Return type:
str
- Returns:
WKT data
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- boundary(self) QgsSfcgalGeometry | None¶
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the geometry). For instance, a polygon geometry will have a boundary consisting of the linestrings for each ring in the polygon.
- Return type:
- Returns:
boundary for geometry. May be
Nonefor some geometry types.
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- buffer2D(self, radius: float, segments: int, joinStyle: Qgis.JoinStyle) QgsSfcgalGeometry | None¶
Calculate a 2D buffer where all points are at
distancefrom the original geometry. A negative distance shrinks the geometry rather than expanding it. If the operation fails, a null pointer is returned.- Parameters:
radius (float) – the buffer radius
segments (int) – the number of segments to use for approximating curved
joinStyle (Qgis.JoinStyle) – the type of buffer to compute. Only round is supported.
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- buffer3D(self, radius: float, segments: int, joinStyle3D: Qgis.JoinStyle3D) QgsSfcgalGeometry | None¶
Calculate a 3D buffer where all points are at
distancefrom the original geometry. A negative distance shrinks the geometry rather than expanding it. It is limited to Point and LineString. If the operation fails, a null pointer is returned.- Parameters:
radius (float) – the buffer radius
segments (int) – the number of segments to use for approximating curved
joinStyle3D (Qgis.JoinStyle3D) – the type of buffer to compute
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- centroid(self) QgsPoint[source]¶
Calculates the centroid of this geometry.
- Return type:
- Returns:
geometry centroid
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- clearCache(self)[source]¶
Clears any cached parameters associated with the geometry, e.g., bounding boxes
- clone(self) QgsSfcgalGeometry | None¶
Clones the geometry by performing a deep copy
- Return type:
- combine(self, geomList: Iterable[QgsAbstractGeometry]) QgsSfcgalGeometry | None¶
Calculate the combination of this and
geomList.- Parameters:
geomList (Iterable[QgsAbstractGeometry]) – list of geometries to perform the operation
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- convexHull(self) QgsSfcgalGeometry | None¶
Calculate the convex hull (bounding box).
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- covers(self, otherGeom: QgsSfcgalGeometry) bool[source]¶
Cover test on 2D or 3D geometries Checks if this covers
otherGeom. A 3D covers test is conducted when at least one geometry is 3D; otherwise, a 2D covers test is carried out.- Parameters:
otherGeom (QgsSfcgalGeometry) – second geometry to perform the operation
- Return type:
bool
- Returns:
true if coverage exists
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- static createCube(size: float) QgsSfcgalGeometry | None¶
Create a cube primitive
- Parameters:
size (float) – the cube size
- Raises:
QgsSfcgalException – if an error was encountered during the operation
QgsNotSupportedException – on QGIS builds based on SFCGAL < 2.3.
- Return type:
- difference(self, otherGeom: QgsAbstractGeometry | None) QgsSfcgalGeometry | None¶
Calculate the difference of this and
otherGeom.- Parameters:
otherGeom (Optional[QgsAbstractGeometry]) – geometry to perform the operation
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
difference(self, otherGeom:
QgsSfcgalGeometry) -> Optional[QgsSfcgalGeometry] Calculate the difference of this andotherGeom.- Parameters:
otherGeom – geometry to perform the operation
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- dimension(self) int[source]¶
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.
- Return type:
int
- Returns:
geometry dimension
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- dropMValue(self) bool[source]¶
Drops the m coordinate of the geometry
- Return type:
bool
- Returns:
true if success
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- dropZValue(self) bool[source]¶
Drops the z coordinate of the geometry
- Return type:
bool
- Returns:
true if success
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- envelope(self) QgsSfcgalGeometry | None¶
Calculate the envelope (bounding box).
- Return type:
- Returns:
new geometry
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- extrude(self, extrusion: QgsVector3D) QgsSfcgalGeometry | None¶
Calculate an extrusion of the original geometry. If the operation fails, a null pointer is returned.
- Parameters:
extrusion (QgsVector3D) – extrusion vector (2D or 3D)
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- static fromWkb(wkbPtr: QgsConstWkbPtr) QgsSfcgalGeometry | None¶
Creates a new geometry from a WKB byte pointer
- Parameters:
wkbPtr (QgsConstWkbPtr) – WKB byte pointer
- Return type:
- Returns:
new geometry from WKB
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- static fromWkt(wkt: str | None) QgsSfcgalGeometry | None¶
Creates a new geometry from a WKT string.
- Parameters:
wkt (Optional[str]) – WTK string
- Return type:
- Returns:
new geometry from WKT
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- fuzzyEqual(self, other: QgsSfcgalGeometry, epsilon: float) bool[source]¶
Returns true if this == other geometry modulo
epsilondistance- Parameters:
other (QgsSfcgalGeometry) – geometry to perform the operation
epsilon (float) – tolerance
- Return type:
bool
- Returns:
true if this == other geometry modulo
epsilondistance
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- geometryType(self) str[source]¶
Returns type of the geometry as a OGC string in CamelCase
- Return type:
str
- Returns:
type of the geometry as a OGC string in CamelCase
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – when working with primitive and SFCGAL is less than 2.3.
QgsSfcgalException – if an error was encountered during the operation
- intersection(self, otherGeom: QgsAbstractGeometry | None) QgsSfcgalGeometry | None¶
Calculate the intersection of this and
otherGeom.- Parameters:
otherGeom (Optional[QgsAbstractGeometry]) – geometry to perform the operation
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
intersection(self, otherGeom:
QgsSfcgalGeometry) -> Optional[QgsSfcgalGeometry] Calculate the intersection of this andotherGeom.- Parameters:
otherGeom – geometry to perform the operation
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- intersects(self, otherGeom: QgsAbstractGeometry | None) bool[source]¶
Checks if
otherGeomintersects this.- Parameters:
otherGeom (Optional[QgsAbstractGeometry]) – geometry to perform the operation
- Returns:
true if intersection exists
- Raises:
QgsSfcgalException – if an error was encountered during the operation
intersects(self, otherGeom:
QgsSfcgalGeometry) -> bool Checks ifotherGeomintersects this.- Parameters:
otherGeom – geometry to perform the operation
- Return type:
bool
- Returns:
true if intersection exists
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- isEmpty(self) bool[source]¶
Checks if
geomis empty.- Return type:
bool
- Returns:
true if empty
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- isSimple(self) bool[source]¶
Checks this geometry is simple.
See also
QgsSfcgalEngine.isSimple()- Return type:
bool
- Returns:
true if simple
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- isValid(self) bool[source]¶
Checks if
geomis valid.- Return type:
bool
- Returns:
true if valid
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- length(self) float[source]¶
Computes the max length of
geom.- Return type:
float
- Returns:
geometry length
This method requires a QGIS build based on SFCGAL 2.1 or later.
pre apply only on geometry
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- partCount(self) int[source]¶
Returns the
geompart count.POINT, TRIANGLE, LINESTRING: vertex number
POLYGON, SOLID, POLYHEDRALSURFACE, TRIANGULATEDSURFACE: ring or patch or shell number
MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, MULTISOLID, GEOMETRYCOLLECTION: number of geom in collection
- Return type:
int
- Returns:
geometry part count
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- primitiveAsPolyhedralSurface(self) QgsSfcgalGeometry | None¶
Converts the current primitive to geometry. Works only with primitives.
- Raises:
QgsSfcgalException – if an error was encountered during the operation
QgsNotSupportedException – on QGIS builds based on SFCGAL < 2.3.
- Return type:
- primitiveParameter(self, name: str | None) Any[source]¶
Returns the parameter value according to its
name- Parameters:
name (Optional[str]) – parameter name
- Raises:
QgsSfcgalException – if an error was encountered during the operation
QgsNotSupportedException – on QGIS builds based on SFCGAL < 2.3.
- Return type:
- primitiveParameters(self) list[tuple[str, str]]¶
Returns the list of available parameter description for this primitive.
Parameter description is a pair of string: name and type. Type can be one of int, double,
QgsPoint,QgsVector3D- Raises:
QgsSfcgalException – if an error was encountered during the operation
QgsNotSupportedException – on QGIS builds based on SFCGAL < 2.3.
- Return type:
list[tuple[str, str]]
- primitiveSetParameter(self, name: str | None, value: Any)[source]¶
Updates parameter value
- Parameters:
- Raises:
QgsSfcgalException – if an error was encountered during the operation
QgsNotSupportedException – on QGIS builds based on SFCGAL < 2.3.
- primitiveTransform(self) QgsMatrix4x4[source]¶
Returns the primitive transform matrix.
- Raises:
QgsSfcgalException – if an error was encountered during the operation
QgsNotSupportedException – on QGIS builds based on SFCGAL < 2.3.
- Return type:
- rotate2D(self, angle: float, center: QgsPoint) QgsSfcgalGeometry | None¶
2D Rotate this geometry around point
centerby angleangle- Parameters:
angle (float) – rotation angle in radians
center (QgsPoint) – rotation center
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- rotate3D(self, angle: float, axisVector: QgsVector3D, center: QgsPoint = QgsPoint()) QgsSfcgalGeometry | None¶
3D Rotate this geometry around axis
axisVectorby angleangle- Parameters:
angle (float) – rotation angle in radians
axisVector (QgsVector3D) – rotation axis
center (
QgsPoint= QgsPoint()) – optional parameter. If specified, rotation will be applied around axis and center point
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- scale(self, scaleFactor: QgsVector3D, center: QgsPoint = QgsPoint()) QgsSfcgalGeometry | None¶
Scale this geometry by vector
scaleFactor.- Parameters:
scaleFactor (QgsVector3D) – scale factor vector (2D or 3D)
center (
QgsPoint= QgsPoint()) – optional parameter. If specified, scaling will be performed relative to this center
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- simplify(self, tolerance: float, preserveTopology: bool) QgsSfcgalGeometry | None¶
Simplifies a geometry using the CGAL algorithm
- Parameters:
tolerance (float) – The distance (in geometry unit) threshold
preserveTopology (bool) – Whether to preserve topology during simplification
- Return type:
- Returns:
new geometry
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- swapXy(self)[source]¶
Swaps the x and y coordinates of the geometry
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- toPolyhedralSurface(self) QgsSfcgalGeometry | None¶
Converts the geometry to a PolyhedralSurface geometry. The geometry must be of type Solid
- Return type:
- Returns:
geometry as a PolyhedralSurface
- Raises:
QgsSfcgalException – if an error was encountered during the operation
Added in version 4.2.
- toSolid(self) QgsSfcgalGeometry | None¶
Converts the geometry to a Solid geometry. The geometry must be of type PolyhedralSurface
- Return type:
- Returns:
geometry as a Solid
- Raises:
QgsSfcgalException – if an error was encountered during the operation
Added in version 4.2.
- transform(self, mat: QgsMatrix4x4) QgsSfcgalGeometry | None¶
Apply 3D matrix transform
matto geometrygeom- Parameters:
mat (QgsMatrix4x4) – 4x4 transformation matrix (translation is defined in the 4th column)
errorMsg – Error message returned by SFGCAL
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
QgsNotSupportedException – on QGIS builds based on SFCGAL < 2.3.
- translate(self, translation: QgsVector3D) QgsSfcgalGeometry | None¶
Translate this geometry by vector
translation.- Parameters:
translation (QgsVector3D) – translation vector (2D or 3D)
- Return type:
- Returns:
new geometry
This method requires a QGIS build based on SFCGAL 2.1 or later.
- Raises:
QgsNotSupportedException – on QGIS builds based on SFCGAL 2.0.
QgsSfcgalException – if an error was encountered during the operation
- triangulate(self) QgsSfcgalGeometry | None¶
Triangulates this geometry using constraint 2D Delaunay Triangulation (keep Z if defined)
- Return type:
- Returns:
new geometry
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- volume(self, withDiscretization: bool = False) float[source]¶
Computes the volume of the primitive
prim.- Parameters:
withDiscretization (bool = False) – If true, the volume is computed using the real discretization with radial segments. If false, the volume is computed for a perfect primitive. Defaults to false.
- Return type:
float
- Returns:
primitive volume
pre apply only on primitive
- Raises:
QgsSfcgalException – if an error was encountered during the operation
- wkbType(self) Qgis.WkbType[source]¶
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
- Return type:
- Returns:
type of the geometry as a WKB type (point / linestring / polygon etc.)
- Raises:
QgsNotSupportedException – when working with primitive and SFCGAL is less than 2.3.
QgsSfcgalException – if an error was encountered during the operation