File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -278,8 +278,8 @@ void QgsExpression::initGeomCalculator( const QgsExpressionContext *context )
278
278
// actually don't do it right away, cos it's expensive to create and only a very small number of expression
279
279
// functions actually require it. Let's lazily construct it when needed
280
280
d->mDaEllipsoid = context->variable ( QStringLiteral ( " project_ellipsoid" ) ).toString ();
281
- d->mDaCrs = context->variable ( QStringLiteral ( " _layer_crs" ) ).value <QgsCoordinateReferenceSystem>();
282
- d->mDaTransformContext = context->variable ( QStringLiteral ( " _project_transform_context" ) ).value <QgsCoordinateTransformContext>();
281
+ d->mDaCrs = qgis::make_unique<QgsCoordinateReferenceSystem>( context->variable ( QStringLiteral ( " _layer_crs" ) ).value <QgsCoordinateReferenceSystem>() );
282
+ d->mDaTransformContext = qgis::make_unique<QgsCoordinateTransformContext>( context->variable ( QStringLiteral ( " _project_transform_context" ) ).value <QgsCoordinateTransformContext>() );
283
283
}
284
284
285
285
// Set the distance units from the context if it has not been set by setDistanceUnits()
@@ -396,12 +396,12 @@ QString QgsExpression::dump() const
396
396
397
397
QgsDistanceArea *QgsExpression::geomCalculator ()
398
398
{
399
- if ( !d->mCalc && d->mDaCrs . isValid () )
399
+ if ( !d->mCalc && d->mDaCrs && d-> mDaCrs -> isValid () && d-> mDaTransformContext )
400
400
{
401
401
// calculator IS required, so initialize it now...
402
402
d->mCalc = std::shared_ptr<QgsDistanceArea>( new QgsDistanceArea () );
403
403
d->mCalc ->setEllipsoid ( d->mDaEllipsoid .isEmpty () ? geoNone () : d->mDaEllipsoid );
404
- d->mCalc ->setSourceCrs ( d->mDaCrs , d->mDaTransformContext );
404
+ d->mCalc ->setSourceCrs ( * d->mDaCrs . get (), * d->mDaTransformContext . get () );
405
405
}
406
406
407
407
return d->mCalc .get ();
Original file line number Diff line number Diff line change @@ -47,12 +47,15 @@ class QgsExpressionPrivate
47
47
, mParserErrors( other.mParserErrors )
48
48
, mExp( other.mExp )
49
49
, mDaEllipsoid( other.mDaEllipsoid )
50
- , mDaCrs( other.mDaCrs )
51
- , mDaTransformContext( other.mDaTransformContext )
52
50
, mCalc( other.mCalc )
53
51
, mDistanceUnit( other.mDistanceUnit )
54
52
, mAreaUnit( other.mAreaUnit )
55
- {}
53
+ {
54
+ if ( other.mDaCrs )
55
+ mDaCrs = qgis::make_unique<QgsCoordinateReferenceSystem>( *other.mDaCrs .get () );
56
+ if ( other.mDaTransformContext )
57
+ mDaTransformContext = qgis::make_unique<QgsCoordinateTransformContext>( *other.mDaTransformContext .get () );
58
+ }
56
59
57
60
~QgsExpressionPrivate ()
58
61
{
@@ -71,8 +74,8 @@ class QgsExpressionPrivate
71
74
QString mExp ;
72
75
73
76
QString mDaEllipsoid ;
74
- QgsCoordinateReferenceSystem mDaCrs ;
75
- QgsCoordinateTransformContext mDaTransformContext ;
77
+ std::unique_ptr< QgsCoordinateReferenceSystem> mDaCrs ;
78
+ std::unique_ptr< QgsCoordinateTransformContext> mDaTransformContext ;
76
79
77
80
std::shared_ptr<QgsDistanceArea> mCalc ;
78
81
QgsUnitTypes::DistanceUnit mDistanceUnit = QgsUnitTypes::DistanceUnknownUnit;
You can’t perform that action at this time.
0 commit comments