I am developing a plugin for the GIS software, QGIS 2.14.3. I am also using Qt Designer 4.8.5.
I have several checkboxes which, when individually checked, executes their associated function. This selects polygon features on a GIS map and prints the sum of their area:
There's 5 ranks in total so 5 check boxes, the function for each are practically the same but here are the first 2:
selectedLayerIndex = self.dockwidget.combo_box.currentText()
sel_layer = QgsMapLayerRegistry.instance().mapLayersByName(str(selectedLayerIndex))[0]
self.iface.setActiveLayer(sel_layer)
def rank_0():
expr = QgsExpression( "\"Rank\"IS NULL" )
it = sel_layer.getFeatures( QgsFeatureRequest( expr ) )
ids = [i.id() for i in it]
if self.dockwidget.rank0_checkbox.isChecked():
sel_layer.setSelectedFeatures( ids )
for f in sel_layer.selectedFeatures():
sel_area = 0
sel_area += f.geometry().area()
self.dockwidget.lineEdit.setText("{:,.2f}".format(sel_area))
else:
sel_layer.removeSelection()
def rank_1():
expr = QgsExpression( "\"Rank\"= 1" )
it = sel_layer.getFeatures( QgsFeatureRequest( expr ) )
ids = [i.id() for i in it]
if self.dockwidget.rank1_checkbox.isChecked():
sel_layer.setSelectedFeatures( ids )
for f in sel_layer.selectedFeatures():
sel_area = 0
sel_area += f.geometry().area()
self.dockwidget.lineEdit.setText("{:,.2f}".format(sel_area))
else:
sel_layer.removeSelection()
How could I make it so that when multiple checkboxes are checked, the printed area is the sum from those checkboxes?
My guess is I would need to define another function to calculate the sum of the area and print it off but not sure how to proceed.