[GRASS-SVN] r38150 - in grass/branches/develbranch_6/gui/wxpython: . gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 1 16:09:13 EDT 2009


Author: martinl
Date: 2009-07-01 16:09:12 -0400 (Wed, 01 Jul 2009)
New Revision: 38150

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
   grass/branches/develbranch_6/gui/wxpython/wxgui.py
Log:
wxGUI: latlong bug-fixes


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2009-07-01 17:07:22 UTC (rev 38149)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2009-07-01 20:09:12 UTC (rev 38150)
@@ -554,19 +554,21 @@
                     proj, coord  = utils.ReprojectCoordinates(coord = (e, n),
                                                               projOut = UserSettings.Get(group='display',
                                                                                          key='projection',
-                                                                                         subkey='proj4'))
+                                                                                         subkey='proj4'),
+                                                              flags = 'd')
                     if coord:
+                        e, n = coord
                         if proj in ('ll', 'latlong', 'longlat'):
-                            self.statusbar.SetStatusText("%s, %s" % (coord[0], coord[1]), 0)
+                            self.statusbar.SetStatusText("%s" % utils.Deg2DMS(e, n), 0)
                         else:
-                            self.statusbar.SetStatusText("%.2f, %.2f" % (coord[0], coord[1]), 0)
+                            self.statusbar.SetStatusText("%.2f; %.2f" % (e, n), 0)
                     else:
                         self.statusbar.SetStatusText(_("Error in projection"), 0)
                 else:
                     if self.Map.projinfo['proj'] == 'll':
                         self.statusbar.SetStatusText("%s" % utils.Deg2DMS(e, n), 0)
                     else:
-                        self.statusbar.SetStatusText("%.2f, %.2f" % (e, n), 0)
+                        self.statusbar.SetStatusText("%.2f; %.2f" % (e, n), 0)
                 
         event.Skip()
 
@@ -787,16 +789,55 @@
         Go to position
         """
         try:
-            e, n = map(float, self.statusbarWin['goto'].GetValue().split(','))
+            if UserSettings.Get(group='display', key='projection', subkey='enabled') and \
+                    UserSettings.Get(group='display', key='projection', subkey='proj4'):
+                # reproject values
+                projIn = UserSettings.Get(group='display',
+                                          key='projection',
+                                          subkey='proj4')
+                projOut = gcmd.RunCommand('g.proj',
+                                          flags = 'jf',
+                                          read = True)
+                proj = projIn.split(' ')[0].split('=')[1]
+                if proj in ('ll', 'latlong', 'longlat'):
+                    e, n = self.statusbarWin['goto'].GetValue().split(';')
+                    e, n = utils.DMS2Deg(e, n)
+                    proj, coord1 = utils.ReprojectCoordinates(coord = (e, n),
+                                                              projIn = projIn,
+                                                              projOut = projOut, flags = 'd')
+                    e, n = coord1
+                else:
+                    e, n = map(float, self.statusbarWin['goto'].GetValue().split(';'))
+                    proj, coord1 = utils.ReprojectCoordinates(coord = (e, n),
+                                                              projIn = projIn,
+                                                              projOut = projOut, flags = 'd')
+                    e, n = coord1
+            else:
+                if self.Map.projinfo['proj'] == 'll':
+                    e, n = self.statusbarWin['goto'].GetValue().split(';')
+                else:
+                    e, n = map(float, self.statusbarWin['goto'].GetValue().split(';'))
+                    
+            region = self.Map.GetCurrentRegion()
+            if UserSettings.Get(group='display', key='projection', subkey='enabled') and \
+                    UserSettings.Get(group='display', key='projection', subkey='proj4'):
+                region['center_easting'], region['center_northing'] = e, n
+            else:
+                if self.Map.projinfo['proj'] == 'll':
+                    region['center_easting'], region['center_northing'] = utils.DMS2Deg(e, n)
+                else:
+                    region['center_easting'], region['center_northing'] = e, n
         except ValueError:
             region = self.Map.GetCurrentRegion()
-            self.statusbarWin['goto'].SetValue("%.2f, %.2f" % (region['center_easting'],
-                                                               region['center_northing']))
+            if self.Map.projinfo['proj'] == 'll':
+                    self.statusbarWin['goto'].SetValue("%s" % utils.Deg2DMS(region['center_easting'], 
+                                                                            region['center_northing']))
+            else:
+                self.statusbarWin['goto'].SetValue("%.2f; %.2f" % (region['center_easting'],
+                                                                   region['center_northing']))
             return
-
-        region = self.Map.GetCurrentRegion()
-        region['center_northing'] = n
-        region['center_easting'] = e
+        
+        
         dn = (region['nsres'] * region['rows']) / 2.
         region['n'] = region['center_northing'] + dn
         region['s'] = region['center_northing'] - dn
@@ -828,67 +869,73 @@
             # enable long help
             self.StatusbarEnableLongHelp()
 
-        elif self.statusbarWin['toggle'].GetSelection() == 1: # Extent
-            if UserSettings.Get(group='display', key='projection', subkey='enabled') and \
-                    UserSettings.Get(group='display', key='projection', subkey='proj4'):
-                projOut = UserSettings.Get(group='display',
-                                           key='projection',
-                                           subkey='proj4')
-                proj, coord1 = utils.ReprojectCoordinates(coord = (self.Map.region["w"], self.Map.region["s"]),
-                                                  projOut = projOut)
-                proj, coord2 = utils.ReprojectCoordinates(coord = (self.Map.region["e"], self.Map.region["n"]),
-                                                  projOut = projOut)
-                
-                if coord1 and coord2:
-                    if proj in ('ll', 'latlong', 'longlat'):
-                        self.statusbar.SetStatusText("%s - %s, %s - %s" %
-                                                     (coord1[0], coord2[0],
-                                                      coord1[1], coord2[1]))
-                    else:
-                        self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f" %
-                                                     (float(coord1[0]), float(coord2[0]),
-                                                      float(coord1[1]), float(coord2[1])))
-                else:
-                    self.statusbar.SetStatusText(_("Error in projection"), 0)
+        elif self.statusbarWin['toggle'].GetSelection() in (1, 2): # Extent
+            sel = self.statusbarWin['toggle'].GetSelection()
+            if sel == 1:
+                region = self.Map.region
             else:
-                self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f" %
-                                             (self.Map.region["w"], self.Map.region["e"],
-                                              self.Map.region["s"], self.Map.region["n"]), 0)
-            # enable long help
-            self.StatusbarEnableLongHelp()
+                region = self.Map.GetRegion() # computation region
 
-        elif self.statusbarWin['toggle'].GetSelection() == 2: # Comp. region
-            compregion = self.Map.GetRegion()
             if UserSettings.Get(group='display', key='projection', subkey='enabled') and \
                     UserSettings.Get(group='display', key='projection', subkey='proj4'):
                 projOut = UserSettings.Get(group='display',
                                            key='projection',
                                            subkey='proj4')
-                proj, coord1 = utils.ReprojectCoordinates(coord = (compregion["w"], compregion["s"]),
+                proj, coord1 = utils.ReprojectCoordinates(coord = (region["w"], region["s"]),
                                                           projOut = projOut)
-                proj, coord2 = utils.ReprojectCoordinates(coord = (compregion["e"], compregion["n"]),
+                proj, coord2 = utils.ReprojectCoordinates(coord = (region["e"], region["n"]),
                                                           projOut = projOut)
-                proj, coord3 = utils.ReprojectCoordinates(coord = (compregion["ewres"], compregion["nsres"]),
-                                                          projOut = projOut)
+                if sel == 2:
+                    proj, coord3 = utils.ReprojectCoordinates(coord = (region["ewres"], region["nsres"]),
+                                                              projOut = projOut)
                 
-                if coord1 and coord2 and coord3:
+                if coord1 and coord2:
                     if proj in ('ll', 'latlong', 'longlat'):
-                        self.statusbar.SetStatusText("%s - %s, %s - %s (%s, %s)" %
-                                                     (coord1[0], coord2[0],
-                                                      coord1[1], coord2[1],
-                                                      coord3[0], coord3[1]))
+                        w, s = utils.Deg2DMS(coord1[0], coord1[1], string = False)
+                        e, n = utils.Deg2DMS(coord2[0], coord2[1], string = False)
+                        if sel == 1:
+                            self.statusbar.SetStatusText("%s - %s, %s - %s" %
+                                                         (w, e, s, n), 0)
+                        else:
+                            ewres, nsres = utils.Deg2DMS(coord3[0], coord3[1], string = False)
+                            self.statusbar.SetStatusText("%s - %s, %s - %s (%s, %s)" %
+                                                         (w, e, s, n, ewres, nsres), 0)
                     else:
-                        self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f (%.2f, %.2f)" %
-                                                     (float(coord1[0]), float(coord2[0]),
-                                                      float(coord1[1]), float(coord2[1]),
-                                                      float(coord3[0]), float(coord3[1])))
+                        w, s = coord1
+                        e, n = coord2
+                        if sel == 1:
+                            self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f" %
+                                                         (w, e, s, n), 0)
+                        else:
+                            ewres, nsres = coord3
+                            self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f (%.2f, %.2f)" %
+                                                         (w, e, s, n, ewres, nsres), 0)
                 else:
                     self.statusbar.SetStatusText(_("Error in projection"), 0)
             else:
-                self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f (%.2f, %.2f)" %
-                                             (compregion["w"], compregion["e"],
-                                              compregion["s"], compregion["n"],
-                                              compregion["ewres"], compregion["nsres"]), 0)
+                if self.Map.projinfo['proj'] == 'll':
+                    w, s = utils.Deg2DMS(region["w"], region["s"],
+                                         string = False)
+                    e, n = utils.Deg2DMS(region["e"], region["n"],
+                                         string = False)
+                    if sel == 1:
+                        self.statusbar.SetStatusText("%s - %s, %s - %s" %
+                                                     (w, e, s, n), 0)
+                    else:
+                        ewres, nsres = utils.Deg2DMS(region['ewres'], region['nsres'],
+                                                     string = False)
+                        self.statusbar.SetStatusText("%s - %s, %s - %s (%s, %s)" %
+                                                     (w, e, s, n, ewres, nsres), 0)
+                else:
+                    w, s = region["w"], region["s"]
+                    e, n = region["e"], region["n"]
+                    if sel == 1:
+                        self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f" %
+                                                     (w, e, s, n), 0)
+                    else:
+                        ewres, nsres = region['ewres'], region['nsres']
+                        self.statusbar.SetStatusText("%s - %s, %s - %s (%s, %s)" %
+                                                     (w, e, s, n, ewres, nsres), 0)
             # enable long help
             self.StatusbarEnableLongHelp()
 
@@ -972,14 +1019,20 @@
                                                                                      subkey='proj4'))
                 if coord:
                     if proj in ('ll', 'latlong', 'longlat'):
-                        self.statusbarWin['goto'].SetValue("%s, %s" % (coord[0],
+                        self.statusbarWin['goto'].SetValue("%s; %s" % (coord[0],
                                                                            coord[1]))
                     else:
-                        self.statusbarWin['goto'].SetValue("%.2f, %.2f" % (coord[0],
+                        self.statusbarWin['goto'].SetValue("%.2f; %.2f" % (coord[0],
                                                                            coord[1]))
+                else:
+                    self.statusbar.SetStatusText(_("Error in projection"), 0)
             else:
-                self.statusbarWin['goto'].SetValue("%.2f, %.2f" % (region['center_easting'],
-                                                                   region['center_northing']))
+                if self.Map.projinfo['proj'] == 'll':
+                    self.statusbarWin['goto'].SetValue("%s" % utils.Deg2DMS(region['center_easting'], 
+                                                                            region['center_northing']))
+                else:
+                    self.statusbarWin['goto'].SetValue("%.2f; %.2f" % (region['center_easting'],
+                                                                       region['center_northing']))
             self.statusbarWin['goto'].Show()
 
             # disable long help

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-07-01 17:07:22 UTC (rev 38149)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-07-01 20:09:12 UTC (rev 38150)
@@ -1600,11 +1600,15 @@
         choices = map(str, self.epsgCodeDict.keys())
 
         list.SetItems(choices)
-        list.SetSelection(0)
-        code = int(list.GetStringSelection())
+        code = int(list.GetValue())
         win = self.FindWindowById(self.winId['display:projection:proj4'])
-        win.SetValue(self.epsgCodeDict[code][1])
-
+        if self.epsgCodeDict.has_key(code):
+            win.SetValue(self.epsgCodeDict[code][1])
+        else:
+            list.SetSelection(0)
+            code = int(list.GetStringSelection())
+            win.SetValue(self.epsgCodeDict[code][1])
+        
     def OnSetProj(self, event):
         """!Enable mapdisplay window statusbar projection"""
         checked = event.IsChecked()

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2009-07-01 17:07:22 UTC (rev 38149)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2009-07-01 20:09:12 UTC (rev 38150)
@@ -264,20 +264,24 @@
     
     return layers
 
-def Deg2DMS(lon, lat):
+def Deg2DMS(lon, lat, string = True):
     """!Convert deg value to dms string
 
-    @param lat latitude
-    @param lon longitude
-
-    @return DMS string
+    @param lon longitude (x)
+    @param lat latitude (y)
+    @param string True to return string otherwise tuple
+    
+    @return DMS string or tuple of values
     @return empty string on error
     """
     try:
         flat = float(lat)
         flon = float(lon)
     except ValueError:
-        return ''
+        if string:
+            return ''
+        else:
+            return None
 
     # fix longitude
     while flon > 180.0:
@@ -301,31 +305,88 @@
     slat = __ll_parts(flat)
     slon = __ll_parts(flon)
 
-    return slon + hlon + '; ' + slat + hlat
+    if string:
+        return slon + hlon + '; ' + slat + hlat
+    
+    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'
+def DMS2Deg(lon, lat):
+    """!Convert dms value to deg
+
+    @param lon longitude (x)
+    @param lat latitude (y)
     
-    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 tuple of converted values
+    @return ValueError on error
+    """
+    x = __ll_parts(lon, reverse = True)
+    y = __ll_parts(lat, reverse = True)
     
-    return str(d) + ':' + m + ':' + s
+    return (x, y)
 
+def __ll_parts(value, reverse = False):
+    """!Converts deg to d:m:s string
+
+    @param value value to be converted
+    @param reverse True to convert from d:m:s to deg
+
+    @return converted value (string/float)
+    @return ValueError on error (reverse == True)
+    """
+    if not reverse:
+        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
+    else: # -> reverse
+        try:
+            d, m, s = value.split(':')
+            hs = s[-1]
+            s = s[:-1]
+        except ValueError:
+            try:
+                d, m = value.split(':')
+                hs = m[-1]
+                m = m[:-1]
+                s = '0.0'
+            except ValueError:
+                try:
+                    d = value
+                    hs = d[-1]
+                    d = d[:-1]
+                    m = '0'
+                    s = '0.0'
+                except ValueError:
+                    raise ValueError
+        
+        if hs not in ('N', 'S', 'E', 'W'):
+            raise ValueError
+        
+        coef = 1.0
+        if hs in ('S', 'W'):
+            coef = -1.0
+        
+        fm = int(m) / 60.0
+        fs = float(s) / (60 * 60)
+        
+        return coef * (float(d) + fm + fs)
+    
 def GetCmdString(cmd):
     """
     Get GRASS command as string.
@@ -437,7 +498,7 @@
             proj = projOut.split(' ')[0].split('=')[1]
         except IndexError:
             proj = ''
-        if proj in ('ll', 'latlong', 'longlat'):
+        if proj in ('ll', 'latlong', 'longlat') and 'd' not in flags:
             return (proj, (e, n))
         else:
             return (proj, (float(e), float(n)))

Modified: grass/branches/develbranch_6/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/wxgui.py	2009-07-01 17:07:22 UTC (rev 38149)
+++ grass/branches/develbranch_6/gui/wxpython/wxgui.py	2009-07-01 20:09:12 UTC (rev 38150)
@@ -936,7 +936,9 @@
         
     def OnPreferences(self, event):
         """!General GUI preferences/settings"""
-        preferences.PreferencesDialog(parent=self).ShowModal()
+        dlg = preferences.PreferencesDialog(parent=self)
+        dlg.CenterOnScreen()
+        dlg.ShowModal()
         
     def DispHistogram(self, event):
         """



More information about the grass-commit mailing list