Skip to content

Commit

Permalink
Implement spatial index detection for OGR provider
Browse files Browse the repository at this point in the history
Provides warnings in Processing algorithms when running on layers
which don't have a spatial index present (e.g. geojson files) and
where performance will be severely hurt as a result

Fixes #30530
  • Loading branch information
nyalldawson committed May 20, 2020
1 parent 2099261 commit f20801a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -3863,6 +3863,16 @@ QStringList QgsOgrProvider::uniqueStringsMatching( int index, const QString &sub
return results;
}

QgsFeatureSource::SpatialIndexPresence QgsOgrProvider::hasSpatialIndex() const
{
if ( mOgrLayer && mOgrLayer->TestCapability( OLCFastSpatialFilter ) )
return QgsFeatureSource::SpatialIndexPresent;
else if ( mOgrLayer )
return QgsFeatureSource::SpatialIndexNotPresent;
else
return QgsFeatureSource::SpatialIndexUnknown;
}

QVariant QgsOgrProvider::minimumValue( int index ) const
{
if ( !mValid || index < 0 || index >= mAttributeFields.count() )
Expand Down
1 change: 1 addition & 0 deletions src/core/providers/ogr/qgsogrprovider.h
Expand Up @@ -144,6 +144,7 @@ class QgsOgrProvider final: public QgsVectorDataProvider
QSet< QVariant > uniqueValues( int index, int limit = -1 ) const override;
QStringList uniqueStringsMatching( int index, const QString &substring, int limit = -1,
QgsFeedback *feedback = nullptr ) const override;
QgsFeatureSource::SpatialIndexPresence hasSpatialIndex() const override;

QString name() const override;
static QString providerKey();
Expand Down

0 comments on commit f20801a

Please sign in to comment.