|
@@ -648,3 +648,67 @@ def UnicodeString(string):
|
|
|
return unicode(string, enc)
|
|
|
|
|
|
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
|