Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 4ddf58c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/src/python/featuresourcetestbase.py
Expand Up @@ -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)}
Expand Down

0 comments on commit 4ddf58c

Please sign in to comment.