Преглед на файлове

wxGUI: use g.proj list_codes=EPSG to read EPSG codes

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@74175 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz преди 6 години
родител
ревизия
f7c61a219c
променени са 3 файла, в които са добавени 11 реда и са изтрити 35 реда
  1. 8 32
      gui/wxpython/core/utils.py
  2. 1 1
      gui/wxpython/gui_core/preferences.py
  3. 2 2
      gui/wxpython/location_wizard/wizard.py

+ 8 - 32
gui/wxpython/core/utils.py

@@ -509,44 +509,20 @@ def PathJoin(*args):
     return path
 
 
-def ReadEpsgCodes(path):
-    """Read EPSG code from the file
-
-    :param path: full path to the file with EPSG codes
-
-    Raise OpenError on failure.
+def ReadEpsgCodes():
+    """Read EPSG codes with g.proj
 
     :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
-
-            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))
 
-            if code is not None:
-                epsgCodeDict[code] = (descr, params)
-                code = None
+    ret = RunCommand('g.proj',
+                     read=True,
+                     list_codes="EPSG")
 
-        f.close()
-    except Exception as e:
-        raise OpenError('{0}'.format(e))
+    for line in ret.splitlines():
+        code, descr, params = line.split("|")
+        epsgCodeDict[code] = (descr, params)
 
     return epsgCodeDict
 

+ 1 - 1
gui/wxpython/gui_core/preferences.py

@@ -1901,7 +1901,7 @@ class PreferencesDialog(PreferencesBaseDialog):
             self.winId['projection:statusbar:epsg'])
         wx.BeginBusyCursor()
         try:
-            self.epsgCodeDict = ReadEpsgCodes(path)
+            self.epsgCodeDict = ReadEpsgCodes()
         except OpenError as e:
             wx.EndBusyCursor()
             epsgCombo.SetItems([])

+ 2 - 2
gui/wxpython/location_wizard/wizard.py

@@ -1699,7 +1699,7 @@ class EPSGPage(TitledPage):
     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 @@ class IAUPage(TitledPage):
     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,