From c0e8a3adb8f336a6dca77446eff3ffefd6715e86 Mon Sep 17 00:00:00 2001 From: Overmeen Date: Wed, 28 May 2025 11:06:52 +0200 Subject: [PATCH 1/2] Update dem_sampling_algorithms.py --- .../dem_sampling_algorithms.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/threedi_beta_processing/dem_sampling_algorithms.py b/threedi_beta_processing/dem_sampling_algorithms.py index 396192c..a1953b1 100644 --- a/threedi_beta_processing/dem_sampling_algorithms.py +++ b/threedi_beta_processing/dem_sampling_algorithms.py @@ -68,6 +68,11 @@ ogr.UseExceptions() gdal.UseExceptions() +def safe_float(val): + try: + return float(val) + except (TypeError, ValueError): + return np.nan def cross_section_max_width(shape: int, width: float, table: str): if shape in [0, 1, 2, 3]: @@ -783,9 +788,14 @@ def processAlgorithm(self, parameters, context, feedback): )): if feedback.isCanceled(): break - crest_level_right = np.nan if feature[dem_sampler.target_field_idx] is None else feature[dem_sampler.target_field_idx] - crest_level_left = np.nan if crest_levels_left[i] is None else crest_levels_left[i] - crest_level_fid_dict[feature[0]] = float(np.nanmin([crest_level_right, crest_level_left])) + right_val = feature.attribute(dem_sampler.target_field_idx) + left_val = crest_levels_left[i] + + crest_level_right = safe_float(right_val) + crest_level_left = safe_float(left_val) + + crest_level_fid_dict[feature.id()] = float(np.nanmin([crest_level_right, crest_level_left])) + feedback.setProgress(50 + int(i/2 * total)) for source_feature in cross_section_locations_layer.getFeatures(): From 82d3c0bb1035ce1219fddaeda5ae74cb8b44eec6 Mon Sep 17 00:00:00 2001 From: Overmeen Date: Tue, 10 Jun 2025 14:36:15 +0200 Subject: [PATCH 2/2] Update dem_sampling_algorithms.py --- threedi_beta_processing/dem_sampling_algorithms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/threedi_beta_processing/dem_sampling_algorithms.py b/threedi_beta_processing/dem_sampling_algorithms.py index a1953b1..4496f4c 100644 --- a/threedi_beta_processing/dem_sampling_algorithms.py +++ b/threedi_beta_processing/dem_sampling_algorithms.py @@ -794,7 +794,7 @@ def processAlgorithm(self, parameters, context, feedback): crest_level_right = safe_float(right_val) crest_level_left = safe_float(left_val) - crest_level_fid_dict[feature.id()] = float(np.nanmin([crest_level_right, crest_level_left])) + crest_level_fid_dict[feature[0]] = float(np.nanmin([crest_level_right, crest_level_left])) feedback.setProgress(50 + int(i/2 * total))