Skip to Content
Mastering Geospatial Analysis with Python
book

Mastering Geospatial Analysis with Python

by Silas Toms, Paul Crickard, Eric van Rees
April 2018
Beginner to intermediate content levelBeginner to intermediate
440 pages
11h 36m
English
Packt Publishing
Content preview from Mastering Geospatial Analysis with Python

Selecting features using expressions

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Geospatial Analysis with Python

Learning Geospatial Analysis with Python

Joel Lawhead

Publisher Resources

ISBN: 9781788293334Supplemental Content