Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial port to QGIS 3 #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions GeomorphicFloodIndex/GeomorphicFloodIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
"""

# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import QAction
from qgis.core import *
# Initialize Qt resources from file resources.py
import resources
from .resources import *
# Import the code for the dialog
#from FlowPathDown_BBDialog import FlowPathDown_BBDialog
from Ui_GeomorphicFloodIndex import Ui_GeomorphicFloodIndex
import doGeomorphicFloodIndex
from .Ui_GeomorphicFloodIndex import Ui_GeomorphicFloodIndex
from .doGeomorphicFloodIndex import *

class GeomorphicFloodIndex:

Expand All @@ -44,7 +45,8 @@ def initGui(self):
"GeomorphicFloodArea", self.iface.mainWindow())

# connect the action to the run method
QObject.connect(self.action, SIGNAL("activated()"), self.run)
# QObject.connect(self.action, SIGNAL("activated()"), self.run)
self.action.triggered.connect(self.run)

# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
Expand All @@ -54,11 +56,12 @@ def initGui(self):
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu("GFA",self.action)
self.iface.removeToolBarIcon(self.action)


# run method that performs all the real work
def run(self):

dlg = doGeomorphicFloodIndex.GeomorphicFloodIndexDialog(self.iface)
dlg = GeomorphicFloodIndexDialog(self.iface)
dlg.exec_()

116 changes: 58 additions & 58 deletions GeomorphicFloodIndex/Ui_GeomorphicFloodIndex.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion GeomorphicFloodIndex/Ui_GeomorphicFloodIndex.ui
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@
<property name="geometry">
<rect>
<x>290</x>
<y>10</y>
<y>20</y>
<width>99</width>
<height>126</height>
</rect>
Expand Down
2 changes: 1 addition & 1 deletion GeomorphicFloodIndex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@

def classFactory(iface):

from GeomorphicFloodIndex import GeomorphicFloodIndex
from .GeomorphicFloodIndex import GeomorphicFloodIndex
return GeomorphicFloodIndex(iface)
97 changes: 55 additions & 42 deletions GeomorphicFloodIndex/doGeomorphicFloodIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.core import *
import qgis.utils
from Ui_GeomorphicFloodIndex import Ui_GeomorphicFloodIndex
from PyQt4.QtGui import QProgressBar
from .Ui_GeomorphicFloodIndex import *
from qgis.PyQt.QtWidgets import QProgressBar, QDialog, QMessageBox, QFileDialog
import os, sys, time, math
from osgeo import gdal, ogr
from osgeo.gdalconst import *
from scipy import ndimage
import osr
from osgeo import osr
import numpy
#from sklearn import metrics
import matplotlib.pyplot as plt
Expand All @@ -55,22 +55,36 @@ def __init__(self, iface):
self.NOVALUE=-340282346638528859811704183484516925440.000000
self.checkBoxManualSet.setChecked(True)
self.checkBoxCalibration.setChecked(False)
self.connect(self.toolButtonDemCon, SIGNAL("clicked()"), self.demconFile)
self.connect(self.toolButtonDemVoid, SIGNAL("clicked()"), self.demvoidFile)
self.connect(self.toolButtonFlowDir, SIGNAL("clicked()"), self.flowdirFile)
self.connect(self.toolButtonFlowAcc, SIGNAL("clicked()"), self.flowaccFile)
self.connect(self.toolButtonSFM, SIGNAL("clicked()"), self.sfmFile)

self.connect(self.checkBoxCalibration,SIGNAL("clicked()"),self.calibration_clicked)
self.connect(self.checkBoxManualSet,SIGNAL("clicked()"),self.manualset_clicked)

self.connect(self.btnOutput, SIGNAL("clicked()"), self.outFile)
self.connect(self.btnOutputBin, SIGNAL("clicked()"), self.outFileBin)
self.connect(self.btnOutputWD, SIGNAL("clicked()"), self.outFileWD)

self.connect(self.buttonBox, SIGNAL("accepted()"),self.accept)
QObject.connect(self.buttonBox, SIGNAL("rejected()"),self, SLOT("reject()"))
QObject.connect(self.buttonBox, SIGNAL("helpRequested()"),self.call_help)
# self.connect(self.toolButtonDemCon, SIGNAL("clicked()"), self.demconFile)
self.toolButtonDemCon.clicked.connect(self.demconFile)
# self.connect(self.toolButtonDemVoid, SIGNAL("clicked()"), self.demvoidFile)
self.toolButtonDemVoid.clicked.connect(self.demvoidFile)
# self.connect(self.toolButtonFlowDir, SIGNAL("clicked()"), self.flowdirFile)
self.toolButtonFlowDir.clicked.connect(self.flowdirFile)
# self.connect(self.toolButtonFlowAcc, SIGNAL("clicked()"), self.flowaccFile)
self.toolButtonFlowAcc.clicked.connect(self.flowaccFile)
# self.connect(self.toolButtonSFM, SIGNAL("clicked()"), self.sfmFile)
self.toolButtonSFM.clicked.connect(self.sfmFile)

# self.connect(self.checkBoxCalibration,SIGNAL("clicked()"),self.calibration_clicked)
# self.checkBoxCalibration.stateChanged.connect(self.calibration_clicked)
# self.connect(self.checkBoxManualSet,SIGNAL("clicked()"),self.manualset_clicked)
# self.checkBoxManualSet.stateChanged.connect(self.manualset_clicked)

# self.connect(self.btnOutput, SIGNAL("clicked()"), self.outFile)
self.btnOutput.clicked.connect(self.outFile)
# self.connect(self.btnOutputBin, SIGNAL("clicked()"), self.outFileBin)
self.btnOutputBin.clicked.connect(self.outFileBin)
# self.connect(self.btnOutputWD, SIGNAL("clicked()"), self.outFileWD)
self.btnOutputWD.clicked.connect(self.outFileWD)

# self.connect(self.buttonBox, SIGNAL("accepted()"),self.accept)
self.buttonBox.accepted.connect(self.accept)

# QObject.connect(self.buttonBox, SIGNAL("rejected()"),self, SLOT("reject()"))
self.buttonBox.rejected.connect(self.reject)
# QObject.connect(self.buttonBox, SIGNAL("helpRequested()"),self.call_help)
self.buttonBox.helpRequested.connect(self.call_help)

mapCanvas = self.iface.mapCanvas()
# init dictionaries of items:
Expand Down Expand Up @@ -139,7 +153,7 @@ def call_help(self):
def outFile(self):
"Display file dialog for output file"
self.lineOutput.clear()
outName = QFileDialog.getSaveFileName(self, "GFI output file",".", "GeoTiff (*.tif)")
outName, filter_string = QFileDialog.getSaveFileName(self, "GFI output file",".", "GeoTiff (*.tif)")

if len(outName)>0:
self.lineOutput.clear()
Expand All @@ -149,7 +163,7 @@ def outFile(self):
def outFileBin(self):
"Display file dialog for output file"
self.lineOutputBin.clear()
outNameBin = QFileDialog.getSaveFileName(self, "GFI output file",".", "GeoTiff (*.tif)")
outNameBin, filter_string = QFileDialog.getSaveFileName(self, "GFI output file",".", "GeoTiff (*.tif)")

if len(outNameBin)>0:
self.lineOutputBin.clear()
Expand All @@ -160,7 +174,7 @@ def outFileBin(self):
def outFileWD(self):
"Display file dialog for output file"
self.lineOutputWD.clear()
outNameWD = QFileDialog.getSaveFileName(self, "WD output file",".", "GeoTiff (*.tif)")
outNameWD, filter_string = QFileDialog.getSaveFileName(self, "WD output file",".", "GeoTiff (*.tif)")

if len(outNameWD)>0:
self.lineOutputWD.clear()
Expand All @@ -169,49 +183,49 @@ def outFileWD(self):
return outNameWD

def demconFile(self):
"Display file dialog for output file"
demconName = QFileDialog.getOpenFileName(self, "FILL Dem input file",".", "ESRI ascii (*.txt);; GeoTiff (*.tif);;All files (*.*)")
"Display file dialog for input file"
demconName, filter_string = QFileDialog.getOpenFileName(self, "FILL Dem input file",".", "ESRI ascii (*.txt);; GeoTiff (*.tif);;All files (*.*)")
if len(demconName)>0:
self.cmbDemCon.insertItem (0, demconName)
self.cmbDemCon.setCurrentIndex(0)
return demconName

def demvoidFile(self):
"Display file dialog for output file"
demvoidName = QFileDialog.getOpenFileName(self, "Dem input file",".", "ESRI ascii (*.txt);; GeoTiff (*.tif);;All files (*.*)")
"Display file dialog for input file"
demvoidName, filter_string = QFileDialog.getOpenFileName(self, "Dem input file",".", "ESRI ascii (*.txt);; GeoTiff (*.tif);;All files (*.*)")
if len(demvoidName)>0:
self.cmbDemVoid.insertItem (0, demvoidName)
self.cmbDemVoid.setCurrentIndex(0)
return demvoidName

def flowdirFile(self):
"Display file dialog for output file"
flowdirName = QFileDialog.getOpenFileName(self, "Flowdir input file",".", "ESRI ascii (*.txt);; GeoTiff (*.tif);;All files (*.*)")
"Display file dialog for input file"
flowdirName, filter_string = QFileDialog.getOpenFileName(self, "Flowdir input file",".", "ESRI ascii (*.txt);; GeoTiff (*.tif);;All files (*.*)")
if len(flowdirName)>0:
self.cmbFlowDir.insertItem (0, flowdirName)
self.cmbFlowDir.setCurrentIndex(0)
return flowdirName

def flowaccFile(self):
"Display file dialog for output file"
flowaccName = QFileDialog.getOpenFileName(self, "Flowacc input file",".", "ESRI ascii (*.txt);; GeoTiff (*.tif);;All files (*.*)")
"Display file dialog for input file"
flowaccName, filter_string = QFileDialog.getOpenFileName(self, "Flowacc input file",".", "ESRI ascii (*.txt);; GeoTiff (*.tif);;All files (*.*)")
if len(flowaccName)>0:
self.cmbFlowAcc.insertItem (0, flowaccName)
self.cmbFlowAcc.setCurrentIndex(0)
return flowaccName

def sfmFile(self):
"Display file dialog for output file"
sfmName = QFileDialog.getOpenFileName(self, "Standard Flood Map calibration file",".", "ESRI ascii (*.txt);; GeoTiff (*.tif);;All files (*.*)")
"Display file dialog for input file"
sfmName, filter_string = QFileDialog.getOpenFileName(self, "Standard Flood Map calibration file",".", "ESRI ascii (*.txt);; GeoTiff (*.tif);;All files (*.*)")
if len(sfmName)>0:
self.cmbSFM.insertItem (0, sfmName)
self.cmbSFM.setCurrentIndex(0)
return sfmName

def calibration_clicked(self):
self.checkBoxManualSet.nextCheckState()
def manualset_clicked(self):
self.checkBoxCalibration.nextCheckState()
# def calibration_clicked(self, state):
# self.checkBoxManualSet.nextCheckState()
# def manualset_clicked(self):
# self.checkBoxCalibration.nextCheckState()
###########################################################################################
def from_flowacc_to_stream(self,tab_flowacc,threshold_cell):

Expand Down Expand Up @@ -394,8 +408,7 @@ def writeOutputGeoTiff(self,arrayData, transform, prj,rows, cols, outFile):
format = "GTiff"
driver = gdal.GetDriverByName( format )
metadata = driver.GetMetadata()
if metadata.has_key(gdal.DCAP_CREATE) \
and metadata[gdal.DCAP_CREATE] == 'YES':
if gdal.DCAP_CREATE in metadata and metadata[gdal.DCAP_CREATE] == 'YES':
pass
else:
QMessageBox.information(None,"info","Driver %s does not support Create() method." % format)
Expand Down Expand Up @@ -947,9 +960,9 @@ def accept(self):
n_ok=len(id_ok)
ln_hronHbin=numpy.zeros((rows,cols))
for ct_ok in range(0,n_ok):
print ct_ok
print(ct_ok)
ct_label=id_ok[ct_ok]
print ct_label
print(ct_label)
ln_hronHbin[label_im==ct_label] = 1


Expand Down
10 changes: 6 additions & 4 deletions GeomorphicFloodIndex/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ name=GeomorphicFloodArea
description=GFA - tool is an open-source QGIS plug-in to realize a fast and cost-effective delineation of the floodplains in the contexts where the available data is scarce to carry out hydrological/hydraulic analyses.
about=Samela, C., Albano, R., Sole, A., Manfreda, S. (2018). Geomorphic Flood Area (GFA): a QGIS tool for a cost-effective delineation of the flood-prone areas, Computers, Environment and Urban Systems, (doi: 10.1016/j.compenvurbsys.2018.01.013)
category=Plugins
version=2.0
qgisMinimumVersion=2.0
qgisMaximumVersion=2.99
version=3.0.0
qgisMinimumVersion=3.16
qgisMaximumVersion=3.99
author= Raffaele ALbano, Caterina Samela, Salvatore Manfreda, Aurelia Sole
email= [email protected]
icon=icona.png
Expand All @@ -25,7 +25,9 @@ icon=icona.png
# Optional items:

# Uncomment the following line and add your changelog entries:
# changelog=
changelog=
3.0.0 - initial port to QGIS 3, by Andrea Giudiceandrea
2.0 - original version 2.0

# tags are comma separated with spaces allowed
tags=
Expand Down
8 changes: 4 additions & 4 deletions GeomorphicFloodIndex/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore
from qgis.PyQt import QtCore

qt_resource_data = "\
qt_resource_data = b"\
\x00\x01\x8e\xb5\
\x89\
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
Expand Down Expand Up @@ -6394,7 +6394,7 @@
\xae\x42\x60\x82\
"

qt_resource_name = "\
qt_resource_name = b"\
\x00\x07\
\x07\x3b\xe0\xb3\
\x00\x70\
Expand All @@ -6410,7 +6410,7 @@
\x00\x63\x00\x6f\x00\x6e\x00\x61\x00\x2e\x00\x70\x00\x6e\x00\x67\
"

qt_resource_struct = "\
qt_resource_struct = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
\x00\x00\x00\x14\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**GFA v.2.0**
**GFA v.3.0**
----------

### Geomorphic Flood Area
Expand Down