Skip to content

Commit 4ddf58c

Browse files
committedJun 3, 2018
Add feature source test for combination of filterfids AND filterrect
Both these conditions must be honored when set, i.e. features with matching IDs but which fail the rect check should not be returned.
1 parent 851319f commit 4ddf58c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
 

‎tests/src/python/featuresourcetestbase.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,36 @@ def testRectAndExpression(self):
521521
for f in self.source.getFeatures():
522522
self.assertEqual(request.acceptFeature(f), f['pk'] in expected)
523523

524+
def testRectAndFids(self):
525+
"""
526+
Test the combination of a filter rect along with filterfids
527+
"""
528+
529+
# first get feature ids
530+
ids = {f['pk']: f.id() for f in self.source.getFeatures()}
531+
532+
extent = QgsRectangle(-70, 67, -60, 80)
533+
request = QgsFeatureRequest().setFilterFids([ids[3], ids[4]]).setFilterRect(extent)
534+
result = set([f['pk'] for f in self.source.getFeatures(request)])
535+
all_valid = (all(f.isValid() for f in self.source.getFeatures(request)))
536+
expected = [4]
537+
assert set(expected) == result, 'Expected {} and got {} when testing for combination of filterRect and expression'.format(set(expected), result)
538+
self.assertTrue(all_valid)
539+
540+
# shouldn't matter what order this is done in
541+
request = QgsFeatureRequest().setFilterRect(extent).setFilterFids([ids[3], ids[4]])
542+
result = set([f['pk'] for f in self.source.getFeatures(request)])
543+
all_valid = (all(f.isValid() for f in self.source.getFeatures(request)))
544+
expected = [4]
545+
assert set(
546+
expected) == result, 'Expected {} and got {} when testing for combination of filterRect and expression'.format(
547+
set(expected), result)
548+
self.assertTrue(all_valid)
549+
550+
# test that results match QgsFeatureRequest.acceptFeature
551+
for f in self.source.getFeatures():
552+
self.assertEqual(request.acceptFeature(f), f['pk'] in expected)
553+
524554
def testGetFeaturesDestinationCrs(self):
525555
request = QgsFeatureRequest().setDestinationCrs(QgsCoordinateReferenceSystem('epsg:3785'), QgsProject.instance().transformContext())
526556
features = {f['pk']: f for f in self.source.getFeatures(request)}

0 commit comments

Comments
 (0)
Please sign in to comment.