Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.
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
Binary file removed .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion FlowEstimator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-------------------
begin : 2015-05-21
git sha : $Format:%H$
copyright : (C) 2015 by M. Weier - North Dakota State Water Commision
copyright : (C) 2015 by M. Weier - North Dakota State Water Commission
email : mweier@nd.gov
***************************************************************************/

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# -------------------
# begin : 2015-05-21
# git sha : $Format:%H$
# copyright : (C) 2015 by M. Weier - North Dakota State Water Commision
# copyright : (C) 2015 by M. Weier - North Dakota State Water Commission
# email : mweier@nd.gov
# ***************************************************************************/
#
Expand Down
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Estimates steady, uniform flow using the Manning equation for trapezoidal and DEM sampled channels.
-------------------
begin : 2015-05-21
copyright : (C) 2015 by M. Weier - North Dakota State Water Commision
copyright : (C) 2015 by M. Weier - North Dakota State Water Commission
email : mweier@nd.gov
git sha : $Format:%H$
***************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion flow_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-------------------
begin : 2015-05-21
git sha : $Format:%H$
copyright : (C) 2015 by M. Weier - North Dakota State Water Commision
copyright : (C) 2015 by M. Weier - North Dakota State Water Commission
email : mweier@nd.gov
***************************************************************************/

Expand Down
76 changes: 61 additions & 15 deletions flow_estimator_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-------------------
begin : 2015-05-21
git sha : $Format:%H$
copyright : (C) 2015 by M. Weier - North Dakota State Water Commision
copyright : (C) 2015 by M. Weier - North Dakota State Water Commission
email : mweier@nd.gov
***************************************************************************/

Expand Down Expand Up @@ -58,11 +58,14 @@ def __init__(self, iface, parent=None):
self.iface = iface
self.setupUi(self)

self.btnOk = self.buttonBox.button(QtGui.QDialogButtonBox.Ok)
self.btnOk.setText("Save Data")
self.btnOk = self.buttonBox.button(QtGui.QDialogButtonBox.Save)
#ajh: it seems this wasn't working, so I have changed from a stock OK button to a stock Save button
#self.btnOk.setText("Save Data")
self.btnClose = self.buttonBox.button(QtGui.QDialogButtonBox.Close)
self.btnBrowse.clicked.connect(self.writeDirName)
self.btnLoadTXT.clicked.connect(self.loadTxt)
# ajh trying to make it work
#self.inputFile.textChanged.connect(self.run)
self.btnSampleLine.setEnabled(False)
self.btnSampleSlope.setEnabled(False)
self.calcType = 'Trap'
Expand Down Expand Up @@ -101,6 +104,8 @@ def __init__(self, iface, parent=None):
self.ft.clicked.connect(self.run)
self.m.clicked.connect(self.run)
self.cbUDwse.valueChanged.connect(self.run)
#ajh: this doesn't fix it
#self.btnRefresh.clicked.connect(self.run)

self.manageGui()

Expand Down Expand Up @@ -132,7 +137,12 @@ def plotter(self):
if Q != 0:
self.axes.plot(xWater, yWater, 'blue')
self.axes.fill_between(xWater, yWater, yWater0, where=yWater>=yWater0, facecolor='blue', interpolate=True, alpha = 0.1)
self.outText = 'R: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.2f} {5}$^3$/s\nVelocity {4:,.2f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth)
if self.calcType == 'DEM':
self.outText = 'INPUT\n\nSlope: {7:.3f}\nRoughness: {8:.3f}\nWSE: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.3f} {5}$^3$/s\nVelocity {4:,.1f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.cbWSE.value())
elif self.calcType == 'UD':
self.outText = 'INPUT\n\nSlope: {7:.3f}\nRoughness: {8:.3f}\nWSE: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.3f} {5}$^3$/s\nVelocity {4:,.1f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.cbUDwse.value())
else:
self.outText = 'INPUT\n\nSlope: {7:.3f}\nRoughness: {8:.3f}\nDepth: {9:.2f} {5}\n\nCALCULATED\n\nR: {0:.2f} {5}\nArea: {1:,.2f} {5}$^2$\nTop Width: {2:.2f} {5}\nDepth: {6:,.2f} {5}\nQ: {3:,.3f} {5}$^3$/s\nVelocity {4:,.1f} {5}/s'.format(R, area, topWidth, Q, v, self.units, depth, self.slope.value(), self.n.value(), self.depth.value())
self.axes.set_xlabel('Station, '+self.units)
self.axes.set_ylabel('Elevation, '+self.units)
self.axes.set_title('Cross Section')
Expand All @@ -145,7 +155,7 @@ def plotter(self):

def refreshPlotText(self):

self.axes.annotate(self.outText, xy=(.8,.35), xycoords='figure fraction')
self.axes.annotate(self.outText, xy=(.8,0.17), xycoords='figure fraction')
#at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
#self.axes.add_artist(at)
self.mplCanvas.draw()
Expand Down Expand Up @@ -173,6 +183,7 @@ def run(self):

try:
self.calcType = 'UD'
#print 'self.cbUDwse.value(), self.n.value(), self.slope.value(), staElev = self.staElev, units = self.units'
self.args = flowEstimator(self.cbUDwse.value(), self.n.value(), self.slope.value(), staElev = self.staElev, units = self.units)
self.plotter()
except:
Expand All @@ -182,7 +193,12 @@ def run(self):

def sampleLine(self):
try:
self.deactivate()
# ajh: this doesn't seem to do anything on Windows
self.iface.deactivate()
# ajh: neither does this!
#self.iface.showMinimized()
# ajh: this causes an error
#self.iface.mainWindow.setWindowState(Qt.WindowNoState)
except:
pass
self.btnSampleLine.setEnabled(False)
Expand All @@ -207,13 +223,13 @@ def rubberBand(self):

print 'rubberband '
self.canvas = self.iface.mapCanvas()
#Init classe variables
#Init class variables
if self.sampleBtnCode=='sampleLine':
self.tool = ProfiletoolMapTool(self.canvas, self.btnSampleLine) #the mouselistener
else:
self.tool = ProfiletoolMapTool(self.canvas, self.btnSampleSlope) #the mouselistener
self.pointstoDraw = None #Polyline in mapcanvas CRS analysed
self.dblclktemp = False #enable disctinction between leftclick and doubleclick
self.dblclktemp = False #enable distinction between leftclick and doubleclick
self.selectionmethod = 0 #The selection method defined in option
self.saveTool = self.canvas.mapTool() #Save the standard mapttool for restoring it at the end
self.textquit0 = "Click for polyline and double click to end (right click to cancel then quit)"
Expand Down Expand Up @@ -273,6 +289,13 @@ def rightClicked(self,position): #used to quit the current action
self.rubberband.reset(self.polygon)
else:
self.cleaning()
# ajh: need this otherwise the plugin needs to be restarted to reenable the button
if self.sampleBtnCode == 'sampleLine':
self.btnSampleLine.setEnabled(True)
else :
self.btnSampleSlope.setEnabled(True)
# ajh: need to raise the window
self.activateWindow()



Expand Down Expand Up @@ -305,6 +328,7 @@ def doubleClicked(self,position):
self.staElev, error = self.doRubberbandProfile()
if error:
self.deactivate()
#ajh it would be good to restart the selection again after an error
else:
self.doIrregularProfileFlowEstimator()
self.btnSampleLine.setEnabled(True)
Expand All @@ -313,6 +337,7 @@ def doubleClicked(self,position):
staElev, error = self.doRubberbandProfile()
if error:
self.deactivate()
#ajh it would be good to restart the selection again after an error
else:
self.doRubberbandSlopeEstimator(staElev)
self.btnSampleSlope.setEnabled(True)
Expand All @@ -324,7 +349,19 @@ def doubleClicked(self,position):
#temp point to distinct leftclick and dbleclick
self.dblclktemp = newPoints
self.iface.mainWindow().statusBar().showMessage(self.textquit0)
self.iface.mainWindow().activateWindow()

# ajh trying to make something like this work:
#self.iface.mainWindow.setWindowState(self.iface.mainWindow.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
#self.iface.mainWindow.raise_()
#self.iface.mainWindow.show()

# ajh: thought this just wasn't working on windows as per
# https://stackoverflow.com/questions/22815608/how-to-find-the-active-pyqt-window-and-bring-it-to-the-front
# see https://forum.qt.io/topic/1939/activatewindow-does-not-send-window-to-front/11
#self.iface.mainWindow.activateWindow()

# but actually, this is the solution:
self.activateWindow()
return


Expand Down Expand Up @@ -428,7 +465,8 @@ def doIrregularProfileFlowEstimator(self):
else:
return

self.run()
# ajh: I don't think this was doing anything
#self.run()


def doRubberbandSlopeEstimator(self, staElev):
Expand Down Expand Up @@ -477,6 +515,8 @@ def loadTxt(self):
self.calcType = 'UD'
self.doIrregularProfileFlowEstimator()
except:
if (filePath == ('')): # null string for cancel
return
QMessageBox.warning(self,'Error',
'Please check that the text file is space or tab delimited and does not contain header information')

Expand All @@ -488,10 +528,15 @@ def accept(self):
if outPath == '':
outPath = os.path.join(home,'Desktop','QGIS2FlowEstimatorFiles')
self.outputDir.setText(outPath)
if not os.path.exists(outPath):
os.makedirs(outPath)
# Note that in Python 3.2+ we will be able to just do: os.makedirs("path/to/directory", exist_ok=True)
if not os.path.exists(outPath):
os.makedirs(outPath)
os.chdir(outPath)
fileName = 'FlowEstimatorResults.txt'
# ajh not sure how to reliably reproduce, but on Windows it seems sometimes a lock is kept on the file until QGIS is closed
# one way to prevent it may be to open like this:
# outFile = open(fileName, 'w', False)
# another way may be to do outFile = None after closing
outFile = open(fileName,'w')
outHeader = '*'*20 + '\nFlow Estimator - A QGIS plugin\nEstimates uniform, steady flow in a channel using Mannings equation\n' + '*'*20
if self.calcType == 'DEM':
Expand All @@ -502,15 +547,14 @@ def accept(self):
wseMax = self.cbWSE.value()
wseMin = self.cbWSE.minimum()
elif self.calcType =='UD':
proj4 = utils.getRasterLayerByName(self.cbDEM.currentText().split(' EPSG')[0]).crs().toProj4()
outHeader += '\n'*5 + 'Type:\tUser Defined Cross Section\nUnits:\t{0}\nChannel Slope:\t{1:.06f}\nMannings n:\t{2:.02f}\n\n\n\nstation\televation\n'.format(self.units, self.slope.value(), self.n.value())
outFile.write(outHeader)
np.savetxt(outFile, self.staElev, fmt = '%.3f', delimiter = '\t')
wseMax = self.cbUDwse.value()
wseMin = self.cbUDwse.minimum()

else:
outHeader += '\n'*5 + 'Type:\tTrapizodal Channel\nUnits:\t{0}\nChannel Slope:\t{1:.06f}\nMannings n:\t{2:.02f}\nBottom Width:\t{3:.02f}\nRight Side Slope:\t{4:.02f}\nLeft Side Slope:\t{5:.02f}\n'.format(self.units, self.slope.value(), self.n.value(), self.botWidth.value(), self.rightSS.value(), self.leftSS.value())
outHeader += '\n'*5 + 'Type:\tTrapezoidal Channel\nUnits:\t{0}\nChannel Slope:\t{1:.06f}\nMannings n:\t{2:.02f}\nBottom Width:\t{3:.02f}\nRight Side Slope:\t{4:.02f}\nLeft Side Slope:\t{5:.02f}\n'.format(self.units, self.slope.value(), self.n.value(), self.botWidth.value(), self.rightSS.value(), self.leftSS.value())
outFile.write(outHeader)
wseMax = self.depth.value()
wseMin = 0.0
Expand Down Expand Up @@ -545,6 +589,8 @@ def accept(self):


outFile.close()
#ajh this may help force the file lock to be released
outFile = None

self.iface.messageBar().pushMessage("Flow Estimator", 'Output files located here {}. Please delete when finished'.format(outPath),duration=30)
self.iface.messageBar().pushMessage("Flow Estimator", 'Output files saved to {}'.format(outPath),duration=30)

33 changes: 21 additions & 12 deletions flow_estimator_dialog_base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
<property name="value">
<double>5.000000000000000</double>
</property>
<property name="singleStep">
<double>0.500000000000000</double>
</property>
<property name="decimals">
<number>3</number>
</property>
</widget>
</item>
<item row="0" column="1">
Expand All @@ -136,11 +142,14 @@
<double>0.010000000000000</double>
</property>
<property name="singleStep">
<double>0.500000000000000</double>
<double>0.050000000000000</double>
</property>
<property name="value">
<double>5.000000000000000</double>
</property>
<property name="decimals">
<number>4</number>
</property>
</widget>
</item>
<item row="0" column="3">
Expand Down Expand Up @@ -196,13 +205,13 @@
<item>
<widget class="QDoubleSpinBox" name="cbWSE">
<property name="decimals">
<number>2</number>
<number>4</number>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
<double>0.050000000000000</double>
</property>
</widget>
</item>
Expand Down Expand Up @@ -288,13 +297,13 @@
</size>
</property>
<property name="decimals">
<number>2</number>
<number>4</number>
</property>
<property name="maximum">
<double>999999.989999999990687</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
<double>0.050000000000000</double>
</property>
</widget>
</item>
Expand Down Expand Up @@ -371,16 +380,16 @@
<property name="text">
<string>ft</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="m">
<property name="text">
<string>m</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -415,16 +424,16 @@
<item row="0" column="3">
<widget class="QDoubleSpinBox" name="slope">
<property name="decimals">
<number>5</number>
<number>3</number>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="singleStep">
<double>0.000010000000000</double>
<double>0.005000000000000</double>
</property>
<property name="value">
<double>0.000500000000000</double>
<double>0.0050000000000000</double>
</property>
</widget>
</item>
Expand Down Expand Up @@ -542,7 +551,7 @@ p, li { white-space: pre-wrap; }
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
Expand Down
Loading