Skip to content
Permalink
Browse files

[Vector] Use XML Extent even if data provider has metadata

The XML extent was only used if the data provider has no metadata.
This means that only PostGIS views and materialized views can benefit from the use of the XML Extent.

This commit removes this constraint
  • Loading branch information
rldhont committed Mar 30, 2021
1 parent 764c652 commit b681de9a2f1b1a854f88175ac375c965e1ef8536
Showing with 12 additions and 2 deletions.
  1. +1 −1 src/core/vector/qgsvectorlayer.cpp
  2. +11 −1 tests/src/python/test_provider_postgres.py
@@ -846,7 +846,7 @@ QgsRectangle QgsVectorLayer::extent() const
if ( !isSpatial() )
return rect;

if ( !mValidExtent && mLazyExtent && mDataProvider && !mDataProvider->hasMetadata() && mReadExtentFromXml && !mXmlExtent.isNull() )
if ( !mValidExtent && mLazyExtent && mReadExtentFromXml && !mXmlExtent.isNull() )
{
updateExtent( mXmlExtent );
mValidExtent = true;
@@ -2046,13 +2046,23 @@ def testReadExtentOnTable(self):
self.assertEqual(vl1.extent(), originalExtent)

# read xml with custom extent with readExtent option. Extent read from
# xml document should NOT be used because we don't have a view or a
# xml document should be used even if we don't have a view or a
# materialized view
vl2 = QgsVectorLayer()
vl2.setReadExtentFromXml(True)
vl2.readLayerXml(elem, QgsReadWriteContext())
self.assertTrue(vl2.isValid())

self.assertEqual(vl2.extent(), customExtent)

# but a force update on extent should allow retrieveing the data
# provider extent
vl2.updateExtents()
vl2.readLayerXml(elem, QgsReadWriteContext())
self.assertEqual(vl2.extent(), customExtent)

vl2.updateExtents(force=True)
vl2.readLayerXml(elem, QgsReadWriteContext())
self.assertEqual(vl2.extent(), originalExtent)

def testDeterminePkey(self):

0 comments on commit b681de9

Please sign in to comment.