Skip to content

Commit a9092f4

Browse files
committed
handle dip, dipdir, orientation type for structure in sorter.py
1 parent fb873f3 commit a9092f4

1 file changed

Lines changed: 87 additions & 26 deletions

File tree

m2l/processing/algorithms/sorter.py

Lines changed: 87 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
SorterUseNetworkX,
3737
SorterUseHint, # kept for backwards compatibility
3838
)
39-
from map2loop.contact_extractor import ContactExtractor
4039
from ...main.vectorLayerWrapper import qgsLayerToGeoDataFrame
4140

4241
# a lookup so we don’t need a giant if/else block
@@ -113,28 +112,13 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
113112
)
114113

115114
self.addParameter(
116-
QgsProcessingParameterFeatureSource(
117-
self.INPUT_STRUCTURE,
118-
"Structure",
119-
[QgsProcessing.TypeVectorPoint],
120-
optional=True,
121-
)
122-
)
123-
124-
self.addParameter(
125-
QgsProcessingParameterRasterLayer(
126-
self.INPUT_DTM,
127-
"DTM",
128-
optional=True,
129-
)
130-
)
131-
132-
self.addParameter(
133-
QgsProcessingParameterFeatureSource(
134-
"CONTACTS_LAYER",
135-
"Contacts Layer",
136-
[QgsProcessing.TypeVectorLine],
137-
optional=True,
115+
QgsProcessingParameterField(
116+
'UNIT_NAME_FIELD',
117+
'Unit Name Field',
118+
parentLayerParameterName=self.INPUT_GEOLOGY,
119+
type=QgsProcessingParameterField.Any,
120+
defaultValue='UNITNAME',
121+
optional=True
138122
)
139123
)
140124

@@ -143,7 +127,7 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
143127
'MIN_AGE_FIELD',
144128
'Minimum Age Field',
145129
parentLayerParameterName=self.INPUT_GEOLOGY,
146-
type=QgsProcessingParameterField.String,
130+
type=QgsProcessingParameterField.Any,
147131
defaultValue='MIN_AGE',
148132
optional=True
149133
)
@@ -154,7 +138,7 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
154138
'MAX_AGE_FIELD',
155139
'Maximum Age Field',
156140
parentLayerParameterName=self.INPUT_GEOLOGY,
157-
type=QgsProcessingParameterField.String,
141+
type=QgsProcessingParameterField.Any,
158142
defaultValue='MAX_AGE',
159143
optional=True
160144
)
@@ -165,11 +149,67 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
165149
'GROUP_FIELD',
166150
'Group Field',
167151
parentLayerParameterName=self.INPUT_GEOLOGY,
168-
type=QgsProcessingParameterField.String,
152+
type=QgsProcessingParameterField.Any,
169153
defaultValue='GROUP',
170154
optional=True
171155
)
172156
)
157+
158+
self.addParameter(
159+
QgsProcessingParameterFeatureSource(
160+
self.INPUT_STRUCTURE,
161+
"Structure",
162+
[QgsProcessing.TypeVectorPoint],
163+
optional=True,
164+
)
165+
)
166+
167+
self.addParameter(
168+
QgsProcessingParameterField(
169+
'DIP_FIELD',
170+
'Dip Field',
171+
parentLayerParameterName=self.INPUT_STRUCTURE,
172+
type=QgsProcessingParameterField.Any,
173+
defaultValue='DIP',
174+
optional=True
175+
)
176+
)
177+
self.addParameter(
178+
QgsProcessingParameterField(
179+
'DIPDIR_FIELD',
180+
'Dip Direction Field',
181+
parentLayerParameterName=self.INPUT_STRUCTURE,
182+
type=QgsProcessingParameterField.Any,
183+
defaultValue='DIPDIR',
184+
optional=True
185+
)
186+
)
187+
188+
self.addParameter(
189+
QgsProcessingParameterEnum(
190+
'ORIENTATION_TYPE',
191+
'Orientation Type',
192+
options=['Dip Direction', 'Strike'],
193+
defaultValue=0
194+
)
195+
)
196+
197+
self.addParameter(
198+
QgsProcessingParameterRasterLayer(
199+
self.INPUT_DTM,
200+
"DTM",
201+
optional=True,
202+
)
203+
)
204+
205+
self.addParameter(
206+
QgsProcessingParameterFeatureSource(
207+
"CONTACTS_LAYER",
208+
"Contacts Layer",
209+
[QgsProcessing.TypeVectorLine],
210+
optional=True,
211+
)
212+
)
173213

174214

175215
# enum so the user can pick the strategy from a dropdown
@@ -236,6 +276,27 @@ def processAlgorithm(
236276
relationships_df = relationships_df.drop(columns=['length'])
237277
if 'geometry' in contacts_df.columns:
238278
relationships_df = relationships_df.drop(columns=['geometry'])
279+
280+
unit_name_field = parameters.get('UNIT_NAME_FIELD', 'UNITNAME') if parameters else 'UNITNAME'
281+
if unit_name_field != 'UNITNAME' and unit_name_field in geology_gdf.columns:
282+
geology_gdf = geology_gdf.rename(columns={unit_name_field: 'UNITNAME'})
283+
284+
dip_field = parameters.get('DIP_FIELD', 'DIP') if parameters else 'DIP'
285+
if dip_field != 'DIP' and dip_field in structure_gdf.columns:
286+
structure_gdf = structure_gdf.rename(columns={dip_field: 'DIP'})
287+
288+
orientation_type = self.parameterAsEnum(parameters, 'ORIENTATION_TYPE', context)
289+
orientation_type_name = ['Dip Direction', 'Strike'][orientation_type]
290+
dipdir_field = parameters.get('DIPDIR_FIELD', 'DIPDIR') if parameters else 'DIPDIR'
291+
if dipdir_field in structure_gdf.columns:
292+
if orientation_type_name == 'Strike':
293+
structure_gdf['DIPDIR'] = structure_gdf[dipdir_field].apply(
294+
lambda val: (val + 90.0) % 360.0 if pd.notnull(val) else val
295+
)
296+
else:
297+
structure_gdf = structure_gdf.rename(columns={dipdir_field: 'DIPDIR'})
298+
299+
239300
order = sorter.sort(
240301
units_df,
241302
relationships_df,

0 commit comments

Comments
 (0)