April 2018
Beginner to intermediate
440 pages
11h 36m
English
Using expressions, you can iterate through features and evaluate the expression returning true(1) or false(0). Before we get into expressions, let's select and highlight a feature. Selecting a feature is accomplished by calling setSelectedFeatures() and passing a list of IDs. The following code will select a single feature:
from qgis.PyQt.QtGui import *from qgis.PyQt.QtWidgets import *iface.mapCanvas().setSelectionColor( QColor("red") )scf.setSelectedFeatures([100])
The previous code, imports QtGUI, and Qt.Widgets. These are needed to set the color using QColor. The next line gets the map canvas and sets the section color to red. Lastly, the code selects the feature with an id of 100. It will now display ...