22QString QgsRotateFeaturesAlgorithm::name()
const
24 return QStringLiteral(
"rotatefeatures" );
27QString QgsRotateFeaturesAlgorithm::displayName()
const
29 return QObject::tr(
"Rotate" );
32QStringList QgsRotateFeaturesAlgorithm::tags()
const
34 return QObject::tr(
"rotate,around,center,point" ).split(
',' );
37QString QgsRotateFeaturesAlgorithm::group()
const
39 return QObject::tr(
"Vector geometry" );
42QString QgsRotateFeaturesAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorgeometry" );
47QString QgsRotateFeaturesAlgorithm::outputName()
const
49 return QObject::tr(
"Rotated" );
52QString QgsRotateFeaturesAlgorithm::shortHelpString()
const
54 return QObject::tr(
"This algorithm rotates feature geometries, by the specified angle clockwise" )
55 + QStringLiteral(
"\n\n" )
56 + QObject::tr(
"Optionally, the rotation can occur around a preset point. If not set the rotation occurs around each feature's centroid." );
59QgsRotateFeaturesAlgorithm *QgsRotateFeaturesAlgorithm::createInstance()
const
61 return new QgsRotateFeaturesAlgorithm();
64void QgsRotateFeaturesAlgorithm::initParameters(
const QVariantMap & )
66 std::unique_ptr<QgsProcessingParameterNumber> rotation = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"ANGLE" ), QObject::tr(
"Rotation (degrees clockwise)" ),
Qgis::ProcessingNumberParameterType::Double, 0.0 );
67 rotation->setIsDynamic(
true );
69 rotation->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
70 addParameter( rotation.release() );
72 std::unique_ptr<QgsProcessingParameterPoint> anchor = std::make_unique<QgsProcessingParameterPoint>( QStringLiteral(
"ANCHOR" ), QObject::tr(
"Rotation anchor point" ), QVariant(),
true );
73 addParameter( anchor.release() );
78 mAngle = parameterAsDouble( parameters, QStringLiteral(
"ANGLE" ), context );
81 mAngleProperty = parameters.value( QStringLiteral(
"ANGLE" ) ).value<
QgsProperty>();
83 mUseAnchor = parameters.
value( QStringLiteral(
"ANCHOR" ) ).isValid();
86 mAnchor = parameterAsPoint( parameters, QStringLiteral(
"ANCHOR" ), context );
87 mAnchorCrs = parameterAsPointCrs( parameters, QStringLiteral(
"ANCHOR" ), context );
95 if ( mUseAnchor && !mTransformedAnchor )
97 mTransformedAnchor =
true;
98 if ( mAnchorCrs != sourceCrs() )
103 mAnchor = ct.transform( mAnchor );
117 double angle = mAngle;
123 geometry.
rotate( angle, mAnchor );
129 if ( !centroid.isNull() )
131 geometry.
rotate( angle, centroid.asPoint() );
136 feedback->
reportError( QObject::tr(
"Could not calculate centroid for feature %1: %2" ).arg( feature.
id() ).arg( centroid.lastError() ) );
@ Double
Double/float values.
Custom exception class for Coordinate Reference System related exceptions.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
static bool isDynamic(const QVariantMap ¶meters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
Definition for a property.
@ Rotation
Rotation (value between 0-360 degrees)
A store for object properties.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
QList< QgsFeature > QgsFeatureList