Skip to content

Commit

Permalink
Handle request crs transform in cached feature iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 8, 2017
1 parent 8ef6722 commit 1a418f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/core/qgscachedfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache
: QgsAbstractFeatureIterator( featureRequest )
, mVectorLayerCache( vlCache )
{
if ( mRequest.destinationCrs().isValid() && mRequest.destinationCrs() != mVectorLayerCache->sourceCrs() )
{
mTransform = QgsCoordinateTransform( mVectorLayerCache->sourceCrs(), mRequest.destinationCrs() );
}
mFilterRect = transformedFilterRect( mTransform );
if ( !mFilterRect.isNull() )
{
// update request to be the unprojected filter rect
mRequest.setFilterRect( mFilterRect );
}

switch ( featureRequest.filterType() )
{
case QgsFeatureRequest::FilterFids:
Expand Down Expand Up @@ -61,6 +72,7 @@ bool QgsCachedFeatureIterator::fetchFeature( QgsFeature &f )
if ( mRequest.acceptFeature( f ) )
{
f.setValid( true );
transformFeatureGeometry( f, mTransform );
return true;
}
}
Expand All @@ -85,7 +97,18 @@ QgsCachedFeatureWriterIterator::QgsCachedFeatureWriterIterator( QgsVectorLayerCa
: QgsAbstractFeatureIterator( featureRequest )
, mVectorLayerCache( vlCache )
{
mFeatIt = vlCache->layer()->getFeatures( featureRequest );
if ( mRequest.destinationCrs().isValid() && mRequest.destinationCrs() != mVectorLayerCache->sourceCrs() )
{
mTransform = QgsCoordinateTransform( mVectorLayerCache->sourceCrs(), mRequest.destinationCrs() );
}
mFilterRect = transformedFilterRect( mTransform );
if ( !mFilterRect.isNull() )
{
// update request to be the unprojected filter rect
mRequest.setFilterRect( mFilterRect );
}

mFeatIt = vlCache->layer()->getFeatures( mRequest );
}

bool QgsCachedFeatureWriterIterator::fetchFeature( QgsFeature &f )
Expand All @@ -100,6 +123,7 @@ bool QgsCachedFeatureWriterIterator::fetchFeature( QgsFeature &f )
// As long as features can be fetched from the provider: Write them to cache
mVectorLayerCache->cacheFeature( f );
mFids.insert( f.id() );
transformFeatureGeometry( f, mTransform );
return true;
}
else
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgscachedfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class CORE_EXPORT QgsCachedFeatureIterator : public QgsAbstractFeatureIterator
QgsFeatureIds mFeatureIds;
QgsVectorLayerCache *mVectorLayerCache = nullptr;
QgsFeatureIds::ConstIterator mFeatureIdIterator;
QgsCoordinateTransform mTransform;
QgsRectangle mFilterRect;
};

/** \ingroup core
Expand Down Expand Up @@ -127,5 +129,7 @@ class CORE_EXPORT QgsCachedFeatureWriterIterator : public QgsAbstractFeatureIter
QgsFeatureIterator mFeatIt;
QgsVectorLayerCache *mVectorLayerCache = nullptr;
QgsFeatureIds mFids;
QgsCoordinateTransform mTransform;
QgsRectangle mFilterRect;
};
#endif // QGSCACHEDFEATUREITERATOR_H

0 comments on commit 1a418f5

Please sign in to comment.