I'm trying to select features using a string comparison within my script using a
roadsRequest = QgsFeatureRequest() roadsExpression = str(roadsIDField) + ' LIKE ' + str(featIDUnique) feedback.pushInfo(roadsExpression)
For reference then, the roadsExpression looks like the below or I have tried using an " = " operator too:
identifier LIKE 534553B5-9A71-4DE2-B8C2-56B0B31D5EB2
I've then set the filter expression of the
QgsFeatureRequest() object and passed attempted to get features as below and
getFeatures() should return a
roadsRequest.setFilterExpression(roadsExpression) roadsFeatures = roadsSource.getFeatures(roadsRequest)
Now, I've brought
roadsSource in as a
parameterAsSource() to provide a
QgsProcessingFeatureSource() object and I therefore get a valid
QgsFeatureIterator object in
roadsFeatures but this is empty.
However, I am unable to edit a
QgsProcessingFeatureSource object therefore I tried bringing
roadsSource in using
parameterAsVectorLayer() to provide a
QgsVectorLayer() object that I can edit. However when I use
getFeatures(roadsRequest) on this vector layer object, I get an invalid feature iterator.
I think I am doing something wrong with how I've built my request using the strings but I don't know what as everything is compiling and running without any errors, I'm just not getting the results out that I expect.