[GRASS-SVN] r34834 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Dec 12 08:32:48 EST 2008


Author: martinl
Date: 2008-12-12 08:32:48 -0500 (Fri, 12 Dec 2008)
New Revision: 34834

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: can't handle whole-Earth extent (trac #395)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-12-12 13:22:43 UTC (rev 34833)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-12-12 13:32:48 UTC (rev 34834)
@@ -2183,8 +2183,16 @@
 
         # if new region has been calculated, set the values
         if newreg != {}:
+            # LL locations
+            if self.parent.Map.projinfo['proj'] == 'll':
+                if newreg['n'] > 90.0:
+                    newreg['n'] = 90.0
+                if newreg['s'] < -90.0:
+                    newreg['s'] = -90.0
+            
             ce = newreg['w'] + (newreg['e'] - newreg['w']) / 2
             cn = newreg['s'] + (newreg['n'] - newreg['s']) / 2
+            
             if hasattr(self, "vdigitMove"):
                 # xo = self.Cell2Pixel((self.Map.region['center_easting'], self.Map.region['center_northing']))
                 # xn = self.Cell2Pixel(ce, cn))
@@ -2641,13 +2649,8 @@
         # Init print module and classes
         #
         self.printopt = disp_print.PrintOptions(self, self.MapWindow)
-
+        
         #
-        # Current location information
-        #
-        self.projinfo = self.Map.ProjInfo()
-
-        #
         # Initialization of digitization tool
         #
         self.digit = None
@@ -2915,7 +2918,10 @@
                 self.statusbar.SetStatusText("%.2f, %.2f (seg: %.2f; tot: %.2f)" % \
                                                  (e, n, distance_seg, distance_tot), 0)
             else:
-                self.statusbar.SetStatusText("%.2f, %.2f" % (e, n), 0)
+                if self.Map.projinfo['proj'] == 'll':
+                    self.statusbar.SetStatusText("%s" % utils.Deg2DMS(e, n), 0)
+                else:
+                    self.statusbar.SetStatusText("%.2f, %.2f" % (e, n), 0)
         
         event.Skip()
 
@@ -3663,8 +3669,8 @@
                                            'to measure.%s'
                                            'Double click with left button to clear.') % \
                                              (os.linesep), style)
-        if self.projinfo['proj'] != 'xy':
-            units = self.projinfo['units']
+        if self.Map.projinfo['proj'] != 'xy':
+            units = self.Map.projinfo['units']
             style = self.gismanager.goutput.cmd_output.StyleCommand
             self.gismanager.goutput.WriteLog(_('Measuring distance') + ' ('
                                              + units + '):',
@@ -3693,7 +3699,7 @@
         strdist = str(d)
         strtotdist = str(td)
 
-        if self.projinfo['proj'] == 'xy' or 'degree' not in self.projinfo['unit']:
+        if self.Map.projinfo['proj'] == 'xy' or 'degree' not in self.Map.projinfo['unit']:
             angle = int(math.degrees(math.atan2(north,east)) + 0.5)
             angle = angle+90
             if angle < 0: angle = 360+angle
@@ -3727,7 +3733,7 @@
         as a function of length. From code by Hamish Bowman
         Grass Development Team 2006"""
 
-        mapunits = self.projinfo['units']
+        mapunits = self.Map.projinfo['units']
         if mapunits == 'metres': mapunits = 'meters'
         outunits = mapunits
         dist = float(dist)
@@ -3820,7 +3826,7 @@
         id = 0 # unique index for overlay layer
 
         # If location is latlon, only display north arrow (scale won't work)
-        #        proj = self.projinfo['proj']
+        #        proj = self.Map.projinfo['proj']
         #        if proj == 'll':
         #            barcmd = 'd.barscale -n'
         #        else:

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py	2008-12-12 13:22:43 UTC (rev 34833)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py	2008-12-12 13:32:48 UTC (rev 34834)
@@ -391,6 +391,8 @@
         os.environ["GRASS_TRANSPARENT"] = "TRUE"
         os.environ["GRASS_BACKGROUNDCOLOR"] = "ffffff"
 
+        self.projinfo = self.ProjInfo()
+        
     def InitRegion(self):
         """
         Initialize current region settings.
@@ -547,6 +549,13 @@
         self.region['e'] = self.region['center_easting'] + ew
         self.region['w'] = self.region['center_easting'] - ew
 
+        # LL locations
+        if self.projinfo['proj'] == 'll':
+            if self.region['n'] > 90.0:
+                self.region['n'] = 90.0
+            if self.region['s'] < -90.0:
+                self.region['s'] = -90.0
+        
     def ChangeMapSize(self, (width, height)):
         """Change size of rendered map.
         

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2008-12-12 13:22:43 UTC (rev 34833)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2008-12-12 13:32:48 UTC (rev 34834)
@@ -260,6 +260,68 @@
     
     return layers
 
+def Deg2DMS(lon, lat):
+    """Convert deg value to dms string
+
+    @param lat latitude
+    @param lon longitude
+
+    @return DMS string
+    @return empty string on error
+    """
+    try:
+        flat = float(lat)
+        flon = float(lon)
+    except ValueError:
+        return ''
+
+    # fix longitude
+    while flon > 180.0:
+        flon -= 360.0
+    while flon < -180.0:
+        flon += 360.0
+
+    # hemisphere
+    if flat < 0.0:
+        flat = abs(flat)
+        hlat = 'S'
+    else:
+        hlat = 'N'
+
+    if flon < 0.0:
+        hlon = 'W'
+        flon = abs(flon)
+    else:
+        hlon = 'E'
+
+    slat = __ll_parts(flat)
+    slon = __ll_parts(flon)
+
+    return slon + hlon + '; ' + slat + hlat
+
+def __ll_parts(value):
+    """Converts deg to d:m:s string"""
+    if value == 0.0:
+        return '00:00:00.0000'
+    
+    d = int(int(value))
+    m = int((value - d) * 60)
+    s = ((value - d) * 60 - m) * 60
+    if m < 0:
+        m = '00'
+    elif m < 10:
+        m = '0' + str(m)
+    else:
+        m = str(m)
+    if s < 0:
+        s = '00.0000'
+    elif s < 10.0:
+        s = '0%.4f' % s
+    else:
+        s = '%.4f' % s
+    
+    return str(d) + ':' + m + ':' + s
+
 def reexec_with_pythonw():
     """Re-execute Python on Mac OS"""
     if sys.platform == 'darwin' and \



More information about the grass-commit mailing list