Skip to content
Permalink
Browse files

Merge pull request #8184 from rouault/fix_20098

[OGR provider] Make again a feature iterator to be resetable on a OSM layer (fixes #20098)
  • Loading branch information
rouault committed Oct 15, 2018
2 parents 530397c + 906f802 commit b777ab23b18619e32486e0c61fc8b3a894bac41c
@@ -311,7 +311,7 @@ bool QgsOgrFeatureIterator::fetchFeature( QgsFeature &feature )
// see more details here: https://trac.osgeo.org/gdal/wiki/rfc66_randomlayerreadwrite

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,2,0)
if ( mSource->mDriverName == QLatin1String( "OSM" ) )
if ( !QgsOgrProviderUtils::canDriverShareSameDatasetAmongLayers( mSource->mDriverName ) )
{
OGRLayerH nextFeatureBelongingLayer;
while ( fet.reset( GDALDatasetGetNextFeature( mConn->ds, &nextFeatureBelongingLayer, nullptr, nullptr, nullptr ) ), fet )
@@ -323,6 +323,7 @@ bool QgsOgrFeatureIterator::fetchFeature( QgsFeature &feature )
}
}
else
#endif
{

while ( fet.reset( OGR_L_GetNextFeature( mOgrLayer ) ), fet )
@@ -333,20 +334,25 @@ bool QgsOgrFeatureIterator::fetchFeature( QgsFeature &feature )
}
}
}
#else
while ( fet.reset( OGR_L_GetNextFeature( mOgrLayer ) ), fet )
{
if ( checkFeature( fet, feature ) )
{
return true;
}
}
#endif

close();
return false;
}

void QgsOgrFeatureIterator::resetReading()
{
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,2,0)
if ( !QgsOgrProviderUtils::canDriverShareSameDatasetAmongLayers( mSource->mDriverName ) )
{
GDALDatasetResetReading( mConn->ds );
}
else
#endif
{
OGR_L_ResetReading( mOgrLayer );
}
}


bool QgsOgrFeatureIterator::rewind()
{
@@ -355,7 +361,7 @@ bool QgsOgrFeatureIterator::rewind()
if ( mClosed || !mOgrLayer )
return false;

OGR_L_ResetReading( mOgrLayer );
resetReading();

mFilterFidsIt = mFilterFids.constBegin();

@@ -387,7 +393,7 @@ bool QgsOgrFeatureIterator::close()
// Will for example release SQLite3 statements
if ( mOgrLayer )
{
OGR_L_ResetReading( mOgrLayer );
resetReading();
}

if ( mOgrOrigLayer )
@@ -100,6 +100,8 @@ class QgsOgrFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsOgr
QgsFields mFieldsWithoutFid;

bool fetchFeatureWithId( QgsFeatureId id, QgsFeature &feature ) const;

void resetReading();
};

#endif // QGSOGRFEATUREITERATOR_H
@@ -454,6 +454,10 @@ def testOSM(self):
self.assertTrue(iter_multipolygons.nextFeature(f))
self.assertFalse(iter_multipolygons.nextFeature(f))

# Re-start an iterator (tests #20098)
iter_multipolygons = vl_multipolygons.getFeatures(QgsFeatureRequest())
self.assertTrue(iter_multipolygons.nextFeature(f))


if __name__ == '__main__':
unittest.main()

0 comments on commit b777ab2

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