Skip to content

Commit

Permalink
[OGR] fix feature count issue for OSM datasets (fixes #16402) (#4322)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Apr 6, 2017
1 parent b601467 commit 25d9936
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
11 changes: 11 additions & 0 deletions python/core/qgsvectordataprovider.sip
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3300,7 +3300,7 @@ void QgsOgrProvider::recalculateFeatureCount()
{
if ( !ogrLayer )
{
mFeaturesCounted = 0;
mFeaturesCounted = QgsVectorDataProvider::Uncounted;
return;
}

Expand All @@ -3316,6 +3316,10 @@ void QgsOgrProvider::recalculateFeatureCount()
if ( mOgrGeometryTypeFilter == wkbUnknown )
{
mFeaturesCounted = OGR_L_GetFeatureCount( ogrLayer, true );
if ( mFeaturesCounted == -1 )
{
mFeaturesCounted = QgsVectorDataProvider::UnknownCount;
}
}
else
{
Expand Down

0 comments on commit 25d9936

Please sign in to comment.