# sec_interp.core.utils.sampling module

Sampling Utilities Module.

This module provides elevation sampling and profile context preparation tools.

sec_interp.core.utils.sampling.interpolate_elevation(topo_data: list[tuple[float, float]], distance: float) → float

  Interpolate elevation at a given distance along the topography profile.

  Uses linear interpolation between the two nearest sampled points.

  Parameters:

    - topo_data – List of (distance, elevation) tuples.

    - distance – Horizontal distance along the section.

  Returns:

    The interpolated elevation value (Z) at that distance.

sec_interp.core.utils.sampling.prepare_profile_context(line_lyr: qgis.core.QgsVectorLayer) → tuple[qgis.core.QgsGeometry, qgis.core.QgsPointXY, qgis.core.QgsDistanceArea]

  Prepare a common context for profile calculation operations.

  Parameters:

    line_lyr – The cross-section line vector layer.

  Returns:

    - line_geom: The geometry of the section line.

    - line_start: The starting point of the line.

    - distance_area: Fully configured geodesic distance object.

  Return type:

    A tuple containing

  Raises:

    ValueError – If the input layer is empty or has invalid geometry.

sec_interp.core.utils.sampling.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.

  Densifies the line at raster resolution and samples the elevation at each vertex.

  Parameters:

    - geometry – The line geometry to sample along.

    - raster_layer – The source DEM raster layer.

    - band_number – The raster band index to sample.

    - distance_area – Object for geodesic distance calculations.

    - reference_point – Optional start point for distance measurements.

    - interval – Optional sampling interval. If None, uses raster resolution.

  Returns:

    A list of QgsPointXY objects where x is horizontal distance and y is elevation.

sec_interp.core.utils.sampling.sample_point_elevation(raster_layer: qgis.core.QgsRasterLayer, point: qgis.core.QgsPointXY, band_number: int = 1) → float

  Sample elevation from a raster layer at a specific 2D coordinate.

  Parameters:

    - raster_layer – The DEM raster layer.

    - point – The coordinate point (X, Y) to sample.

    - band_number – The raster band index (default 1).

  Returns:

    The sampled elevation value (Z) or 0.0 if the point is out of bounds.