From 384b736279bce3e9b2783b9f8a5a9165fea5d229 Mon Sep 17 00:00:00 2001 From: Yoann Quenach de Quivillic Date: Tue, 21 Mar 2023 09:47:17 +0100 Subject: [PATCH] Add processing parameter to keep geometries as curves (default false) --- .../processing/qgsalgorithmtransform.cpp | 19 +++++++++++++++---- .../processing/qgsalgorithmtransform.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/analysis/processing/qgsalgorithmtransform.cpp b/src/analysis/processing/qgsalgorithmtransform.cpp index 3ebca019f2f..70c70fe2b1b 100644 --- a/src/analysis/processing/qgsalgorithmtransform.cpp +++ b/src/analysis/processing/qgsalgorithmtransform.cpp @@ -24,8 +24,14 @@ void QgsTransformAlgorithm::initParameters( const QVariantMap & ) { addParameter( new QgsProcessingParameterCrs( QStringLiteral( "TARGET_CRS" ), QObject::tr( "Target CRS" ), QStringLiteral( "EPSG:4326" ) ) ); - std::unique_ptr< QgsProcessingParameterCoordinateOperation > crsOpParam = std::make_unique< QgsProcessingParameterCoordinateOperation >( QStringLiteral( "OPERATION" ), QObject::tr( "Coordinate operation" ), - QVariant(), QStringLiteral( "INPUT" ), QStringLiteral( "TARGET_CRS" ), QVariant(), QVariant(), true ); + // Convert curves to straight segments + auto convertCurvesParam = std::make_unique( QStringLiteral( "CONVERT_CURVED_GEOMETRIES" ), QObject::tr( "Convert curved geometries to straight segments" ), false ); + convertCurvesParam->setHelp( QObject::tr( "If checked, curved geometries will be converted to straight segments. Otherwise, they will be kept as curves. This can fix distortion issues." ) ); + addParameter( convertCurvesParam.release() ); + + // Optional coordinate operation + auto crsOpParam = std::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() ); } @@ -87,6 +93,7 @@ bool QgsTransformAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, Qgs prepareSource( parameters, context ); mDestCrs = parameterAsCrs( parameters, QStringLiteral( "TARGET_CRS" ), context ); mTransformContext = context.transformContext(); + mConvertCurveToSegments = parameterAsBoolean( parameters, QStringLiteral( "CONVERT_CURVED_GEOMETRIES" ), context ); mCoordOp = parameterAsString( parameters, QStringLiteral( "OPERATION" ), context ); return true; } @@ -107,8 +114,12 @@ QgsFeatureList QgsTransformAlgorithm::processFeature( const QgsFeature &f, QgsPr if ( feature.hasGeometry() ) { QgsGeometry g = feature.geometry(); - // convert to straight segments to avoid issues with distorted curves - g.convertToStraightSegment(); + + if ( !mTransform.isShortCircuited() && mConvertCurveToSegments ) + { + // convert to straight segments to avoid issues with distorted curves + g.convertToStraightSegment(); + } try { if ( g.transform( mTransform ) == Qgis::GeometryOperationResult::Success ) diff --git a/src/analysis/processing/qgsalgorithmtransform.h b/src/analysis/processing/qgsalgorithmtransform.h index 3d477c73b76..88939a6c896 100644 --- a/src/analysis/processing/qgsalgorithmtransform.h +++ b/src/analysis/processing/qgsalgorithmtransform.h @@ -58,6 +58,7 @@ class QgsTransformAlgorithm : public QgsProcessingFeatureBasedAlgorithm QgsCoordinateReferenceSystem mDestCrs; QgsCoordinateTransform mTransform; QgsCoordinateTransformContext mTransformContext; + bool mConvertCurveToSegments = false; QString mCoordOp; bool mWarnedAboutFallbackTransform = false;