[GRASS-SVN] r74175 - in grass/trunk/gui/wxpython: core gui_core location_wizard

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 7 08:07:02 PST 2019


Author: mmetz
Date: 2019-03-07 08:07:02 -0800 (Thu, 07 Mar 2019)
New Revision: 74175

Modified:
   grass/trunk/gui/wxpython/core/utils.py
   grass/trunk/gui/wxpython/gui_core/preferences.py
   grass/trunk/gui/wxpython/location_wizard/wizard.py
Log:
wxGUI: use g.proj list_codes=EPSG to read EPSG codes

Modified: grass/trunk/gui/wxpython/core/utils.py
===================================================================
--- grass/trunk/gui/wxpython/core/utils.py	2019-03-07 16:04:56 UTC (rev 74174)
+++ grass/trunk/gui/wxpython/core/utils.py	2019-03-07 16:07:02 UTC (rev 74175)
@@ -509,45 +509,21 @@
     return path
 
 
-def ReadEpsgCodes(path):
-    """Read EPSG code from the file
+def ReadEpsgCodes():
+    """Read EPSG codes with g.proj
 
-    :param path: full path to the file with EPSG codes
-
-    Raise OpenError on failure.
-
     :return: dictionary of EPSG code
     """
     epsgCodeDict = dict()
-    try:
-        try:
-            f = open(path, "r")
-        except IOError:
-            raise OpenError(_("failed to open '{0}'").format(path))
 
-        code = None
-        for line in f.readlines():
-            line = line.strip()
-            if len(line) < 1 or line.startswith('<metadata>'):
-                continue
+    ret = RunCommand('g.proj',
+                     read=True,
+                     list_codes="EPSG")
 
-            if line[0] == '#':
-                descr = line[1:].strip()
-            elif line[0] == '<':
-                code, params = line.split(" ", 1)
-                try:
-                    code = int(code.replace('<', '').replace('>', ''))
-                except ValueError as e:
-                    raise OpenError('{0}'.format(e))
+    for line in ret.splitlines():
+        code, descr, params = line.split("|")
+        epsgCodeDict[code] = (descr, params)
 
-            if code is not None:
-                epsgCodeDict[code] = (descr, params)
-                code = None
-
-        f.close()
-    except Exception as e:
-        raise OpenError('{0}'.format(e))
-
     return epsgCodeDict
 
 

Modified: grass/trunk/gui/wxpython/gui_core/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/preferences.py	2019-03-07 16:04:56 UTC (rev 74174)
+++ grass/trunk/gui/wxpython/gui_core/preferences.py	2019-03-07 16:07:02 UTC (rev 74175)
@@ -1901,7 +1901,7 @@
             self.winId['projection:statusbar:epsg'])
         wx.BeginBusyCursor()
         try:
-            self.epsgCodeDict = ReadEpsgCodes(path)
+            self.epsgCodeDict = ReadEpsgCodes()
         except OpenError as e:
             wx.EndBusyCursor()
             epsgCombo.SetItems([])

Modified: grass/trunk/gui/wxpython/location_wizard/wizard.py
===================================================================
--- grass/trunk/gui/wxpython/location_wizard/wizard.py	2019-03-07 16:04:56 UTC (rev 74174)
+++ grass/trunk/gui/wxpython/location_wizard/wizard.py	2019-03-07 16:07:02 UTC (rev 74175)
@@ -1699,7 +1699,7 @@
     def OnBrowseCodes(self, event, search=None):
         """Browse EPSG codes"""
         try:
-            self.epsgCodeDict = utils.ReadEpsgCodes(self.tfile.GetValue())
+            self.epsgCodeDict = utils.ReadEpsgCodes()
         except OpenError as e:
             GError(
                 parent=self,
@@ -1946,7 +1946,7 @@
     def OnBrowseCodes(self, event, search=None):
         """Browse IAU codes"""
         try:
-            self.epsgCodeDict = utils.ReadEpsgCodes(self.tfile.GetValue())
+            self.epsgCodeDict = utils.ReadEpsgCodes()
         except OpenError as e:
             GError(
                 parent=self,



More information about the grass-commit mailing list