Explorar o código

Fixing bugs in profile module (hanging/crashing with many transect nodes, and nodes off map) and making interface a little more robust (including better enforcement of proper profiling steps: 1) choose map to profile, 2) draw transect, 3) create profile)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@35111 15284696-431f-4ddb-bdfa-cd5b030d7da7
Michael Barton %!s(int64=16) %!d(string=hai) anos
pai
achega
50187d2636

+ 3 - 0
gui/wxpython/gui_modules/mapdisp.py

@@ -3734,6 +3734,9 @@ class MapFrame(wx.Frame):
                                             id=wx.ID_ANY, pos=wx.DefaultPosition, size=(700,300),
                                             id=wx.ID_ANY, pos=wx.DefaultPosition, size=(700,300),
                                             style=wx.DEFAULT_FRAME_STYLE, rasterList=raster)
                                             style=wx.DEFAULT_FRAME_STYLE, rasterList=raster)
         self.profile.Show()
         self.profile.Show()
+        # Open raster select dialog to make sure that a raster (and the desired raster)
+        # is selected to be profiled
+        self.profile.OnSelectRaster(None)
 
 
     def FormatDist(self, dist):
     def FormatDist(self, dist):
         """Format length numbers and units in a nice way,
         """Format length numbers and units in a nice way,

+ 17 - 11
gui/wxpython/gui_modules/profile.py

@@ -55,6 +55,7 @@ import toolbars
 from debug import Debug as Debug
 from debug import Debug as Debug
 from icon import Icons as Icons
 from icon import Icons as Icons
 from preferences import globalSettings as UserSettings
 from preferences import globalSettings as UserSettings
+import grass
 
 
 class ProfileFrame(wx.Frame):
 class ProfileFrame(wx.Frame):
     """
     """
@@ -250,11 +251,12 @@ class ProfileFrame(wx.Frame):
         #
         #
         # create list of coordinate points for r.profile
         # create list of coordinate points for r.profile
         #
         #
+                
         dist = 0
         dist = 0
         cumdist = 0
         cumdist = 0
         self.coordstr = ''
         self.coordstr = ''
         lasteast = lastnorth = None
         lasteast = lastnorth = None
-
+        
         if len(self.mapwin.polycoords) > 0:
         if len(self.mapwin.polycoords) > 0:
             for point in self.mapwin.polycoords:
             for point in self.mapwin.polycoords:
                 # build string of coordinate points for r.profile
                 # build string of coordinate points for r.profile
@@ -272,13 +274,13 @@ class ProfileFrame(wx.Frame):
         #
         #
         # create datalist for each raster map
         # create datalist for each raster map
         #
         #
+        
         for r in self.raster.itervalues():
         for r in self.raster.itervalues():
             if r['name'] == '':
             if r['name'] == '':
                 continue
                 continue
             r['datalist'] = self.CreateDatalist(r['name'], self.coordstr)
             r['datalist'] = self.CreateDatalist(r['name'], self.coordstr)
             r['plegend'] = _('Profile of %s') % r['name']
             r['plegend'] = _('Profile of %s') % r['name']
 
 
-
             p = gcmd.Command(['r.info',
             p = gcmd.Command(['r.info',
                               'map=%s' % r['name'],
                               'map=%s' % r['name'],
                               '-u',
                               '-u',
@@ -295,6 +297,7 @@ class ProfileFrame(wx.Frame):
         #
         #
         self.ylabel = ''
         self.ylabel = ''
         i = 0
         i = 0
+        
         for r in self.raster.itervalues():
         for r in self.raster.itervalues():
             if r['name'] == '':
             if r['name'] == '':
                 continue
                 continue
@@ -309,6 +312,7 @@ class ProfileFrame(wx.Frame):
         #
         #
         # create list of coordinates for transect segment markers
         # create list of coordinates for transect segment markers
         #
         #
+
         if len(self.mapwin.polycoords) > 0:
         if len(self.mapwin.polycoords) > 0:
             for point in self.mapwin.polycoords:
             for point in self.mapwin.polycoords:
                 # get value of raster cell at coordinate point
                 # get value of raster cell at coordinate point
@@ -400,16 +404,18 @@ class ProfileFrame(wx.Frame):
         Build a list of distance, value pairs for points along transect
         Build a list of distance, value pairs for points along transect
         """
         """
         datalist = []
         datalist = []
+        import subprocess
+        
         try:
         try:
-            cmdlist = ['r.profile',
-                       'input=%s' % raster,
-                       'profile=%s' % coords,
-                       'null=nan',
-                       '--quiet']
-            p = gcmd.Command(cmdlist)
-            for outline in p.ReadStdOutput():
+            p = grass.read_command("r.profile",
+                       input=raster,
+                       profile=coords,
+                       null="nan",
+                       quiet=True
+                       )
+            for outline in p.strip().split('\n'):
                 dist, elev = outline.split(' ')
                 dist, elev = outline.split(' ')
-                datalist.append((dist,elev))
+                if elev != 'nan': datalist.append((dist,elev))
 
 
             return datalist
             return datalist
         except gcmd.CmdError, e:
         except gcmd.CmdError, e:
@@ -424,7 +430,7 @@ class ProfileFrame(wx.Frame):
         segments, these are drawn as points. Profile transect is drawn, using
         segments, these are drawn as points. Profile transect is drawn, using
         methods in mapdisp.py
         methods in mapdisp.py
         """
         """
-        
+    
         if len(self.mapwin.polycoords) == 0 or self.raster[0]['name'] == '':
         if len(self.mapwin.polycoords) == 0 or self.raster[0]['name'] == '':
             dlg = wx.MessageDialog(parent=self,
             dlg = wx.MessageDialog(parent=self,
                                    message=_('You must draw a transect to profile in the map display window.'),
                                    message=_('You must draw a transect to profile in the map display window.'),

+ 3 - 3
gui/wxpython/gui_modules/toolbars.py

@@ -1245,12 +1245,12 @@ class ProfileToolbar(AbstractToolbar):
                 
                 
         # tool, label, bitmap, kind, shortHelp, longHelp, handler
         # tool, label, bitmap, kind, shortHelp, longHelp, handler
         return   (
         return   (
-            (self.transect, 'transect', Icons["transect"].GetBitmap(),
-             wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
-             self.parent.OnDrawTransect),
             (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
             (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
              wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
              self.parent.OnSelectRaster),
              self.parent.OnSelectRaster),
+            (self.transect, 'transect', Icons["transect"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
+             self.parent.OnDrawTransect),
             (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
             (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
              wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
              self.parent.OnCreateProfile),
              self.parent.OnCreateProfile),