Skip to content

Commit

Permalink
fix processing ogr postgis import when db name or password are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Manghi committed Jan 30, 2015
1 parent 57a5794 commit ef0c955
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
33 changes: 18 additions & 15 deletions python/plugins/processing/algs/gdal/ogr2ogrtopostgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -256,4 +259,4 @@ def processAlgorithm(self, progress):
else:
commands = ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]

GdalUtils.runGdal(commands, progress)
GdalUtils.runGdal(commands, progress)
35 changes: 18 additions & 17 deletions python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand All @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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.