Skip to content
Permalink
Browse files

Merge pull request #1874 from gioman/fix_processing_ogr_postgis_import_2

new fixes for processing/ogr import in postgis tools
  • Loading branch information
alexbruy committed Feb 2, 2015
2 parents db89a04 + de2b3ea commit 9143bd7b22dc6321a768a320982f0703fc6506b4
@@ -31,6 +31,7 @@
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterExtent
from processing.core.parameters import ParameterTableField

from processing.tools.system import isWindows

@@ -53,6 +54,7 @@ class Ogr2OgrToPostGis(OgrAlgorithm):
SCHEMA = 'SCHEMA'
TABLE = 'TABLE'
PK = 'PK'
PRIMARY_KEY = 'PRIMARY_KEY'
GEOCOLUMN = 'GEOCOLUMN'
DIM = 'DIM'
DIMLIST = ['2','3']
@@ -68,6 +70,8 @@ class Ogr2OgrToPostGis(OgrAlgorithm):
LAUNDER = 'LAUNDER'
INDEX = 'INDEX'
SKIPFAILURES = 'SKIPFAILURES'
PRECISION = 'PRECISION'
PROMOTETOMULTI = 'PROMOTETOMULTI'
OPTIONS = 'OPTIONS'

def defineCharacteristics(self):
@@ -76,7 +80,7 @@ def defineCharacteristics(self):
self.addParameter(ParameterVector(self.INPUT_LAYER,
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY], False))
self.addParameter(ParameterSelection(self.GTYPE,
self.tr('Output geometry type'), self.GEOMTYPE, 5))
self.tr('Output geometry type'), self.GEOMTYPE, 0))
self.addParameter(ParameterCrs(self.A_SRS,
self.tr('Assign an output CRS'), ''))
self.addParameter(ParameterCrs(self.T_SRS,
@@ -99,7 +103,9 @@ def defineCharacteristics(self):
self.tr('Table name, leave blank to use input name'),
'', optional=True))
self.addParameter(ParameterString(self.PK,
self.tr('Primary Key'), 'id', optional=True))
self.tr('Primary key (new field)'), 'id', optional=True))
self.addParameter(ParameterTableField(self.PRIMARY_KEY,
self.tr('Primary key (existing field, used if the above option is left empty)'), self.INPUT_LAYER, optional=True))
self.addParameter(ParameterString(self.GEOCOLUMN,
self.tr('Geometry column name'), 'geom', optional=True))
self.addParameter(ParameterSelection(self.DIM,
@@ -133,6 +139,12 @@ def defineCharacteristics(self):
self.tr('Do not create spatial index'), False))
self.addParameter(ParameterBoolean(self.SKIPFAILURES,
self.tr('Continue after a failure, skipping the failed feature'), False))
self.addParameter(ParameterBoolean(self.PROMOTETOMULTI,
self.tr('Promote to Multipart'),
True))
self.addParameter(ParameterBoolean(self.PRECISION,
self.tr('Keep width and precision of input attributes'),
True))
self.addParameter(ParameterString(self.OPTIONS,
self.tr('Additional creation options'), '', optional=True))

@@ -152,6 +164,7 @@ def processAlgorithm(self, progress):
table = unicode(self.getParameterValue(self.TABLE))
pk = unicode(self.getParameterValue(self.PK))
pkstring = "-lco FID="+pk
primary_key = self.getParameterValue(self.PRIMARY_KEY)
geocolumn = unicode(self.getParameterValue(self.GEOCOLUMN))
geocolumnstring = "-lco GEOMETRY_NAME="+geocolumn
dim = self.DIMLIST[self.getParameterValue(self.DIM)]
@@ -172,6 +185,8 @@ def processAlgorithm(self, progress):
index = self.getParameterValue(self.INDEX)
indexstring = "-lco SPATIAL_INDEX=OFF"
skipfailures = self.getParameterValue(self.SKIPFAILURES)
promotetomulti = self.getParameterValue(self.PROMOTETOMULTI)
precision = self.getParameterValue(self.PRECISION)
options = unicode(self.getParameterValue(self.OPTIONS))

arguments = []
@@ -182,9 +197,9 @@ def processAlgorithm(self, progress):
arguments.append('PG:"host='+host)
arguments.append('port='+port)
if len(dbname) > 0:
arguments.append('dbname='+dbname)
arguments.append('dbname='+dbname)
if len(password) > 0:
arguments.append('password='+password)
arguments.append('password='+password)
arguments.append('user='+user+'"')
arguments.append(dimstring)
arguments.append(ogrLayer)
@@ -208,6 +223,8 @@ def processAlgorithm(self, progress):
arguments.append(geocolumnstring)
if len(pk) > 0:
arguments.append(pkstring)
elif primary_key != None:
arguments.append("-lco FID="+primary_key)
if len(table) > 0:
arguments.append('-nln')
arguments.append(table)
@@ -242,6 +259,10 @@ def processAlgorithm(self, progress):
if len(gt) > 0:
arguments.append('-gt')
arguments.append(gt)
if promotetomulti:
arguments.append('-nlt PROMOTE_TO_MULTI')
if precision is False:
arguments.append('-lco PRECISION=NO')
if len(options) > 0:
arguments.append(options)

@@ -252,4 +273,4 @@ def processAlgorithm(self, progress):
else:
commands = ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]

GdalUtils.runGdal(commands, progress)
GdalUtils.runGdal(commands, progress)
@@ -25,6 +25,7 @@

__revision__ = '$Format:%H$'


from PyQt4.QtCore import QSettings

from processing.core.parameters import ParameterVector
@@ -33,6 +34,7 @@
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterExtent
from processing.core.parameters import ParameterTableField

from processing.tools.system import isWindows

@@ -56,6 +58,7 @@ class Ogr2OgrToPostGisList(OgrAlgorithm):
SCHEMA = 'SCHEMA'
TABLE = 'TABLE'
PK = 'PK'
PRIMARY_KEY = 'PRIMARY_KEY'
GEOCOLUMN = 'GEOCOLUMN'
DIM = 'DIM'
DIMLIST = ['2','3']
@@ -71,6 +74,8 @@ class Ogr2OgrToPostGisList(OgrAlgorithm):
LAUNDER = 'LAUNDER'
INDEX = 'INDEX'
SKIPFAILURES = 'SKIPFAILURES'
PRECISION = 'PRECISION'
PROMOTETOMULTI = 'PROMOTETOMULTI'
OPTIONS = 'OPTIONS'

def dbConnectionNames(self):
@@ -87,7 +92,7 @@ def defineCharacteristics(self):
self.addParameter(ParameterVector(self.INPUT_LAYER,
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY], False))
self.addParameter(ParameterSelection(self.GTYPE,
self.tr('Output geometry type'), self.GEOMTYPE, 5))
self.tr('Output geometry type'), self.GEOMTYPE, 0))
self.addParameter(ParameterCrs(self.A_SRS,
self.tr('Assign an output CRS'), ''))
self.addParameter(ParameterCrs(self.T_SRS,
@@ -100,7 +105,9 @@ def defineCharacteristics(self):
self.tr('Table name, leave blank to use input name'),
'', optional=True))
self.addParameter(ParameterString(self.PK,
self.tr('Primary key'), 'id', optional=True))
self.tr('Primary key (new field)'), 'id', optional=True))
self.addParameter(ParameterTableField(self.PRIMARY_KEY,
self.tr('Primary key (existing field, used if the above option is left empty)'), self.INPUT_LAYER, optional=True))
self.addParameter(ParameterString(self.GEOCOLUMN,
self.tr('Geometry column name'), 'geom', optional=True))
self.addParameter(ParameterSelection(self.DIM,
@@ -135,6 +142,12 @@ def defineCharacteristics(self):
self.addParameter(ParameterBoolean(self.SKIPFAILURES,
self.tr('Continue after a failure, skipping the failed feature'),
False))
self.addParameter(ParameterBoolean(self.PROMOTETOMULTI,
self.tr('Promote to Multipart'),
True))
self.addParameter(ParameterBoolean(self.PRECISION,
self.tr('Keep width and precision of input attributes'),
True))
self.addParameter(ParameterString(self.OPTIONS,
self.tr('Additional creation options'), '', optional=True))

@@ -157,6 +170,7 @@ def processAlgorithm(self, progress):
table = unicode(self.getParameterValue(self.TABLE))
pk = unicode(self.getParameterValue(self.PK))
pkstring = "-lco FID="+pk
primary_key = self.getParameterValue(self.PRIMARY_KEY)
geocolumn = unicode(self.getParameterValue(self.GEOCOLUMN))
geocolumnstring = "-lco GEOMETRY_NAME="+geocolumn
dim = self.DIMLIST[self.getParameterValue(self.DIM)]
@@ -177,6 +191,8 @@ def processAlgorithm(self, progress):
index = self.getParameterValue(self.INDEX)
indexstring = "-lco SPATIAL_INDEX=OFF"
skipfailures = self.getParameterValue(self.SKIPFAILURES)
promotetomulti = self.getParameterValue(self.PROMOTETOMULTI)
precision = self.getParameterValue(self.PRECISION)
options = unicode(self.getParameterValue(self.OPTIONS))

arguments = []
@@ -187,9 +203,9 @@ def processAlgorithm(self, progress):
arguments.append('PG:"host='+host)
arguments.append('port='+port)
if len(dbname) > 0:
arguments.append('dbname='+dbname)
arguments.append('dbname='+dbname)
if len(password) > 0:
arguments.append('password='+password)
arguments.append('password='+password)
arguments.append('user='+user+'"')
arguments.append(dimstring)
arguments.append(ogrLayer)
@@ -213,6 +229,8 @@ def processAlgorithm(self, progress):
arguments.append(geocolumnstring)
if len(pk) > 0:
arguments.append(pkstring)
elif primary_key != None:
arguments.append("-lco FID="+primary_key)
if len(table) > 0:
arguments.append('-nln')
arguments.append(table)
@@ -247,6 +265,10 @@ def processAlgorithm(self, progress):
if len(gt) > 0:
arguments.append('-gt')
arguments.append(gt)
if promotetomulti:
arguments.append('-nlt PROMOTE_TO_MULTI')
if precision is False:
arguments.append('-lco PRECISION=NO')
if len(options) > 0:
arguments.append(options)

@@ -257,4 +279,4 @@ def processAlgorithm(self, progress):
else:
commands = ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]

GdalUtils.runGdal(commands, progress)
GdalUtils.runGdal(commands, progress)

0 comments on commit 9143bd7

Please sign in to comment.
You can’t perform that action at this time.