25 QString QgsFlattenRelationshipsAlgorithm::name()
const
27 return QStringLiteral(
"flattenrelationships" );
30 QString QgsFlattenRelationshipsAlgorithm::displayName()
const
32 return QObject::tr(
"Flatten relationship" );
35 QStringList QgsFlattenRelationshipsAlgorithm::tags()
const
37 return QObject::tr(
"join,export,single,table" ).split(
',' );
40 QString QgsFlattenRelationshipsAlgorithm::group()
const
42 return QObject::tr(
"Vector general" );
45 QString QgsFlattenRelationshipsAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeneral" );
50 QString QgsFlattenRelationshipsAlgorithm::shortDescription()
const
52 return QObject::tr(
"Flatten a relationship for a vector layer." );
55 QString QgsFlattenRelationshipsAlgorithm::shortHelpString()
const
57 return QObject::tr(
"This algorithm flattens a relationship for a vector layer, exporting a single layer "
58 "containing one master feature per related feature. This master feature contains all "
59 "the attributes for the related features." );
62 QgsProcessingAlgorithm::Flags QgsFlattenRelationshipsAlgorithm::flags()
const
67 void QgsFlattenRelationshipsAlgorithm::initAlgorithm(
const QVariantMap & )
75 QgsFlattenRelationshipsAlgorithm *QgsFlattenRelationshipsAlgorithm::createInstance()
const
77 return new QgsFlattenRelationshipsAlgorithm();
86 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral(
"INPUT" ), context );
91 if ( relations.size() > 1 )
92 throw QgsProcessingException( QObject::tr(
"Found %n relation(s). This algorithm currently supports only a single relation.",
nullptr, relations.size() ) );
93 else if ( relations.empty() )
96 mRelation = relations.at( 0 );
99 if ( !referencingLayer )
102 mReferencingSource = std::make_unique< QgsVectorLayerFeatureSource >( referencingLayer );
103 mReferencingFields = referencingLayer->
fields();
110 std::unique_ptr< QgsProcessingFeatureSource > input( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
117 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, outFields,
119 if ( parameters.value( QStringLiteral(
"OUTPUT" ) ).isValid() && !sink )
123 const double step = input->featureCount() > 0 ? 100.0 / input->featureCount() : 1;
137 QgsFeatureRequest referencingRequest = mRelation.getRelatedFeaturesRequest( feat );
154 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );