25QString QgsFlattenRelationshipsAlgorithm::name()
const
27 return QStringLiteral(
"flattenrelationships" );
30QString QgsFlattenRelationshipsAlgorithm::displayName()
const
32 return QObject::tr(
"Flatten relationship" );
35QStringList QgsFlattenRelationshipsAlgorithm::tags()
const
37 return QObject::tr(
"join,export,single,table" ).split(
',' );
40QString QgsFlattenRelationshipsAlgorithm::group()
const
42 return QObject::tr(
"Vector general" );
45QString QgsFlattenRelationshipsAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeneral" );
50QString QgsFlattenRelationshipsAlgorithm::shortDescription()
const
52 return QObject::tr(
"Flatten a relationship for a vector layer." );
55QString 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." );
72void QgsFlattenRelationshipsAlgorithm::initAlgorithm(
const QVariantMap & )
80QgsFlattenRelationshipsAlgorithm *QgsFlattenRelationshipsAlgorithm::createInstance()
const
82 return new QgsFlattenRelationshipsAlgorithm();
91 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral(
"INPUT" ), context );
96 if ( relations.size() > 1 )
97 throw QgsProcessingException( QObject::tr(
"Found %n relation(s). This algorithm currently supports only a single relation.",
nullptr, relations.size() ) );
98 else if ( relations.empty() )
101 mRelation = relations.at( 0 );
104 if ( !referencingLayer )
107 mReferencingSource = std::make_unique< QgsVectorLayerFeatureSource >( referencingLayer );
108 mReferencingFields = referencingLayer->
fields();
115 std::unique_ptr< QgsProcessingFeatureSource > input( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
122 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, outFields,
124 if ( parameters.value( QStringLiteral(
"OUTPUT" ) ).isValid() && !sink )
128 const double step = input->featureCount() > 0 ? 100.0 / input->featureCount() : 1;
142 QgsFeatureRequest referencingRequest = mRelation.getRelatedFeaturesRequest( feat );
161 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ VectorAnyGeometry
Any vector layer with geometry.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
@ RequiresProject
The algorithm requires that a valid QgsProject is available from the processing context in order to e...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
Qgis::FeatureRequestFlags flags() const
Returns the flags which affect how features are fetched.
@ 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
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 Qgis::ProcessingAlgorithmFlags 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.
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).
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.