Skip to content
Permalink
Browse files

[OGR provider] Make extent() return a isNull() rectangle on empty lay…

…er (fixes #16721)
  • Loading branch information
rouault committed Nov 12, 2017
1 parent 7e699f1 commit 3ff0f6979407f4dbc466b37b8087d585900cc3de
Showing with 8 additions and 6 deletions.
  1. +6 −6 src/providers/ogr/qgsogrprovider.cpp
  2. +2 −0 tests/src/python/test_provider_ogr_gpkg.py
@@ -1097,25 +1097,25 @@ QgsRectangle QgsOgrProvider::extent() const
}
#endif

mExtent->MinX = std::numeric_limits<double>::max();
mExtent->MinY = std::numeric_limits<double>::max();
mExtent->MaxX = -std::numeric_limits<double>::max();
mExtent->MaxY = -std::numeric_limits<double>::max();

// TODO: This can be expensive, do we really need it!
if ( mOgrLayer == mOgrOrigLayer )
{
mOgrLayer->GetExtent( mExtent, true );
}
else
{
mExtent->MinX = std::numeric_limits<double>::max();
mExtent->MinY = std::numeric_limits<double>::max();
mExtent->MaxX = -std::numeric_limits<double>::max();
mExtent->MaxY = -std::numeric_limits<double>::max();

gdal::ogr_feature_unique_ptr f;

mOgrLayer->ResetReading();
while ( f.reset( mOgrLayer->GetNextFeature() ), f )
{
OGRGeometryH g = OGR_F_GetGeometryRef( f.get() );
if ( g )
if ( g && !OGR_G_IsEmpty( g ) )
{
OGREnvelope env;
OGR_G_GetEnvelope( g, &env );
@@ -589,6 +589,8 @@ def testGeopackageRefreshIfTableListUpdated(self):

vl = QgsVectorLayer(u'{}'.format(tmpfile) + "|layername=" + "test", 'test', u'ogr')

self.assertTrue(vl.extent().isNull())

time.sleep(1) # so timestamp gets updated
ds = ogr.Open(tmpfile, update=1)
ds.CreateLayer('test2', geom_type=ogr.wkbPoint)

0 comments on commit 3ff0f69

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