Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add processing parameter to keep geometries as curves (default false)
  • Loading branch information
YoannQDQ authored and nyalldawson committed Mar 29, 2023
1 parent a54e0c5 commit 384b736
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/analysis/processing/qgsalgorithmtransform.cpp
Expand Up @@ -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<QgsProcessingParameterBoolean>( 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() );
}
Expand Down Expand Up @@ -87,6 +93,7 @@ bool QgsTransformAlgorithm::prepareAlgorithm( const QVariantMap &parameters, 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;
}
Expand All @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/analysis/processing/qgsalgorithmtransform.h
Expand Up @@ -58,6 +58,7 @@ class QgsTransformAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QgsCoordinateReferenceSystem mDestCrs;
QgsCoordinateTransform mTransform;
QgsCoordinateTransformContext mTransformContext;
bool mConvertCurveToSegments = false;
QString mCoordOp;
bool mWarnedAboutFallbackTransform = false;

Expand Down

0 comments on commit 384b736

Please sign in to comment.