What is the equivalent in QGIS (or other FOSS) to this:
rows = arcpy.SearchCursor(table,
fields="ORIG_FID; field1; field2; field3; field4",
sort_fields="ORIG_FID A")
for row in rows:
What is the equivalent in QGIS (or other FOSS) to this:
rows = arcpy.SearchCursor(table,
fields="ORIG_FID; field1; field2; field3; field4",
sort_fields="ORIG_FID A")
for row in rows:
Check out the PyQGIS Cookbook's section on Using Vector Layers.
Hacking together the examples there:
# The expression will filter the features where the field "location_name" contains
# the word "Lake" (case insensitive)
exp = QgsExpression('location_name ILIKE \'%Lake%\'')
request = QgsFeatureRequest(exp)
request.setSubsetOfAttributes(['name','id'],layer.pendingFields())
for feature in layer.getFeatures(request):
# do whatever you need with the feature
Also, see this question for some other hints: What are QGIS Arcpy Equivalent Functions for Update/Delete Row/Field?
Use .getFeatures(), this returns all layer field values:
Query the provider for features specified in request.
for feature in table.getFeatures():
if feature['myField'] == someVariable:
# do something