Skip to content
Permalink
Browse files

Handle request crs transform in cached feature iterators

  • Loading branch information
nyalldawson committed Jun 8, 2017
1 parent 8ef6722 commit 1a418f5d640660bc6670712e6b397c281e4b7ae8
Showing with 29 additions and 1 deletion.
  1. +25 −1 src/core/qgscachedfeatureiterator.cpp
  2. +4 −0 src/core/qgscachedfeatureiterator.h
@@ -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:
@@ -61,6 +72,7 @@ bool QgsCachedFeatureIterator::fetchFeature( QgsFeature &f )
if ( mRequest.acceptFeature( f ) )
{
f.setValid( true );
transformFeatureGeometry( f, mTransform );
return true;
}
}
@@ -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 )
@@ -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
@@ -78,6 +78,8 @@ class CORE_EXPORT QgsCachedFeatureIterator : public QgsAbstractFeatureIterator
QgsFeatureIds mFeatureIds;
QgsVectorLayerCache *mVectorLayerCache = nullptr;
QgsFeatureIds::ConstIterator mFeatureIdIterator;
QgsCoordinateTransform mTransform;
QgsRectangle mFilterRect;
};

/** \ingroup core
@@ -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.
You can’t perform that action at this time.