Skip to content
Permalink
Browse files

Add geometry and id field parameters

  • Loading branch information
anitagraser committed May 29, 2018
1 parent 1ed5bb5 commit 70afe2d8eb82be964056f03d8ccd038800afcfd6
Showing with 14 additions and 1 deletion.
  1. +14 −1 python/plugins/processing/algs/qgis/PostGISExecuteAndLoadSQL.py
@@ -47,6 +47,8 @@ class PostGISExecuteAndLoadSQL(QgisAlgorithm):
DATABASE = 'DATABASE'
SQL = 'SQL'
OUTPUT = 'OUTPUT'
ID_FIELD = 'ID_FIELD'
GEOMETRY_FIELD = 'GEOMETRY_FIELD'

def group(self):
return self.tr('Database')
@@ -69,6 +71,15 @@ def initAlgorithm(self, config=None):
self.SQL,
self.tr('SQL query (must return unique id and geom field)'),
multiLine=True))
self.addParameter(QgsProcessingParameterString(
self.ID_FIELD,
self.tr('ID field name'),
defaultValue='id'))
self.addParameter(QgsProcessingParameterString(
self.GEOMETRY_FIELD,
self.tr('Geometry field name'),
defaultValue='geom',
optional=True))
self.addOutput(QgsProcessingOutputVectorLayer(
self.OUTPUT,
self.tr("Output layer"),
@@ -82,10 +93,12 @@ def displayName(self):

def processAlgorithm(self, parameters, context, feedback):
connection = self.parameterAsString(parameters, self.DATABASE, context)
id_field = self.parameterAsString(parameters, self.ID_FIELD, context)
geom_field = self.parameterAsString(parameters, self.GEOMETRY_FIELD, context)
uri = postgis.uri_from_name(connection)
sql = self.parameterAsString(parameters, self.SQL, context)
sql = sql.replace('\n', ' ')
uri.setDataSource("", "(" + sql + ")", "geom", "", "id")
uri.setDataSource("", "(" + sql + ")", geom_field, "", id_field)

vlayer = QgsVectorLayer(uri.uri(), "layername", "postgres")

0 comments on commit 70afe2d

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