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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 1 10:39:07 EDT 2009


Author: martinl
Date: 2009-07-01 10:39:07 -0400 (Wed, 01 Jul 2009)
New Revision: 38143

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
Log:
wxGUI: statusbar projection settings (part 2)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2009-07-01 13:49:17 UTC (rev 38142)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2009-07-01 14:39:07 UTC (rev 38143)
@@ -203,7 +203,7 @@
         # go to
         self.statusbarWin['goto'] = wx.TextCtrl(parent=self.statusbar, id=wx.ID_ANY,
                                                 value="", style=wx.TE_PROCESS_ENTER,
-                                                size=(200, -1))
+                                                size=(300, -1))
         self.statusbarWin['goto'].Hide()
         self.statusbar.Bind(wx.EVT_TEXT_ENTER, self.OnGoTo, self.statusbarWin['goto'])
 
@@ -551,29 +551,15 @@
             else:
                 if UserSettings.Get(group='display', key='projection', subkey='enabled') and \
                         UserSettings.Get(group='display', key='projection', subkey='proj4'):
-                    projIn = gcmd.RunCommand('g.proj',
-                                             flags = 'jf',
-                                             read = True)
-                    projOut = UserSettings.Get(group='display',
-                                               key='projection',
-                                               subkey='proj4').replace('<>', '').strip()
-                    coors = gcmd.RunCommand('m.proj',
-                                            proj_in = projIn,
-                                            proj_out = projOut,
-                                            stdin = '%f|%f' % (e, n),
-                                            read = True)
-                    if coors:
-                        coors = coors.split('\t')
-                        e = coors[0]
-                        n = coors[1].split(' ')[0].strip()
-                        try:
-                            proj = projOut.split(' ')[0].split('=')[1]
-                        except IndexError:
-                            proj = ''
+                    proj, coord  = utils.ReprojectCoordinates(coord = (e, n),
+                                                              projOut = UserSettings.Get(group='display',
+                                                                                         key='projection',
+                                                                                         subkey='proj4'))
+                    if coord:
                         if proj in ('ll', 'latlong', 'longlat'):
-                            self.statusbar.SetStatusText("%s %s" % (e, n), 0)
+                            self.statusbar.SetStatusText("%s, %s" % (coord[0], coord[1]), 0)
                         else:
-                            self.statusbar.SetStatusText("%.2f, %.2f" % (float(e), float(n)), 0)
+                            self.statusbar.SetStatusText("%.2f, %.2f" % (coord[0], coord[1]), 0)
                     else:
                         self.statusbar.SetStatusText(_("Error in projection"), 0)
                 else:
@@ -843,18 +829,66 @@
             self.StatusbarEnableLongHelp()
 
         elif self.statusbarWin['toggle'].GetSelection() == 1: # Extent
-            self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f" %
-                                         (self.Map.region["w"], self.Map.region["e"],
-                                          self.Map.region["s"], self.Map.region["n"]), 0)
+            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)
+            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()
 
         elif self.statusbarWin['toggle'].GetSelection() == 2: # Comp. region
             compregion = self.Map.GetRegion()
-            self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f (%.2f, %.2f)" %
-                                         (compregion["w"], compregion["e"],
-                                          compregion["s"], compregion["n"],
-                                          compregion["ewres"], compregion["nsres"]), 0)
+            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"]),
+                                                          projOut = projOut)
+                proj, coord2 = utils.ReprojectCoordinates(coord = (compregion["e"], compregion["n"]),
+                                                          projOut = projOut)
+                proj, coord3 = utils.ReprojectCoordinates(coord = (compregion["ewres"], compregion["nsres"]),
+                                                          projOut = projOut)
+                
+                if coord1 and coord2 and coord3:
+                    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]))
+                    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])))
+                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)
             # enable long help
             self.StatusbarEnableLongHelp()
 
@@ -929,8 +963,23 @@
         elif self.statusbarWin['toggle'].GetSelection() == 7: # go to
             self.statusbar.SetStatusText("")
             region = self.Map.GetCurrentRegion()
-            self.statusbarWin['goto'].SetValue("%.2f, %.2f" % (region['center_easting'],
-                                                               region['center_northing']))
+            if UserSettings.Get(group='display', key='projection', subkey='enabled') and \
+                        UserSettings.Get(group='display', key='projection', subkey='proj4'):
+                proj, coord  = utils.ReprojectCoordinates(coord = (region['center_easting'],
+                                                                   region['center_northing']),
+                                                          projOut = UserSettings.Get(group='display',
+                                                                                     key='projection',
+                                                                                     subkey='proj4'))
+                if coord:
+                    if proj in ('ll', 'latlong', 'longlat'):
+                        self.statusbarWin['goto'].SetValue("%s, %s" % (coord[0],
+                                                                           coord[1]))
+                    else:
+                        self.statusbarWin['goto'].SetValue("%.2f, %.2f" % (coord[0],
+                                                                           coord[1]))
+            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 13:49:17 UTC (rev 38142)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-07-01 14:39:07 UTC (rev 38143)
@@ -1155,11 +1155,11 @@
         label = wx.StaticText(parent=panel, id=wx.ID_ANY,
                               label=_("EPSG code:"))
         epsgCode = wx.ComboBox(parent=panel, id=wx.ID_ANY,
-                               name="GetStringSelection",
+                               name="GetValue",
                                size = (150, -1))
         self.epsgCodeDict = dict()
-        epsgCode.SetStringSelection(self.settings.Get(group='display', key='projection', subkey='epsg'))
-        self.winId['display:projection:epgs'] = epsgCode.GetId()
+        epsgCode.SetValue(str(self.settings.Get(group='display', key='projection', subkey='epsg')))
+        self.winId['display:projection:epsg'] = epsgCode.GetId()
         
         gridSizer.Add(item=label,
                       pos=(row, 0),
@@ -1586,10 +1586,10 @@
         path = win.GetValue()
 
         self.epsgCodeDict = utils.ReadEpsgCodes(path)
-        list = self.FindWindowById(self.winId['display:projection:epgs'])
+        list = self.FindWindowById(self.winId['display:projection:epsg'])
         if type(self.epsgCodeDict) == type(''):
             wx.MessageBox(parent=self,
-                          message=_("Unable to read EPGS codes: %s") % self.epsgCodeDict,
+                          message=_("Unable to read EPSG codes: %s") % self.epsgCodeDict,
                           caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
             self.epsgCodeDict = dict()
             list.SetItems([])
@@ -1609,7 +1609,7 @@
         """!Enable mapdisplay window statusbar projection"""
         checked = event.IsChecked()
 
-        winCode = self.FindWindowById(self.winId['display:projection:epgs'])
+        winCode = self.FindWindowById(self.winId['display:projection:epsg'])
         winString = self.FindWindowById(self.winId['display:projection:proj4'])
         
         winCode.Enable(checked)
@@ -1621,7 +1621,7 @@
         win = self.FindWindowById(self.winId['display:projection:proj4'])
         if not self.epsgCodeDict:
             wx.MessageBox(parent=self,
-                          message=_("EPSG code %s not found") % str(code),
+                          message=_("EPSG code %s not found") % event.GetString(),
                           caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
             winCode.SetValue('')
             win.SetValue('')
@@ -1637,7 +1637,7 @@
         
         
         try:
-            win.SetValue(self.epsgCodeDict[code][1])
+            win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
         except KeyError:
             wx.MessageBox(parent=self,
                           message=_("EPSG code %s not found") % str(code),

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2009-07-01 13:49:17 UTC (rev 38142)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2009-07-01 14:39:07 UTC (rev 38143)
@@ -409,3 +409,37 @@
         return str(e)
     
     return epsgCodeDict
+
+def ReprojectCoordinates(coord, projOut, projIn = None, flags = ''):
+    """!Reproject coordinates
+
+    @param coord coordinates given as tuple
+    @param projOut output projection
+    @param projIn input projection (use location projection settings)
+
+    @return reprojected coordinates (returned as tuple)
+    """
+    if not projIn:
+        projIn = gcmd.RunCommand('g.proj',
+                                 flags = 'jf',
+                                 read = True)
+    coors = gcmd.RunCommand('m.proj',
+                            flags = flags,
+                            proj_in = projIn,
+                            proj_out = projOut,
+                            stdin = '%f|%f' % (coord[0], coord[1]),
+                            read = True)
+    if coors:
+        coors = coors.split('\t')
+        e = coors[0]
+        n = coors[1].split(' ')[0].strip()
+        try:
+            proj = projOut.split(' ')[0].split('=')[1]
+        except IndexError:
+            proj = ''
+        if proj in ('ll', 'latlong', 'longlat'):
+            return (proj, (e, n))
+        else:
+            return (proj, (float(e), float(n)))
+    
+    return (None, None)



More information about the grass-commit mailing list