Skip to content
Permalink
Browse files

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.
  • Loading branch information
nyalldawson committed Jun 3, 2018
1 parent 851319f commit 4ddf58c01c4c0a80b43c0ba2d9d654bddd49ccb6
Showing with 30 additions and 0 deletions.
  1. +30 −0 tests/src/python/featuresourcetestbase.py
@@ -521,6 +521,36 @@ def testRectAndExpression(self):
for f in self.source.getFeatures():
self.assertEqual(request.acceptFeature(f), f['pk'] in expected)

def testRectAndFids(self):
"""
Test the combination of a filter rect along with filterfids
"""

# first get feature ids
ids = {f['pk']: f.id() for f in self.source.getFeatures()}

extent = QgsRectangle(-70, 67, -60, 80)
request = QgsFeatureRequest().setFilterFids([ids[3], ids[4]]).setFilterRect(extent)
result = set([f['pk'] for f in self.source.getFeatures(request)])
all_valid = (all(f.isValid() for f in self.source.getFeatures(request)))
expected = [4]
assert set(expected) == result, 'Expected {} and got {} when testing for combination of filterRect and expression'.format(set(expected), result)
self.assertTrue(all_valid)

# shouldn't matter what order this is done in
request = QgsFeatureRequest().setFilterRect(extent).setFilterFids([ids[3], ids[4]])
result = set([f['pk'] for f in self.source.getFeatures(request)])
all_valid = (all(f.isValid() for f in self.source.getFeatures(request)))
expected = [4]
assert set(
expected) == result, 'Expected {} and got {} when testing for combination of filterRect and expression'.format(
set(expected), result)
self.assertTrue(all_valid)

# test that results match QgsFeatureRequest.acceptFeature
for f in self.source.getFeatures():
self.assertEqual(request.acceptFeature(f), f['pk'] in expected)

def testGetFeaturesDestinationCrs(self):
request = QgsFeatureRequest().setDestinationCrs(QgsCoordinateReferenceSystem('epsg:3785'), QgsProject.instance().transformContext())
features = {f['pk']: f for f in self.source.getFeatures(request)}

0 comments on commit 4ddf58c

Please sign in to comment.
You can’t perform that action at this time.