[Qgis-user] applying qml to vector layer with pyqgis

Stefan Giese Stefan.Giese at wheregroup.com
Fri Mar 1 00:41:15 PST 2019


Hello Reginald,

strange, because for me it works having the qml and shapefile in the 
same directory with the same names (QGIS 3.6, Windows).

Best regards

Stefan

Mit freundlichen Grüßen
Stefan Giese
Projektleiter/Consultant
****************************************************************************
FOSS Academy Kompaktkurs "Winterschule 2019"
Grundwissen zum Aufbau von Geodateninfrastrukturen mit Open-Source-Software
https://foss-academy.com/kompaktkurse
****************************************************************************
WhereGroup GmbH & Co. KG
Schwimmbadstr. 2
79100 Freiburg
Germany

Fon: +49 (0)761 / 519 102 - 61
Fax: +49 (0)761 / 519 102 - 11

stefan.giese at wheregroup.com
www.wheregroup.com
Amtsgericht Bonn, HRA 6788
-------------------------------
Komplementärin:
WhereGroup Verwaltungs GmbH
vertreten durch:
Olaf Knopp, Peter Stamm
-------------------------------

Am 01.03.2019 um 09:23 schrieb Reginald:
> Hello list,
>
> I have a whole series of shapefiles and qml files residing in the same
> directory.
> The shapefiles and the qmlfiles have according names: eg.
> Adp36007.shp --> Adp36007.qml
> I have read somewhere that those qml files would be applied automaticaly
> when I load the shapefiles in the map. That doesn't happen.
> So I wrote a quick script:
>
> from qgis.PyQt.QtCore import *
> from qgis.PyQt.QtGui import *
> from qgis.PyQt.QtWidgets import *
> from qgis.utils import iface
> from qgis.core import *
>
> layers = [layer for layer in QgsProject.instance().mapLayers().values()]
> dirname = "F:/GRB/Recent/"
> for lay in layers:
>      qmlname = dirname + lay.name() + ".qml"
>      lay.loadNamedStyle(qmlname)
>      print("processed " + qmlname)
>      lay.triggerRepaint()
> print("done")
>
> But that doesn't work. Applying the qml via the GUI works so there is
> nothing wrong with the qml files.
> Has anything changed in QGIS 3.4 with loadNamedStyle?
>
> Regards,
>
>
>
> --
> Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


More information about the Qgis-user mailing list