mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-22 00:14:55 -05:00
Add processing parameter to keep geometries as curves (default false)
This commit is contained in:
parent
a54e0c5e56
commit
384b736279
@ -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() );
|
||||
}
|
||||
@ -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 )
|
||||
|
||||
@ -58,6 +58,7 @@ class QgsTransformAlgorithm : public QgsProcessingFeatureBasedAlgorithm
|
||||
QgsCoordinateReferenceSystem mDestCrs;
|
||||
QgsCoordinateTransform mTransform;
|
||||
QgsCoordinateTransformContext mTransformContext;
|
||||
bool mConvertCurveToSegments = false;
|
||||
QString mCoordOp;
|
||||
bool mWarnedAboutFallbackTransform = false;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user