2

I have a layer, which I made multiple symbology/label-styles for:

enter image description here

When I use geometry tools that have to create a new layer, I have to copy all these styles to the new layer. Most times, I don't need the old layer and just want to replace it. So in the picture above, I want all styles 1-N in my new layer.

Is there an option, to quickly copy all styles and not do it one by one?

I currently have two workaround options, that I use. Neither are really satisfying and I think I am just missing a common workflow here.

Workaround 1: replacing files

I can just close QGIS, replace my shapefile with the newly generated one, then open GIS again and I have my new layer with my old styles. Probably a lot of things, that can go wrong here, I know. I used this only after geometry tools, that didn't affect attributes, etc. Haven't dared to try with anything else apart from shapefiles. It's dirty, but it's quick.

Workaround 2: manually copying all style one after another

I put my results in a temporary layer, then add all styles one after another. Then I delete my old file from GIS, safe my new temp layer and override the old one.

It's a really click-heavy process (right click>activate style>right click again>copy style/symbologies (or more)>right click new layer>insert style>right click again>add style>type name>click OK). Doing that for 5, sometimes up to 12 different styles is a long process. I found this solution (QGIS Load Multiple styles on single layer at once) via Python and qml files, but I am looking for a solution, that is working hopefully without saving all styles as qml and without Python.

4
  • How many layers are we talking about? How often does this process happen?
    – Erik
    Jul 20, 2022 at 8:29
  • I have multiple layers, I use these processes on, but I don't want to share the styles of layer A with layers B-N, it's just about taking the styles from layer A-old to layer A-new. It's nothing that happens on a regular basis. Depending on the project, there are times I do that 5 times a day, then later maybe once in a month
    – e-shirt
    Jul 20, 2022 at 8:47
  • 1
    can't you just export your styles to .qml and then either load the styles file (.qml) within qgis or copy the .qml and rename it to have the same name as your shapefile ?
    – Kalak
    Jul 20, 2022 at 9:05
  • @LouisCottereau I think you did not get my question. I am talking about saving and loading 12 qml files into a layer and making a new style for each of them, I want to shorten exactly that process.
    – e-shirt
    Jul 20, 2022 at 9:14

2 Answers 2

1

With a python script or in the console you can copy all styles from one layer to another with the QgsMapLayerStyleManager.copyStylesFrom() function since QGIS 3.14

example:

from qgis.utils import iface
# point1 is the name of the layer whose styles will be copied
# point2 is the name of the layer where the copied styles will be applied
layer_from = QgsProject.instance().mapLayersByName("point1")[0]
layer_to = QgsProject.instance().mapLayersByName("point2")[0]
layer_to.styleManager().copyStylesFrom(layer_from.styleManager())

There currently is no possible way to do this in the QGIS GUI as far as I know (https://github.com/qgis/QGIS/issues/35293)

3
  • 2
    You're talking about copying more than one category, this is not the issue. I am talking about copying all categories in different sets multiple times. I'll try to underline my post with pictures.
    – e-shirt
    Jul 20, 2022 at 9:15
  • What "sets" are you talking about, this does exactly what you say you want, copying all categories of styles
    – Kalak
    Jul 20, 2022 at 9:16
  • Updated know that its actually clear what you want to do
    – Kalak
    Jul 20, 2022 at 10:16
1

A GUI solution:

  1. Duplicate the layer (by right clicking on layer name in layer tree and choosing Duplicate) with the styles you want to copy. All styles get automatically copied to the duplicate.

  2. Change the datasource (right click on the new duplicate layer, for instance) to point to the right datasource.

Alternately, you can also open up an existing project file in the Browser panel, find the layer whose styles you want, and drag them into your existing project. This is in lieu of step 1, you still need to do step 2.

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.