'Testing the Layer.spatial_filter property.'

def test06_spatial_filter(self):

    ds = DataSource(get_ds_file('cities', 'shp'))
    lyr = ds[0]
    self.assertEqual(None, lyr.spatial_filter)
    self.assertRaises(TypeError, lyr._set_spatial_filter, 'foo')
    self.assertRaises(ValueError, lyr._set_spatial_filter, list(range(5)))
    filter_extent = ((-105.609252), 37.255001, (-103.609252), 39.255001)
    lyr.spatial_filter = ((-105.609252), 37.255001, (-103.609252), 39.255001)
    self.assertEqual(OGRGeometry.from_bbox(filter_extent), lyr.spatial_filter)
    feats = [feat for feat in lyr]
    self.assertEqual(1, len(feats))
    self.assertEqual('Pueblo', feats[0].get('Name'))
    filter_geom = OGRGeometry('POLYGON((-96.363151    28.763374,-94.363151    28.763374,-94.363151    30.763374,-96.363151    30.763374,-96.363151    28.763374))')
    lyr.spatial_filter = filter_geom
    self.assertEqual(filter_geom, lyr.spatial_filter)
    feats = [feat for feat in lyr]
    self.assertEqual(1, len(feats))
    self.assertEqual('Houston', feats[0].get('Name'))
    lyr.spatial_filter = None
    self.assertEqual(3, len(lyr))
