Skip to content

Commit

Permalink
[processing] Add optional parameter for specifying the primary key fi…
Browse files Browse the repository at this point in the history
…eld in Import to PostGIS algorithm
  • Loading branch information
nyalldawson committed May 20, 2014
1 parent 2eda533 commit ed076d0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion python/plugins/processing/algs/admintools/ImportIntoPostGIS.py
Expand Up @@ -36,6 +36,7 @@
from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterString import ParameterString
from processing.parameters.ParameterSelection import ParameterSelection
from processing.parameters.ParameterTableField import ParameterTableField
from processing.tools import dataobjects
import postgis_utils

Expand All @@ -51,6 +52,7 @@ class ImportIntoPostGIS(GeoAlgorithm):
GEOMETRY_COLUMN = 'GEOMETRY_COLUMN'
LOWERCASE_NAMES = 'LOWERCASE_NAMES'
DROP_STRING_LENGTH = 'DROP_STRING_LENGTH'
PRIMARY_KEY = 'PRIMARY_KEY'

def getIcon(self):
return QIcon(os.path.dirname(__file__) + '/../../images/postgis.png')
Expand All @@ -62,6 +64,7 @@ def processAlgorithm(self, progress):
createIndex = self.getParameterValue(self.CREATEINDEX)
convertLowerCase = self.getParameterValue(self.LOWERCASE_NAMES)
dropStringLength = self.getParameterValue(self.DROP_STRING_LENGTH)
primaryKeyField = self.getParameterValue(self.PRIMARY_KEY)
settings = QSettings()
mySettings = '/PostgreSQL/connections/' + connection
try:
Expand Down Expand Up @@ -91,7 +94,10 @@ def processAlgorithm(self, progress):

uri = QgsDataSourceURI()
uri.setConnection(host, str(port), database, username, password)
uri.setDataSource(schema, table, geomColumn, '')
if primaryKeyField:
uri.setDataSource(schema, table, geomColumn, '', primaryKeyField)
else:
uri.setDataSource(schema, table, geomColumn, '')

options = {}
if overwrite:
Expand Down Expand Up @@ -137,6 +143,8 @@ def defineCharacteristics(self):
self.addParameter(ParameterString(self.SCHEMA, 'Schema (schema name)'))
self.addParameter(ParameterString(self.TABLENAME, 'Table to import to'
))
self.addParameter(ParameterTableField(self.PRIMARY_KEY, 'Primary key field',
self.INPUT, optional=True))
self.addParameter(ParameterString(self.GEOMETRY_COLUMN, 'Geometry column', 'the_geom'
))
self.addParameter(ParameterBoolean(self.OVERWRITE, 'Overwrite', True))
Expand Down

0 comments on commit ed076d0

Please sign in to comment.