25
25
26
26
__revision__ = '$Format:%H$'
27
27
28
- from PyQt4 .QtCore import QSettings
28
+ import os
29
+
30
+ from PyQt4 .QtCore import *
31
+ from PyQt4 .QtGui import *
32
+
33
+ from qgis .core import *
29
34
30
35
from processing .core .parameters import ParameterVector
31
36
from processing .core .parameters import ParameterString
32
37
from processing .core .parameters import ParameterCrs
33
38
from processing .core .parameters import ParameterSelection
34
39
from processing .core .parameters import ParameterBoolean
35
40
from processing .core .parameters import ParameterExtent
41
+ from processing .core .parameters import ParameterTableField
36
42
37
- from processing .tools .system import isWindows
43
+ from processing .tools .system import *
38
44
39
45
from processing .algs .gdal .OgrAlgorithm import OgrAlgorithm
40
46
from processing .algs .gdal .GdalUtils import GdalUtils
@@ -56,6 +62,7 @@ class Ogr2OgrToPostGisList(OgrAlgorithm):
56
62
SCHEMA = 'SCHEMA'
57
63
TABLE = 'TABLE'
58
64
PK = 'PK'
65
+ PRIMARY_KEY = 'PRIMARY_KEY'
59
66
GEOCOLUMN = 'GEOCOLUMN'
60
67
DIM = 'DIM'
61
68
DIMLIST = ['2' ,'3' ]
@@ -71,6 +78,8 @@ class Ogr2OgrToPostGisList(OgrAlgorithm):
71
78
LAUNDER = 'LAUNDER'
72
79
INDEX = 'INDEX'
73
80
SKIPFAILURES = 'SKIPFAILURES'
81
+ PRECISION = 'PRECISION'
82
+ PROMOTETOMULTI = 'PROMOTETOMULTI'
74
83
OPTIONS = 'OPTIONS'
75
84
76
85
def dbConnectionNames (self ):
@@ -87,7 +96,7 @@ def defineCharacteristics(self):
87
96
self .addParameter (ParameterVector (self .INPUT_LAYER ,
88
97
self .tr ('Input layer' ), [ParameterVector .VECTOR_TYPE_ANY ], False ))
89
98
self .addParameter (ParameterSelection (self .GTYPE ,
90
- self .tr ('Output geometry type' ), self .GEOMTYPE , 5 ))
99
+ self .tr ('Output geometry type' ), self .GEOMTYPE , 0 ))
91
100
self .addParameter (ParameterCrs (self .A_SRS ,
92
101
self .tr ('Assign an output CRS' ), '' ))
93
102
self .addParameter (ParameterCrs (self .T_SRS ,
@@ -100,7 +109,9 @@ def defineCharacteristics(self):
100
109
self .tr ('Table name, leave blank to use input name' ),
101
110
'' , optional = True ))
102
111
self .addParameter (ParameterString (self .PK ,
103
- self .tr ('Primary key' ), 'id' , optional = True ))
112
+ self .tr ('Primary key (new field)' ), 'id' , optional = True ))
113
+ self .addParameter (ParameterTableField (self .PRIMARY_KEY ,
114
+ self .tr ('Primary key (existing field, used if the above option is left empty)' ), self .INPUT_LAYER , optional = True ))
104
115
self .addParameter (ParameterString (self .GEOCOLUMN ,
105
116
self .tr ('Geometry column name' ), 'geom' , optional = True ))
106
117
self .addParameter (ParameterSelection (self .DIM ,
@@ -135,6 +146,12 @@ def defineCharacteristics(self):
135
146
self .addParameter (ParameterBoolean (self .SKIPFAILURES ,
136
147
self .tr ('Continue after a failure, skipping the failed feature' ),
137
148
False ))
149
+ self .addParameter (ParameterBoolean (self .PROMOTETOMULTI ,
150
+ self .tr ('Promote to Multipart' ),
151
+ True ))
152
+ self .addParameter (ParameterBoolean (self .PRECISION ,
153
+ self .tr ('Keep width and precision of input attributes' ),
154
+ True ))
138
155
self .addParameter (ParameterString (self .OPTIONS ,
139
156
self .tr ('Additional creation options' ), '' , optional = True ))
140
157
@@ -151,12 +168,13 @@ def processAlgorithm(self, progress):
151
168
ogrLayer = self .ogrConnectionString (inLayer )[1 :- 1 ]
152
169
ssrs = unicode (self .getParameterValue (self .S_SRS ))
153
170
tsrs = unicode (self .getParameterValue (self .T_SRS ))
154
- asrs = unicode (self .getParameterValue (self .A_SRS ))
171
+ asrs = unicode (self .getParameterValue (self .A_SRS ))
155
172
schema = unicode (self .getParameterValue (self .SCHEMA ))
156
173
schemastring = "-lco SCHEMA=" + schema
157
174
table = unicode (self .getParameterValue (self .TABLE ))
158
175
pk = unicode (self .getParameterValue (self .PK ))
159
176
pkstring = "-lco FID=" + pk
177
+ primary_key = self .getParameterValue (self .PRIMARY_KEY )
160
178
geocolumn = unicode (self .getParameterValue (self .GEOCOLUMN ))
161
179
geocolumnstring = "-lco GEOMETRY_NAME=" + geocolumn
162
180
dim = self .DIMLIST [self .getParameterValue (self .DIM )]
@@ -177,6 +195,8 @@ def processAlgorithm(self, progress):
177
195
index = self .getParameterValue (self .INDEX )
178
196
indexstring = "-lco SPATIAL_INDEX=OFF"
179
197
skipfailures = self .getParameterValue (self .SKIPFAILURES )
198
+ promotetomulti = self .getParameterValue (self .PROMOTETOMULTI )
199
+ precision = self .getParameterValue (self .PRECISION )
180
200
options = unicode (self .getParameterValue (self .OPTIONS ))
181
201
182
202
arguments = []
@@ -187,9 +207,9 @@ def processAlgorithm(self, progress):
187
207
arguments .append ('PG:"host=' + host )
188
208
arguments .append ('port=' + port )
189
209
if len (dbname ) > 0 :
190
- arguments .append ('dbname=' + dbname )
210
+ arguments .append ('dbname=' + dbname )
191
211
if len (password ) > 0 :
192
- arguments .append ('password=' + password )
212
+ arguments .append ('password=' + password )
193
213
arguments .append ('user=' + user + '"' )
194
214
arguments .append (dimstring )
195
215
arguments .append (ogrLayer )
@@ -213,6 +233,8 @@ def processAlgorithm(self, progress):
213
233
arguments .append (geocolumnstring )
214
234
if len (pk ) > 0 :
215
235
arguments .append (pkstring )
236
+ elif primary_key != None :
237
+ arguments .append ("-lco FID=" + primary_key )
216
238
if len (table ) > 0 :
217
239
arguments .append ('-nln' )
218
240
arguments .append (table )
@@ -247,6 +269,10 @@ def processAlgorithm(self, progress):
247
269
if len (gt ) > 0 :
248
270
arguments .append ('-gt' )
249
271
arguments .append (gt )
272
+ if promotetomulti :
273
+ arguments .append ('-nlt PROMOTE_TO_MULTI' )
274
+ if precision is False :
275
+ arguments .append ('-lco PRECISION=NO' )
250
276
if len (options ) > 0 :
251
277
arguments .append (options )
252
278
@@ -257,4 +283,4 @@ def processAlgorithm(self, progress):
257
283
else :
258
284
commands = ['ogr2ogr' , GdalUtils .escapeAndJoin (arguments )]
259
285
260
- GdalUtils .runGdal (commands , progress )
286
+ GdalUtils .runGdal (commands , progress )
0 commit comments