Пример #1
0
class PostGISExecuteSQL(GeoAlgorithm):

    DATABASE = "DATABASE"
    SQL = "SQL"

    def getIcon(self):
        return QIcon(os.path.dirname(__file__) + "/../images/postgis.png")

    def processAlgorithm(self, progress):

        connection = self.getParameterValue(self.DATABASE)
        settings = QSettings()
        mySettings = "/PostgreSQL/connections/" + connection
        try:
            database = settings.value(mySettings + "/database").toString()
            username = settings.value(mySettings + "/username").toString()
            host = settings.value(mySettings + "/host").toString()
            port = int(settings.value(mySettings + "/port").toString())
            password = settings.value(mySettings + "/password").toString()
        except Exception, e:
            raise GeoAlgorithmExecutionException(
                "Wrong database connection name: " + connection)
        try:
            self.db = postgis_utils.GeoDB(host=host,
                                          port=port,
                                          dbname=database,
                                          user=username,
                                          passwd=password)
        except postgis_utils.DbError, e:
            raise GeoAlgorithmExecutionException(
                "Couldn't connect to database:\n" + e.message)
Пример #2
0
 def processAlgorithm(self, progress):
     
     connection = self.getParameterValue(self.DATABASE) 
     settings = QSettings()
     mySettings = "/PostgreSQL/connections/"+ connection
     database = settings.value(mySettings+"/database").toString()
     username = settings.value(mySettings+"/username").toString()
     host = settings.value(mySettings+"/host").toString()
     port = settings.value(mySettings+"/port").toString()
     password = settings.value(mySettings+"/password").toString()        
     
     # connect to DB
     try:
         self.db = postgis_utils.GeoDB(host=host, port=port, dbname=database, user=username, passwd=password)
     except postgis_utils.DbError, e:
         raise GeoAlgorithmExecutionException("Couldn't connect to database:\n"+e.message)                
Пример #3
0
class ImportIntoPostGIS(GeoAlgorithm):

    DATABASE = "DATABASE"
    TABLENAME = "TABLENAME"
    INPUT = "INPUT"
    OVERWRITE = "OVERWRITE"
    CREATEINDEX = "CREATEINDEX"

    def getIcon(self):
        return QIcon(os.path.dirname(__file__) + "/../images/postgis.png")

    def processAlgorithm(self, progress):
        connection = self.getParameterValue(self.DATABASE)
        overwrite = self.getParameterValue(self.OVERWRITE)
        createIndex = self.getParameterValue(self.CREATEINDEX)
        settings = QSettings()
        mySettings = "/PostgreSQL/connections/" + connection
        try:
            database = settings.value(mySettings + "/database").toString()
            username = settings.value(mySettings + "/username").toString()
            host = settings.value(mySettings + "/host").toString()
            port = int(settings.value(mySettings + "/port").toString())
            password = settings.value(mySettings + "/password").toString()
        except Exception, e:
            raise GeoAlgorithmExecutionException(
                "Wrong database connection name: " + connection)

        table = self.getParameterValue(self.TABLENAME)
        table.replace(" ", "")
        providerName = "postgres"

        try:
            db = postgis_utils.GeoDB(host=host,
                                     port=port,
                                     dbname=database,
                                     user=username,
                                     passwd=password)
        except postgis_utils.DbError, e:
            raise GeoAlgorithmExecutionException(
                "Couldn't connect to database:\n" + e.message)