mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-27 00:07:16 -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" ) ) );
|
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" ),
|
// Convert curves to straight segments
|
||||||
QVariant(), QStringLiteral( "INPUT" ), QStringLiteral( "TARGET_CRS" ), QVariant(), QVariant(), true );
|
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 );
|
crsOpParam->setFlags( crsOpParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
|
||||||
addParameter( crsOpParam.release() );
|
addParameter( crsOpParam.release() );
|
||||||
}
|
}
|
||||||
@ -87,6 +93,7 @@ bool QgsTransformAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, Qgs
|
|||||||
prepareSource( parameters, context );
|
prepareSource( parameters, context );
|
||||||
mDestCrs = parameterAsCrs( parameters, QStringLiteral( "TARGET_CRS" ), context );
|
mDestCrs = parameterAsCrs( parameters, QStringLiteral( "TARGET_CRS" ), context );
|
||||||
mTransformContext = context.transformContext();
|
mTransformContext = context.transformContext();
|
||||||
|
mConvertCurveToSegments = parameterAsBoolean( parameters, QStringLiteral( "CONVERT_CURVED_GEOMETRIES" ), context );
|
||||||
mCoordOp = parameterAsString( parameters, QStringLiteral( "OPERATION" ), context );
|
mCoordOp = parameterAsString( parameters, QStringLiteral( "OPERATION" ), context );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -107,8 +114,12 @@ QgsFeatureList QgsTransformAlgorithm::processFeature( const QgsFeature &f, QgsPr
|
|||||||
if ( feature.hasGeometry() )
|
if ( feature.hasGeometry() )
|
||||||
{
|
{
|
||||||
QgsGeometry g = feature.geometry();
|
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
|
try
|
||||||
{
|
{
|
||||||
if ( g.transform( mTransform ) == Qgis::GeometryOperationResult::Success )
|
if ( g.transform( mTransform ) == Qgis::GeometryOperationResult::Success )
|
||||||
|
|||||||
@ -58,6 +58,7 @@ class QgsTransformAlgorithm : public QgsProcessingFeatureBasedAlgorithm
|
|||||||
QgsCoordinateReferenceSystem mDestCrs;
|
QgsCoordinateReferenceSystem mDestCrs;
|
||||||
QgsCoordinateTransform mTransform;
|
QgsCoordinateTransform mTransform;
|
||||||
QgsCoordinateTransformContext mTransformContext;
|
QgsCoordinateTransformContext mTransformContext;
|
||||||
|
bool mConvertCurveToSegments = false;
|
||||||
QString mCoordOp;
|
QString mCoordOp;
|
||||||
bool mWarnedAboutFallbackTransform = false;
|
bool mWarnedAboutFallbackTransform = false;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user