|
12 | 12 | # This will get replaced with a git SHA1 when you do a git archive
|
13 | 13 | __revision__ = '$Format:%H$'
|
14 | 14 |
|
| 15 | +from qgis.core import QgsRectangle, QgsFeatureRequest |
| 16 | + |
15 | 17 | def runGetFeatureTests( vl ):
|
16 | 18 | assert len( [f for f in vl.getFeatures()] ) == 5
|
17 |
| - assert len( [f for f in vl.getFeatures( 'name IS NOT NULL' )] ) == 4 |
18 |
| - assert len( [f for f in vl.getFeatures( 'name LIKE \'Apple\'' )] ) == 1 |
19 |
| - assert len( [f for f in vl.getFeatures( 'name ILIKE \'aPple\'' )] ) == 1 |
20 |
| - assert len( [f for f in vl.getFeatures( 'name ILIKE \'%pp%\'' )] ) == 1 |
21 |
| - assert len( [f for f in vl.getFeatures( 'cnt > 0' )] ) == 4 |
22 |
| - assert len( [f for f in vl.getFeatures( 'cnt < 0' )] ) == 1 |
23 |
| - assert len( [f for f in vl.getFeatures( 'cnt >= 100' )] ) == 4 |
24 |
| - assert len( [f for f in vl.getFeatures( 'cnt <= 100' )] ) == 2 |
25 |
| - assert len( [f for f in vl.getFeatures( 'pk IN (1, 2, 4, 8)' )] ) == 3 |
| 19 | + assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression( 'name IS NOT NULL' ) )] ) == 4 |
| 20 | + assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('name LIKE \'Apple\'' ) )] ) == 1 |
| 21 | + assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('name ILIKE \'aPple\'' ) )] ) == 1 |
| 22 | + assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('name ILIKE \'%pp%\'' ) )] ) == 1 |
| 23 | + assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('cnt > 0' ) ) ] ) == 4 |
| 24 | + assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('cnt < 0' ) ) ] ) == 1 |
| 25 | + assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('cnt >= 100' ) ) ] ) == 4 |
| 26 | + assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('cnt <= 100' ) ) ] ) == 2 |
| 27 | + assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('pk IN (1, 2, 4, 8)' ) )] ) == 3 |
26 | 28 |
|
| 29 | +def runGetFilterRectTests( vl ): |
| 30 | + extent = QgsRectangle(-70, 67, -60, 80) |
| 31 | + features = [ f.id() for f in vl.getFeatures( QgsFeatureRequest().setFilterRect( extent ) ) ] |
| 32 | + print (features) |
| 33 | + assert set( features ) == set( [2L, 4L] ) |
0 commit comments