sec_interp.core.utils.geometry module

Geometry Utilities Module.

Spatial geometry operations using QGIS native algorithms.

sec_interp.core.utils.geometry.create_memory_layer(geometry: qgis.core.QgsGeometry, crs: qgis.core.QgsCoordinateReferenceSystem, name: str = 'temp', fields: qgis.core.QgsFields | None = None) qgis.core.QgsVectorLayer

Create a temporary QGIS memory layer with a single geometry feature.

Parameters:
  • geometry – The QGIS geometry to add to the layer.

  • crs – The Coordinate Reference System for the new layer.

  • name – Internal name for the layer (default: “temp”).

  • fields – Optional field definitions for attributes.

Returns:

A valid (but potentially empty on failure) QGIS memory layer.

Return type:

QgsVectorLayer

Raises:
  • ValueError – If the input geometry is null or invalid.

  • RuntimeError – If the memory layer cannot be initialized.

sec_interp.core.utils.geometry.extract_all_vertices(geometry: qgis.core.QgsGeometry) List[qgis.core.QgsPointXY]

Extract all vertices from any QGIS geometry type.

Handles points, lines, and polygons, including multipart geometries.

Parameters:

geometry – The input QGIS geometry.

Returns:

A flat list of all vertices found in the geometry.

Return type:

List[QgsPointXY]

sec_interp.core.utils.geometry.get_line_vertices(geometry: qgis.core.QgsGeometry) List[qgis.core.QgsPointXY]

Extract vertices specifically from a line or multiline geometry.

Parameters:

geometry – A QGIS geometry of type LineGeometry.

Returns:

A flat list of vertices.

Return type:

List[QgsPointXY]

Raises:

ValueError – If the geometry is null, not a line, or contains no vertices.

sec_interp.core.utils.geometry.run_processing_algorithm(algorithm: str, parameters: dict, silent: bool = True) dict

Execute a QGIS processing algorithm with consistent error handling.

Parameters:
  • algorithm – The provider:algorithm ID (e.g., “native:buffer”).

  • parameters – A dictionary of algorithm parameters.

  • silent – If True, uses a silent feedback object (default: True).

Returns:

The result dictionary returned by processing.run.

Return type:

dict

Raises:

RuntimeError – If the algorithm fails to execute or returns an error.

sec_interp.core.utils.geometry.run_geometry_operation(algorithm: str, geometry: qgis.core.QgsGeometry, crs: qgis.core.QgsCoordinateReferenceSystem, parameters: dict) qgis.core.QgsGeometry

Run a processing algorithm on a single geometry by wrapping it in a memory layer.

Parameters:
  • algorithm – The algorithm ID to run.

  • geometry – The input geometry.

  • crs – The CRS of the input geometry.

  • parameters – Additional parameters (INPUT and OUTPUT are automatically handled).

Returns:

The resulting geometry from the operation’s output layer.

Return type:

QgsGeometry

Raises:
  • ValueError – If the operation yields no features or an invalid geometry.

  • RuntimeError – If the underlying processing algorithm fails.

sec_interp.core.utils.geometry.create_buffer_geometry(geometry: qgis.core.QgsGeometry, crs: qgis.core.QgsCoordinateReferenceSystem, distance: float, segments: int = 25) qgis.core.QgsGeometry

Create buffer geometry using native QGIS processing algorithm.

Parameters:
  • geometry – Input geometry to buffer.

  • crs – Coordinate reference system.

  • distance – Buffer distance in CRS units.

  • segments – Number of segments for curves (default: 25).

Returns:

Buffered geometry.

Return type:

QgsGeometry

sec_interp.core.utils.geometry.filter_features_by_buffer(features_layer: qgis.core.QgsVectorLayer, buffer_geometry: qgis.core.QgsGeometry, buffer_crs: qgis.core.QgsCoordinateReferenceSystem | None = None) List[qgis.core.QgsFeature]

Filter features that intersect with buffer using spatial index.

Parameters:
  • features_layer – Layer containing features to filter.

  • buffer_geometry – Buffer geometry to use for spatial filter.

  • buffer_crs – CRS of the buffer geometry (optional, for compatibility).

Returns:

Features that intersect the buffer.

Return type:

List[QgsFeature]

Raises:

ValueError – If inputs are invalid.

sec_interp.core.utils.geometry.densify_line_by_interval(geometry: qgis.core.QgsGeometry, interval: float) qgis.core.QgsGeometry

Densify line geometry by adding vertices at regular intervals.

Parameters:
  • geometry – Line geometry to densify.

  • interval – Distance between vertices in geometry units.

Returns:

Densified line geometry.

Return type:

QgsGeometry

Raises:

ValueError – If geometry is not a line.