Skip to content
Permalink
Browse files

[bugfix][ogr] Update extent when subsetstring is set in the ctor

Fixes #17863 - Zoom to layer has inconsistent behavior with filter
  • Loading branch information
elpaso committed Jan 25, 2018
1 parent 6424ceb commit e9c9b5dfb6016322d60add6277ee3e0ab5e9113e
Showing with 46 additions and 5 deletions.
  1. +9 −5 src/providers/ogr/qgsogrprovider.cpp
  2. +37 −0 tests/src/python/test_provider_shapefile.py
@@ -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 @@
__revision__ = '$Format:%H$'

import os
import re
import tempfile
import shutil
import glob
@@ -635,6 +636,42 @@ def testSubSetStringEditable_bug17795(self):
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()

0 comments on commit e9c9b5d

Please sign in to comment.
You can’t perform that action at this time.