Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
target layer with different crs reproject support
  • Loading branch information
enricofer authored and m-kuhn committed Jul 3, 2020
1 parent d724b88 commit d5f8adb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -5679,8 +5679,8 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
QgsSpatialIndex spatialIndex;
std::shared_ptr<QgsVectorLayer> cachedTarget;

QgsVectorLayer *layer = QgsExpressionUtils::getVectorLayer( targetLayerValue, parent );
if ( !layer ) // No layer, no joy
QgsVectorLayer *targetLayer = QgsExpressionUtils::getVectorLayer( targetLayerValue, parent );
if ( !targetLayer ) // No layer, no joy
{
parent->setEvalErrorString( QObject::tr( "Layer '%1' could not be loaded." ).arg( targetLayerValue.toString() ) );
return QVariant();
Expand All @@ -5696,6 +5696,12 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
request.setFilterExpression( filterString ); //filter cached features
}

if (targetLayer->crs().authid() != sourceLayer->crs().authid())
{
QgsCoordinateTransformContext TransformContext;
request.setDestinationCrs(sourceLayer->crs(), TransformContext); //if crs are not the same, cached target will be reprojected to source crs
}

node = QgsExpressionUtils::getNode( values.at( 3 ), parent ); //in expressions overlay functions throw the exception: Eval Error: Cannot convert '' to int
ENSURE_NO_EVAL_ERROR
QVariant limitValue = node->eval( parent, context );
Expand All @@ -5719,13 +5725,13 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
}
*/

const QString cacheBase { QStringLiteral( "%1:%2" ).arg( layer->id(), subExpression ) };
const QString cacheBase { QStringLiteral( "%1:%2" ).arg( targetLayer->id(), subExpression ) };
const QString cacheLayer { QStringLiteral( "ovrlaylyr:%1" ).arg( cacheBase ) };
const QString cacheIndex { QStringLiteral( "ovrlayidx:%1" ).arg( cacheBase ) };

if ( !context->hasCachedValue( cacheLayer ) ) // should check for same crs. if not the same we could think to reproject target layer before charging cache
{
cachedTarget.reset( layer->materialize( request ) );
cachedTarget.reset( targetLayer->materialize( request ) );
if ( layerCanBeCached )
context->setCachedValue( cacheLayer, QVariant::fromValue( cachedTarget ) );
}
Expand Down

0 comments on commit d5f8adb

Please sign in to comment.