24QString QgsGeometryByExpressionAlgorithm::name()
const
26 return QStringLiteral(
"geometrybyexpression" );
29QString QgsGeometryByExpressionAlgorithm::displayName()
const
31 return QObject::tr(
"Geometry by expression" );
34QStringList QgsGeometryByExpressionAlgorithm::tags()
const
36 return QObject::tr(
"geometry,expression,create,modify,update" ).split(
',' );
39QString QgsGeometryByExpressionAlgorithm::group()
const
41 return QObject::tr(
"Vector geometry" );
44QString QgsGeometryByExpressionAlgorithm::groupId()
const
46 return QStringLiteral(
"vectorgeometry" );
49QString QgsGeometryByExpressionAlgorithm::outputName()
const
51 return QObject::tr(
"Modified geometry" );
54QString QgsGeometryByExpressionAlgorithm::shortHelpString()
const
56 return QObject::tr(
"This algorithm updates existing geometries (or creates new geometries) for input "
57 "features by use of a QGIS expression. This allows complex geometry modifications "
58 "which can utilize all the flexibility of the QGIS expression engine to manipulate "
59 "and create geometries for output features.\n\n"
60 "For help with QGIS expression functions, see the inbuilt help for specific functions "
61 "which is available in the expression builder." );
64QString QgsGeometryByExpressionAlgorithm::shortDescription()
const
66 return QObject::tr(
"Updates existing geometries (or creates new geometries) for input "
67 "features by use of a QGIS expression." );
70QgsGeometryByExpressionAlgorithm *QgsGeometryByExpressionAlgorithm::createInstance()
const
72 return new QgsGeometryByExpressionAlgorithm();
75QList<int> QgsGeometryByExpressionAlgorithm::inputLayerTypes()
const
90void QgsGeometryByExpressionAlgorithm::initParameters(
const QVariantMap & )
92 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"OUTPUT_GEOMETRY" ), QObject::tr(
"Output geometry type" ), QStringList() << QObject::tr(
"Polygon" ) << QObject::tr(
"Line" ) << QObject::tr(
"Point" ),
false, 0 ) );
95 addParameter(
new QgsProcessingParameterExpression( QStringLiteral(
"EXPRESSION" ), QObject::tr(
"Geometry expression" ), QStringLiteral(
"@geometry" ), QStringLiteral(
"INPUT" ) ) );
100 const int geometryType = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_GEOMETRY" ), context );
101 switch ( geometryType )
114 if ( parameterAsBoolean( parameters, QStringLiteral(
"WITH_Z" ), context ) )
118 if ( parameterAsBoolean( parameters, QStringLiteral(
"WITH_M" ), context ) )
123 mExpression =
QgsExpression( parameterAsString( parameters, QStringLiteral(
"EXPRESSION" ), context ) );
124 if ( mExpression.hasParserError() )
126 feedback->
reportError( mExpression.parserErrorString() );
130 mExpressionContext = createExpressionContext( parameters, context );
131 mExpression.prepare( &mExpressionContext );
139 mExpressionContext.setFeature( feature );
140 const QVariant value = mExpression.evaluate( &mExpressionContext );
142 if ( mExpression.hasEvalError() )
144 throw QgsProcessingException( QObject::tr(
"Evaluation error: %1" ).arg( mExpression.evalErrorString() ) );
153 if ( value.userType() == qMetaTypeId<QgsGeometry>() )
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
WkbType
The WKB type describes the number of dimensions a geometry has.
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Handles parsing and evaluation of expressions (formerly called "search strings").
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
Contains information about the context in which a processing algorithm is executed.
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.
A boolean parameter for processing algorithms.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
An expression parameter for processing algorithms.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
QList< QgsFeature > QgsFeatureList