24 #include <QRegularExpression>
28 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::name()
const
30 return QStringLiteral(
"splitfeaturesbycharacter" );
33 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::displayName()
const
35 return QObject::tr(
"Split features by character" );
38 QStringList QgsSplitFeaturesByAttributeCharacterAlgorithm::tags()
const
40 return QObject::tr(
"separate,attribute,value,string" ).split(
',' );
43 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::group()
const
45 return QObject::tr(
"Vector general" );
48 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::groupId()
const
50 return QStringLiteral(
"vectorgeneral" );
53 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::shortHelpString()
const
55 return QObject::tr(
"This algorithm splits features into multiple output features by splitting a field's value with a specified character.\n\n"
56 "For instance, if a layer contains features with multiple comma separated values contained in a single field, this "
57 "algorithm can be used to split these values up across multiple output features.\n\n"
58 "Geometries and other attributes remain unchanged in the output.\n\n"
59 "Optionally, the separator string can be a regular expression for added flexibility." );
62 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::shortDescription()
const
64 return QObject::tr(
"Splits features into multiple output features by splitting a field by a character." );
67 QList<int> QgsSplitFeaturesByAttributeCharacterAlgorithm::inputLayerTypes()
const
72 void QgsSplitFeaturesByAttributeCharacterAlgorithm::initParameters(
const QVariantMap & )
74 addParameter(
new QgsProcessingParameterField( QStringLiteral(
"FIELD" ), QObject::tr(
"Split using values in field" ), QVariant(), QStringLiteral(
"INPUT" ) ) );
76 std::unique_ptr< QgsProcessingParameterDefinition > regexParam = std::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"REGEX" ), QObject::tr(
"Use regular expression separator" ) );
78 addParameter( regexParam.release() );
86 QgsSplitFeaturesByAttributeCharacterAlgorithm *QgsSplitFeaturesByAttributeCharacterAlgorithm::createInstance()
const
88 return new QgsSplitFeaturesByAttributeCharacterAlgorithm();
91 QgsFields QgsSplitFeaturesByAttributeCharacterAlgorithm::outputFields(
const QgsFields &inputFields )
const
93 mFieldIndex = inputFields.
lookupField( mFieldName );
95 for (
int i = 0; i < inputFields.
count(); ++i )
97 if ( i != mFieldIndex )
99 outputFields.
append( inputFields.
at( i ) );
110 QString QgsSplitFeaturesByAttributeCharacterAlgorithm::outputName()
const
112 return QObject::tr(
"Split" );
117 mChar = parameterAsString( parameters, QStringLiteral(
"CHAR" ), context );
118 mFieldName = parameterAsString( parameters, QStringLiteral(
"FIELD" ), context );
119 mUseRegex = parameterAsBoolean( parameters, QStringLiteral(
"REGEX" ), context );
121 mRegex = QRegularExpression( mChar );
128 const QString val = f.
attribute( mFieldIndex ).toString();
129 const QStringList parts = mUseRegex ? val.split( mRegex ) : val.split( mChar );
130 res.reserve( parts.size() );
131 for (
const QString &p : parts )
140 QgsFeatureSink::SinkFlags QgsSplitFeaturesByAttributeCharacterAlgorithm::sinkFlags()
const
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
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)
int count() const
Returns number of items.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
A vector layer or feature source field parameter for processing algorithms.
A string parameter for processing algorithms.
SourceType
Data source types enum.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
QList< QgsFeature > QgsFeatureList