27 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::name()
const 29 return QStringLiteral(
"splitfeaturesbycharacter" );
32 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::displayName()
const 34 return QObject::tr(
"Split features by character" );
37 QStringList QgsSplitFeaturesByAttributeCharacterAlgorithm::tags()
const 39 return QObject::tr(
"separate,attribute,value,string" ).split(
',' );
42 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::group()
const 44 return QObject::tr(
"Vector general" );
47 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::groupId()
const 49 return QStringLiteral(
"vectorgeneral" );
52 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::shortHelpString()
const 54 return QObject::tr(
"This algorithm splits features into multiple output features by splitting a field's value with a specified character.\n\n" 55 "For instance, if a layer contains features with multiple comma separated values contained in a single field, this " 56 "algorithm can be used to split these values up across multiple output features.\n\n" 57 "Geometries and other attributes remain unchanged in the output.\n\n" 58 "Optionally, the separator string can be a regular expression for added flexibility." );
61 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::shortDescription()
const 63 return QObject::tr(
"Splits features into multiple output features by splitting a field by a character." );
66 QList<int> QgsSplitFeaturesByAttributeCharacterAlgorithm::inputLayerTypes()
const 71 void QgsSplitFeaturesByAttributeCharacterAlgorithm::initParameters(
const QVariantMap & )
73 addParameter(
new QgsProcessingParameterField( QStringLiteral(
"FIELD" ), QObject::tr(
"Split using values in field" ), QVariant(), QStringLiteral(
"INPUT" ) ) );
75 std::unique_ptr< QgsProcessingParameterDefinition > regexParam = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"REGEX" ), QObject::tr(
"Use regular expression separator" ) );
77 addParameter( regexParam.release() );
85 QgsSplitFeaturesByAttributeCharacterAlgorithm *QgsSplitFeaturesByAttributeCharacterAlgorithm::createInstance()
const 87 return new QgsSplitFeaturesByAttributeCharacterAlgorithm();
90 QgsFields QgsSplitFeaturesByAttributeCharacterAlgorithm::outputFields(
const QgsFields &inputFields )
const 92 mFieldIndex = inputFields.
lookupField( mFieldName );
94 for (
int i = 0; i < inputFields.
count(); ++i )
96 if ( i != mFieldIndex )
98 outputFields.
append( inputFields.
at( i ) );
109 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::outputName()
const 111 return QObject::tr(
"Split" );
116 mChar = parameterAsString( parameters, QStringLiteral(
"CHAR" ), context );
117 mFieldName = parameterAsString( parameters, QStringLiteral(
"FIELD" ), context );
118 mUseRegex = parameterAsBoolean( parameters, QStringLiteral(
"REGEX" ), context );
120 mRegex = QRegularExpression( mChar );
127 const QString val = f.
attribute( mFieldIndex ).toString();
128 const QStringList parts = mUseRegex ? val.split( mRegex ) : val.split( mChar );
129 res.reserve( parts.size() );
130 for (
const QString &p : parts )
139 QgsFeatureSink::SinkFlags QgsSplitFeaturesByAttributeCharacterAlgorithm::sinkFlags()
const int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Base class for providing feedback from a processing algorithm.
Parameter is an advanced parameter which should be hidden from users by default.
A vector layer or feature source field parameter for processing algorithms.
QList< QgsFeature > QgsFeatureList
Container of fields for a vector layer.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
int count() const
Returns number of items.
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
SourceType
Data source types enum.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Contains information about the context in which a processing algorithm is executed.
A string parameter for processing algorithms.