Skip to content

Commit

Permalink
[Vector] Use XML Extent even if data provider has metadata
Browse files Browse the repository at this point in the history
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

(cherry picked from commit b681de9)
  • Loading branch information
rldhont authored and nyalldawson committed Apr 17, 2021
1 parent 0b3495e commit a339465
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -838,7 +838,7 @@ QgsRectangle QgsVectorLayer::extent() const
if ( !isSpatial() )
return rect;

if ( !mValidExtent && mLazyExtent && mDataProvider && !mDataProvider->hasMetadata() && mReadExtentFromXml && !mXmlExtent.isNull() )
if ( !mValidExtent && mLazyExtent && mReadExtentFromXml && !mXmlExtent.isNull() )
{
mExtent = mXmlExtent;
mValidExtent = true;
Expand Down
12 changes: 11 additions & 1 deletion tests/src/python/test_provider_postgres.py
Expand Up @@ -2044,13 +2044,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):
Expand Down

0 comments on commit a339465

Please sign in to comment.