Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I do

from qgis.core import *
layer = QgsVectorLayer(r"D:\file.shp", "boundingBoxes", "ogr")

outcome is 428

outcome is 0

Why the results are not equal?

share|improve this question
up vote 6 down vote accepted
  • layer.featureCount() - Total Number of features in the layer.
  • layer.selectedFeatureCount() - Total number of features that are actually selected on the map canvas for the particular layer
  • - This does not in fact make any visible map selection. What this does is to create an iterator to loop over all the features in the layer.

For making a real selection in the map, you will need to iterate and store the feature ids to a list and then pass it to setSelectedFeatures(const QgsFeatureIds & ids) method. Like below..
ids = []
for feature in layer:
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.