mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[bugfix][ogr] Update extent when subsetstring is set in the ctor
Fixes #17863 - Zoom to layer has inconsistent behavior with filter
This commit is contained in:
parent
6424ceb113
commit
e9c9b5dfb6
@ -3909,10 +3909,10 @@ void QgsOgrProvider::open( OpenMode mode )
|
||||
QgsDebugMsg( QString( "Trying %1 syntax, mFilePath= %2" ).arg( vsiPrefix, mFilePath ) );
|
||||
}
|
||||
|
||||
QgsDebugMsg( "mFilePath: " + mFilePath );
|
||||
QgsDebugMsg( "mLayerIndex: " + QString::number( mLayerIndex ) );
|
||||
QgsDebugMsg( "mLayerName: " + mLayerName );
|
||||
QgsDebugMsg( "mSubsetString: " + mSubsetString );
|
||||
QgsDebugMsgLevel( "mFilePath: " + mFilePath, 3 );
|
||||
QgsDebugMsgLevel( "mLayerIndex: " + QString::number( mLayerIndex ), 3 );
|
||||
QgsDebugMsgLevel( "mLayerName: " + mLayerName, 3 );
|
||||
QgsDebugMsgLevel( "mSubsetString: " + mSubsetString, 3 );
|
||||
CPLSetConfigOption( "OGR_ORGANIZE_POLYGONS", "ONLY_CCW" ); // "SKIP" returns MULTIPOLYGONs for multiringed POLYGONs
|
||||
CPLSetConfigOption( "GPX_ELE_AS_25D", "YES" ); // use GPX elevation as z values
|
||||
|
||||
@ -4053,7 +4053,11 @@ void QgsOgrProvider::open( OpenMode mode )
|
||||
int featuresCountedBackup = mFeaturesCounted;
|
||||
mFeaturesCounted = -1;
|
||||
// Do not update capabilities here
|
||||
mValid = _setSubsetString( mSubsetString, false, false );
|
||||
// but ensure subset is set (setSubsetString does nothing if the passed sql subset string is equal to
|
||||
// mSubsetString, which is the case when reloading the dataset)
|
||||
QString origSubsetString = mSubsetString;
|
||||
mSubsetString.clear();
|
||||
mValid = _setSubsetString( origSubsetString, false, false );
|
||||
mFeaturesCounted = featuresCountedBackup;
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ __copyright__ = 'Copyright 2015, The QGIS Project'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import re
|
||||
import tempfile
|
||||
import shutil
|
||||
import glob
|
||||
@ -635,6 +636,42 @@ class TestPyQgsShapefileProvider(unittest.TestCase, ProviderTestCase):
|
||||
vl.setSubsetString('')
|
||||
self.assertTrue(vl.dataProvider().capabilities() & isEditable)
|
||||
|
||||
def testSubsetStringExtent_bug17863(self):
|
||||
"""Check that the extent is correct when applied in the ctor and when
|
||||
modified after a subset string is set """
|
||||
|
||||
def _lessdigits(s):
|
||||
return re.sub(r'(\d+\.\d{3})\d+', r'\1', s)
|
||||
|
||||
testPath = TEST_DATA_DIR + '/' + 'points.shp'
|
||||
subSetString = '"Class" = \'Biplane\''
|
||||
subSet = '|layerid=0|subset=%s' % subSetString
|
||||
|
||||
# unfiltered
|
||||
vl = QgsVectorLayer(testPath, 'test', 'ogr')
|
||||
self.assertTrue(vl.isValid())
|
||||
unfiltered_extent = _lessdigits(vl.extent().toString())
|
||||
del(vl)
|
||||
|
||||
# filter after construction ...
|
||||
subSet_vl2 = QgsVectorLayer(testPath, 'test', 'ogr')
|
||||
self.assertEqual(_lessdigits(subSet_vl2.extent().toString()), unfiltered_extent)
|
||||
# ... apply filter now!
|
||||
subSet_vl2.setSubsetString(subSetString)
|
||||
self.assertEqual(subSet_vl2.subsetString(), subSetString)
|
||||
self.assertNotEqual(_lessdigits(subSet_vl2.extent().toString()), unfiltered_extent)
|
||||
filtered_extent = _lessdigits(subSet_vl2.extent().toString())
|
||||
del(subSet_vl2)
|
||||
|
||||
# filtered in constructor
|
||||
subSet_vl = QgsVectorLayer(testPath + subSet, 'subset_test', 'ogr')
|
||||
self.assertEqual(subSet_vl.subsetString(), subSetString)
|
||||
self.assertTrue(subSet_vl.isValid())
|
||||
|
||||
# This was failing in bug 17863
|
||||
self.assertEqual(_lessdigits(subSet_vl.extent().toString()), filtered_extent)
|
||||
self.assertNotEqual(_lessdigits(subSet_vl.extent().toString()), unfiltered_extent)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user