25
25
26
26
__revision__ = '$Format:%H$'
27
27
28
+
28
29
from PyQt4 .QtCore import QSettings
29
30
30
31
from processing .core .parameters import ParameterVector
33
34
from processing .core .parameters import ParameterSelection
34
35
from processing .core .parameters import ParameterBoolean
35
36
from processing .core .parameters import ParameterExtent
37
+ from processing .core .parameters import ParameterTableField
36
38
37
39
from processing .tools .system import isWindows
38
40
@@ -56,6 +58,7 @@ class Ogr2OgrToPostGisList(OgrAlgorithm):
56
58
SCHEMA = 'SCHEMA'
57
59
TABLE = 'TABLE'
58
60
PK = 'PK'
61
+ PRIMARY_KEY = 'PRIMARY_KEY'
59
62
GEOCOLUMN = 'GEOCOLUMN'
60
63
DIM = 'DIM'
61
64
DIMLIST = ['2' ,'3' ]
@@ -71,6 +74,8 @@ class Ogr2OgrToPostGisList(OgrAlgorithm):
71
74
LAUNDER = 'LAUNDER'
72
75
INDEX = 'INDEX'
73
76
SKIPFAILURES = 'SKIPFAILURES'
77
+ PRECISION = 'PRECISION'
78
+ PROMOTETOMULTI = 'PROMOTETOMULTI'
74
79
OPTIONS = 'OPTIONS'
75
80
76
81
def dbConnectionNames (self ):
@@ -87,7 +92,7 @@ def defineCharacteristics(self):
87
92
self .addParameter (ParameterVector (self .INPUT_LAYER ,
88
93
self .tr ('Input layer' ), [ParameterVector .VECTOR_TYPE_ANY ], False ))
89
94
self .addParameter (ParameterSelection (self .GTYPE ,
90
- self .tr ('Output geometry type' ), self .GEOMTYPE , 5 ))
95
+ self .tr ('Output geometry type' ), self .GEOMTYPE , 0 ))
91
96
self .addParameter (ParameterCrs (self .A_SRS ,
92
97
self .tr ('Assign an output CRS' ), '' ))
93
98
self .addParameter (ParameterCrs (self .T_SRS ,
@@ -100,7 +105,9 @@ def defineCharacteristics(self):
100
105
self .tr ('Table name, leave blank to use input name' ),
101
106
'' , optional = True ))
102
107
self .addParameter (ParameterString (self .PK ,
103
- self .tr ('Primary key' ), 'id' , optional = True ))
108
+ self .tr ('Primary key (new field)' ), 'id' , optional = True ))
109
+ self .addParameter (ParameterTableField (self .PRIMARY_KEY ,
110
+ self .tr ('Primary key (existing field, used if the above option is left empty)' ), self .INPUT_LAYER , optional = True ))
104
111
self .addParameter (ParameterString (self .GEOCOLUMN ,
105
112
self .tr ('Geometry column name' ), 'geom' , optional = True ))
106
113
self .addParameter (ParameterSelection (self .DIM ,
@@ -135,6 +142,12 @@ def defineCharacteristics(self):
135
142
self .addParameter (ParameterBoolean (self .SKIPFAILURES ,
136
143
self .tr ('Continue after a failure, skipping the failed feature' ),
137
144
False ))
145
+ self .addParameter (ParameterBoolean (self .PROMOTETOMULTI ,
146
+ self .tr ('Promote to Multipart' ),
147
+ True ))
148
+ self .addParameter (ParameterBoolean (self .PRECISION ,
149
+ self .tr ('Keep width and precision of input attributes' ),
150
+ True ))
138
151
self .addParameter (ParameterString (self .OPTIONS ,
139
152
self .tr ('Additional creation options' ), '' , optional = True ))
140
153
@@ -157,6 +170,7 @@ def processAlgorithm(self, progress):
157
170
table = unicode (self .getParameterValue (self .TABLE ))
158
171
pk = unicode (self .getParameterValue (self .PK ))
159
172
pkstring = "-lco FID=" + pk
173
+ primary_key = self .getParameterValue (self .PRIMARY_KEY )
160
174
geocolumn = unicode (self .getParameterValue (self .GEOCOLUMN ))
161
175
geocolumnstring = "-lco GEOMETRY_NAME=" + geocolumn
162
176
dim = self .DIMLIST [self .getParameterValue (self .DIM )]
@@ -177,6 +191,8 @@ def processAlgorithm(self, progress):
177
191
index = self .getParameterValue (self .INDEX )
178
192
indexstring = "-lco SPATIAL_INDEX=OFF"
179
193
skipfailures = self .getParameterValue (self .SKIPFAILURES )
194
+ promotetomulti = self .getParameterValue (self .PROMOTETOMULTI )
195
+ precision = self .getParameterValue (self .PRECISION )
180
196
options = unicode (self .getParameterValue (self .OPTIONS ))
181
197
182
198
arguments = []
@@ -187,9 +203,9 @@ def processAlgorithm(self, progress):
187
203
arguments .append ('PG:"host=' + host )
188
204
arguments .append ('port=' + port )
189
205
if len (dbname ) > 0 :
190
- arguments .append ('dbname=' + dbname )
206
+ arguments .append ('dbname=' + dbname )
191
207
if len (password ) > 0 :
192
- arguments .append ('password=' + password )
208
+ arguments .append ('password=' + password )
193
209
arguments .append ('user=' + user + '"' )
194
210
arguments .append (dimstring )
195
211
arguments .append (ogrLayer )
@@ -213,6 +229,8 @@ def processAlgorithm(self, progress):
213
229
arguments .append (geocolumnstring )
214
230
if len (pk ) > 0 :
215
231
arguments .append (pkstring )
232
+ elif primary_key != None :
233
+ arguments .append ("-lco FID=" + primary_key )
216
234
if len (table ) > 0 :
217
235
arguments .append ('-nln' )
218
236
arguments .append (table )
@@ -247,6 +265,10 @@ def processAlgorithm(self, progress):
247
265
if len (gt ) > 0 :
248
266
arguments .append ('-gt' )
249
267
arguments .append (gt )
268
+ if promotetomulti :
269
+ arguments .append ('-nlt PROMOTE_TO_MULTI' )
270
+ if precision is False :
271
+ arguments .append ('-lco PRECISION=NO' )
250
272
if len (options ) > 0 :
251
273
arguments .append (options )
252
274
@@ -257,4 +279,4 @@ def processAlgorithm(self, progress):
257
279
else :
258
280
commands = ['ogr2ogr' , GdalUtils .escapeAndJoin (arguments )]
259
281
260
- GdalUtils .runGdal (commands , progress )
282
+ GdalUtils .runGdal (commands , progress )
0 commit comments