浏览代码

wxGUI: get gdal formats on request

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42165 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 15 年之前
父节点
当前提交
17e30e1935
共有 3 个文件被更改,包括 69 次插入61 次删除
  1. 0 56
      gui/wxpython/gui_modules/globalvar.py
  2. 5 5
      gui/wxpython/gui_modules/gselect.py
  3. 64 0
      gui/wxpython/gui_modules/utils.py

+ 0 - 56
gui/wxpython/gui_modules/globalvar.py

@@ -158,59 +158,3 @@ if 'g.mlist' in grassCmd['all']:
     have_mlist = True
     have_mlist = True
 else:
 else:
     have_mlist = False
     have_mlist = False
-
-def _getGDALFormats():
-    """!Get dictionary of avaialble GDAL drivers"""
-    if not grass.find_program('r.in.gdal'):
-        return _parseFormats(None)
-    
-    ret = grass.read_command('r.in.gdal',
-                             quiet = True,
-                             flags = 'f')
-    
-    return _parseFormats(ret)
-
-def _getOGRFormats():
-    """!Get dictionary of avaialble OGR drivers"""
-    if not grass.find_program('v.in.ogr'):
-        return _parseFormats(None)
-    
-    ret = grass.read_command('v.in.ogr',
-                             quiet = True,
-                             flags = 'f')
-    
-    return _parseFormats(ret)
-
-def _parseFormats(output):
-    """!Parse r.in.gdal/v.in.ogr -f output"""
-    formats = { 'file'     : list(),
-                'database' : list(),
-                'protocol' : list()
-                }
-    
-    if not output:
-        return formats
-    
-    for line in output.splitlines():
-        format = line.strip().rsplit(':', -1)[1].strip()
-        if format in ('Memory', 'Virtual Raster', 'In Memory Raster'):
-            continue
-        if format in ('PostgreSQL', 'SQLite',
-                      'ODBC', 'ESRI Personal GeoDatabase',
-                      'Rasterlite',
-                      'PostGIS WKT Raster driver'):
-            formats['database'].append(format)
-        elif format in ('GeoJSON',
-                        'OGC Web Coverage Service',
-                        'OGC Web Map Service',
-                        'HTTP Fetching Wrapper'):
-            formats['protocol'].append(format)
-        else:
-            formats['file'].append(format)
-
-    return formats
-
-formats = {
-    'gdal' : _getGDALFormats(),
-    'ogr' : _getOGRFormats()
-    }

+ 5 - 5
gui/wxpython/gui_modules/gselect.py

@@ -831,7 +831,7 @@ class FormatSelect(wx.Choice):
             ftype = 'gdal'
             ftype = 'gdal'
         
         
         formats = list()
         formats = list()
-        for f in globalvar.formats[ftype].values():
+        for f in utils.GetFormats()[ftype].values():
             formats += f
             formats += f
         self.SetItems(formats)
         self.SetItems(formats)
         
         
@@ -1011,16 +1011,16 @@ class GdalSelect(wx.Panel):
             fType = 'gdal'
             fType = 'gdal'
         self.input = { 'file' : [_("File:"),
         self.input = { 'file' : [_("File:"),
                                  dsnFile,
                                  dsnFile,
-                                 globalvar.formats[fType]['file']],
+                                 utils.GetFormats()[fType]['file']],
                        'dir'  : [_("Directory:"),
                        'dir'  : [_("Directory:"),
                                  dsnDir,
                                  dsnDir,
-                                 globalvar.formats[fType]['file']],
+                                 utils.GetFormats()[fType]['file']],
                        'db'   : [_("Database:"),
                        'db'   : [_("Database:"),
                                  dsnDbFile,
                                  dsnDbFile,
-                                 globalvar.formats[fType]['database']],
+                                 utils.GetFormats()[fType]['database']],
                        'pro'  : [_("Protocol:"),
                        'pro'  : [_("Protocol:"),
                                  dsnPro,
                                  dsnPro,
-                                 globalvar.formats[fType]['protocol']],
+                                 utils.GetFormats()[fType]['protocol']],
                        'db-win' : { 'file'   : dsnDbFile,
                        'db-win' : { 'file'   : dsnDbFile,
                                     'text'   : dsnDbText,
                                     'text'   : dsnDbText,
                                     'choice' : dsnDbChoice },
                                     'choice' : dsnDbChoice },

+ 64 - 0
gui/wxpython/gui_modules/utils.py

@@ -648,3 +648,67 @@ def UnicodeString(string):
         return unicode(string, enc)
         return unicode(string, enc)
     
     
     return string
     return string
+
+def _getGDALFormats():
+    """!Get dictionary of avaialble GDAL drivers"""
+    if not grass.find_program('r.in.gdal'):
+        return _parseFormats(None)
+    
+    ret = grass.read_command('r.in.gdal',
+                             quiet = True,
+                             flags = 'f')
+    
+    return _parseFormats(ret)
+
+def _getOGRFormats():
+    """!Get dictionary of avaialble OGR drivers"""
+    if not grass.find_program('v.in.ogr'):
+        return _parseFormats(None)
+    
+    ret = grass.read_command('v.in.ogr',
+                             quiet = True,
+                             flags = 'f')
+    
+    return _parseFormats(ret)
+
+def _parseFormats(output):
+    """!Parse r.in.gdal/v.in.ogr -f output"""
+    formats = { 'file'     : list(),
+                'database' : list(),
+                'protocol' : list()
+                }
+    
+    if not output:
+        return formats
+    
+    for line in output.splitlines():
+        format = line.strip().rsplit(':', -1)[1].strip()
+        if format in ('Memory', 'Virtual Raster', 'In Memory Raster'):
+            continue
+        if format in ('PostgreSQL', 'SQLite',
+                      'ODBC', 'ESRI Personal GeoDatabase',
+                      'Rasterlite',
+                      'PostGIS WKT Raster driver'):
+            formats['database'].append(format)
+        elif format in ('GeoJSON',
+                        'OGC Web Coverage Service',
+                        'OGC Web Map Service',
+                        'HTTP Fetching Wrapper'):
+            formats['protocol'].append(format)
+        else:
+            formats['file'].append(format)
+
+    return formats
+
+formats = None
+
+def GetFormats():
+    """!Get GDAL/OGR formats"""
+    global formats
+    if not formats:
+        formats = {
+            'gdal' : _getGDALFormats(),
+            'ogr' : _getOGRFormats()
+            }
+    
+    return formats