sec_interp.gui.adapters.geometry module
Geometry extraction adapter (Extract phase).
Compatibility facade for the QGIS-dependent geometry helpers. The implementation is split by concern:
geometry_crs: distance area, CRS transforms and sampling intervals.geometry_lines: vertex extraction, densification and segment ranges.geometry_sampling: point and line raster sampling.geometry_stats: per-cell profile statistics.geometry_sections: section-feature resolution and profile context.
These perform the “Extract” step of the Extract-then-Compute pattern; the core layer stays QGIS-agnostic.
- class sec_interp.gui.adapters.geometry.ProfileRasterStats(count: int, minimum: float, maximum: float, mean: float, resolution: float, length: float)
Bases:
objectRead-only elevation statistics of the section over the DEM.
- count
Number of distinct raster cells sampled.
- Type:
int
- minimum
Minimum elevation (m).
- Type:
float
- maximum
Maximum elevation (m).
- Type:
float
- mean
Mean elevation (m).
- Type:
float
- resolution
Sampling interval in line-CRS units (raster pixel size).
- Type:
float
- length
Total sampled distance along the line (line-CRS units).
- Type:
float
- count: int
- length: float
- maximum: float
- mean: float
- minimum: float
- resolution: float
- sec_interp.gui.adapters.geometry.build_sampling_transform(line_crs: QgsCoordinateReferenceSystem | None, raster_layer: QgsRasterLayer) QgsCoordinateTransform | None
Build a transform from the line CRS to the raster CRS, or
None.A transform is only needed when both CRSs are known and differ. Across different CRSs, sampling with raw layer coordinates reads the wrong pixels.
- Parameters:
line_crs – CRS of the section line (
Noneif unknown).raster_layer – The DEM/raster layer being sampled.
- Returns:
A
QgsCoordinateTransform(line -> raster) orNonewhen the CRSs match, are unknown, or the transform cannot be created.
- sec_interp.gui.adapters.geometry.calculate_segment_range(seg_geom: qgis.core.QgsGeometry, line_start: qgis.core.QgsPointXY, da: qgis.core.QgsDistanceArea) tuple[float, float] | None
Calculate the start and end distance for a segment geometry along the line.
- sec_interp.gui.adapters.geometry.create_distance_area(crs: qgis.core.QgsCoordinateReferenceSystem) qgis.core.QgsDistanceArea
Create and configure a QgsDistanceArea object.
- sec_interp.gui.adapters.geometry.densify_line_by_interval(geometry: qgis.core.QgsGeometry, interval: float) qgis.core.QgsGeometry
Densify a line geometry by a specific distance interval.
- sec_interp.gui.adapters.geometry.extract_all_vertices(geometry: qgis.core.QgsGeometry) list[qgis.core.QgsPointXY]
Extract all vertices from any QGIS geometry type.
- sec_interp.gui.adapters.geometry.extract_lines_from_geometry(geometry: qgis.core.QgsGeometry) list[qgis.core.QgsGeometry]
Extract individual LineString geometries from a (possibly Multi) geometry.
- sec_interp.gui.adapters.geometry.get_line_vertices(geometry: qgis.core.QgsGeometry) list[qgis.core.QgsPointXY]
Extract vertices specifically from a line or multiline geometry.
- sec_interp.gui.adapters.geometry.line_length(line_lyr: qgis.core.QgsVectorLayer, feature_id: int | None = None) float | None
Return the length of the section feature’s geometry in a line layer.
- sec_interp.gui.adapters.geometry.prepare_profile_context(line_lyr: qgis.core.QgsVectorLayer, feature_id: int | None = None) tuple[qgis.core.QgsGeometry, qgis.core.QgsPointXY, qgis.core.QgsDistanceArea]
Prepare a common context for profile calculation operations.
- sec_interp.gui.adapters.geometry.profile_raster_statistics(line_geom: qgis.core.QgsGeometry, raster_layer: qgis.core.QgsRasterLayer, band_number: int, distance_area: qgis.core.QgsDistanceArea) ProfileRasterStats | None
Compute min/max/mean elevation over unique DEM cells along the line.
Densifies at the CRS-aware raster resolution, reprojects each sample into the raster CRS and collapses samples that fall in the same pixel cell (so repeated cells from the densification do not bias min/max/mean). Returns
Nonewhen there is nothing usable to sample.
- sec_interp.gui.adapters.geometry.raster_resolution_in_crs(raster_layer: QgsRasterLayer, target_crs: QgsCoordinateReferenceSystem | None) float | None
Return the raster pixel size expressed in
target_crsunits.rasterUnitsPerPixelX()is expressed in the raster’s own CRS. When the section line lives in a different CRS (on-the-fly reprojection), using that value directly as a sampling interval is meaningless and can densify the line into millions of vertices. This transforms a one-pixel-long segment from the raster CRS intotarget_crsto recover a usable interval.- Parameters:
raster_layer – The DEM/raster layer.
target_crs – CRS in which to express the resolution (
Noneto return the raw value).
- Returns:
Pixel size in
target_crsunits, orNoneif it cannot be determined.
- sec_interp.gui.adapters.geometry.resolve_sampling_interval(geometry: QgsGeometry, raster_layer: QgsRasterLayer, line_crs: QgsCoordinateReferenceSystem | None) float
Resolve a safe sampling interval for a raster profile.
Prefers the DEM pixel size expressed in the line’s CRS. Falls back to a length-derived interval when the resolution cannot be resolved, and always returns a strictly positive value.
- Parameters:
geometry – The section line geometry (in
line_crsunits).raster_layer – The DEM/raster layer.
line_crs – CRS of the section line (
Noneif unknown).
- Returns:
A positive sampling interval in
line_crsunits.
- sec_interp.gui.adapters.geometry.resolve_section_feature(line_lyr: QgsVectorLayer | None, feature_id: int | None = None) QgsFeature | None
Return the section feature to use (first by default, or
feature_id).This is the single resolution point for the section line, so every extractor picks the same feature.
Nonereturns the first feature; a fid filters by it. Defensive: an invalid layer or a missing feature returnsNone.
- sec_interp.gui.adapters.geometry.resolve_section_geometry(line_lyr: QgsVectorLayer | None, feature_id: int | None = None) QgsGeometry | None
Return the section feature geometry, or
Nonewhen unavailable.
- sec_interp.gui.adapters.geometry.sample_elevation_along_line(geometry: QgsGeometry, raster_layer: QgsRasterLayer, band_number: int, distance_area: QgsDistanceArea, reference_point: QgsPointXY | None = None, interval: float | None = None) list[QgsPointXY]
Sample elevation values along a line geometry from a raster layer.
The sampling interval is the raster pixel size expressed in the section line’s CRS. When the line and raster CRSs differ (on-the-fly reprojection), the pixel size is transformed before use and each sample point is reprojected into the raster CRS.
- sec_interp.gui.adapters.geometry.sample_point_elevation(raster_layer: QgsRasterLayer, point: Any, band_number: int = 1, source_crs: QgsCoordinateReferenceSystem | None = None) float
Sample elevation from a raster layer at a 2D coordinate.
pointmay be aQgsPointXYor a(x, y)tuple. Whensource_crsdiffers from the raster CRS, the point is reprojected before sampling.
- sec_interp.gui.adapters.geometry.section_line_start_point(geometry: qgis.core.QgsGeometry) qgis.core.QgsPointXY
Return the first vertex of a line geometry (start of the section).