3

I have a project with many layers that have the same columns, I need to copy paste a join with a table to each of those layers, but the copy/paste style with "JOIN" settings doesn't work.

Is there a way to perform this task auto or semiautomatically?

Basically every single layer has to be joined with a table, but I don't want to do it manually for every single layer.

1 Answer 1

1

The following PyQGIS code might solve this challenge for you:

# Set the original layer containing the join to be copied to other layers
sourceLayer = iface.activeLayer()
# The join properties to be copied (=a list of joins)
joinsToCopy = sourceLayer.vectorJoins()

# Loop over all layers in the project
for layer in QgsProject.instance().mapLayers().values():
    # Confirm that the layer is not the source layer and that it is a QgsVectorLayer
    if layer != sourceLayer and layer.type() == 0:
        # Copy all joins to the current layer
        for joinToCopy in joinsToCopy:
            layer.addJoin(joinToCopy)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.