Skip to content
Permalink
Browse files

fix processing ogr postgis import when db name or password are empty

  • Loading branch information
Giovanni Manghi
Giovanni Manghi committed Jan 30, 2015
1 parent 57a5794 commit ef0c955c9566983fde6dccf8576c10664961b841
@@ -51,6 +51,7 @@ class Ogr2OgrToPostGis(OgrAlgorithm):
GEOMTYPE = ['','NONE','GEOMETRY','POINT','LINESTRING','POLYGON','GEOMETRYCOLLECTION','MULTIPOINT','MULTIPOLYGON','MULTILINESTRING']
S_SRS = 'S_SRS'
T_SRS = 'T_SRS'
A_SRS = 'A_SRS'
HOST = 'HOST'
PORT= 'PORT'
USER = 'USER'
@@ -83,10 +84,12 @@ def defineCharacteristics(self):
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY], False))
self.addParameter(ParameterSelection(self.GTYPE,
self.tr('Output geometry type'), self.GEOMTYPE, 5))
self.addParameter(ParameterCrs(self.S_SRS,
self.tr('Input CRS'), 'EPSG:4326'))
self.addParameter(ParameterCrs(self.A_SRS,
self.tr('Assign an output CRS '), ''))
self.addParameter(ParameterCrs(self.T_SRS,
self.tr('Output CRS'), 'EPSG:4326'))
self.tr('Reproject to this CRS on output '), ''))
self.addParameter(ParameterCrs(self.S_SRS,
self.tr('Override source CRS'), ''))
self.addParameter(ParameterString(self.HOST,
self.tr('Host'), 'localhost', optional=False))
self.addParameter(ParameterString(self.PORT,
@@ -145,6 +148,7 @@ def processAlgorithm(self, progress):
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
ssrs = unicode(self.getParameterValue(self.S_SRS))
tsrs = unicode(self.getParameterValue(self.T_SRS))
asrs = unicode(self.getParameterValue(self.A_SRS))
host = unicode(self.getParameterValue(self.HOST))
port = unicode(self.getParameterValue(self.PORT))
user = unicode(self.getParameterValue(self.USER))
@@ -182,17 +186,13 @@ def processAlgorithm(self, progress):
arguments.append('--config PG_USE_COPY YES')
arguments.append('-f')
arguments.append('PostgreSQL')
arguments.append('PG:"host=')
arguments.append(host)
arguments.append('port=')
arguments.append(port)
arguments.append('user=')
arguments.append(user)
arguments.append('dbname=')
arguments.append(dbname)
arguments.append('password=')
arguments.append(password)
arguments.append('"')
arguments.append('PG:"host='+host)
arguments.append('port='+port)
if len(dbname) > 0:
arguments.append('dbname='+dbname)
if len(password) > 0:
arguments.append('password='+password)
arguments.append('user='+user+'"')
arguments.append(dimstring)
arguments.append(ogrLayer)
arguments.append(self.ogrLayerName(inLayer))
@@ -224,6 +224,9 @@ def processAlgorithm(self, progress):
if len(tsrs) > 0:
arguments.append('-t_srs')
arguments.append(tsrs)
if len(asrs) > 0:
arguments.append('-a_srs')
arguments.append(asrs)
if len(spat) > 0:
regionCoords = ogrspat.split(',')
arguments.append('-spat')
@@ -256,4 +259,4 @@ def processAlgorithm(self, progress):
else:
commands = ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]

GdalUtils.runGdal(commands, progress)
GdalUtils.runGdal(commands, progress)
@@ -38,8 +38,6 @@
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterExtent
from processing.tools import dataobjects
from processing.algs.qgis import postgis_utils

from processing.tools.system import *

@@ -54,6 +52,7 @@ class Ogr2OgrToPostGisList(OgrAlgorithm):
GEOMTYPE = ['','NONE','GEOMETRY','POINT','LINESTRING','POLYGON','GEOMETRYCOLLECTION','MULTIPOINT','MULTIPOLYGON','MULTILINESTRING']
S_SRS = 'S_SRS'
T_SRS = 'T_SRS'
A_SRS = 'A_SRS'
HOST = 'HOST'
PORT= 'PORT'
USER = 'USER'
@@ -94,10 +93,12 @@ def defineCharacteristics(self):
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY], False))
self.addParameter(ParameterSelection(self.GTYPE,
self.tr('Output geometry type'), self.GEOMTYPE, 5))
self.addParameter(ParameterCrs(self.S_SRS,
self.tr('Input CRS'), 'EPSG:4326'))
self.addParameter(ParameterCrs(self.A_SRS,
self.tr('Assign an output CRS '), ''))
self.addParameter(ParameterCrs(self.T_SRS,
self.tr('Output CRS'), 'EPSG:4326'))
self.tr('Reproject to this CRS on output '), ''))
self.addParameter(ParameterCrs(self.S_SRS,
self.tr('Override source CRS'), ''))
self.addParameter(ParameterString(self.SCHEMA,
self.tr('Schema name'), 'public', optional=True))
self.addParameter(ParameterString(self.TABLE,
@@ -155,6 +156,7 @@ def processAlgorithm(self, progress):
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
ssrs = unicode(self.getParameterValue(self.S_SRS))
tsrs = unicode(self.getParameterValue(self.T_SRS))
asrs = unicode(self.getParameterValue(self.A_SRS))
schema = unicode(self.getParameterValue(self.SCHEMA))
schemastring = "-lco SCHEMA="+schema
table = unicode(self.getParameterValue(self.TABLE))
@@ -187,17 +189,13 @@ def processAlgorithm(self, progress):
arguments.append('--config PG_USE_COPY YES')
arguments.append('-f')
arguments.append('PostgreSQL')
arguments.append('PG:"host=')
arguments.append(host)
arguments.append('port=')
arguments.append(port)
arguments.append('user=')
arguments.append(user)
arguments.append('dbname=')
arguments.append(dbname)
arguments.append('password=')
arguments.append(password)
arguments.append('"')
arguments.append('PG:"host='+host)
arguments.append('port='+port)
if len(dbname) > 0:
arguments.append('dbname='+dbname)
if len(password) > 0:
arguments.append('password='+password)
arguments.append('user='+user+'"')
arguments.append(dimstring)
arguments.append(ogrLayer)
arguments.append(self.ogrLayerName(inLayer))
@@ -229,6 +227,9 @@ def processAlgorithm(self, progress):
if len(tsrs) > 0:
arguments.append('-t_srs')
arguments.append(tsrs)
if len(asrs) > 0:
arguments.append('-a_srs')
arguments.append(asrs)
if len(spat) > 0:
regionCoords = ogrspat.split(',')
arguments.append('-spat')
@@ -261,4 +262,4 @@ def processAlgorithm(self, progress):
else:
commands = ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]

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

0 comments on commit ef0c955

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