Skip to content

Commit 384b736

Browse files
YoannQDQnyalldawson
authored andcommittedMar 29, 2023
Add processing parameter to keep geometries as curves (default false)
1 parent a54e0c5 commit 384b736

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed
 

‎src/analysis/processing/qgsalgorithmtransform.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ void QgsTransformAlgorithm::initParameters( const QVariantMap & )
2424
{
2525
addParameter( new QgsProcessingParameterCrs( QStringLiteral( "TARGET_CRS" ), QObject::tr( "Target CRS" ), QStringLiteral( "EPSG:4326" ) ) );
2626

27-
std::unique_ptr< QgsProcessingParameterCoordinateOperation > crsOpParam = std::make_unique< QgsProcessingParameterCoordinateOperation >( QStringLiteral( "OPERATION" ), QObject::tr( "Coordinate operation" ),
28-
QVariant(), QStringLiteral( "INPUT" ), QStringLiteral( "TARGET_CRS" ), QVariant(), QVariant(), true );
27+
// Convert curves to straight segments
28+
auto convertCurvesParam = std::make_unique<QgsProcessingParameterBoolean>( QStringLiteral( "CONVERT_CURVED_GEOMETRIES" ), QObject::tr( "Convert curved geometries to straight segments" ), false );
29+
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." ) );
30+
addParameter( convertCurvesParam.release() );
31+
32+
// Optional coordinate operation
33+
auto crsOpParam = std::make_unique< QgsProcessingParameterCoordinateOperation >( QStringLiteral( "OPERATION" ), QObject::tr( "Coordinate operation" ),
34+
QVariant(), QStringLiteral( "INPUT" ), QStringLiteral( "TARGET_CRS" ), QVariant(), QVariant(), true );
2935
crsOpParam->setFlags( crsOpParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
3036
addParameter( crsOpParam.release() );
3137
}
@@ -87,6 +93,7 @@ bool QgsTransformAlgorithm::prepareAlgorithm( const QVariantMap &parameters, Qgs
8793
prepareSource( parameters, context );
8894
mDestCrs = parameterAsCrs( parameters, QStringLiteral( "TARGET_CRS" ), context );
8995
mTransformContext = context.transformContext();
96+
mConvertCurveToSegments = parameterAsBoolean( parameters, QStringLiteral( "CONVERT_CURVED_GEOMETRIES" ), context );
9097
mCoordOp = parameterAsString( parameters, QStringLiteral( "OPERATION" ), context );
9198
return true;
9299
}
@@ -107,8 +114,12 @@ QgsFeatureList QgsTransformAlgorithm::processFeature( const QgsFeature &f, QgsPr
107114
if ( feature.hasGeometry() )
108115
{
109116
QgsGeometry g = feature.geometry();
110-
// convert to straight segments to avoid issues with distorted curves
111-
g.convertToStraightSegment();
117+
118+
if ( !mTransform.isShortCircuited() && mConvertCurveToSegments )
119+
{
120+
// convert to straight segments to avoid issues with distorted curves
121+
g.convertToStraightSegment();
122+
}
112123
try
113124
{
114125
if ( g.transform( mTransform ) == Qgis::GeometryOperationResult::Success )

‎src/analysis/processing/qgsalgorithmtransform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class QgsTransformAlgorithm : public QgsProcessingFeatureBasedAlgorithm
5858
QgsCoordinateReferenceSystem mDestCrs;
5959
QgsCoordinateTransform mTransform;
6060
QgsCoordinateTransformContext mTransformContext;
61+
bool mConvertCurveToSegments = false;
6162
QString mCoordOp;
6263
bool mWarnedAboutFallbackTransform = false;
6364

0 commit comments

Comments
 (0)
Please sign in to comment.