|
15 | 15 | import qgis # NOQA
|
16 | 16 |
|
17 | 17 | import os
|
| 18 | +import re |
18 | 19 | import sys
|
19 | 20 | import shutil
|
20 | 21 | import tempfile
|
@@ -187,6 +188,37 @@ def setUpClass(cls):
|
187 | 188 | sql = "CREATE TABLE test_defaults (id INTEGER NOT NULL PRIMARY KEY, name TEXT DEFAULT 'qgis ''is good', number INTEGER DEFAULT 5, number2 REAL DEFAULT 5.7, no_default REAL)"
|
188 | 189 | cur.execute(sql)
|
189 | 190 |
|
| 191 | + # simple table with catgorized points |
| 192 | + sql = "CREATE TABLE test_filter (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL)" |
| 193 | + cur.execute(sql) |
| 194 | + sql = "SELECT AddGeometryColumn('test_filter', 'geometry', 4326, 'POINT', 'XY')" |
| 195 | + cur.execute(sql) |
| 196 | + sql = "INSERT INTO test_filter (id, name, geometry) " |
| 197 | + sql += "VALUES (1, 'ext', GeomFromText('POINT(0 0)', 4326))" |
| 198 | + cur.execute(sql) |
| 199 | + sql = "INSERT INTO test_filter (id, name, geometry) " |
| 200 | + sql += "VALUES (2, 'ext', GeomFromText('POINT(0 3)', 4326))" |
| 201 | + cur.execute(sql) |
| 202 | + sql = "INSERT INTO test_filter (id, name, geometry) " |
| 203 | + sql += "VALUES (3, 'ext', GeomFromText('POINT(3 3)', 4326))" |
| 204 | + cur.execute(sql) |
| 205 | + sql = "INSERT INTO test_filter (id, name, geometry) " |
| 206 | + sql += "VALUES (4, 'ext', GeomFromText('POINT(3 0)', 4326))" |
| 207 | + cur.execute(sql) |
| 208 | + |
| 209 | + sql = "INSERT INTO test_filter (id, name, geometry) " |
| 210 | + sql += "VALUES (5, 'int', GeomFromText('POINT(1 1)', 4326))" |
| 211 | + cur.execute(sql) |
| 212 | + sql = "INSERT INTO test_filter (id, name, geometry) " |
| 213 | + sql += "VALUES (6, 'int', GeomFromText('POINT(1 2)', 4326))" |
| 214 | + cur.execute(sql) |
| 215 | + sql = "INSERT INTO test_filter (id, name, geometry) " |
| 216 | + sql += "VALUES (7, 'int', GeomFromText('POINT(2 2)', 4326))" |
| 217 | + cur.execute(sql) |
| 218 | + sql = "INSERT INTO test_filter (id, name, geometry) " |
| 219 | + sql += "VALUES (8, 'int', GeomFromText('POINT(2 1)', 4326))" |
| 220 | + cur.execute(sql) |
| 221 | + |
190 | 222 | cur.execute("COMMIT")
|
191 | 223 | con.close()
|
192 | 224 |
|
@@ -663,6 +695,52 @@ def testCreateAttributeIndex(self):
|
663 | 695 | self.assertEqual(set(indexed_columns), set(['name', 'number']))
|
664 | 696 | con.close()
|
665 | 697 |
|
| 698 | + def testSubsetStringExtent_bug17863(self): |
| 699 | + """Check that the extent is correct when applied in the ctor and when |
| 700 | + modified after a subset string is set """ |
| 701 | + |
| 702 | + def _lessdigits(s): |
| 703 | + return re.sub(r'(\d+\.\d{3})\d+', r'\1', s) |
| 704 | + |
| 705 | + testPath = "dbname=%s table='test_filter' (geometry) key='id'" % self.dbname |
| 706 | + |
| 707 | + subSetString = '"name" = \'int\'' |
| 708 | + subSet = ' sql=%s' % subSetString |
| 709 | + |
| 710 | + # unfiltered |
| 711 | + vl = QgsVectorLayer(testPath, 'test', 'spatialite') |
| 712 | + self.assertTrue(vl.isValid()) |
| 713 | + self.assertEqual(vl.featureCount(), 8) |
| 714 | + unfiltered_extent = _lessdigits(vl.extent().toString()) |
| 715 | + self.assertNotEqual('Empty', unfiltered_extent) |
| 716 | + del(vl) |
| 717 | + |
| 718 | + # filter after construction ... |
| 719 | + subSet_vl2 = QgsVectorLayer(testPath, 'test', 'spatialite') |
| 720 | + self.assertEqual(_lessdigits(subSet_vl2.extent().toString()), unfiltered_extent) |
| 721 | + self.assertEqual(subSet_vl2.featureCount(), 8) |
| 722 | + # ... apply filter now! |
| 723 | + subSet_vl2.setSubsetString(subSetString) |
| 724 | + self.assertEqual(subSet_vl2.featureCount(), 4) |
| 725 | + self.assertEqual(subSet_vl2.subsetString(), subSetString) |
| 726 | + self.assertNotEqual(_lessdigits(subSet_vl2.extent().toString()), unfiltered_extent) |
| 727 | + filtered_extent = _lessdigits(subSet_vl2.extent().toString()) |
| 728 | + del(subSet_vl2) |
| 729 | + |
| 730 | + # filtered in constructor |
| 731 | + subSet_vl = QgsVectorLayer(testPath + subSet, 'subset_test', 'spatialite') |
| 732 | + self.assertEqual(subSet_vl.subsetString(), subSetString) |
| 733 | + self.assertTrue(subSet_vl.isValid()) |
| 734 | + |
| 735 | + # This was failing in bug 17863 |
| 736 | + self.assertEqual(subSet_vl.featureCount(), 4) |
| 737 | + self.assertEqual(_lessdigits(subSet_vl.extent().toString()), filtered_extent) |
| 738 | + self.assertNotEqual(_lessdigits(subSet_vl.extent().toString()), unfiltered_extent) |
| 739 | + |
| 740 | + self.assertTrue(subSet_vl.setSubsetString('')) |
| 741 | + self.assertEqual(subSet_vl.featureCount(), 8) |
| 742 | + self.assertEqual(_lessdigits(subSet_vl.extent().toString()), unfiltered_extent) |
| 743 | + |
666 | 744 |
|
667 | 745 | if __name__ == '__main__':
|
668 | 746 | unittest.main()
|
0 commit comments