6

I would like to write a python macro that upon opening my QGIS project file will reload the default style for each layer from the postgres 'layer_style' table. I have had a look at the documentation and can only work out how this is done from a sqlite db or .qml file.

Any pointers would be appreciated.

  • Matt, from QGIS 2.0, It will be possible to save layer styles in Postgresql\postgis database. I know it's not the same, but maybe it solves your need. Take a look here https://www.youtube.com/watch?feature=player_embedded&v=zC-_AmmGTQ8 – Alexandre Neto Jun 27 '13 at 8:53
  • 2
    I have done that, I would like to know if it is possible to reload the default styles from the postgresql layer_style table using Python. – Matt Jun 27 '13 at 9:21
  • Sorry, I misunderstood it. – Alexandre Neto Jun 27 '13 at 9:24
0

Resurrecting the topic with QGIS 3.0 :). Looking at the QgsVectorLayer API documentation instead of QgsMapLayer API, you have the answer. You can use method saveStyleToDatabase

There are related recipes to manipulate styles in PostgreSQL database from QGIS Python tests including saveStyleToDatabase case at https://github.com/qgis/QGIS/blob/master/tests/src/python/test_provider_postgres.py#L1553

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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