QgsVectorLayer *layer = QgsVectorLayer("/path/to/layer.shp", "layer", "ogr"); QgsFeatureIterator iterator = layer->getFeatures(); while (iterator.nextFeature()) { QgsFeature feature = iterator.feature(); // Do something with the feature }
QgsExpression *expression = QgsExpression("AREA > 1000"); QgsFeatureRequest request = QgsFeatureRequest(expression); QgsFeatureIterator iterator = layer->getFeatures(request); while (iterator.nextFeature()) { QgsFeature feature = iterator.feature(); // Do something with the feature }In this example, we create a QgsFeatureRequest using a QgsExpression to filter the features that we want to iterate through. We then get a QgsFeatureIterator from the layer's features using the request and loop through each feature that matches the expression. The package library containing QgsFeatureIterator is the QGIS C++ API library.