From 25d9936df8ab920519e0f44f01c7a7bf457b7601 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Thu, 6 Apr 2017 16:04:48 +0700 Subject: [PATCH] [OGR] fix feature count issue for OSM datasets (fixes #16402) (#4322) --- python/core/qgsvectordataprovider.sip | 11 +++++++++++ src/core/qgsvectordataprovider.h | 11 +++++++++++ src/providers/ogr/qgsogrprovider.cpp | 10 +++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/python/core/qgsvectordataprovider.sip b/python/core/qgsvectordataprovider.sip index 3c43a1e6f05..a7f6c2d7f32 100644 --- a/python/core/qgsvectordataprovider.sip +++ b/python/core/qgsvectordataprovider.sip @@ -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 diff --git a/src/core/qgsvectordataprovider.h b/src/core/qgsvectordataprovider.h index 492c9be12e4..acc99a84686 100644 --- a/src/core/qgsvectordataprovider.h +++ b/src/core/qgsvectordataprovider.h @@ -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 diff --git a/src/providers/ogr/qgsogrprovider.cpp b/src/providers/ogr/qgsogrprovider.cpp index 0398301ebef..16d9226a1d5 100644 --- a/src/providers/ogr/qgsogrprovider.cpp +++ b/src/providers/ogr/qgsogrprovider.cpp @@ -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 {