From a32386b645fdecfa4889aba6a9ef26fc202ec4b6 Mon Sep 17 00:00:00 2001
From: "arnaud.morvan@camptocamp.com" <arnaud.morvan@camptocamp.com>
Date: Sat, 29 Jun 2024 09:26:04 +0200
Subject: [PATCH] Rename fiels sec_name to sec_id

---
 .../processing/import_points_algorithm.py     | 14 +++++-----
 .../import_prepared_points_algorithm.py       | 27 +++++++++----------
 .../join_points_to_profiles_algorithm.py      | 14 +++++-----
 test/processing/test_import_points.py         |  4 +--
 .../processing/test_import_prepared_points.py |  4 +--
 .../test_join_points_to_profiles_algorithm.py |  2 +-
 6 files changed, 32 insertions(+), 33 deletions(-)

diff --git a/PreCourlis/processing/import_points_algorithm.py b/PreCourlis/processing/import_points_algorithm.py
index c33b16b..81bf60d 100644
--- a/PreCourlis/processing/import_points_algorithm.py
+++ b/PreCourlis/processing/import_points_algorithm.py
@@ -13,7 +13,7 @@ from PreCourlis.processing.precourlis_algorithm import PreCourlisAlgorithm
 
 class ImportPointsAlgorithm(PreCourlisAlgorithm):
     TRACKS = "TRACKS"
-    TRACKS_FIELD_SEC_NAME = "TRACKS_FIELD_SEC_NAME"
+    TRACKS_FIELD_SEC_ID = "TRACKS_FIELD_SEC_ID"
     AXIS = "AXIS"
     SOURCE_POINTS = "SOURCE_POINTS"
     SOURCE_FIELD_Z = "SOURCE_FIELD_Z"
@@ -31,10 +31,10 @@ class ImportPointsAlgorithm(PreCourlisAlgorithm):
         )
         self.addParameter(
             QgsProcessingParameterField(
-                self.TRACKS_FIELD_SEC_NAME,
-                self.tr("Tracks section name field"),
+                self.TRACKS_FIELD_SEC_ID,
+                self.tr("Tracks unique identifier field"),
                 parentLayerParameterName=self.TRACKS,
-                defaultValue="sec_name",
+                defaultValue="sec_id",
             )
         )
         self.addParameter(
@@ -89,7 +89,7 @@ class ImportPointsAlgorithm(PreCourlisAlgorithm):
         alg_params = {
             "SOURCE_POINTS": parameters[self.SOURCE_POINTS],
             "TARGET_PROFILES": parameters[self.TRACKS],
-            "TARGET_PROFILES_FIELD_SEC_NAME": parameters[self.TRACKS_FIELD_SEC_NAME],
+            "TARGET_PROFILES_FIELD_SEC_ID": parameters[self.TRACKS_FIELD_SEC_ID],
             "BUFFER_DISTANCE": parameters[self.BUFFER_DISTANCE],
             "OUTPUT": QgsProcessing.TEMPORARY_OUTPUT,
         }
@@ -109,10 +109,10 @@ class ImportPointsAlgorithm(PreCourlisAlgorithm):
         # import_prepared_points
         alg_params = {
             "TRACKS": parameters[self.TRACKS],
-            "TRACKS_FIELD_SEC_NAME": parameters[self.TRACKS_FIELD_SEC_NAME],
+            "TRACKS_FIELD_SEC_ID": parameters[self.TRACKS_FIELD_SEC_ID],
             "AXIS": parameters[self.AXIS],
             "SOURCE_POINTS": joined_points,
-            "SOURCE_FIELD_SEC_NAME": "sec_name",
+            "SOURCE_FIELD_SEC_ID": parameters[self.TRACKS_FIELD_SEC_ID],
             "SOURCE_FIELD_Z": parameters[self.SOURCE_FIELD_Z],
             "OUTPUT": parameters[self.OUTPUT],
         }
diff --git a/PreCourlis/processing/import_prepared_points_algorithm.py b/PreCourlis/processing/import_prepared_points_algorithm.py
index 0eb2dc6..71a5033 100644
--- a/PreCourlis/processing/import_prepared_points_algorithm.py
+++ b/PreCourlis/processing/import_prepared_points_algorithm.py
@@ -20,10 +20,10 @@ from PreCourlis.processing.precourlis_algorithm import PreCourlisAlgorithm
 
 class ImportPreparedPointsAlgorithm(PreCourlisAlgorithm):
     TRACKS = "TRACKS"
-    TRACKS_FIELD_SEC_NAME = "TRACKS_FIELD_SEC_NAME"
+    TRACKS_FIELD_SEC_ID = "TRACKS_FIELD_SEC_ID"
     AXIS = "AXIS"
     SOURCE_POINTS = "SOURCE_POINTS"
-    SOURCE_FIELD_SEC_NAME = "SOURCE_FIELD_SEC_NAME"
+    SOURCE_FIELD_SEC_ID = "SOURCE_FIELD_SEC_ID"
     SOURCE_FIELD_Z = "SOURCE_FIELD_Z"
     OUTPUT = "OUTPUT"
 
@@ -38,10 +38,10 @@ class ImportPreparedPointsAlgorithm(PreCourlisAlgorithm):
         )
         self.addParameter(
             QgsProcessingParameterField(
-                self.TRACKS_FIELD_SEC_NAME,
-                self.tr("Tracks section name field"),
+                self.TRACKS_FIELD_SEC_ID,
+                self.tr("Tracks identifier field"),
                 parentLayerParameterName=self.TRACKS,
-                defaultValue="sec_name",
+                defaultValue="sec_id",
             )
         )
         self.addParameter(
@@ -62,10 +62,10 @@ class ImportPreparedPointsAlgorithm(PreCourlisAlgorithm):
         )
         self.addParameter(
             QgsProcessingParameterField(
-                self.SOURCE_FIELD_SEC_NAME,
-                self.tr("Source section name field"),
+                self.SOURCE_FIELD_SEC_ID,
+                self.tr("Source tracks identifier field"),
                 parentLayerParameterName=self.SOURCE_POINTS,
-                defaultValue=None,
+                defaultValue="sec_id",
             )
         )
         self.addParameter(
@@ -88,8 +88,8 @@ class ImportPreparedPointsAlgorithm(PreCourlisAlgorithm):
 
     def processAlgorithm(self, parameters, context, feedback):
         tracks_source = self.parameterAsSource(parameters, self.TRACKS, context)
-        tracks_field_sec_name = self.parameterAsString(
-            parameters, self.TRACKS_FIELD_SEC_NAME, context
+        tracks_field_sec_id = self.parameterAsString(
+            parameters, self.TRACKS_FIELD_SEC_ID, context
         )
 
         axis_source = self.parameterAsSource(parameters, self.AXIS, context)
@@ -98,8 +98,8 @@ class ImportPreparedPointsAlgorithm(PreCourlisAlgorithm):
         source_points_source = self.parameterAsSource(
             parameters, self.SOURCE_POINTS, context
         )
-        source_field_sec_name = self.parameterAsString(
-            parameters, self.SOURCE_FIELD_SEC_NAME, context
+        source_field_sec_id = self.parameterAsString(
+            parameters, self.SOURCE_FIELD_SEC_ID, context
         )
         source_field_z = self.parameterAsString(
             parameters, self.SOURCE_FIELD_Z, context
@@ -123,7 +123,7 @@ class ImportPreparedPointsAlgorithm(PreCourlisAlgorithm):
 
             request = QgsFeatureRequest()
             request.setFilterExpression(
-                f"{source_field_sec_name} = '{track.attribute(tracks_field_sec_name)}'"
+                f"{source_field_sec_id} = '{track.attribute(tracks_field_sec_id)}'"
             )
             source_points_features = list(source_points_source.getFeatures(request))
 
@@ -158,7 +158,6 @@ class ImportPreparedPointsAlgorithm(PreCourlisAlgorithm):
 
             intersection_point = intersection.constGet().clone()
             abs_long = axis.geometry().lineLocatePoint(intersection)
-            # sec_name = track.attribute(tracks_field_sec_name)
             sec_name = "{}_{:04.3f}".format("P" if abs_long >= 0 else "N", abs_long)
             axis_x = intersection_point.x()
             axis_y = intersection_point.y()
diff --git a/PreCourlis/processing/join_points_to_profiles_algorithm.py b/PreCourlis/processing/join_points_to_profiles_algorithm.py
index accee38..fcfe1be 100644
--- a/PreCourlis/processing/join_points_to_profiles_algorithm.py
+++ b/PreCourlis/processing/join_points_to_profiles_algorithm.py
@@ -18,7 +18,7 @@ from PreCourlis.processing.precourlis_algorithm import PreCourlisAlgorithm
 class JoinPointsToProfilesAlgorithm(PreCourlisAlgorithm):
     SOURCE_POINTS = "SOURCE_POINTS"
     TARGET_PROFILES = "TARGET_PROFILES"
-    TARGET_PROFILES_FIELD_SEC_NAME = "TARGET_PROFILES_FIELD_SEC_NAME"
+    TARGET_PROFILES_FIELD_SEC_ID = "TARGET_PROFILES_FIELD_SEC_ID"
     BUFFER_DISTANCE = "BUFFER_DISTANCE"
     OUTPUT = "OUTPUT"
 
@@ -41,10 +41,10 @@ class JoinPointsToProfilesAlgorithm(PreCourlisAlgorithm):
         )
         self.addParameter(
             QgsProcessingParameterField(
-                self.TARGET_PROFILES_FIELD_SEC_NAME,
-                self.tr("Target profiles section name field"),
+                self.TARGET_PROFILES_FIELD_SEC_ID,
+                self.tr("Target profiles unique identifier field"),
                 parentLayerParameterName=self.TARGET_PROFILES,
-                defaultValue="sec_name",
+                defaultValue="sec_id",
                 optional=True,
             )
         )
@@ -70,8 +70,8 @@ class JoinPointsToProfilesAlgorithm(PreCourlisAlgorithm):
         feedback = QgsProcessingMultiStepFeedback(3, model_feedback)
         outputs = {}
 
-        target_profiles_field_sec_name = self.parameterAsFields(
-            parameters, self.TARGET_PROFILES_FIELD_SEC_NAME, context
+        target_profiles_field_sec_id = self.parameterAsFields(
+            parameters, self.TARGET_PROFILES_FIELD_SEC_ID, context
         )
 
         source_points_source = self.parameterAsSource(
@@ -122,7 +122,7 @@ class JoinPointsToProfilesAlgorithm(PreCourlisAlgorithm):
                 "INPUT": parameters[self.SOURCE_POINTS],
                 "PREDICATE": [0],
                 "JOIN": outputs["Buffer"]["OUTPUT"],
-                "JOIN_FIELDS": target_profiles_field_sec_name,
+                "JOIN_FIELDS": target_profiles_field_sec_id,
                 "METHOD": 0,
                 "DISCARD_NONMATCHING": False,
                 "PREFIX": "",
diff --git a/test/processing/test_import_points.py b/test/processing/test_import_points.py
index 79aebc0..b63d3ac 100644
--- a/test/processing/test_import_points.py
+++ b/test/processing/test_import_points.py
@@ -13,10 +13,10 @@ class TestImportPointsAlgorithm(TestCase):
     ALGORITHM_ID = "precourlis:import_points"
     DEFAULT_PARAMS = {
         "TRACKS": TRACKS_PATH,
-        "TRACKS_FIELD_SEC_NAME": "sec_name",
+        "TRACKS_FIELD_SEC_ID": "sec_name",
         "AXIS": AXIS_PATH,
         "SOURCE_POINTS": SOURCE_POINTS_PATH,
-        "SOURCE_FIELD_SEC_NAME": "sec_name",
+        "SOURCE_FIELD_SEC_ID": "sec_name",
         "SOURCE_FIELD_Z": "ELEVATION",
         "BUFFER_DISTANCE": 1.0,
     }
diff --git a/test/processing/test_import_prepared_points.py b/test/processing/test_import_prepared_points.py
index 2c19ce9..9cedd9b 100644
--- a/test/processing/test_import_prepared_points.py
+++ b/test/processing/test_import_prepared_points.py
@@ -13,10 +13,10 @@ class TestImportPreparedPointsAlgorithm(TestCase):
     ALGORITHM_ID = "precourlis:import_prepared_points"
     DEFAULT_PARAMS = {
         "TRACKS": TRACKS_PATH,
-        "TRACKS_FIELD_SEC_NAME": "sec_name",
+        "TRACKS_FIELD_SEC_ID": "sec_name",
         "AXIS": AXIS_PATH,
         "SOURCE_POINTS": SOURCE_POINTS_PATH,
-        "SOURCE_FIELD_SEC_NAME": "sec_name",
+        "SOURCE_FIELD_SEC_ID": "sec_name",
         "SOURCE_FIELD_Z": "ELEVATION",
     }
 
diff --git a/test/processing/test_join_points_to_profiles_algorithm.py b/test/processing/test_join_points_to_profiles_algorithm.py
index ad74141..c8be1a4 100644
--- a/test/processing/test_join_points_to_profiles_algorithm.py
+++ b/test/processing/test_join_points_to_profiles_algorithm.py
@@ -14,7 +14,7 @@ class TestJoinPointsToProfilesAlgorithm(TestCase):
     DEFAULT_PARAMS = {
         "SOURCE_POINTS": SOURCE_POINTS_PATH,
         "TARGET_PROFILES": TARGET_PROFILES_PATH,
-        # "TARGET_PROFILES_FIELD_SEC_NAME": "sec_name",
+        "TARGET_PROFILES_FIELD_SEC_ID": "sec_name",
         "BUFFER_DISTANCE": 1.0,
     }
 
-- 
GitLab