[GRASS-SVN] r51107 - grass/trunk/gui/wxpython/gui_core
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Mar 18 09:49:33 EDT 2012
Author: martinl
Date: 2012-03-18 06:49:33 -0700 (Sun, 18 Mar 2012)
New Revision: 51107
Modified:
grass/trunk/gui/wxpython/gui_core/dialogs.py
grass/trunk/gui/wxpython/gui_core/gselect.py
Log:
wxGUI: support postgis links (v.external -p)
Modified: grass/trunk/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/dialogs.py 2012-03-18 12:59:01 UTC (rev 51106)
+++ grass/trunk/gui/wxpython/gui_core/dialogs.py 2012-03-18 13:49:33 UTC (rev 51107)
@@ -1727,7 +1727,8 @@
else:
self.SetTitle(_("Import raster data"))
- self.dsnInput = GdalSelect(parent = self, panel = self.panel, ogr = ogr)
+ self.dsnInput = GdalSelect(parent = self, panel = self.panel,
+ ogr = ogr, link = link)
if link:
self.add.SetLabel(_("Add linked layers into layer tree"))
@@ -1758,9 +1759,8 @@
self.commandId = -1
data = self.list.GetLayers()
- dsn = self.dsnInput.GetDsn()
+ dsn, flags = self.dsnInput.GetDsn(flags = True)
ext = self.dsnInput.GetFormatExt()
-
for layer, output in data:
if self.importType == 'ogr':
if ext and layer.rfind(ext) > -1:
@@ -1797,6 +1797,9 @@
if self.options[key].IsChecked():
cmd.append('-%s' % key)
+ for f in flags:
+ cmd.append('-%s' % f)
+
if UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'):
cmd.append('--overwrite')
@@ -2035,10 +2038,10 @@
def LoadData(self, data = None):
"""!Load data into list"""
+ self.DeleteAllItems()
if data is None:
return
- self.DeleteAllItems()
for item in data:
index = self.InsertStringItem(sys.maxint, str(item[0]))
for i in range(1, len(item)):
Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py 2012-03-18 12:59:01 UTC (rev 51106)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py 2012-03-18 13:49:33 UTC (rev 51107)
@@ -1097,7 +1097,7 @@
return ''
class GdalSelect(wx.Panel):
- def __init__(self, parent, panel, ogr = False, dest = False,
+ def __init__(self, parent, panel, ogr = False, link = False, dest = False,
default = 'file', exclude = [], envHandler = None):
"""!Widget for selecting GDAL/OGR datasource, format
@@ -1123,31 +1123,40 @@
# source type
sources = list()
- self.sourceMap = { 'file' : -1,
- 'dir' : -1,
- 'db' : -1,
- 'pro' : -1,
+ self.sourceMap = { 'file' : -1,
+ 'dir' : -1,
+ 'db' : -1,
+ 'db-pg' : -1,
+ 'pro' : -1,
'native' : -1 }
idx = 0
+ if ogr and link:
+ extraLabel = " (OGR)"
+ else:
+ extraLabel = ""
if dest:
sources.append(_("Native"))
self.sourceMap['native'] = idx
idx += 1
if 'file' not in exclude:
- sources.append(_("File"))
+ sources.append(_("File") + extraLabel)
self.sourceMap['file'] = idx
idx += 1
if 'directory' not in exclude:
- sources.append(_("Directory"))
+ sources.append(_("Directory") + extraLabel)
self.sourceMap['dir'] = idx
idx += 1
if 'database' not in exclude:
- sources.append(_("Database"))
+ sources.append(_("Database") + extraLabel)
self.sourceMap['db'] = idx
idx += 1
if 'protocol' not in exclude:
- sources.append(_("Protocol"))
+ sources.append(_("Protocol") + extraLabel)
self.sourceMap['pro'] = idx
+ idx += 1
+ if 'database' not in exclude and ogr and link:
+ sources.append(_("PostGIS (PG)"))
+ self.sourceMap['db-pg'] = idx
if self.ogr:
self.settingsFile = os.path.join(GetSettingsPath(), 'wxOGR')
@@ -1250,6 +1259,9 @@
'text' : dsnDbText,
'choice' : dsnDbChoice },
'native' : [_("Name:"), dsnDir, ''],
+ 'db-pg' : [_("Name:"),
+ dsnDbChoice,
+ ["PostgreSQL"]],
}
if self.dest:
@@ -1486,6 +1498,8 @@
self.dsnType = 'pro'
elif sel == self.sourceMap['native']:
self.dsnType = 'native'
+ elif sel == self.sourceMap['db-pg']: # PostGIS database (PG data provider)
+ self.dsnType = 'db-pg'
if self.dsnType == 'db':
self.input[self.dsnType][1] = self.input['db-win']['text']
@@ -1494,7 +1508,8 @@
self.dsnSizer.Add(item = self.input[self.dsnType][1],
flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
pos = (1, 1), span = (1, 3))
- win.SetValue('')
+ if self.dsnType != 'db-pg':
+ win.SetValue('')
win.Show()
if sel == self.sourceMap['native']: # native
@@ -1512,12 +1527,13 @@
if self.parent.GetName() == 'MultiImportDialog':
self.parent.list.DeleteAllItems()
- if sel in (self.sourceMap['file'],
- self.sourceMap['dir']):
+ if sel in (self.sourceMap['file'], self.sourceMap['dir']):
if not self.ogr:
self.OnSetFormat(event = None, format = 'GeoTIFF')
else:
self.OnSetFormat(event = None, format = 'ESRI Shapefile')
+ elif sel == self.sourceMap['db-pg']:
+ self.OnSetFormat(event = None, format = 'PostgreSQL')
if sel == self.sourceMap['dir'] and not self.dest:
if not self.extension.IsShown():
@@ -1530,12 +1546,23 @@
self.dsnSizer.Layout()
- def GetDsn(self):
- """!Get datasource name"""
+ def GetDsn(self, flags = False):
+ """!Get datasource name
+
+ @param flags True to get tuple (dsn, flags)
+ """
+ flgs = []
if self.format.GetStringSelection() == 'PostgreSQL':
- return 'PG:dbname=%s' % self.input[self.dsnType][1].GetStringSelection()
+ if self.source.GetSelection() == self.sourceMap['db-pg']:
+ flgs.append('p')
+ dsn = 'PG:dbname=%s' % self.input[self.dsnType][1].GetStringSelection()
+ else:
+ dsn = self.input[self.dsnType][1].GetValue()
- return self.input[self.dsnType][1].GetValue()
+ if flags:
+ return (dsn, flgs)
+
+ return dsn
def OnSetDsn(self, event, path = None):
"""!Input DXF file/OGR dsn defined, update list of layer
@@ -1575,12 +1602,11 @@
layerId = 1
if self.ogr:
- ret = RunCommand('v.in.ogr',
+ ret = RunCommand('v.external',
quiet = True,
read = True,
- flags = 'a',
+ flags = 't',
dsn = dsn)
-
if not ret:
self.parent.list.LoadData()
if hasattr(self, "btn_run"):
@@ -1627,7 +1653,7 @@
def OnSetFormat(self, event, format = None):
"""!Format changed"""
- if self.dsnType not in ['file', 'dir', 'db']:
+ if self.dsnType not in ['file', 'dir', 'db', 'db-pg']:
return
win = self.input[self.dsnType][1]
@@ -1709,13 +1735,6 @@
"""!Get source type"""
return self.dsnType
- def GetDsn(self):
- """!Get DSN"""
- if self.format.GetStringSelection() == 'PostgreSQL':
- return 'PG:dbname=%s' % self.input[self.dsnType][1].GetStringSelection()
-
- return self.input[self.dsnType][1].GetValue()
-
def GetDsnWin(self):
"""!Get list of DSN windows"""
win = list()
More information about the grass-commit
mailing list