Skip to content

Commit

Permalink
Add a->b tool
Browse files Browse the repository at this point in the history
  • Loading branch information
marioba committed Mar 10, 2023
1 parent 5ce2e96 commit 323eb0f
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 3 deletions.
69 changes: 69 additions & 0 deletions pzp/a_b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from qgis.core import QgsExpressionContextUtils, edit


def a_b(layer):
process_type = int(
QgsExpressionContextUtils.layerScope(layer).variable("pzp_process")
)
selection = layer.selectedFeatures()

if not selection:
selection = layer.getFeatures()

with edit(layer):
for feature in selection:
matrice = feature["matrice"]
if process_type == 1200: # Flusso detrito
if matrice == 2:
feature["grado_pericolo"] = 1003
elif matrice == 4:
feature["grado_pericolo"] = 1003
elif matrice == 6:
feature["grado_pericolo"] = 1004

elif process_type in [2001, 2002]: # Sciv. spontaneo and colata detritica
if matrice == 3:
feature["grado_pericolo"] = 1003
elif matrice == 5:
feature["grado_pericolo"] = 1003
elif process_type == 3000: # Caduta sassi
if matrice == 6:
feature["grado_pericolo"] = 1004
else:
pass

layer.updateFeature(feature)


def b_a(layer):
process_type = int(
QgsExpressionContextUtils.layerScope(layer).variable("pzp_process")
)
selection = layer.selectedFeatures()

if not selection:
selection = layer.getFeatures()

with edit(layer):
for feature in selection:
matrice = feature["matrice"]
if process_type == 1200: # Flusso detrito
if matrice == 2:
feature["grado_pericolo"] = 1002
elif matrice == 4:
feature["grado_pericolo"] = 1002
elif matrice == 6:
feature["grado_pericolo"] = 1003

elif process_type in [2001, 2002]: # Sciv. spontaneo and colata detritica
if matrice == 3:
feature["grado_pericolo"] = 1002
elif matrice == 5:
feature["grado_pericolo"] = 1002
elif process_type == 3000: # Caduta sassi
if matrice == 6:
feature["grado_pericolo"] = 1003
else:
pass

layer.updateFeature(feature)
41 changes: 38 additions & 3 deletions pzp/pzp.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import webbrowser

from qgis.core import QgsLayerTreeGroup
from qgis.core import QgsExpressionContextUtils, QgsLayerTreeGroup
from qgis.gui import QgsOptionsPageWidget, QgsOptionsWidgetFactory
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QHBoxLayout, QMenu, QToolButton

from pzp import no_impact, utils
from pzp import a_b, no_impact, utils
from pzp.add_process import AddProcessDialog
from pzp.calculation import CalculationDialog
from pzp.check_dock import CheckResultsDock
Expand Down Expand Up @@ -53,12 +53,23 @@ def initGui(self):

self.toolbar.addAction(
self.create_action(
"ok_hand.png",
"no_impact.png",
"Aggiungi zone nessun impatto",
self.do_calculate_no_impact,
)
)

a_b_menu = QMenu()
a_b_action = self.create_action("a_b.png", "A->B", self.do_a_b)
a_b_menu.addAction(a_b_action)
a_b_menu.addAction(self.create_action("b_a.png", "B->A", self.do_b_a))

toolButton = QToolButton()
toolButton.setDefaultAction(a_b_action)
toolButton.setMenu(a_b_menu)
toolButton.setPopupMode(QToolButton.MenuButtonPopup)
self.toolbar.addWidget(toolButton)

self.toolbar.addAction(self.create_action("help.png", "Aiuto", self.do_help))
self.options_factory = PluginOptionsFactory()
self.options_factory.setTitle("PZP")
Expand Down Expand Up @@ -117,6 +128,30 @@ def do_calculate_no_impact(self):
else:
utils.push_error("Selezionare il gruppo che contiene il processo", 3)

def do_a_b(self):
layer = self.iface.activeLayer()
if layer:
if (
QgsExpressionContextUtils.layerScope(layer).variable("pzp_layer")
== "danger_zones"
):
a_b.a_b(layer)
return

utils.push_error("Selezionare il layer con le zone di pericolo", 3)

def do_b_a(self):
layer = self.iface.activeLayer()
if layer:
if (
QgsExpressionContextUtils.layerScope(layer).variable("pzp_layer")
== "danger_zones"
):
a_b.b_a(layer)
return

utils.push_error("Selezionare il layer con le zone di pericolo", 3)

def do_help(self):
webbrowser.open("https://opengisch.github.io/pzp/")

Expand Down

0 comments on commit 323eb0f

Please sign in to comment.