def urban_zoom(self):
        ''' Zoom to layer 'urban' filtering values of all combos '''  

        # Build expresion search
        aux = ""
        layer = self.layers['urban_propierties_layer']      
        fieldname = self.params['urban_propierties_field_pzone']
        combo =  self.dlg.urban_properties_zone
        text = utils_giswater.getSelectedItem(combo)
        if text != "null":
            if aux != "":
                aux+= " AND "
            aux+= fieldname+" = '"+str(text)+"'"
            
        fieldname = self.params['urban_propierties_field_block']
        combo =  self.dlg.urban_properties_block
        text = utils_giswater.getSelectedItem(combo)
        if text != "null":
            if aux != "":
                aux+= " AND "
            aux+= fieldname+" = '"+str(text)+"'"
            
        fieldname = self.params['urban_propierties_field_number']
        combo =  self.dlg.urban_properties_number
        text = utils_giswater.getSelectedItem(combo)
        if text != "null":
            if aux != "":
                aux+= " AND "
            aux+= fieldname+" = '"+str(text)+"'"
         
        # Build a list of feature id's from the expression and select them       
        if aux != '':
            expr = QgsExpression(aux)    
            if expr.hasParserError():   
                message = expr.parserErrorString() + ": " + aux
                self.controller.show_warning(message)        
                return              
            it = layer.getFeatures(QgsFeatureRequest(expr))
            ids = [i.id() for i in it]
            layer.setSelectedFeatures(ids)
        # Select all features
        else:
            layer.selectAll()       
        
        # Copy selected features to memory layer     
        self.urbanMemLayer = self.copy_selected(layer, self.urbanMemLayer, "Polygon")       

        # Zoom to generated memory layer
        self.zoom_to_scale()
        
        # Load style
        if self.QML_URBAN is not None:
            self.load_style(self.urbanMemLayer, self.QML_URBAN) 
              
        # Toggles 'Show feature count'
        self.show_feature_count()                             
Example #2
0
    def initConfig(self):

        self.node_id = utils_giswater.getStringValue2("node_id")
        self.epa_type = utils_giswater.getSelectedItem("epa_type")

        # initialize plugin directory
        user_folder = os.path.expanduser("~")
        self.plugin_name = 'giswater'
        self.plugin_dir = os.path.join(
            user_folder, '.qgis2/python/plugins/' + self.plugin_name)

        # Get config file
        setting_file = os.path.join(self.plugin_dir, 'config',
                                    self.plugin_name + '.config')
        if not os.path.isfile(setting_file):
            message = "Config file not found at: " + setting_file
            self.iface.messageBar().pushMessage(message, QgsMessageBar.WARNING,
                                                5)
            self.close()
            return

        self.settings = QSettings(setting_file, QSettings.IniFormat)
        self.settings.setIniCodec(sys.getfilesystemencoding())

        # Get widget controls
        self.cbo_cat_nodetype_id = self.dialog.findChild(
            QComboBox, "cat_nodetype_iddd")
        self.cbo_nodecat_id = self.dialog.findChild(QComboBox, "nodecat_id")
        self.tab_analysis = self.dialog.findChild(QTabWidget, "tab_analysis")
        self.tab_event = self.dialog.findChild(QTabWidget, "tab_event")

        # Set controller to handle settings and database connection
        # TODO: Try to make only one connection
        self.controller = DaoController(self.settings, self.plugin_name)
        status = self.controller.set_database_connection()
        if not status:
            message = self.controller.getLastError()
            self.iface.messageBar().pushMessage(message, QgsMessageBar.WARNING,
                                                5)
            return

        self.schema_name = self.controller.getSchemaName()
        self.dao = self.controller.getDao()

        # Manage tab visibility
        self.setTabsVisibility()

        # Manage i18n
        self.translateForm()

        # Fill combo 'node type' from 'epa_type'
        self.fillNodeType()

        # Load data from related tables
        self.loadData()

        # Set layer in editing mode
        self.layer.startEditing()
 def changeNodeType(self, index):
     """ Define and execute query to populate combo 'nodecat_id_dummy' """
     cat_nodetype_id = utils_giswater.getSelectedItem("cat_nodetype_id")     
     sql = "SELECT id FROM "+self.schema_name+".cat_arc WHERE arctype_id = '"+cat_nodetype_id+"' UNION "
     sql+= "SELECT id FROM "+self.schema_name+".cat_node WHERE nodetype_id = '"+cat_nodetype_id+"' ORDER BY id"   
     rows = self.dao.get_rows(sql)
     self.cbo_nodecat_id = self.dialog.findChild(QComboBox, "nodecat_id_dummy")
     utils_giswater.fillComboBox(self.cbo_nodecat_id, rows, False)  
     self.changeNodeCat(0)       
 def fillNodeType(self):
     """ Define and execute query to populate combo 'cat_nodetype_id' """
     cat_nodetype_id = utils_giswater.getSelectedItem("cat_nodetype_id")     
     sql = "SELECT id, man_table, epa_table FROM "+self.schema_name+".arc_type WHERE epa_default = '"+self.epa_type+"' UNION "
     sql+= "SELECT id, man_table, epa_table FROM "+self.schema_name+".node_type WHERE epa_default = '"+self.epa_type+"' ORDER BY id"
     rows = self.dao.get_rows(sql)     
     self.cbo_cat_nodetype_id = self.dialog.findChild(QComboBox, "cat_nodetype_id")    
     utils_giswater.fillComboBox(self.cbo_cat_nodetype_id, rows)
     utils_giswater.setSelectedItem('cat_nodetype_id', cat_nodetype_id)
 def urban_field_block(self):
     ''' Executed when 'urban_propierties_field_block' is activated '''
     
     text_zone = utils_giswater.getSelectedItem(self.dlg.urban_properties_zone)
     text_block = utils_giswater.getSelectedItem(self.dlg.urban_properties_block)
         
     # Filter combo 'urban_properties_number' with values selected in combos 'urban_properties_zone' and 'urban_properties_block'
     sql = "SELECT DISTINCT("+self.params['urban_propierties_field_number']+"::int4)"
     sql+= " FROM "+self.controller.schema_name+"."+self.params['urban_propierties_layer']
     if text_zone != 'null':
         sql+= " WHERE "+self.params['urban_propierties_field_pzone']+" = '"+str(text_zone)+"'"
     if text_block != 'null':
         sql+= " AND "+self.params['urban_propierties_field_block']+" = '"+str(text_block)+"'"
     sql+= " ORDER BY "+self.params['urban_propierties_field_number']
     rows = self.controller.dao.get_rows(sql)
     utils_giswater.fillComboBox(self.dlg.urban_properties_number, rows)
     
     # Make zoom to selected elements
     self.urban_zoom()   
Example #6
0
 def changeNodeType(self, index):
     """ Define and execute query to populate combo 'nodecat_id_dummy' """
     cat_nodetype_id = utils_giswater.getSelectedItem("cat_nodetype_id")
     sql = "SELECT id FROM " + self.schema_name + ".cat_arc WHERE arctype_id = '" + cat_nodetype_id + "' UNION "
     sql += "SELECT id FROM " + self.schema_name + ".cat_node WHERE nodetype_id = '" + cat_nodetype_id + "' ORDER BY id"
     rows = self.dao.get_rows(sql)
     self.cbo_nodecat_id = self.dialog.findChild(QComboBox,
                                                 "nodecat_id_dummy")
     utils_giswater.fillComboBox(self.cbo_nodecat_id, rows, False)
     self.changeNodeCat(0)
Example #7
0
 def fillNodeType(self):
     """ Define and execute query to populate combo 'cat_nodetype_id' """
     cat_nodetype_id = utils_giswater.getSelectedItem("cat_nodetype_id")
     sql = "SELECT id, man_table, epa_table FROM " + self.schema_name + ".arc_type WHERE epa_default = '" + self.epa_type + "' UNION "
     sql += "SELECT id, man_table, epa_table FROM " + self.schema_name + ".node_type WHERE epa_default = '" + self.epa_type + "' ORDER BY id"
     rows = self.dao.get_rows(sql)
     self.cbo_cat_nodetype_id = self.dialog.findChild(
         QComboBox, "cat_nodetype_id")
     utils_giswater.fillComboBox(self.cbo_cat_nodetype_id, rows)
     utils_giswater.setSelectedItem('cat_nodetype_id', cat_nodetype_id)
 def initConfig(self):    
     
     self.node_id = utils_giswater.getStringValue2("node_id")
     self.epa_type = utils_giswater.getSelectedItem("epa_type")
         
     # initialize plugin directory
     user_folder = os.path.expanduser("~") 
     self.plugin_name = 'giswater'  
     self.plugin_dir = os.path.join(user_folder, '.qgis2/python/plugins/'+self.plugin_name)    
     
     # Get config file
     setting_file = os.path.join(self.plugin_dir, 'config', self.plugin_name+'.config')
     if not os.path.isfile(setting_file):
         message = "Config file not found at: "+setting_file
         self.iface.messageBar().pushMessage(message, QgsMessageBar.WARNING, 5)  
         self.close()
         return
         
     self.settings = QSettings(setting_file, QSettings.IniFormat)
     self.settings.setIniCodec(sys.getfilesystemencoding())
     
     # Get widget controls
     self.cbo_cat_nodetype_id = self.dialog.findChild(QComboBox, "cat_nodetype_iddd")      
     self.cbo_nodecat_id = self.dialog.findChild(QComboBox, "nodecat_id")   
     self.tab_analysis = self.dialog.findChild(QTabWidget, "tab_analysis")            
     self.tab_event = self.dialog.findChild(QTabWidget, "tab_event")         
     
     # Set controller to handle settings and database connection
     # TODO: Try to make only one connection
     self.controller = DaoController(self.settings, self.plugin_name)
     status = self.controller.set_database_connection()      
     if not status:
         message = self.controller.getLastError()
         self.iface.messageBar().pushMessage(message, QgsMessageBar.WARNING, 5) 
         return 
          
     self.schema_name = self.controller.getSchemaName()            
     self.dao = self.controller.getDao()
          
     # Manage tab visibility
     self.setTabsVisibility()
     
     # Manage i18n
     self.translateForm()
     
     # Fill combo 'node type' from 'epa_type'
     self.fillNodeType()
     
     # Load data from related tables
     self.loadData()
     
     # Set layer in editing mode
     self.layer.startEditing()
def initConfig():
     
    node_dialog.dialog.findChild(QComboBox, "nodecat_id").setVisible(False)         
    node_dialog.dialog.findChild(QComboBox, "cat_nodetype_id").activated.connect(node_dialog.changeNodeType)    
    node_dialog.changeNodeType(-1)  
    nodecat_id = utils_giswater.getSelectedItem("nodecat_id")
    utils_giswater.setSelectedItem("nodecat_id_dummy", nodecat_id)            
    node_dialog.dialog.findChild(QComboBox, "nodecat_id_dummy").activated.connect(node_dialog.changeNodeCat)          
    node_dialog.dialog.findChild(QComboBox, "epa_type").activated.connect(node_dialog.changeEpaType)    
    
    node_dialog.dialog.findChild(QPushButton, "btnAccept").clicked.connect(node_dialog.save)            
    node_dialog.dialog.findChild(QPushButton, "btnClose").clicked.connect(node_dialog.close)        
 def ppoint_field_zone(self):
     ''' Executed when field_zone is activated '''
     
     # Filter combo 'ppoint_number' with value selected in combo 'ppoint_field_zone'
     text = utils_giswater.getSelectedItem(self.dlg.ppoint_field_zone) 
     sql = "SELECT DISTINCT("+self.params['ppoint_field_number']+"::int4)"
     sql+= " FROM "+self.controller.schema_name+"."+self.params['ppoint_layer']
     if text != 'null':
         sql+= " WHERE "+self.params['ppoint_field_zone']+" = '"+str(text)+"'"
     sql+= " ORDER BY "+self.params['ppoint_field_number']
     rows = self.controller.dao.get_rows(sql)
     utils_giswater.fillComboBox(self.dlg.ppoint_number, rows)
     
     # Make zoom to selected elements
     self.ppoint_zoom()   
Example #11
0
def initConfig():

    node_dialog.dialog.findChild(QComboBox, "nodecat_id").setVisible(False)
    node_dialog.dialog.findChild(QComboBox,
                                 "cat_nodetype_id").activated.connect(
                                     node_dialog.changeNodeType)
    node_dialog.changeNodeType(-1)
    nodecat_id = utils_giswater.getSelectedItem("nodecat_id")
    utils_giswater.setSelectedItem("nodecat_id_dummy", nodecat_id)
    node_dialog.dialog.findChild(QComboBox,
                                 "nodecat_id_dummy").activated.connect(
                                     node_dialog.changeNodeCat)
    node_dialog.dialog.findChild(QComboBox, "epa_type").activated.connect(
        node_dialog.changeEpaType)

    node_dialog.dialog.findChild(QPushButton,
                                 "btnAccept").clicked.connect(node_dialog.save)
    node_dialog.dialog.findChild(QPushButton,
                                 "btnClose").clicked.connect(node_dialog.close)
Example #12
0
 def changeEpaType(self, index):
     """ Just select item to 'real' combo 'nodecat_id' (that is hidden) """
     epa_type = utils_giswater.getSelectedItem("epa_type")
     self.save()
     self.iface.openFeatureForm(self.layer, self.feature)
Example #13
0
 def changeNodeCat(self, index):
     """ Just select item to 'real' combo 'nodecat_id' (that is hidden) """
     dummy = utils_giswater.getSelectedItem("nodecat_id_dummy")
     utils_giswater.setSelectedItem("nodecat_id", dummy)
 def changeEpaType(self, index):
     """ Just select item to 'real' combo 'nodecat_id' (that is hidden) """
     epa_type = utils_giswater.getSelectedItem("epa_type")
     self.save()
     self.iface.openFeatureForm(self.layer, self.feature)        
 def changeNodeCat(self, index):
     """ Just select item to 'real' combo 'nodecat_id' (that is hidden) """
     dummy = utils_giswater.getSelectedItem("nodecat_id_dummy")
     utils_giswater.setSelectedItem("nodecat_id", dummy)