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