Skip to content

Commit 9b29cc3

Browse files
committed
merge with noelle/thickness_calculator
1 parent b8bfa7e commit 9b29cc3

2 files changed

Lines changed: 54 additions & 18 deletions

File tree

m2l/processing/algorithms/sampler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"""
1111
# Python imports
1212
from typing import Any, Optional
13-
from qgis.PyQt.QtCore import QMetaType
13+
from qgis.PyQt.QtCore import QVariant
1414
from osgeo import gdal
1515
import pandas as pd
1616

@@ -182,11 +182,11 @@ def processAlgorithm(
182182
dtype_str = str(dtype)
183183

184184
if dtype_str in ['float16', 'float32', 'float64']:
185-
field_type = QMetaType.Type.Double
185+
field_type = QVariant.Double
186186
elif dtype_str in ['int8', 'int16', 'int32', 'int64']:
187-
field_type = QMetaType.Type.Int
187+
field_type = QVariant.Int
188188
else:
189-
field_type = QMetaType.Type.QString
189+
field_type = QVariant.String
190190

191191
fields.append(QgsField(column_name, field_type))
192192

m2l/processing/algorithms/thickness_calculator.py

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ThicknessCalculatorAlgorithm(QgsProcessingAlgorithm):
4848

4949
INPUT_THICKNESS_CALCULATOR_TYPE = 'THICKNESS_CALCULATOR_TYPE'
5050
INPUT_DTM = 'DTM'
51+
INPUT_BOUNDING_BOX_TYPE = 'BOUNDING_BOX_TYPE'
5152
INPUT_BOUNDING_BOX = 'BOUNDING_BOX'
5253
INPUT_MAX_LINE_LENGTH = 'MAX_LINE_LENGTH'
5354
INPUT_STRATI_COLUMN = 'STRATIGRAPHIC_COLUMN'
@@ -56,7 +57,7 @@ class ThicknessCalculatorAlgorithm(QgsProcessingAlgorithm):
5657
INPUT_DIPDIR_FIELD = 'DIPDIR_FIELD'
5758
INPUT_DIP_FIELD = 'DIP_FIELD'
5859
INPUT_GEOLOGY = 'GEOLOGY'
59-
INPUT_THICKNESS_ORIENTATION_TYPE = 'THICKNESS_ORIENTATION_TYPE'
60+
INPUT_ORIENTATION_TYPE = 'ORIENTATION_TYPE'
6061
INPUT_UNIT_NAME_FIELD = 'UNIT_NAME_FIELD'
6162
INPUT_SAMPLED_CONTACTS = 'SAMPLED_CONTACTS'
6263
INPUT_STRATIGRAPHIC_COLUMN_LAYER = 'STRATIGRAPHIC_COLUMN_LAYER'
@@ -100,6 +101,29 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
100101
)
101102
)
102103

104+
self.addParameter(
105+
QgsProcessingParameterEnum(
106+
self.INPUT_BOUNDING_BOX_TYPE,
107+
"Bounding Box Type",
108+
options=['Extract from geology layer', 'User defined'],
109+
allowMultiple=False,
110+
defaultValue=1
111+
)
112+
)
113+
114+
bbox_settings = QgsSettings()
115+
last_bbox = bbox_settings.value("m2l/bounding_box", "")
116+
self.addParameter(
117+
QgsProcessingParameterMatrix(
118+
self.INPUT_BOUNDING_BOX,
119+
description="Static Bounding Box",
120+
headers=['minx','miny','maxx','maxy'],
121+
numberRows=1,
122+
defaultValue=last_bbox,
123+
optional=True
124+
)
125+
)
126+
103127
self.addParameter(
104128
QgsProcessingParameterNumber(
105129
self.INPUT_MAX_LINE_LENGTH,
@@ -171,8 +195,8 @@ def initAlgorithm(self, config: Optional[dict[str, Any]] = None) -> None:
171195
)
172196
self.addParameter(
173197
QgsProcessingParameterEnum(
174-
'THICKNESS_ORIENTATION_TYPE',
175-
'Thickness Orientation Type',
198+
self.INPUT_ORIENTATION_TYPE,
199+
'Orientation Type',
176200
options=['Dip Direction', 'Strike'],
177201
defaultValue=0 # Default to Dip Direction
178202
)
@@ -213,26 +237,38 @@ def processAlgorithm(
213237
thickness_type_index = self.parameterAsEnum(parameters, self.INPUT_THICKNESS_CALCULATOR_TYPE, context)
214238
thickness_type = ['InterpolatedStructure', 'StructuralPoint'][thickness_type_index]
215239
dtm_data = self.parameterAsRasterLayer(parameters, self.INPUT_DTM, context)
216-
bounding_box = self.parameterAsMatrix(parameters, self.INPUT_BOUNDING_BOX, context)
240+
bounding_box_type = self.parameterAsEnum(parameters, self.INPUT_BOUNDING_BOX_TYPE, context)
217241
max_line_length = self.parameterAsSource(parameters, self.INPUT_MAX_LINE_LENGTH, context)
218242
basal_contacts = self.parameterAsSource(parameters, self.INPUT_BASAL_CONTACTS, context)
219243
geology_data = self.parameterAsSource(parameters, self.INPUT_GEOLOGY, context)
220244
structure_data = self.parameterAsSource(parameters, self.INPUT_STRUCTURE_DATA, context)
221-
thickness_orientation_type = self.parameterAsEnum(parameters, self.INPUT_THICKNESS_ORIENTATION_TYPE, context)
222-
is_strike = (thickness_orientation_type == 1)
245+
orientation_type = self.parameterAsEnum(parameters, self.INPUT_ORIENTATION_TYPE, context)
246+
is_strike = (orientation_type == 1)
223247
structure_dipdir_field = self.parameterAsString(parameters, self.INPUT_DIPDIR_FIELD, context)
224248
structure_dip_field = self.parameterAsString(parameters, self.INPUT_DIP_FIELD, context)
225249
sampled_contacts = self.parameterAsSource(parameters, self.INPUT_SAMPLED_CONTACTS, context)
226250
unit_name_field = self.parameterAsString(parameters, self.INPUT_UNIT_NAME_FIELD, context)
227251

228-
geology_layer = self.parameterAsVectorLayer(parameters, self.INPUT_GEOLOGY, context)
229-
extent = geology_layer.extent()
230-
bounding_box = {
231-
'minx': extent.xMinimum(),
232-
'miny': extent.yMinimum(),
233-
'maxx': extent.xMaximum(),
234-
'maxy': extent.yMaximum()
235-
}
252+
if bounding_box_type == 0:
253+
geology_layer = self.parameterAsVectorLayer(parameters, self.INPUT_GEOLOGY, context)
254+
extent = geology_layer.extent()
255+
bounding_box = {
256+
'minx': extent.xMinimum(),
257+
'miny': extent.yMinimum(),
258+
'maxx': extent.xMaximum(),
259+
'maxy': extent.yMaximum()
260+
}
261+
feedback.pushInfo("Using bounding box from geology layer")
262+
else:
263+
static_bbox_matrix = self.parameterAsMatrix(parameters, self.INPUT_BOUNDING_BOX, context)
264+
if not static_bbox_matrix or len(static_bbox_matrix) == 0:
265+
raise QgsProcessingException("Bounding box is required")
266+
267+
bounding_box = matrixToDict(static_bbox_matrix)
268+
269+
bbox_settings = QgsSettings()
270+
bbox_settings.setValue("m2l/bounding_box", static_bbox_matrix)
271+
feedback.pushInfo("Using bounding box from user input")
236272

237273
stratigraphic_column_source = self.parameterAsSource(parameters, self.INPUT_STRATIGRAPHIC_COLUMN_LAYER, context)
238274
stratigraphic_order = []

0 commit comments

Comments
 (0)