sec_interp.gui.adapters.geometry_crs module
CRS, distance-area and sampling-interval helpers for geometry extraction.
- sec_interp.gui.adapters.geometry_crs.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_crs.create_distance_area(crs: qgis.core.QgsCoordinateReferenceSystem) qgis.core.QgsDistanceArea
Create and configure a QgsDistanceArea object.
- sec_interp.gui.adapters.geometry_crs.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_crs.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.