22using namespace Qt::StringLiterals;
26QString QgsRotateFeaturesAlgorithm::name()
const
28 return u
"rotatefeatures"_s;
31QString QgsRotateFeaturesAlgorithm::displayName()
const
33 return QObject::tr(
"Rotate" );
36QStringList QgsRotateFeaturesAlgorithm::tags()
const
38 return QObject::tr(
"rotate,around,center,point" ).split(
',' );
41QString QgsRotateFeaturesAlgorithm::group()
const
43 return QObject::tr(
"Vector geometry" );
46QString QgsRotateFeaturesAlgorithm::groupId()
const
48 return u
"vectorgeometry"_s;
51QString QgsRotateFeaturesAlgorithm::outputName()
const
53 return QObject::tr(
"Rotated" );
56QString QgsRotateFeaturesAlgorithm::shortHelpString()
const
58 return QObject::tr(
"This algorithm rotates feature geometries by the specified angle clockwise." )
60 + QObject::tr(
"Optionally, the rotation can occur around a preset point. If not set the rotation occurs around each feature's centroid." );
63QString QgsRotateFeaturesAlgorithm::shortDescription()
const
65 return QObject::tr(
"Rotates feature geometries by a specified angle clockwise." );
68QgsRotateFeaturesAlgorithm *QgsRotateFeaturesAlgorithm::createInstance()
const
70 return new QgsRotateFeaturesAlgorithm();
73void QgsRotateFeaturesAlgorithm::initParameters(
const QVariantMap & )
76 rotation->setIsDynamic(
true );
78 rotation->setDynamicLayerParameterName( u
"INPUT"_s );
79 addParameter( rotation.release() );
81 auto anchor = std::make_unique<QgsProcessingParameterPoint>( u
"ANCHOR"_s, QObject::tr(
"Rotation anchor point" ), QVariant(),
true );
82 addParameter( anchor.release() );
87 mAngle = parameterAsDouble( parameters, u
"ANGLE"_s, context );
90 mAngleProperty = parameters.value( u
"ANGLE"_s ).value<
QgsProperty>();
92 mUseAnchor = parameters.
value( u
"ANCHOR"_s ).isValid();
95 mAnchor = parameterAsPoint( parameters, u
"ANCHOR"_s, context );
96 mAnchorCrs = parameterAsPointCrs( parameters, u
"ANCHOR"_s, context );
104 if ( mUseAnchor && !mTransformedAnchor )
106 mTransformedAnchor =
true;
107 if ( mAnchorCrs != sourceCrs() )
112 mAnchor = ct.transform( mAnchor );
126 double angle = mAngle;
132 geometry.
rotate( angle, mAnchor );
145 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.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
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