def connect_db(self):
     name = self.cboConnection.currentText()
     try:
         self.conn = dbutils.get_connection(dbutils.get_postgres_conn_info(name))
         self.lblMessage.setText("")
     except StandardError, e:
         self.conn = None
         self.lblMessage.setText("<font color=red>"+ e.message +"</font>")
 def connect_db(self):
     name = self.cboConnection.currentText()
     try:
         self.conn = dbutils.get_connection(dbutils.get_postgres_conn_info(name))
         self.lblMessage.setText("")
     except StandardError, e:
         self.conn = None
         self.lblMessage.setText("<font color=red>"+ e.message +"</font>")
    def read_config(self):
        # the following code reads the configuration file which setups the plugin to search in the correct database,
        # table and method

        settings = QSettings()
        settings.beginGroup("/Discovery")
        connection = settings.value("connection", "", type=str)
        self.postgisschema = settings.value("schema", "", type=str)
        self.postgistable = settings.value("table", "", type=str)
        self.postgissearchcolumn = settings.value("search_column", "", type=str)
        self.postgisdisplaycolumn = settings.value("display_columns", "", type=str)
        self.postgisgeomcolumn = settings.value("geom_column", "", type=str)
        scale_expr = settings.value("scale_expr", "", type=str)
        bbox_expr = settings.value("bbox_expr", "", type=str)

        self.make_enabled(False)   # assume the config is invalid first
        self.db_conn = None
        self.conn_info = dbutils.get_postgres_conn_info(connection)
        self.extra_expr_columns = []
        self.scale_expr = None
        self.bbox_expr = None

        if len(connection) == 0 or len(self.postgisschema) == 0 or len(self.postgistable) == 0 or \
           len(self.postgissearchcolumn) == 0 or len(self.postgisgeomcolumn) == 0:
            #iface.messageBar().pushMessage("Discovery", "Please configure the plugin", level=QgsMessageBar.INFO)
            return

        if len(self.conn_info) == 0:
            iface.messageBar().pushMessage("Discovery", "The database connection '%s' does not exist!" % connection,
                                           level=QgsMessageBar.CRITICAL)
            return

        self.make_enabled(True)

        # optional scale expression when zooming in to results
        if len(scale_expr) != 0:
            expr = QgsExpression(scale_expr)
            if expr.hasParserError():
                iface.messageBar().pushMessage("Discovery", "Invalid scale expression: " + expr.parserErrorString(),
                                               level=QgsMessageBar.WARNING)
            else:
                self.scale_expr = scale_expr
                self.extra_expr_columns += expr.referencedColumns()

        # optional bbox expression when zooming in to results
        if len(bbox_expr) != 0:
            expr = QgsExpression(bbox_expr)
            if expr.hasParserError():
                iface.messageBar().pushMessage("Discovery", "Invalid bbox expression: " + expr.parserErrorString(),
                                               level=QgsMessageBar.WARNING)
            else:
                self.bbox_expr = bbox_expr
                self.extra_expr_columns += expr.referencedColumns()
Пример #4
0
    def add_selected_layers(self):
        """
            Add each of the selected layers to QGIS.
        :return:
        """

        for i in range(self.resultsListWidget.count()):
            # Loop through and add selected items
            if self.resultsListWidget.item(i).isSelected():
                # Add the layer
                uri = QgsDataSourceURI()
                con_info = get_postgres_conn_info(self.config['connection'])
                uri.setConnection(con_info['host'], str(con_info['port']),
                                  con_info['database'], con_info['user'],
                                  con_info['password'])
                res = self.search_results[i]
                uri.setDataSource(res['schema'], res['table'], res['geom_col'])
                layer_name = '%s (%s)' % (res['title'],
                                          res['geom_type'].lower())
                vlayer = QgsVectorLayer(uri.uri(), layer_name, 'postgres')
                QgsMapLayerRegistry.instance().addMapLayer(vlayer)
Пример #5
0
    def add_selected_layers(self):
        """
            Add each of the selected layers to QGIS.
        :return:
        """

        for i in range(self.resultsListWidget.count()):
            # Loop through and add selected items
            if self.resultsListWidget.item(i).isSelected():
                # Add the layer
                uri = QgsDataSourceURI()
                con_info = get_postgres_conn_info(self.config['connection'])
                uri.setConnection(con_info['host'],
                                  str(con_info['port']),
                                  con_info['database'],
                                  con_info['user'],
                                  con_info['password'])
                res = self.search_results[i]
                uri.setDataSource(res['schema'],
                                  res['table'],
                                  res['geom_col'])
                layer_name = '%s (%s)' % (res['title'], res['geom_type'].lower())
                vlayer = QgsVectorLayer(uri.uri(), layer_name, 'postgres')
                QgsMapLayerRegistry.instance().addMapLayer(vlayer)
    def read_config(self):
        # the following code reads the configuration file which setups the plugin to search in the correct database,
        # table and method

        settings = QSettings()
        settings.beginGroup("/Discovery")
        connection = settings.value("connection", "", type=str)
        self.postgisschema = settings.value("schema", "", type=str)
        self.postgistable = settings.value("table", "", type=str)
        self.postgissearchcolumn = settings.value("search_column", "", type=str)
        self.echosearchcolumn = settings.value("echo_search_column", True, type=bool)
        self.postgisdisplaycolumn = settings.value("display_columns", "", type=str)
        self.postgisgeomcolumn = settings.value("geom_column", "", type=str)
        self.set_timer_checkbox = settings.value("timer_checked", "", type=bool)
        if self.set_timer_checkbox:
        	try:
        		self.display_time = settings.value("display_time", type=int)
        	except TypeError:
        		self.display_time = 5000

        scale_expr = settings.value("scale_expr", "", type=str)
        bbox_expr = settings.value("bbox_expr", "", type=str)

        if self.is_displayed:
            self.hide_marker()
            self.is_displayed = False

        self.make_enabled(False)   # assume the config is invalid first
        self.db_conn = None
        self.conn_info = dbutils.get_postgres_conn_info(connection)
        self.extra_expr_columns = []
        self.scale_expr = None
        self.bbox_expr = None

        if len(connection) == 0 or len(self.postgisschema) == 0 or len(self.postgistable) == 0 or \
           len(self.postgissearchcolumn) == 0 or len(self.postgisgeomcolumn) == 0:
            #iface.messageBar().pushMessage("Discovery", "Please configure the plugin", level=QgsMessageBar.INFO)
            return

        if len(self.conn_info) == 0:
            iface.messageBar().pushMessage("Discovery", "The database connection '%s' does not exist!" % connection,
                                           level=QgsMessageBar.CRITICAL)
            return

        self.make_enabled(True)

        # optional scale expression when zooming in to results
        if len(scale_expr) != 0:
            expr = QgsExpression(scale_expr)
            if expr.hasParserError():
                iface.messageBar().pushMessage("Discovery", "Invalid scale expression: " + expr.parserErrorString(),
                                               level=QgsMessageBar.WARNING)
            else:
                self.scale_expr = scale_expr
                self.extra_expr_columns += expr.referencedColumns()

        # optional bbox expression when zooming in to results
        if len(bbox_expr) != 0:
            expr = QgsExpression(bbox_expr)
            if expr.hasParserError():
                iface.messageBar().pushMessage("Discovery", "Invalid bbox expression: " + expr.parserErrorString(),
                                               level=QgsMessageBar.WARNING)
            else:
                self.bbox_expr = bbox_expr
                self.extra_expr_columns += expr.referencedColumns()
 def _get_cur(self):
     ci = get_postgres_conn_info(self.postGisConnectionComboBox.currentText())
     cur = get_connection(ci).cursor()
     return cur
Пример #8
0
 def _get_cur(self):
     ci = get_postgres_conn_info(
         self.postGisConnectionComboBox.currentText())
     cur = get_connection(ci).cursor()
     return cur
Пример #9
0
 def _db_cur(self):
     con_info = get_postgres_conn_info(self.config['connection'])
     con = get_connection(con_info)
     return con.cursor()
Пример #10
0
 def _db_cur(self):
     con_info = get_postgres_conn_info(self.config['connection'])
     con = get_connection(con_info)
     return con.cursor()