I am implementing a tool which allows an user to calculate some statistics with some data from the registration office. My question is, can I set some layer styles using pyQGIS?

The analysis part is already finished and in a next step I want to laod the layer (which also works perfectly) and visualise it in QGIS. The problem is that I have found until now no way to "say" QGIS that the layer should be visualised by using "graduated colors", a special color ramp and a special classification.

Is there a way to do this using pyQGIS (mayber by using map canavas) or does the user has to do it manually in the layer settings?

Regards from Hamburg,


My proposal may not be the most efficient but here goes:

You could script the creation of a .qml file (how QGIS stores its default symbolization for layers) with the ramp and classes you require, and save it with the same basename as the layer you are creating. THis would load the file with that symbolization.

Hope this is helpful :) PS: this link may be helpful: How to create a style file for QGIS from a plain text file?

  • You're very welcome :)
    – s_a
    Sep 11 '12 at 22:03

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.