35
35
from processing .parameters .ParameterBoolean import ParameterBoolean
36
36
from processing .parameters .ParameterVector import ParameterVector
37
37
from processing .parameters .ParameterString import ParameterString
38
+ from processing .parameters .ParameterSelection import ParameterSelection
38
39
from processing .tools import dataobjects
39
40
40
41
from processing .admintools import postgis_utils
@@ -48,12 +49,13 @@ class ImportIntoPostGIS(GeoAlgorithm):
48
49
INPUT = 'INPUT'
49
50
OVERWRITE = 'OVERWRITE'
50
51
CREATEINDEX = 'CREATEINDEX'
52
+ GEOMETRY_COLUMN = 'GEOMETRY_COLUMN'
51
53
52
54
def getIcon (self ):
53
55
return QIcon (os .path .dirname (__file__ ) + '/../images/postgis.png' )
54
56
55
57
def processAlgorithm (self , progress ):
56
- connection = self .getParameterValue (self .DATABASE )
58
+ connection = self .DB_CONNECTIONS [ self . getParameterValue (self .DATABASE )]
57
59
schema = self .getParameterValue (self .SCHEMA )
58
60
overwrite = self .getParameterValue (self .OVERWRITE )
59
61
createIndex = self .getParameterValue (self .CREATEINDEX )
@@ -80,9 +82,13 @@ def processAlgorithm(self, progress):
80
82
raise GeoAlgorithmExecutionException (
81
83
"Couldn't connect to database:\n " + e .message )
82
84
85
+ geomColumn = self .getParameterValue (self .GEOMETRY_COLUMN )
86
+ if not geomColumn :
87
+ geomColumn = 'the_geom'
88
+
83
89
uri = QgsDataSourceURI ()
84
90
uri .setConnection (host , str (port ), database , username , password )
85
- uri .setDataSource (schema , table , 'the_geom' , '' )
91
+ uri .setDataSource (schema , table , geomColumn , '' )
86
92
87
93
options = {}
88
94
if overwrite :
@@ -104,19 +110,29 @@ def processAlgorithm(self, progress):
104
110
'Error importing to PostGIS\n %s' % errMsg )
105
111
106
112
if createIndex :
107
- db .create_spatial_index (table , schema , 'the_geom' )
113
+ db .create_spatial_index (table , schema , geomColumn )
108
114
109
115
db .vacuum_analyze (table , schema )
110
116
117
+ def dbConnectionNames (self ):
118
+ settings = QSettings ()
119
+ settings .beginGroup ('/PostgreSQL/connections/' )
120
+ return settings .childGroups ()
121
+
111
122
def defineCharacteristics (self ):
112
123
self .name = 'Import into PostGIS'
113
124
self .group = 'PostGIS management tools'
114
125
self .addParameter (ParameterVector (self .INPUT , 'Layer to import' ))
115
- self .addParameter (ParameterString (self .DATABASE ,
116
- 'Database (connection name)' ))
126
+
127
+ self .DB_CONNECTIONS = self .dbConnectionNames ()
128
+ self .addParameter (ParameterSelection (self .DATABASE , 'Database (connection name)' ,
129
+ self .DB_CONNECTIONS ))
130
+
117
131
self .addParameter (ParameterString (self .SCHEMA , 'Schema (schema name)' ))
118
132
self .addParameter (ParameterString (self .TABLENAME , 'Table to import to'
119
133
))
134
+ self .addParameter (ParameterString (self .GEOMETRY_COLUMN , 'Geometry column' , 'the_geom'
135
+ ))
120
136
self .addParameter (ParameterBoolean (self .OVERWRITE , 'Overwrite' , True ))
121
137
self .addParameter (ParameterBoolean (self .CREATEINDEX ,
122
138
'Create spatial index' , True ))
0 commit comments