sec_interp.gui.adapters.structure_extractor module
Structure extraction adapter (Extract phase).
Bridges the QGIS object world and the QGIS-agnostic core layer for structural
measurements. It reads the section line and structure layers, buffers the line,
filters features within the buffer, and samples raster elevations — returning
plain tuples/dicts so StructureService never touches QGIS objects.
- class sec_interp.gui.adapters.structure_extractor.SectionContext(line_points: list[tuple[float, float]]=<factory>, line_start: tuple[float, float]=(0.0, 0.0), line_azimuth: float = 0.0, structures: list[dict[str, ~typing.Any]]=<factory>)
Bases:
objectExtracted section data (QGIS-agnostic primitives).
- line_points
Section line vertices as
(x, y)tuples.- Type:
list[tuple[float, float]]
- line_start
First vertex of the section line.
- Type:
tuple[float, float]
- line_azimuth
Compass bearing of the section line.
- Type:
float
- structures
Detached structures as
{"point": (x, y), "attributes": {...}}.- Type:
list[dict[str, Any]]
- line_azimuth: float = 0.0
- line_points: list[tuple[float, float]]
- line_start: tuple[float, float] = (0.0, 0.0)
- structures: list[dict[str, Any]]
- class sec_interp.gui.adapters.structure_extractor.StructureExtractor
Bases:
objectExtract structure-related data from QGIS layers into primitives.
- detach_structures(struct_lyr: qgis.core.QgsVectorLayer, line_geom: qgis.core.QgsGeometry, buffer_m: float) list[dict[str, Any]]
Buffer the line and extract structures within it.
Returns a list of
{"point": (x, y), "attributes": {...}}dicts.
- extract_line(line_geom: qgis.core.QgsGeometry) tuple[list[tuple[float, float]], tuple[float, float], float]
Extract
(line_points, line_start, line_azimuth)from a geometry.- Parameters:
line_geom – The section line geometry.
- Returns:
A tuple of line vertices, the start vertex, and the compass bearing.
- extract_section_and_structures(line_lyr: qgis.core.QgsVectorLayer, struct_lyr: qgis.core.QgsVectorLayer, buffer_m: float, feature_id: int | None = None) SectionContext | None
Extract the section line geometry and structures within the buffer.
- Parameters:
line_lyr – The cross-section line vector layer.
struct_lyr – The structural measurements vector layer.
buffer_m – Buffer distance (in line-layer units).
feature_id – Section feature id (first feature when
None).
- Returns:
A
SectionContextof primitives, or None if the line layer has no valid geometry.
- make_elevation_sampler(raster_lyr: QgsRasterLayer, line_lyr: QgsVectorLayer | None = None, band_number: int = 1) Callable[[float, float], float]
Return an
(x, y) -> elevationsampler reprojecting to the raster CRS.Structural points live in the section line CRS. When the DEM uses a different CRS (on-the-fly reprojection) they must be transformed before sampling, otherwise every elevation comes back as 0. The transform is resolved once here and reused for every point.
- sample_elevation(raster_lyr: QgsRasterLayer, x: float, y: float, band_number: int = 1, line_lyr: QgsVectorLayer | None = None) float
Sample a single elevation value from a raster layer.
- Parameters:
raster_lyr – The DEM raster layer.
x – X coordinate to sample (in the section line CRS).
y – Y coordinate to sample (in the section line CRS).
band_number – Raster band index (default 1).
line_lyr – Section line layer, used to reproject the point.
- Returns:
The sampled elevation, or 0.0 if the raster is invalid or the point is out of bounds.