23 QString QgsGeometryByExpressionAlgorithm::name()
const
25 return QStringLiteral(
"geometrybyexpression" );
28 QString QgsGeometryByExpressionAlgorithm::displayName()
const
30 return QObject::tr(
"Geometry by expression" );
33 QStringList QgsGeometryByExpressionAlgorithm::tags()
const
35 return QObject::tr(
"geometry,expression,create,modify,update" ).split(
',' );
38 QString QgsGeometryByExpressionAlgorithm::group()
const
40 return QObject::tr(
"Vector geometry" );
43 QString QgsGeometryByExpressionAlgorithm::groupId()
const
45 return QStringLiteral(
"vectorgeometry" );
48 QString QgsGeometryByExpressionAlgorithm::outputName()
const
50 return QObject::tr(
"Modified geometry" );
53 QString QgsGeometryByExpressionAlgorithm::shortHelpString()
const
55 return QObject::tr(
"This algorithm updates existing geometries (or creates new geometries) for input "
56 "features by use of a QGIS expression. This allows complex geometry modifications "
57 "which can utilize all the flexibility of the QGIS expression engine to manipulate "
58 "and create geometries for output features.\n\n"
59 "For help with QGIS expression functions, see the inbuilt help for specific functions "
60 "which is available in the expression builder." );
63 QgsGeometryByExpressionAlgorithm *QgsGeometryByExpressionAlgorithm::createInstance()
const
65 return new QgsGeometryByExpressionAlgorithm();
68 QList<int> QgsGeometryByExpressionAlgorithm::inputLayerTypes()
const
83 void QgsGeometryByExpressionAlgorithm::initParameters(
const QVariantMap & )
86 QStringList() << QObject::tr(
"Polygon" ) << QObject::tr(
"Line" ) << QObject::tr(
"Point" ),
false, 0 ) );
90 QStringLiteral(
"$geometry" ), QStringLiteral(
"INPUT" ) ) );
95 const int geometryType = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_GEOMETRY" ), context );
96 switch ( geometryType )
99 mWkbType = QgsWkbTypes::Type::Polygon;
102 mWkbType = QgsWkbTypes::Type::LineString;
105 mWkbType = QgsWkbTypes::Type::Point;
109 if ( parameterAsBoolean( parameters, QStringLiteral(
"WITH_Z" ), context ) )
113 if ( parameterAsBoolean( parameters, QStringLiteral(
"WITH_M" ), context ) )
118 mExpression =
QgsExpression( parameterAsString( parameters, QStringLiteral(
"EXPRESSION" ), context ) );
119 if ( mExpression.hasParserError() )
121 feedback->
reportError( mExpression.parserErrorString() );
125 mExpressionContext = createExpressionContext( parameters, context );
126 mExpression.prepare( &mExpressionContext );
134 mExpressionContext.setFeature( feature );
135 const QVariant value = mExpression.evaluate( &mExpressionContext );
137 if ( mExpression.hasEvalError() )
139 throw QgsProcessingException( QObject::tr(
"Evaluation error: %1" ).arg( mExpression.evalErrorString() ) );
142 if ( value.isNull() )