Skip to content

Commit

Permalink
Merge pull request #2511 from tomtor/master
Browse files Browse the repository at this point in the history
Fix non caching behaviour for WFS
  • Loading branch information
jef-n committed Dec 2, 2015
2 parents 9e5528b + 2305b90 commit 2dfa10f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -123,16 +123,11 @@ QgsWFSProvider::QgsWFSProvider( const QString& uri )
setDataSourceUri( bkUri );
}

#if 0 //non-cached mode is broken
mCached = !uri.contains( "BBOX=" );
if ( mCached )
{ //"Cache Features" option; get all features in layer immediately
reloadData();
} //otherwise, defer feature retrieval until layer is first rendered
#endif //0

mCached = true;
reloadData();

if ( mValid )
{
Expand All @@ -158,14 +153,15 @@ QgsAbstractFeatureSource* QgsWFSProvider::featureSource() const

void QgsWFSProvider::reloadData()
{
mPendingRetrieval = false;
deleteData();
if (mCached)
deleteData();
delete mSpatialIndex;
mSpatialIndex = new QgsSpatialIndex();
mValid = !getFeature( dataSourceUri() );

if ( !mCached )
emit dataChanged();
mPendingRetrieval = false;
}

void QgsWFSProvider::deleteData()
Expand Down Expand Up @@ -285,8 +281,16 @@ QgsFeatureIterator QgsWFSProvider::getFeatures( const QgsFeatureRequest& request
}

}
#endif
return new QgsWFSFeatureIterator( new QgsWFSFeatureSource( this ), true, request );
#else
QgsRectangle rect = request.filterRect();
if ( !( request.flags() & QgsFeatureRequest::NoGeometry ) && !rect.isEmpty() )
{
deleteData();
reloadData();
}
return new QgsWFSFeatureIterator( new QgsWFSFeatureSource( this ), true, request );
#endif
}

int QgsWFSProvider::getFeature( const QString& uri )
Expand Down Expand Up @@ -1720,9 +1724,11 @@ void QgsWFSProvider::extendExtent( const QgsRectangle &extent )

QgsRectangle r( mExtent.intersect( &extent ) );

if ( mGetExtent.contains( r ) )
if ( (extent == mGetExtent || mFeatureCount == 0 || mFeatureCount % 500 != 0)
&& mGetExtent.contains( r ) )
return;

#if 0
if ( mGetExtent.isEmpty() )
{
mGetExtent = r;
Expand All @@ -1738,6 +1744,9 @@ void QgsWFSProvider::extendExtent( const QgsRectangle &extent )
{
mGetExtent.combineExtentWith( &r );
}
#else
mGetExtent = extent;
#endif

setDataSourceUri( dataSourceUri().replace( QRegExp( "BBOX=[^&]*" ),
QString( "BBOX=%1,%2,%3,%4" )
Expand Down

0 comments on commit 2dfa10f

Please sign in to comment.