22 QString QgsRotateFeaturesAlgorithm::name()
const 24 return QStringLiteral(
"rotatefeatures" );
27 QString QgsRotateFeaturesAlgorithm::displayName()
const 29 return QObject::tr(
"Rotate" );
32 QStringList QgsRotateFeaturesAlgorithm::tags()
const 34 return QObject::tr(
"rotate,around,center,point" ).split(
',' );
37 QString QgsRotateFeaturesAlgorithm::group()
const 39 return QObject::tr(
"Vector geometry" );
42 QString QgsRotateFeaturesAlgorithm::groupId()
const 44 return QStringLiteral(
"vectorgeometry" );
47 QString QgsRotateFeaturesAlgorithm::outputName()
const 49 return QObject::tr(
"Rotated" );
52 QString 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." );
59 QgsRotateFeaturesAlgorithm *QgsRotateFeaturesAlgorithm::createInstance()
const 61 return new QgsRotateFeaturesAlgorithm();
64 void QgsRotateFeaturesAlgorithm::initParameters(
const QVariantMap & )
66 std::unique_ptr< QgsProcessingParameterNumber > rotation = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"ANGLE" ),
69 rotation->setIsDynamic(
true );
71 rotation->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
72 addParameter( rotation.release() );
74 std::unique_ptr< QgsProcessingParameterPoint > anchor = qgis::make_unique< QgsProcessingParameterPoint >( QStringLiteral(
"ANCHOR" ),
75 QObject::tr(
"Rotation anchor point" ), QVariant(), true );
76 addParameter( anchor.release() );
81 mAngle = parameterAsDouble( parameters, QStringLiteral(
"ANGLE" ), context );
84 mAngleProperty = parameters.value( QStringLiteral(
"ANGLE" ) ).value<
QgsProperty >();
86 mUseAnchor = parameters.
value( QStringLiteral(
"ANCHOR" ) ).isValid();
89 mAnchor = parameterAsPoint( parameters, QStringLiteral(
"ANCHOR" ), context );
90 mAnchorCrs = parameterAsPointCrs( parameters, QStringLiteral(
"ANCHOR" ), context );
98 if ( mUseAnchor && !mTransformedAnchor )
100 mTransformedAnchor =
true;
101 if ( mAnchorCrs != sourceCrs() )
120 double angle = mAngle;
126 geometry.
rotate( angle, mAnchor );
139 feedback->
reportError( QObject::tr(
"Could not calculate centroid for feature %1: %2" ).arg( feature.
id() ).arg( centroid.
lastError() ) );
Base class for providing feedback from a processing algorithm.
QList< QgsFeature > QgsFeatureList
OperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
A geometry is the spatial representation of a feature.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
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...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
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)
Rotation (value between 0-360 degrees)
Custom exception class for processing related exceptions.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
A store for object properties.
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition for a property.
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.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Custom exception class for Coordinate Reference System related exceptions.
Contains information about the context in which a processing algorithm is executed.
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...