Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref functions #62

Open
wants to merge 12 commits into
base: refFunctions
Choose a base branch
from
14 changes: 10 additions & 4 deletions src/core/expression/qgsexpressionfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4913,8 +4913,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 @@ -4930,6 +4930,12 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
request.setFilterExpression( filterString ); //filter cached features
}

if (targetLayer->crs().authid() != sourceLayer->crs().authid())
Copy link
Owner Author

@m-kuhn m-kuhn Jul 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better compare CRS directly (and not only authid)

Suggested change
if (targetLayer->crs().authid() != sourceLayer->crs().authid())
if ( targetLayer->crs() != sourceLayer->crs() )

{
QgsCoordinateTransformContext TransformContext;
Copy link
Owner Author

@m-kuhn m-kuhn Jul 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "real" transform context is available from the expression context.

Suggested change
QgsCoordinateTransformContext TransformContext;
QgsCoordinateTransformContext transformContext = context->variable( QStringLiteral( "_project_transform_context" ) ).value<QgsCoordinateTransformContext>();

request.setDestinationCrs(sourceLayer->crs(), TransformContext); //if crs are not the same, cached target will be reprojected to source crs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new project for self overlay and different crs test

overlay_test5.zip

}

node = QgsExpressionUtils::getNode( values.at( 3 ), parent ); //in expressions overlay functions throw the exception: Eval Error: Cannot convert '' to int

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that further optional parameters have to be interpreted as an expression and then converted to int. The result is a bit tricky, but goes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it is the proper way to do this....

ENSURE_NO_EVAL_ERROR
QVariant limitValue = node->eval( parent, context );
Expand All @@ -4953,13 +4959,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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking! Added this to the todo list (but it should be done in the call to materialize, once cached we should just be able to assume that CRSes match

{
cachedTarget.reset( layer->materialize( request ) );
cachedTarget.reset( targetLayer->materialize( request ) );
if ( layerCanBeCached )
context->setCachedValue( cacheLayer, QVariant::fromValue( cachedTarget ) );
}
Expand Down