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 %1 relations. This algorithm currently supports only a single relation." ).arg( 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 );
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
Flags flags() const
Returns the flags which affect how features are fetched.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
@ 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...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Container of fields for a vector layer.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Contains information about the context in which a processing algorithm is executed.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Custom exception class for processing related exceptions.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Base class for providing feedback from a processing algorithm.
A feature sink output for processing algorithms.
A vector layer (with or without geometry) parameter for processing algorithms.
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ TypeVectorAnyGeometry
Any vector layer with geometry.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QgsRelationManager * relationManager
QList< QgsRelation > referencedRelations(const QgsVectorLayer *layer=nullptr) const
Gets all relations where this layer is the referenced part (i.e.
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.