Class: QgsSfcgalGeometry

Wraps SFCGAL geometry object.

SfcgalGeometry geometry type.

Added in version 4.0.

List of all members, including inherited members

Methods

addMValue

Adds a m-dimension to the geometry, initialized to a preset value (existing M values remains unchanged).

addZValue

Adds a z-dimension to the geometry, initialized to a preset value (existing Z values remains unchanged).

approximateMedialAxis

Calculate a 2D approximate medial axis of geom based on its straight skeleton.

area

Computes the area of geom.

asQgisGeometry

Returns the geometry converted to a QGIS geometry object.

asWkb

Export the geometry as WKB

asWkt

Export the geometry as WKT

boundary

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

buffer2D

Calculate a 2D buffer where all points are at distance from the original geometry.

buffer3D

Calculate a 3D buffer where all points are at distance from the original geometry.

centroid

Calculates the centroid of this geometry.

clearCache

Clears any cached parameters associated with the geometry, e.g., bounding boxes

clone

Clones the geometry by performing a deep copy

combine

Calculate the combination of this and geomList.

convexHull

Calculate the convex hull (bounding box).

covers

Cover test on 2D or 3D geometries Checks if this covers otherGeom.

difference

Calculate the difference of this and otherGeom.

dimension

Returns the inherent dimension of the geometry.

dropMValue

Drops the m coordinate of the geometry

dropZValue

Drops the z coordinate of the geometry

envelope

Calculate the envelope (bounding box).

extrude

Calculate an extrusion of the original geometry.

fuzzyEqual

Returns true if this == other geometry modulo epsilon distance

geometryType

Returns type of the geometry as a OGC string in CamelCase

intersection

Calculate the intersection of this and otherGeom.

intersects

Checks if otherGeom intersects this.

isEmpty

Checks if geom is empty.

isSimple

Checks this geometry is simple.

isValid

Checks if geom is valid.

length

Computes the max length of geom.

partCount

Returns the geom part count.

primitiveAsPolyhedralSurface

Converts the current primitive to geometry.

primitiveParameter

Returns the parameter value according to its name

primitiveParameters

Returns the list of available parameter description for this primitive.

primitiveSetParameter

Updates parameter value

primitiveTransform

Returns the primitive transform matrix.

rotate2D

2D Rotate this geometry around point center by angle angle

rotate3D

3D Rotate this geometry around axis axisVector by angle angle

scale

Scale this geometry by vector scaleFactor.

simplify

Simplifies a geometry using the CGAL algorithm

swapXy

Swaps the x and y coordinates of the geometry

toPolyhedralSurface

Converts the geometry to a PolyhedralSurface geometry.

toSolid

Converts the geometry to a Solid geometry.

transform

Apply 3D matrix transform mat to geometry geom

translate

Translate this geometry by vector translation.

triangulate

Triangulates this geometry using constraint 2D Delaunay Triangulation (keep Z if defined)

volume

Computes the volume of the primitive prim.

wkbType

Returns type of the geometry as a WKB type (point / linestring / polygon etc.)

Static Methods

createCube

Create a cube primitive

fromWkb

Creates a new geometry from a WKB byte pointer

fromWkt

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 QgsAbstractGeometry pointer.

Will not take ownership.

Raises:

QgsSfcgalException – if an error was encountered during the operation

Parameters:

qgsGeom (Optional[QgsAbstractGeometry])

__init__(qgsGeom: QgsAbstractGeometry)

Constructor with QgsAbstractGeometry reference.

Raises:

QgsSfcgalException – if an error was encountered during the operation

Parameters:

qgsGeom (QgsAbstractGeometry)

__init__(qgsGeom: QgsGeometry)

Constructor with QgsGeometry reference.

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:
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:
approximateMedialAxis(self) QgsSfcgalGeometry | None

Calculate a 2D approximate medial axis of geom based 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:

Optional[QgsSfcgalGeometry]

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:

Optional[QgsAbstractGeometry]

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:

Optional[QgsSfcgalGeometry]

Returns:

boundary for geometry. May be None for some geometry types.

This method requires a QGIS build based on SFCGAL 2.1 or later.

Raises:
buffer2D(self, radius: float, segments: int, joinStyle: Qgis.JoinStyle) QgsSfcgalGeometry | None

Calculate a 2D buffer where all points are at distance from 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:

Optional[QgsSfcgalGeometry]

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 distance from 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:

Optional[QgsSfcgalGeometry]

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:

QgsPoint

Returns:

geometry centroid

This method requires a QGIS build based on SFCGAL 2.1 or later.

Raises:
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:

Optional[QgsSfcgalGeometry]

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:

Optional[QgsSfcgalGeometry]

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:

Optional[QgsSfcgalGeometry]

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:
Return type:

Optional[QgsSfcgalGeometry]

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 and otherGeom.

Parameters:

otherGeom – geometry to perform the operation

Return type:

Optional[QgsSfcgalGeometry]

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:
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:
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:
envelope(self) QgsSfcgalGeometry | None

Calculate the envelope (bounding box).

Return type:

Optional[QgsSfcgalGeometry]

Returns:

new geometry

This method requires a QGIS build based on SFCGAL 2.1 or later.

Raises:
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:

Optional[QgsSfcgalGeometry]

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:

Optional[QgsSfcgalGeometry]

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:

Optional[QgsSfcgalGeometry]

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 epsilon distance

Parameters:
  • other (QgsSfcgalGeometry) – geometry to perform the operation

  • epsilon (float) – tolerance

Return type:

bool

Returns:

true if this == other geometry modulo epsilon distance

This method requires a QGIS build based on SFCGAL 2.1 or later.

Raises:
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:
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 and otherGeom.

Parameters:

otherGeom – geometry to perform the operation

Return type:

Optional[QgsSfcgalGeometry]

Returns:

new geometry

Raises:

QgsSfcgalException – if an error was encountered during the operation

intersects(self, otherGeom: QgsAbstractGeometry | None) bool[source]

Checks if otherGeom intersects 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 if otherGeom intersects 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 geom is 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:
isValid(self) bool[source]

Checks if geom is 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:
partCount(self) int[source]

Returns the geom part 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:
Return type:

Optional[QgsSfcgalGeometry]

primitiveParameter(self, name: str | None) Any[source]

Returns the parameter value according to its name

Parameters:

name (Optional[str]) – parameter name

Raises:
Return type:

Any

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:
Return type:

list[tuple[str, str]]

primitiveSetParameter(self, name: str | None, value: Any)[source]

Updates parameter value

Parameters:
  • name (Optional[str]) – parameter name

  • value (Any) – new parameter value

Raises:
primitiveTransform(self) QgsMatrix4x4[source]

Returns the primitive transform matrix.

Raises:
Return type:

QgsMatrix4x4

rotate2D(self, angle: float, center: QgsPoint) QgsSfcgalGeometry | None

2D Rotate this geometry around point center by angle angle

Parameters:
  • angle (float) – rotation angle in radians

  • center (QgsPoint) – rotation center

Return type:

Optional[QgsSfcgalGeometry]

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 axisVector by angle angle

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:

Optional[QgsSfcgalGeometry]

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:

Optional[QgsSfcgalGeometry]

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:

Optional[QgsSfcgalGeometry]

Returns:

new geometry

This method requires a QGIS build based on SFCGAL 2.1 or later.

Raises:
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:
toPolyhedralSurface(self) QgsSfcgalGeometry | None

Converts the geometry to a PolyhedralSurface geometry. The geometry must be of type Solid

Return type:

Optional[QgsSfcgalGeometry]

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:

Optional[QgsSfcgalGeometry]

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 mat to geometry geom

Parameters:
  • mat (QgsMatrix4x4) – 4x4 transformation matrix (translation is defined in the 4th column)

  • errorMsg – Error message returned by SFGCAL

Return type:

Optional[QgsSfcgalGeometry]

Returns:

new geometry

Raises:
translate(self, translation: QgsVector3D) QgsSfcgalGeometry | None

Translate this geometry by vector translation.

Parameters:

translation (QgsVector3D) – translation vector (2D or 3D)

Return type:

Optional[QgsSfcgalGeometry]

Returns:

new geometry

This method requires a QGIS build based on SFCGAL 2.1 or later.

Raises:
triangulate(self) QgsSfcgalGeometry | None

Triangulates this geometry using constraint 2D Delaunay Triangulation (keep Z if defined)

Return type:

Optional[QgsSfcgalGeometry]

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:

Qgis.WkbType

Returns:

type of the geometry as a WKB type (point / linestring / polygon etc.)

Raises: