Skip to content

Commit

Permalink
272 add available workflow steps for proxy processing (#297)
Browse files Browse the repository at this point in the history
* add binarize to custom proxy processing workflows
* add proximity to anomaly to custom proxy processing workflows
* add proximity to features to custom proxy processing workflows
* fix available workflow steps in custom proxy modification
  • Loading branch information
nmaarnio authored Jan 9, 2025
1 parent ee35090 commit b8c50cc
Show file tree
Hide file tree
Showing 12 changed files with 1,863 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def initAlgorithm(self, config=None):
name=self.alg_parameters[5],
description="Max distance value",
type=QgsProcessingParameterNumber.Double,
minValue=0.0
defaultValue=0.0
)
max_distance_value_param.setHelp(
"Value at and beyond given max distance. Used for scaling the output raster values."
Expand All @@ -109,7 +109,7 @@ def initAlgorithm(self, config=None):
name=self.alg_parameters[6],
description="Anomaly value",
type=QgsProcessingParameterNumber.Double,
minValue=1.0
defaultValue=1.0
)
anomaly_value_param.setHelp("Value at anomaly. Used for scaling the output raster values.")
self.addParameter(anomaly_value_param)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@

FORM_CLASS = load_ui("mineral_proxies/define_custom_proxy.ui")

WORKFLOW_STEPS = ["Distance to features", "Distance to anomaly", "Interpolate"]
WORKFLOW_STEPS = [
"Distance to features",
"Distance to anomaly",
"Interpolate",
"Binarize",
"Proximity to anomaly",
"Proximity to features"
]


class EISWizardDefineProxy(QDialog, FORM_CLASS):
Expand Down Expand Up @@ -53,6 +60,7 @@ def __init__(self, parent: Optional[QWidget] = None):
self.button_box.accepted.connect(self._on_accept)

self.proxy = None
self.add_workflow_step()


def add_workflow_step(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
QWidget,
)

from eis_qgis_plugin.eis_wizard.mineral_proxies.configuration_dialogs.define_proxy import WORKFLOW_STEPS
from eis_qgis_plugin.eis_wizard.mineral_proxies.mineral_system import MineralProxy, MineralSystem, ProxyImportance
from eis_qgis_plugin.qgis_plugin_tools.tools.resources import load_ui
from eis_qgis_plugin.utils.message_manager import EISMessageManager
from eis_qgis_plugin.utils.misc_utils import find_index_for_text_combobox

FORM_CLASS = load_ui("mineral_proxies/modify_custom_proxy.ui")

WORKFLOW_STEPS = ["Distance to features", "Distance to anomaly", "Interpolate"]


class EISWizardModifyProxy(QDialog, FORM_CLASS):

Expand Down
85 changes: 85 additions & 0 deletions eis_qgis_plugin/eis_wizard/mineral_proxies/workflows/binarize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from typing import Literal, Optional

from qgis.core import QgsMapLayerProxyModel
from qgis.gui import (
QgsDoubleSpinBox,
QgsFileWidget,
QgsMapLayerComboBox,
)
from qgis.PyQt.QtWidgets import (
QComboBox,
QGroupBox,
QLabel,
QStackedWidget,
QWidget,
)

from eis_qgis_plugin.eis_wizard.mineral_proxies.proxy_processing import EISWizardProxyProcess
from eis_qgis_plugin.qgis_plugin_tools.tools.resources import load_ui
from eis_qgis_plugin.utils.misc_utils import get_output_path

FORM_CLASS = load_ui("mineral_proxies/proxy_workflow_binarize.ui")



class EISWizardProxyBinarize(EISWizardProxyProcess, FORM_CLASS):

ALG_NAME = "eis:binarize"
WORKFLOW_NAME = "Binarize"

def __init__(self,
proxy_manager: QWidget,
mineral_system: str,
category: str,
proxy_name: str,
mineral_system_component: str,
process_type: Literal["single_step", "multi_step", "multi_step_final"] = "single_step",
parent: Optional[QWidget] = None
) -> None:
super().__init__(parent)
self.setupUi(self)

self.mineral_system = mineral_system
self.mineral_system_component = mineral_system_component
self.process_type = process_type
self.category = category
self.proxy_name = proxy_name
self.proxy_manager = proxy_manager

# DECLARE TYPES
self.raster_layer: QgsMapLayerComboBox

self.method_box: QGroupBox
self.binarizing_threshold_label: QLabel
self.binarizing_threshold: QgsDoubleSpinBox

self.output_raster_path: QgsFileWidget
self.output_raster_settings: QComboBox
self.output_raster_settings_pages: QStackedWidget

self.initialize()


def initialize(self):
self.raster_layer.setFilters(QgsMapLayerProxyModel.RasterLayer)
super().initialize(self.process_type)


def on_output_raster_settings_changed(self, i):
max_height = 50 if i == 0 else 230
self.output_raster_settings_pages.setMaximumHeight(max_height)
self.output_raster_settings_pages.setCurrentIndex(i)


def on_define_anomaly_output_raster_settings_changed(self, i):
self.output_raster_settings_pages.setCurrentIndex(i)


def run(self):
params = {
"input_raster": self.raster_layer.currentLayer(),
"threshold": self.binarizing_threshold.value(),
"output_raster": get_output_path(self.output_raster_path)
}
self.executor.configure(self.ALG_NAME, self.feedback)
self.executor.run(params)
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def __init__(self,

# DECLARE TYPES
self.raster_layer: QgsMapLayerComboBox
# self.band: QgsRasterBandComboBox

self.method_box: QGroupBox
self.threshold_criteria: QComboBox
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from typing import Literal, Optional

from qgis.core import QgsMapLayerProxyModel
from qgis.gui import (
QgsDoubleSpinBox,
QgsFileWidget,
QgsMapLayerComboBox,
)
from qgis.PyQt.QtWidgets import (
QComboBox,
QGroupBox,
QLabel,
QStackedWidget,
QWidget,
)

from eis_qgis_plugin.eis_wizard.mineral_proxies.proxy_processing import EISWizardProxyProcess
from eis_qgis_plugin.qgis_plugin_tools.tools.resources import load_ui
from eis_qgis_plugin.utils.misc_utils import get_output_path

FORM_CLASS = load_ui("mineral_proxies/proxy_workflow_proximity_to_anomaly.ui")



class EISWizardProxyProximityToAnomaly(EISWizardProxyProcess, FORM_CLASS):

ALG_NAME = "eis:proximity_to_anomaly"
WORKFLOW_NAME = "Proximity to anomaly"

def __init__(self,
proxy_manager: QWidget,
mineral_system: str,
category: str,
proxy_name: str,
mineral_system_component: str,
process_type: Literal["single_step", "multi_step", "multi_step_final"] = "single_step",
parent: Optional[QWidget] = None
) -> None:
super().__init__(parent)
self.setupUi(self)

self.mineral_system = mineral_system
self.mineral_system_component = mineral_system_component
self.process_type = process_type
self.category = category
self.proxy_name = proxy_name
self.proxy_manager = proxy_manager

# DECLARE TYPES
self.raster_layer: QgsMapLayerComboBox

self.method_box: QGroupBox
self.threshold_criteria: QComboBox
self.threshold_1: QgsDoubleSpinBox
self.threshold_label_1: QLabel
self.threshold_2: QgsDoubleSpinBox
self.threshold_label_2: QLabel
self.max_distance: QgsDoubleSpinBox
self.max_distance_value: QgsDoubleSpinBox
self.anomaly_value: QgsDoubleSpinBox

self.output_raster_path: QgsFileWidget
self.output_raster_settings: QComboBox
self.output_raster_settings_pages: QStackedWidget

self.initialize()


def initialize(self):
self.raster_layer.setFilters(QgsMapLayerProxyModel.RasterLayer)
self.threshold_criteria.currentTextChanged.connect(self.on_threshold_criteria_changed)
self.on_threshold_criteria_changed("higher")

super().initialize(self.process_type)


def on_output_raster_settings_changed(self, i):
max_height = 50 if i == 0 else 230
self.output_raster_settings_pages.setMaximumHeight(max_height)
self.output_raster_settings_pages.setCurrentIndex(i)


def on_define_anomaly_output_raster_settings_changed(self, i):
self.output_raster_settings_pages.setCurrentIndex(i)


def on_threshold_criteria_changed(self, text: str):
text = text.lower()
if text == "higher" or text == "lower":
self.threshold_label_1.setText("Threshold value")
self.threshold_label_2.hide()
self.threshold_2.hide()
else:
self.threshold_label_1.setText("Threshold value lower")
self.threshold_label_2.show()
self.threshold_2.show()


def run(self):
threshold_criteria = self.threshold_criteria.currentIndex()
anomaly_threshold_2 = self.threshold_2.value()
if threshold_criteria == 0 or threshold_criteria == 1:
anomaly_threshold_2 = None

params = {
"input_raster": self.raster_layer.currentLayer(),
"threshold_criteria": self.threshold_criteria.currentIndex(),
"first_threshold_criteria_value": self.threshold_1.value(),
"second_threshold_criteria_value": anomaly_threshold_2,
"max_distance": self.max_distance.value(),
"max_distance_value": self.max_distance_value.value(),
"anomaly_value": self.anomaly_value.value(),
"output_raster": get_output_path(self.output_raster_path)
}
self.executor.configure(self.ALG_NAME, self.feedback)
self.executor.run(params)
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from typing import Literal, Optional

from qgis.core import QgsMapLayerProxyModel
from qgis.gui import (
QgsDoubleSpinBox,
QgsFieldExpressionWidget,
QgsFileWidget,
QgsMapLayerComboBox,
)
from qgis.PyQt.QtWidgets import (
QComboBox,
QStackedWidget,
QWidget,
)

from eis_qgis_plugin.eis_wizard.mineral_proxies.proxy_processing import EISWizardProxyProcess
from eis_qgis_plugin.qgis_plugin_tools.tools.resources import load_ui
from eis_qgis_plugin.utils.misc_utils import get_output_path

FORM_CLASS = load_ui("mineral_proxies/proxy_workflow_proximity_to_features.ui")

class EISWizardProxyProximityToFeatures(EISWizardProxyProcess, FORM_CLASS):

ALG_NAME = "eis:proximity_computation"
WORKFLOW_NAME = "Proximity to features"

def __init__(
self,
proxy_manager: QWidget,
mineral_system: str,
category: str,
proxy_name: str,
mineral_system_component: str,
process_type: Literal["single_step", "multi_step", "multi_step_final"] = "single_step",
parent: Optional[QWidget] = None
) -> None:
super().__init__(parent)
self.setupUi(self)

self.mineral_system = mineral_system
self.mineral_system_component = mineral_system_component
self.process_type = process_type
self.category = category
self.proxy_name = proxy_name
self.proxy_manager = proxy_manager

# DELCARE TYPES
self.vector_layer: QgsMapLayerComboBox
self.selection: QgsFieldExpressionWidget

self.max_distance: QgsDoubleSpinBox
self.max_distance_value: QgsDoubleSpinBox
self.features_value: QgsDoubleSpinBox

self.output_raster_path: QgsFileWidget
self.output_raster_settings: QComboBox
self.output_raster_settings_pages: QStackedWidget

self.initialize()


def initialize(self):
self.vector_layer.setFilters(QgsMapLayerProxyModel.VectorLayer)
self.vector_layer.layerChanged.connect(self.selection.setLayer)
self.selection.setLayer(self.vector_layer.currentLayer())

super().initialize(self.process_type)


def on_output_raster_settings_changed(self, i: int):
max_height = 50 if i == 0 else 230
self.output_raster_settings_pages.setMaximumHeight(max_height)
self.output_raster_settings_pages.setCurrentIndex(i)


def run(self):
output_raster_params = self.get_output_raster_params()
if output_raster_params is None or self.executor.is_running:
return

params = {
"input_vector": self.vector_layer.currentLayer(), # SELECTION NOT INCLUDED! (yet)
**output_raster_params,
"max_distance": self.max_distance.value(),
"max_distance_value": self.max_distance_value.value(),
"geometries_value": self.features_value.value(),
"output_raster": get_output_path(self.output_raster_path)
}
self.executor.configure(self.ALG_NAME, self.feedback)
self.executor.run(params)
Loading

0 comments on commit b8c50cc

Please sign in to comment.