@@ -521,6 +521,36 @@ def testRectAndExpression(self):
521
521
for f in self .source .getFeatures ():
522
522
self .assertEqual (request .acceptFeature (f ), f ['pk' ] in expected )
523
523
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
+
524
554
def testGetFeaturesDestinationCrs (self ):
525
555
request = QgsFeatureRequest ().setDestinationCrs (QgsCoordinateReferenceSystem ('epsg:3785' ), QgsProject .instance ().transformContext ())
526
556
features = {f ['pk' ]: f for f in self .source .getFeatures (request )}
0 commit comments