Skip to content
Permalink
Browse files

target layer with different crs reproject support

  • Loading branch information
enricofer authored and m-kuhn committed Jul 3, 2020
1 parent d724b88 commit d5f8adb91a67388ecbe7f2b12122d6410b0b6928
Showing with 10 additions and 4 deletions.
  1. +10 −4 src/core/expression/qgsexpressionfunction.cpp
@@ -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();
@@ -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 );
@@ -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 ) );
}

0 comments on commit d5f8adb

Please sign in to comment.