3

Say I have a shapefile with 20 graduated classes that I'm using in QGIS. I want to save the layer style so that I can use it on other shapefiles, but I can't edit the layer transparency without editing each class (20) individually.

Is it possible to edit the layer transparency in a .sld or .qml file? I arbitrarily set the transparency of one class to 53% and another to 78% (just for the sake of testing), saved both a .sld and a .qml, but I couldn't find these values anywhere in the two files. I also searched for things like 'opacity' and 'transparency' but I don't see an indication of how this is saved. However, my changes (of 53% and 78%) are reflected when loading a .qml file with the shapefiles.

It's not the end of the world to have to edit each class individually at first if the changes are reflected after saving a .qml. But I would still prefer something more reproducible since this would be really easy to do with a simple find/replace, and I may have to change the transparency of all classes at various times in the future.

1 Answer 1

3

The transparency is given by the so called Alpha Channel (Alpha compositing)

In a .qml file:

<symbols>
  <symbol alpha="0.10" clip_to_extent="1" type="fill" name="0">

This is the alpha value of the symbol (Layer transparency) and the value is 0.10 which corresponds to a transparency value of 0.9

If you try with multiple values of transparency, you can see that

alpha value = 100 - transparency value

There may be another value (Layer rendering/Layer transparency) and in this case, the values are the same (80 and 80)

<blendMode>0</blendMode>
<featureBlendMode>0</featureBlendMode>
<layerTransparency>80</layerTransparency>

Also, there is greater precision when exporting the .qml file than what is seen on the QGIS transparency slide bar. For example, if you set that bar to 10%, and save the .qml, you may see something like:

<symbols>
  <symbol alpha="0.0985" clip_to_extent="1" type="fill" name="0">

instead.

4
  • Great. Just what I needed. Thanks. Any idea about .sld files though? I view spatial data mostly in QGIS, so this isn't really an issue for me as the .qml will work fine. But from my understanding .sld is more portable and can be used in ArcGIS. Can layer transparency be saved in a .sld?
    – haff
    Commented Mar 9, 2016 at 19:00
  • The opacity/transparency of sld styles is not saved in QGIS for the moment
    – gene
    Commented Mar 9, 2016 at 20:08
  • Ok. Is this something unique to QGIS or all programs that use .sld files?
    – haff
    Commented Mar 9, 2016 at 20:12
  • The Styled Layer Descriptor is an OGC standard for web features (WMS, WFS) and it is used by GeoServer for example.
    – gene
    Commented Mar 9, 2016 at 20:43

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.