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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 1 10:54:20 EDT 2009


Author: martinl
Date: 2009-07-01 10:54:19 -0400 (Wed, 01 Jul 2009)
New Revision: 38145

Modified:
   grass/trunk/gui/wxpython/gui_modules/location_wizard.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: statusbar projection settings
       (merge from devbr6, r38141, r38143)


Modified: grass/trunk/gui/wxpython/gui_modules/location_wizard.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/location_wizard.py	2009-07-01 14:45:33 UTC (rev 38144)
+++ grass/trunk/gui/wxpython/gui_modules/location_wizard.py	2009-07-01 14:54:19 UTC (rev 38145)
@@ -1412,38 +1412,21 @@
         
     def OnBrowseCodes(self, event, search=None):
         """!Browse EPSG codes"""
-#        try:
-        if True:
-            data = []
-            self.epsgCodeDict = {}
-            f = open(self.tfile.GetValue(), "r")
-            i = 0
-            code = None
-            for line in f.readlines():
-                line = line.strip()
-                if len(line) < 1:
-                    continue
-                
-                if line[0] == '#':
-                    descr = line[1:].strip()
-                elif line[0] == '<':
-                    code, params = line.split(" ", 1)
-                    code = int(code.replace('<', '').replace('>', ''))
+        self.epsgCodeDict = utils.ReadEpsgCodes(self.tfile.GetValue())
+        if type(self.epsgCodeDict) == type(''):
+            wx.MessageBox(parent=self,
+                          message=_("Unable to read EPGS codes: %s") % self.epsgCodeDict,
+                          caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            self.epsglist.Populate([], update=True)
+            return
 
-                if code is not None:
-                    data.append((code, descr, params))
-                    self.epsgCodeDict[code] = (descr, params)
-                    code = None
-                i += 1
-            f.close()
-
-            self.epsglist.Populate(data, update=True)
-#         except StandardError, e:
-#             wx.MessageBox(parent=self,
-#                           message=_("Unable to read EPGS codes: %s") % e,
-#                           caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
-#             self.epsglist.Populate([], update=True)
-
+        data = []
+        for code, val in self.epsgCodeDict.iteritems():
+            if code is not None:
+                data.append((code, val[0], val[1]))
+                
+        self.epsglist.Populate(data, update=True)
+        
 class CustomPage(TitledPage):
     """
     Wizard page for entering custom PROJ.4 string

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2009-07-01 14:45:33 UTC (rev 38144)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2009-07-01 14:54:19 UTC (rev 38145)
@@ -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'])
 
@@ -549,11 +549,25 @@
                 self.statusbar.SetStatusText("%.2f, %.2f (seg: %.2f; tot: %.2f)" % \
                                                  (e, n, distance_seg, distance_tot), 0)
             else:
-                if self.Map.projinfo['proj'] == 'll':
-                    self.statusbar.SetStatusText("%s" % utils.Deg2DMS(e, n), 0)
+                if UserSettings.Get(group='display', key='projection', subkey='enabled') and \
+                        UserSettings.Get(group='display', key='projection', subkey='proj4'):
+                    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" % (coord[0], coord[1]), 0)
+                        else:
+                            self.statusbar.SetStatusText("%.2f, %.2f" % (coord[0], coord[1]), 0)
+                    else:
+                        self.statusbar.SetStatusText(_("Error in projection"), 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()
 
     def OnDraw(self, event):
@@ -815,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()
 
@@ -901,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/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2009-07-01 14:45:33 UTC (rev 38144)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2009-07-01 14:54:19 UTC (rev 38145)
@@ -112,7 +112,12 @@
                     },
                 'bgcolor': {
                     'color' : (255, 255, 255, 255),
-                    }
+                    },
+                'projection' : {
+                    'enabled' : False,
+                    'proj4'   : '',
+                    'epsg'    : '',
+                    },
                 },
             #
             # advanced
@@ -1007,6 +1012,9 @@
         sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
         border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
 
+        #
+        # display settings
+        #
         box   = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Default display settings"))
         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
 
@@ -1113,11 +1121,94 @@
 
         sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
         border.Add(item=sizer, proportion=0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
+
+        #
+        # projections statusbar settings
+        #
+        box   = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Projection statusbar settings"))
+        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+
+        gridSizer = wx.GridBagSizer (hgap=3, vgap=3)
+        gridSizer.AddGrowableCol(1)
+
+        row = 0
+        useProj = wx.CheckBox(parent=panel, id=wx.ID_ANY,
+                              label=_("Use defined projection"),
+                              name="IsChecked")
+        useProj.SetValue(self.settings.Get(group='display', key='projection', subkey='enabled'))
+        self.winId['display:projection:enabled'] = useProj.GetId()
+
+        gridSizer.Add(item=useProj,
+                      pos=(row, 0), span=(1, 3))
+
+        # epsg
+        row += 1
+        label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                              label=_("EPSG code:"))
+        epsgCode = wx.ComboBox(parent=panel, id=wx.ID_ANY,
+                               name="GetValue",
+                               size = (150, -1))
+        self.epsgCodeDict = dict()
+        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),
+                      flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item=epsgCode,
+                      pos=(row, 1), span=(1, 2))
+        
+        # proj
+        row += 1
+        label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                              label=_("Proj.4 string:"))
+        projString = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
+                                 value=self.settings.Get(group='display', key='projection', subkey='proj4'),
+                                 name="GetValue", size=(400, -1))
+        self.winId['display:projection:proj4'] = projString.GetId()
+
+        gridSizer.Add(item=label,
+                      pos=(row, 0),
+                      flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item=projString,
+                      pos=(row, 1), span=(1, 2),
+                      flag = wx.ALIGN_CENTER_VERTICAL)
+        
+        # epsg file
+        row += 1
+        label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                              label=_("EPSG file:"))
+        projFile = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
+                               value=utils.PathJoin(os.environ["GRASS_PROJSHARE"], 'epsg'),
+                               name="GetValue", size=(400, -1))
+        epsgLoad = wx.Button(parent=panel, id=wx.ID_ANY,
+                             label=_("&Load EPSG codes"))
+        self.winId['display:projection:projFile'] = projFile.GetId()
+        
+        if not useProj.IsChecked():
+            projString.Enable(False)
+            epsgCode.Enable(False)
+
+        gridSizer.Add(item=label,
+                      pos=(row, 0),
+                      flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item=projFile,
+                      pos=(row, 1),
+                      flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item=epsgLoad,
+                      pos=(row, 2))
+        
+        sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
+        border.Add(item=sizer, proportion=0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
+
         panel.SetSizer(border)
         
         # bindings
         fontButton.Bind(wx.EVT_BUTTON, self.OnSetFont)
+        epsgLoad.Bind(wx.EVT_BUTTON, self.OnLoadEpsgCodes)
+        epsgCode.Bind(wx.EVT_COMBOBOX, self.OnSetEpsgCode)
+        epsgCode.Bind(wx.EVT_TEXT_ENTER, self.OnSetEpsgCode)
+        useProj.Bind(wx.EVT_CHECKBOX, self.OnSetProj)
         
         return panel
 
@@ -1480,6 +1571,71 @@
         
         return panel
 
+    def OnLoadEpsgCodes(self, event):
+        """!Load EPSG codes from the file"""
+        win = self.FindWindowById(self.winId['display:projection:projFile'])
+        path = win.GetValue()
+
+        self.epsgCodeDict = utils.ReadEpsgCodes(path)
+        list = self.FindWindowById(self.winId['display:projection:epsg'])
+        if type(self.epsgCodeDict) == type(''):
+            wx.MessageBox(parent=self,
+                          message=_("Unable to read EPSG codes: %s") % self.epsgCodeDict,
+                          caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            self.epsgCodeDict = dict()
+            list.SetItems([])
+            list.SetValue('')
+            self.FindWindowById(self.winId['display:projection:proj4']).SetValue('')
+            return
+        
+        choices = map(str, self.epsgCodeDict.keys())
+
+        list.SetItems(choices)
+        list.SetSelection(0)
+        code = int(list.GetStringSelection())
+        win = self.FindWindowById(self.winId['display:projection:proj4'])
+        win.SetValue(self.epsgCodeDict[code][1])
+
+    def OnSetProj(self, event):
+        """!Enable mapdisplay window statusbar projection"""
+        checked = event.IsChecked()
+
+        winCode = self.FindWindowById(self.winId['display:projection:epsg'])
+        winString = self.FindWindowById(self.winId['display:projection:proj4'])
+        
+        winCode.Enable(checked)
+        winString.Enable(checked)
+        
+    def OnSetEpsgCode(self, event):
+        """!EPSG code selected"""
+        winCode = self.FindWindowById(event.GetId())
+        win = self.FindWindowById(self.winId['display:projection:proj4'])
+        if not self.epsgCodeDict:
+            wx.MessageBox(parent=self,
+                          message=_("EPSG code %s not found") % event.GetString(),
+                          caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            winCode.SetValue('')
+            win.SetValue('')
+        
+        try:
+            code = int(event.GetString())
+        except ValueError:
+            wx.MessageBox(parent=self,
+                          message=_("EPSG code %s not found") % str(code),
+                          caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            winCode.SetValue('')
+            win.SetValue('')
+        
+        
+        try:
+            win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
+        except KeyError:
+            wx.MessageBox(parent=self,
+                          message=_("EPSG code %s not found") % str(code),
+                          caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            winCode.SetValue('')
+            win.SetValue('')
+        
     def OnSetFont(self, event):
         """'Set font' button pressed"""
         dlg = DefaultFontDialog(parent=self, id=wx.ID_ANY,

Modified: grass/trunk/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/utils.py	2009-07-01 14:45:33 UTC (rev 38144)
+++ grass/trunk/gui/wxpython/gui_modules/utils.py	2009-07-01 14:54:19 UTC (rev 38145)
@@ -377,3 +377,71 @@
             not sys.executable.endswith('MacOS/Python'):
         print >> sys.stderr, 're-executing using pythonw'
         os.execvp('pythonw', ['pythonw', __file__] + sys.argv[1:])
+
+def ReadEpsgCodes(path):
+    """!Read EPSG code from the file
+
+    @param path full path to the file with EPSG codes
+
+    @return dictionary of EPSG code
+    @return string on error
+    """
+    epsgCodeDict = dict()
+    try:
+        f = open(path, "r")
+        i = 0
+        code = None
+        for line in f.readlines():
+            line = line.strip()
+            if len(line) < 1:
+                continue
+                
+            if line[0] == '#':
+                descr = line[1:].strip()
+            elif line[0] == '<':
+                code, params = line.split(" ", 1)
+                code = int(code.replace('<', '').replace('>', ''))
+
+            if code is not None:
+                epsgCodeDict[code] = (descr, params)
+                code = None
+            i += 1
+        f.close()
+    except StandardError, e:
+        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