0

I have a python script, which imports a GeoPackage File into my project at a specific place (inside a group).

After importing the GeoPackage I load a QML-Style-File into it, all via Python.

Works like a charm at first sight. Everything is displayed correctly. I noticed a weird Bug in the Export to PDF via the Layout Manager though: My Export has a grey background with only certain lines. It seems that all styles are missing (see screenshot).

Faulty PDF Export

Additionally: When I try to drag and drop the layer in the panel, all styles are lost (see GIF).

Moving Layer deletes styles

That does not happen, when I load the styles onto the Layer manually. Then the PDF Export is also fine. It seems that the loading of the QML via Python does some damage.

EDIT: I narrowed it further down. The Error persists when loading the style manually onto the python-loaded Geopackage Layer. When importing the Layer manually it works: I can manually load the style and reorder it without any problems. So the import of the GeoPackage Layer must be somehow the problem.

I'm on MacOS, QGIS 3.34 Conda.

Here's the code excerpt which loads the style file:

def load_qml_style(layer, qml_file):
layer.loadNamedStyle(qml_file_path)
layer.triggerRepaint()

# Load QML style file onto GeoPackage layer
if os.path.exists(qml_file_path):
    load_qml_style(gpkg_layer, qml_file_path)
else:
    print("QML style file not found:", qml_file_path)

# Refresh the Layers Panel
iface.layerTreeView().refreshLayerSymbology(gpkg_layer.id())

1 Answer 1

0

Alright, I narrowed it further down: It got something to do with the importing of the GeoPackage.

It works, when importing via "iface".

Moving the Layer to the group does not unfortunately. For now, I select the group manually before triggering the script.

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.