Skip to content
Permalink
Browse files

[FEATURE][processing] Allow selection of specific coordinate operation

to use when reprojecting vector layers via the "Reproject Layer" algorithm

On proj 6+ builds only!

Allows users to set a specific operation to use for a particular reprojection
task, instead of always forcing use of the current project's transformation
settings.

Useful when reprojecting a particular layer and control over the exact transformation
pipeline is required.
  • Loading branch information
nyalldawson committed Dec 20, 2019
1 parent 6bb1ad0 commit 8e64277c1c00d09c1f333dab5048856406cbd26f
@@ -23,6 +23,13 @@
void QgsTransformAlgorithm::initParameters( const QVariantMap & )
{
addParameter( new QgsProcessingParameterCrs( QStringLiteral( "TARGET_CRS" ), QObject::tr( "Target CRS" ), QStringLiteral( "EPSG:4326" ) ) );

#if PROJ_VERSION_MAJOR>=6
std::unique_ptr< QgsProcessingParameterCoordinateOperation > crsOpParam = qgis::make_unique< QgsProcessingParameterCoordinateOperation >( QStringLiteral( "OPERATION" ), QObject::tr( "Coordinate operation" ),
QVariant(), QStringLiteral( "INPUT" ), QStringLiteral( "TARGET_CRS" ), QVariant(), QVariant(), true );
crsOpParam->setFlags( crsOpParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( crsOpParam.release() );
#endif
}

QgsCoordinateReferenceSystem QgsTransformAlgorithm::outputCrs( const QgsCoordinateReferenceSystem & ) const
@@ -81,7 +88,8 @@ bool QgsTransformAlgorithm::prepareAlgorithm( const QVariantMap &parameters, Qgs
{
prepareSource( parameters, context );
mDestCrs = parameterAsCrs( parameters, QStringLiteral( "TARGET_CRS" ), context );
mTransformContext = context.project() ? context.project()->transformContext() : QgsCoordinateTransformContext();
mTransformContext = context.transformContext();
mCoordOp = parameterAsString( parameters, QStringLiteral( "OPERATION" ), context );
return true;
}

@@ -91,6 +99,8 @@ QgsFeatureList QgsTransformAlgorithm::processFeature( const QgsFeature &f, QgsPr
if ( !mCreatedTransform )
{
mCreatedTransform = true;
if ( !mCoordOp.isEmpty() )
mTransformContext.addCoordinateOperation( sourceCrs(), mDestCrs, mCoordOp );
mTransform = QgsCoordinateTransform( sourceCrs(), mDestCrs, mTransformContext );
}

@@ -58,6 +58,7 @@ class QgsTransformAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QgsCoordinateReferenceSystem mDestCrs;
QgsCoordinateTransform mTransform;
QgsCoordinateTransformContext mTransformContext;
QString mCoordOp;

};

0 comments on commit 8e64277

Please sign in to comment.
You can’t perform that action at this time.