Skip to content

Commit

Permalink
[OGR provider] Make extent() return a isNull() rectangle on empty lay…
Browse files Browse the repository at this point in the history
…er (fixes #16721)
  • Loading branch information
rouault committed Nov 12, 2017
1 parent 7e699f1 commit 3ff0f69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_provider_ogr_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3ff0f69

Please sign in to comment.