Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Mastering QGIS
  • Table Of Contents Toc
Mastering QGIS

Mastering QGIS

By : Kurt Menke, GISP
4.6 (12)
close
close
Mastering QGIS

Mastering QGIS

4.6 (12)
By: Kurt Menke, GISP

Overview of this book

If you are a GIS professional, a consultant, a student, or perhaps a fast learner who wants to go beyond the basics of QGIS, then this book is for you. It will prepare you to realize the full potential of QGIS.
Table of Contents (12 chapters)
close
close
11
Index

Iterating over features


Now, it's time to discover how to get all the features or a subset of them. The main way to iterate over all features or records of myVector is by using the following code that shows the ID of each feature:

for feature in myVector.getFeatures():
    feature.id()

This will print a list of all the 653 record IDs as shown here:

0L
1L
...[cut]...
652L

It's not always necessary to parse all records to get a subset of them. In this case, we have to set the QgsFeatureRequest class parameters to instruct getFeatures and then retrieve only a subset of records; in some cases, we must also retrieve a subset of columns.

The following code will get only a subset of features and columns:

rect = QgsRectangle(  1223070.695,  2293653.357 , 9046974.211,  4184988.662)

myVector.setSubsetString(' "AREA_MI" > 1000 ')
request =  QgsFeatureRequest()
request.setSubsetOfAttributes([0, 2])
request.setFilterRect( rect )

for index, feature in enumerate( myVector.getFeatures( request ) ):
  ...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Mastering QGIS
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon