Skip to content
Permalink
Browse files

Fix calculation of feature count in OGR provider (FeatureCount functi…

…on works with current spatial filter)

git-svn-id: http://svn.osgeo.org/qgis/trunk@13345 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Apr 22, 2010
1 parent ea9245f commit 2499f1df54b7134c2a92c3e138e65aed13bafd48
Showing with 25 additions and 5 deletions.
  1. +23 −4 src/providers/ogr/qgsogrprovider.cpp
  2. +2 −1 src/providers/ogr/qgsogrprovider.h
@@ -271,7 +271,7 @@ bool QgsOgrProvider::setSubsetString( QString theSQL )

// getting the total number of features in the layer
// TODO: This can be expensive, do we really need it!
featuresCounted = OGR_L_GetFeatureCount( ogrLayer, TRUE );
recalculateFeatureCount();

// get the extent_ (envelope) of the layer
QgsDebugMsg( "Starting get extent" );
@@ -771,7 +771,6 @@ bool QgsOgrProvider::addFeature( QgsFeature& f )
{
f.setFeatureId( OGR_F_GetFID( feature ) );
}
++featuresCounted;
OGR_F_Destroy( feature );
return returnValue;
}
@@ -792,7 +791,7 @@ bool QgsOgrProvider::addFeatures( QgsFeatureList & flist )
{
returnvalue = false;
}
featuresCounted = OGR_L_GetFeatureCount( ogrLayer, TRUE ); //new feature count
recalculateFeatureCount();

return returnvalue;
}
@@ -997,7 +996,8 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
QString sql = QString( "REPACK %1" ).arg( layerName ); // don't quote the layer name as it works with spaces in the name and won't work if the name is quoted
QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, NULL );
featuresCounted = OGR_L_GetFeatureCount( ogrLayer, TRUE ); //new feature count

recalculateFeatureCount();

OGR_L_GetExtent( ogrOrigLayer, ( OGREnvelope * ) extent_, TRUE );

@@ -1860,3 +1860,22 @@ bool QgsOgrProvider::syncToDisc()

return true;
}

void QgsOgrProvider::recalculateFeatureCount()
{
OGRGeometryH filter = OGR_L_GetSpatialFilter( ogrLayer );
if ( filter )
{
filter = OGR_G_Clone( filter );
OGR_L_SetSpatialFilter( ogrLayer, 0 );
}

// feature count returns number of features within current spatial filter
// so we remove it if there's any and then put it back
featuresCounted = OGR_L_GetFeatureCount( ogrLayer, TRUE );

if ( filter )
{
OGR_L_SetSpatialFilter( ogrLayer, filter );
}
}
@@ -245,7 +245,8 @@ class QgsOgrProvider : public QgsVectorDataProvider
/**Get an attribute associated with a feature*/
void getFeatureAttribute( OGRFeatureH ogrFet, QgsFeature & f, int attindex );


/** find out the number of features of the whole layer */
void recalculateFeatureCount();

private:
unsigned char *getGeometryPointer( OGRFeatureH fet );

0 comments on commit 2499f1d

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