[OGR] fix feature count issue for OSM datasets (fixes #16402) (#4322)

This commit is contained in:
Mathieu Pellerin 2017-04-06 16:04:48 +07:00 committed by GitHub
parent b601467d92
commit 25d9936df8
3 changed files with 29 additions and 3 deletions

View File

@ -57,6 +57,17 @@ class QgsVectorDataProvider : QgsDataProvider
/** Bitmask of all provider's editing capabilities */
static const int EditingCapabilities;
/**
* Enumeration of feature count states
*/
enum FeatureCountState
{
//! Feature count not yet computed
Uncounted = -2,
//! Provider returned an unknown feature count
UnknownCount = -1,
};
/**
* Constructor of the vector provider
* @param uri uniform resource locator (URI) for a dataset

View File

@ -112,6 +112,17 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes |
RenameAttributes;
/**
* Enumeration of feature count states
*/
enum FeatureCountState
{
//! Feature count not yet computed
Uncounted = -2,
//! Provider returned an unknown feature count
UnknownCount = -1,
};
/**
* Constructor of the vector provider
* \param uri uniform resource locator (URI) for a dataset

View File

@ -378,7 +378,7 @@ QgsOgrProvider::QgsOgrProvider( QString const &uri )
, ogrDriver( nullptr )
, mValid( false )
, mOGRGeomType( wkbUnknown )
, mFeaturesCounted( -1 )
, mFeaturesCounted( QgsVectorDataProvider::Uncounted )
, mWriteAccess( false )
, mWriteAccessPossible( false )
, mDynamicWriteAccess( false )
@ -450,7 +450,7 @@ bool QgsOgrProvider::setSubsetString( const QString &theSQL, bool updateFeatureC
if ( !ogrDataSource )
return false;
if ( theSQL == mSubsetString && mFeaturesCounted >= 0 )
if ( theSQL == mSubsetString && mFeaturesCounted != QgsVectorDataProvider::Uncounted )
return true;
OGRLayerH prevLayer = ogrLayer;
@ -3300,7 +3300,7 @@ void QgsOgrProvider::recalculateFeatureCount()
{
if ( !ogrLayer )
{
mFeaturesCounted = 0;
mFeaturesCounted = QgsVectorDataProvider::Uncounted;
return;
}
@ -3316,6 +3316,10 @@ void QgsOgrProvider::recalculateFeatureCount()
if ( mOgrGeometryTypeFilter == wkbUnknown )
{
mFeaturesCounted = OGR_L_GetFeatureCount( ogrLayer, true );
if ( mFeaturesCounted == -1 )
{
mFeaturesCounted = QgsVectorDataProvider::UnknownCount;
}
}
else
{