Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] Added schema parameter to ImportIntoPostGIS.py
  • Loading branch information
volaya committed Sep 14, 2013
1 parent 807ffaa commit 3d775d6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions python/plugins/processing/admintools/ImportIntoPostGIS.py
Expand Up @@ -16,9 +16,6 @@
* *
***************************************************************************
"""
from processing.tools import dataobjects
from processing.parameters.ParameterBoolean import ParameterBoolean


__author__ = 'Victor Olaya'
__date__ = 'October 2012'
Expand All @@ -27,6 +24,8 @@
__revision__ = '$Format:%H$'

import os
from processing.core.QGisLayers import QGisLayers
from processing.parameters.ParameterBoolean import ParameterBoolean
from processing.parameters.ParameterVector import ParameterVector
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
Expand All @@ -40,6 +39,7 @@ class ImportIntoPostGIS(GeoAlgorithm):

DATABASE = "DATABASE"
TABLENAME = "TABLENAME"
SCHEMA = "SCHEMA"
INPUT = "INPUT"
OVERWRITE = "OVERWRITE"
CREATEINDEX = "CREATEINDEX"
Expand All @@ -49,6 +49,7 @@ def getIcon(self):

def processAlgorithm(self, progress):
connection = self.getParameterValue(self.DATABASE)
schema = self.getParameterValue(self.SCHEMA)
overwrite = self.getParameterValue(self.OVERWRITE)
createIndex = self.getParameterValue(self.CREATEINDEX)
settings = QSettings()
Expand All @@ -73,22 +74,22 @@ def processAlgorithm(self, progress):

uri = QgsDataSourceURI()
uri.setConnection(host, str(port), database, username, password)
uri.setDataSource("public", table, "the_geom", "")
uri.setDataSource(schema, table, "the_geom", "")

options = {}
if overwrite:
options['overwrite'] = True

layerUri = self.getParameterValue(self.INPUT);
layer = dataobjects.getObjectFromUri(layerUri)
layer = QGisLayers.getObjectFromUri(layerUri)
ret, errMsg = QgsVectorLayerImport.importLayer(layer, uri.uri(), providerName, self.crs, False, False, options)
if ret != 0:
raise GeoAlgorithmExecutionException(u"Error importing to PostGIS\n%s" % errMsg)

if createIndex:
db.create_spatial_index(table, "public", "the_geom")
db.create_spatial_index(table, schema, "the_geom")

db.vacuum_analyze(table, "public")
db.vacuum_analyze(table, schema)

def defineCharacteristics(self):
self.name = "Import into PostGIS"
Expand Down

0 comments on commit 3d775d6

Please sign in to comment.