[GRASS-SVN] r45897 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 10 18:21:00 EDT 2011


Author: martinl
Date: 2011-04-10 15:21:00 -0700 (Sun, 10 Apr 2011)
New Revision: 45897

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
Log:
wxGUI: fix measuring tool on LL-locations (requires ctypes)


Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2011-04-10 21:55:22 UTC (rev 45896)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2011-04-10 22:21:00 UTC (rev 45897)
@@ -74,6 +74,8 @@
 # for standalone app
 cmdfilename = None
 
+haveCtypes = False
+
 class MapFrame(wx.Frame):
     """!Main frame for map display window. Drawing takes place in
     child double buffered drawing window.
@@ -1613,20 +1615,20 @@
         along transect drawn on map display
         """
         self.totaldist = 0.0 # total measured distance
-
-        # switch GIS Manager to output console to show measure results
+        
+        # switch Layer Manager to output console to show measure results
         self._layerManager.notebook.SetSelection(1)
-
+        
         # change mouse to draw line for measurement
         self.MapWindow.mouse['use'] = "measure"
         self.MapWindow.mouse['box'] = "line"
         self.MapWindow.zoomtype = 0
         self.MapWindow.pen     = wx.Pen(colour = 'red', width = 2, style = wx.SHORT_DASH)
         self.MapWindow.polypen = wx.Pen(colour = 'green', width = 2, style = wx.SHORT_DASH)
-
+        
         # change the cursor
         self.MapWindow.SetCursor(self.cursors["pencil"])
-
+        
         # initiating output
         style = self._layerManager.goutput.cmd_output.StyleWarning
         self._layerManager.goutput.WriteLog(_('Click and drag with left mouse button '
@@ -1635,14 +1637,23 @@
                                                 (os.linesep), style)
         if self.Map.projinfo['proj'] != 'xy':
             units = self.Map.projinfo['units']
-            style = self._layerManager.goutput.cmd_output.StyleCommand
-            self._layerManager.goutput.WriteLog(_('Measuring distance') + ' ('
-                                                + units + '):',
-                                                style)
+            self._layerManager.goutput.WriteCmdLog(_('Measuring distance') + ' ('
+                                                   + units + '):')
         else:
-            self._layerManager.goutput.WriteLog(_('Measuring distance:'),
-                                                style)
+            self._layerManager.goutput.WriteCmdLog(_('Measuring distance:'))
+        
+        if self.Map.projinfo['proj'] == 'll':
+            try:
+                import grass.lib.gis as gislib
+                global haveCtypes
+                haveCtypes = True
 
+                gislib.G_begin_distance_calculations()
+            except ImportError, e:
+                self._layerManager.goutput.WriteWarning(_('Geodesic distance is not yet '
+                                                          'supported by this tool.\n'
+                                                          'Reason: %s' % e))
+        
     def MeasureDist(self, beginpt, endpt):
         """!Calculate map distance from screen distance
         and print to output window
@@ -1665,7 +1676,7 @@
             angle = int(math.degrees(math.atan2(north,east)) + 0.5)
             angle = 180 - angle
             if angle < 0:
-                angle = 360+angle
+                angle = 360 + angle
             
             mstring = '%s = %s %s\n%s = %s %s\n%s = %d %s\n%s' \
                 % (_('segment'), strdist, dunits,
@@ -1726,12 +1737,15 @@
                 divisor = 5280.0
             else:
                 outunits = 'ft'
-        elif 'degree' in mapunits:
+        elif 'degree' in mapunits and \
+                not haveCtypes:
             if dist < 1:
                 outunits = 'min'
                 divisor = (1/60.0)
             else:
                 outunits = 'deg'
+        else:
+            outunits = 'meters'
         
         # format numbers in a nice way
         if (dist/divisor) >= 2500.0:

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-04-10 21:55:22 UTC (rev 45896)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-04-10 22:21:00 UTC (rev 45897)
@@ -38,6 +38,12 @@
 from preferences import globalSettings as UserSettings
 from units import ConvertValue as UnitsConvertValue
 
+try:
+    import grass.lib.gis as gislib
+    haveCtypes = True
+except ImportError:
+    haveCtypes = False
+
 class MapWindow(object):
     """!Abstract map display window class
     
@@ -1746,10 +1752,8 @@
     def Distance(self, beginpt, endpt, screen = True):
         """!Calculete distance
         
-        LL-locations not supported
+        Ctypes required for LL-locations
         
-        @todo Use m.distance
-        
         @param beginpt first point
         @param endpt second point
         @param screen True for screen coordinates otherwise EN
@@ -1764,4 +1768,9 @@
         dEast  = (e2 - e1)
         dNorth = (n2 - n1)
         
-        return (math.sqrt(math.pow((dEast), 2) + math.pow((dNorth), 2)), (dEast, dNorth))
+        if self.parent.Map.projinfo['proj'] == 'll' and haveCtypes:
+            dist = gislib.G_distance(e1, n1, e2, n2)
+        else:
+            dist = math.sqrt(math.pow((dEast), 2) + math.pow((dNorth), 2))
+        
+        return (dist, (dEast, dNorth))



More information about the grass-commit mailing list