[GRASS-SVN] r47308 - grass-addons/grass7/gui/wxpython/wx.stream/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 29 11:41:00 EDT 2011


Author: madi
Date: 2011-07-29 08:41:00 -0700 (Fri, 29 Jul 2011)
New Revision: 47308

Modified:
   grass-addons/grass7/gui/wxpython/wx.stream/gui_modules/rstream_panelOne.py
Log:
OnRun function added - working copy

Modified: grass-addons/grass7/gui/wxpython/wx.stream/gui_modules/rstream_panelOne.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.stream/gui_modules/rstream_panelOne.py	2011-07-29 14:16:22 UTC (rev 47307)
+++ grass-addons/grass7/gui/wxpython/wx.stream/gui_modules/rstream_panelOne.py	2011-07-29 15:41:00 UTC (rev 47308)
@@ -18,9 +18,26 @@
 @author Margherita Di Leo (GSoC student 2011)
 """
 
+import os
+import sys
+
+sys.path.append(os.path.join(os.getenv('GISBASE'), 'etc', 'gui', 'wxpython', 'gui_modules'))
+
 import wx
+import wx.aui
+
+from debug import Debug as Debug
+from preferences import globalSettings as UserSettings
+
+import grass.script as grass
 import gselect
+import gcmd
+import dbm
+import globalvar
+import utils
+import menuform
 
+from rstream_panelOne import *
 
 
 # First panel # Network extraction
@@ -31,6 +48,12 @@
         wx.Panel.__init__(self, parent, id = wx.ID_ANY)
        
         self.parent = parent
+        self.thre = 0
+        self.r_elev = 'r_elev'
+        self.r_acc = 'r_acc'
+        self.r_stre = 'r_stre'
+        self.v_net = 'v_net'
+        self.r_drain = 'r_drain'
         
         # define the panel for select maps
 	self.panel = wx.Panel(self)                        
@@ -69,7 +92,7 @@
         # RadioButton
         hbox1 = wx.BoxSizer(wx.HORIZONTAL)
 
-        cb1 = wx.RadioButton(parent = self.panel, id = wx.ID_ANY, label = "Custom (select existing map)")
+        cb1 = wx.RadioButton(parent = self.panel, id = wx.ID_ANY, label = "Custom (select existing map)", style = wx.RB_GROUP)
         hbox1.Add(item = cb1, flag = wx.LEFT)
         cb2 = wx.RadioButton(parent = self.panel, id = wx.ID_ANY, label = "Create by MFD algorithm")
         hbox1.Add(item = cb2, flag = wx.LEFT)
@@ -80,48 +103,41 @@
 
         # Box to insert name of acc map 
 
-        global select2, textOne, textTwo
+        global select2, textOne
 
         select2 = gselect.Select(parent = self.panel, id = wx.ID_ANY, size = (250, -1),
                                type = 'rast', multiple = False) # select existing map
         select.Add(item = select2, pos = (5,0), span = wx.DefaultSpan)
-        textOne = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, style = wx.TE_LEFT) # MFD
+        textOne = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, style = wx.TE_LEFT) 
         select.Add(item = textOne, flag = wx.LEFT | wx.EXPAND , pos = (6,0), span = wx.DefaultSpan)
-        textTwo = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, style = wx.TE_LEFT) # SFD
-        select.Add(item = textTwo, flag = wx.LEFT | wx.EXPAND , pos = (7,0), span = wx.DefaultSpan)
 
 
         # linking buttons and text
         self.texts = {"Custom (select existing map)" : select2,
                       "Create by MFD algorithm" : textOne,
-                      "Create by SFD algorithm" : textTwo}
+                      "Create by SFD algorithm" : textOne}
 
+
         self.selectedText = select2 # default is select existing map
 
         # Disable 
         textOne.Enable(False)
-        textTwo.Enable(False)
 
-
         # RadioButton binders
         cb1.Bind(wx.EVT_RADIOBUTTON, self.OnSelectExistAcc)
         cb2.Bind(wx.EVT_RADIOBUTTON, self.OnSelectMFDAcc)
         cb3.Bind(wx.EVT_RADIOBUTTON, self.OnSelectSFDAcc)
 
-        #textOne.Bind(wx.EVT_TEXT, self.OnSelectMFDAcc)
-        #textTwo.Bind(wx.EVT_TEXT, self.OnSelectSFDAcc)
-        #select2.Bind(wx.EVT_TEXT, self.OnSelectExistAcc)
-
         #----------------------------
 
         # Ask user for Mask
         text3 = wx.StaticText(parent = self.panel, id = wx.ID_ANY, label = "INPUT : Mask (optional)") 
-        select.Add(item = text3, flag = wx.LEFT, pos = (8,0), span = wx.DefaultSpan)
+        select.Add(item = text3, flag = wx.LEFT, pos = (7,0), span = wx.DefaultSpan)
 
         # Add the box for choosing the map
         select3 = gselect.Select(parent = self.panel, id = wx.ID_ANY, size = (250, -1),
                                type = 'rast', multiple = False)
-        select.Add(item = select3, pos = (9,0), span = wx.DefaultSpan)
+        select.Add(item = select3, pos = (8,0), span = wx.DefaultSpan)
 
         # binder
         select3.Bind(wx.EVT_TEXT, self.OnSelectMask)
@@ -130,11 +146,11 @@
 
         # Ask user for threshold
         text4 = wx.StaticText(parent = self.panel, id = wx.ID_ANY, label = "INPUT : Threshold (required)") 
-        select.Add(item = text4, flag = wx.LEFT, pos = (10,0), span = wx.DefaultSpan)
+        select.Add(item = text4, flag = wx.LEFT, pos = (9,0), span = wx.DefaultSpan)
 
         # Box to insert threshold
         txtTwo = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, style = wx.TE_LEFT)
-        select.Add(item = txtTwo, flag = wx.LEFT, pos = (11,0), span = wx.DefaultSpan)
+        select.Add(item = txtTwo, flag = wx.LEFT, pos = (10,0), span = wx.DefaultSpan)
 
         # binder
         txtTwo.Bind(wx.EVT_TEXT, self.OnSelecTh)
@@ -146,11 +162,11 @@
 
         # Flow direction map
         text5 = wx.StaticText(parent = self.panel, id = wx.ID_ANY, label = "OUTPUT : Flow direction map (required)") 
-        select.Add(item = text5, flag = wx.LEFT | wx.EXPAND, pos = (12,0), span = wx.DefaultSpan)
+        select.Add(item = text5, flag = wx.LEFT | wx.EXPAND, pos = (11,0), span = wx.DefaultSpan)
 
         # Box to insert name of new flow dir map (to be created)
         txtThr = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, style = wx.TE_LEFT)
-        select.Add(item = txtThr, flag = wx.LEFT | wx.EXPAND , pos = (13,0), span = wx.DefaultSpan)
+        select.Add(item = txtThr, flag = wx.LEFT | wx.EXPAND , pos = (12,0), span = wx.DefaultSpan)
 
         # binder
         txtThr.Bind(wx.EVT_TEXT, self.OnSelecFd)
@@ -160,11 +176,11 @@
 
         # Streams map
         text6 = wx.StaticText(parent = self.panel, id = wx.ID_ANY, label = "OUTPUT : Streams (required)") 
-        select.Add(item = text6, flag = wx.LEFT | wx.EXPAND, pos = (14,0), span = wx.DefaultSpan)
+        select.Add(item = text6, flag = wx.LEFT | wx.EXPAND, pos = (13,0), span = wx.DefaultSpan)
 
         # Box to insert name of new streams map (to be created)
         txtFou = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, style = wx.TE_LEFT)
-        select.Add(item = txtFou, flag = wx.LEFT | wx.EXPAND , pos = (15,0), span = wx.DefaultSpan)
+        select.Add(item = txtFou, flag = wx.LEFT | wx.EXPAND , pos = (14,0), span = wx.DefaultSpan)
 
         # binder
         txtFou.Bind(wx.EVT_TEXT, self.OnSelecStr)
@@ -173,11 +189,11 @@
 
         # Network map
         text7 = wx.StaticText(parent = self.panel, id = wx.ID_ANY, label = "OUTPUT : Network (required)") 
-        select.Add(item = text7, flag = wx.LEFT | wx.EXPAND, pos = (16,0), span = wx.DefaultSpan)
+        select.Add(item = text7, flag = wx.LEFT | wx.EXPAND, pos = (15,0), span = wx.DefaultSpan)
 
         # Box to insert name of new streams map (to be created)
         txtFiv = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, style = wx.TE_LEFT)
-        select.Add(item = txtFiv, flag = wx.LEFT | wx.EXPAND , pos = (17,0), span = wx.DefaultSpan)
+        select.Add(item = txtFiv, flag = wx.LEFT | wx.EXPAND , pos = (16,0), span = wx.DefaultSpan)
 
         # binder
         txtFiv.Bind(wx.EVT_TEXT, self.OnSelecNet)
@@ -205,9 +221,7 @@
     def OnSelectElev(self, event):
         """!Gets elevation map and assign it to var
         """
-        r_elev = event.GetString()
-        
-        #import pdb; pdb.set_trace()
+        self.r_elev = event.GetString()
 
     def OnSelectMFDAcc(self, event):
         """!Gets new flow accum map and assign it to var
@@ -215,48 +229,50 @@
         if self.selectedText:
             self.selectedText.Enable(False)
         radioSelected = event.GetEventObject()
-        r_new_acc = textOne.GetString[radioSelected.GetLabel()] #FIXME event 
-        r_new_acc.Enable(True)
-        self.SelectedText = r_new_acc
+        self.r_acc = self.texts[radioSelected.GetLabel()]
+        self.r_acc.Enable(True)
+        self.SelectedText = self.r_acc
 
         #select2.Bind(wx.EVT_TEXT, self.OnSelectExistAcc
-        #r_new_acc = event.GetString()
-        # r.watershed elevation = r_elev accumulation = r_new_acc -a (MFD)
+        #r_acc = event.GetString()
+        # r.watershed elevation = r_elev accumulation = r_acc -a (MFD)
 
+        gcmd.RunCommand('r.watershed', elevation = 'r_elev' , accumulation = 'r_acc' , drainage = 'r_new_dir' , convergence = 5 , flags = 'a')
+
     def OnSelectSFDAcc(self, event):
         """!Gets new flow accum map and assign it to var
         """
         if self.selectedText:
             self.selectedText.Enable(False)
         radioSelected = event.GetEventObject()
-        r_new_acc = textTwo.GetString[radioSelected.GetLabel()] #FIXME
-        r_new_acc.Enable(True)
-        self.SelectedText = r_new_acc
+        self.r_acc = self.texts[radioSelected.GetLabel()]
+        self.r_acc.Enable(True)
+        self.SelectedText = self.r_acc
 
-        #r_new_acc = event.GetString()
-        # r.watershed elevation = r_elev accumulation = r_new_acc -a (SFD, flag = -s)
+        #r_acc = event.GetString()
+        # r.watershed elevation = r_elev accumulation = r_acc -a (SFD, flag = -s)
 
+        gcmd.RunCommand('r.watershed', elevation = 'r_elev' , accumulation = 'r_acc' , drainage = 'r_new_dir' , convergence = 5 , flags = 'sa')
+
     def OnSelectExistAcc(self, event):
         """!Gets existing flow acc map and assign it to var
         """
         if self.selectedText:
             self.selectedText.Enable(False)
         radioSelected = event.GetEventObject()
-        r_ex_acc = select2.GetString[radioSelected.GetLabel()] #FIXME
-        r_ex_acc.Enable(True)
-        self.SelectedText = r_ex_acc
+        self.r_acc = self.texts[radioSelected.GetLabel()]
+        self.r_acc.Enable(True)
+        self.SelectedText = self.r_acc
 
-        #r_ex_acc = event.GetString()
-
     def OnSelectMask(self, event):
         """!Gets mask map and assign it to var
         """
-        r_mask = event.GetString()
+        self.r_mask = event.GetString()
 
     def OnSelecTh(self, event):
         """!Gets threshold and assign it to var
         """
-        thre = event.GetString()
+        self.thre = event.GetString()
 
 
     #-------------output maps-------------
@@ -264,21 +280,19 @@
     def OnSelecFd(self, event):
         """!Gets flow direction map and assign it to var
         """
-        r_drain = event.GetString()
+        self.r_drain = event.GetString()
 
     def OnSelecStr(self, event):
         """!Gets stream map and assign it to var
         """
-        r_stre = event.GetString()
+        self.r_stre = event.GetString()
 
     def OnSelecNet(self, event):
         """!Gets network map and assign it to var
         """
-        v_net = event.GetString()
+        self.v_net = event.GetString()
+    
 
-
-      
-
     #-------------Buttons-------------
 
     def buttonData(self):
@@ -304,11 +318,20 @@
         pass
     
 
-    #-------------Get the network extraction-------------
+    #-------------Network extraction-------------
     
     def OnRun(self, event):
-        pass
+        
+        print self.r_elev
+        print self.r_acc
+        print self.thre
+        print self.r_stre
+        print self.v_net
+        print self.r_drain
 
+        gcmd.RunCommand('r.stream.extract', elevation = self.r_elev , accumulation = self.r_acc , threshold = self.thre, 
+                        stream_rast = self.r_stre, stream_vect = self.v_net, direction = self.r_drain)
 
 
 
+



More information about the grass-commit mailing list