applying qml to vector layer with pyqgis

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

applying qml to vector layer with pyqgis

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
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: applying qml to vector layer with pyqgis

Stefan Giese (WhereGroup)
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

[hidden email]
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
> [hidden email]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: applying qml to vector layer with pyqgis

Francisco Pérez Sampayo

El vie., 1 mar. 2019 a las 9:41, Stefan Giese (<[hidden email]>) escribió:
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).
Same for me on 3.6. All works fine. 

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

[hidden email]
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
> [hidden email]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


--
Francisco Pérez Sampayo

_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: applying qml to vector layer with pyqgis

Reginald
Hi,

Sorry for the noise.
After double checking the filename I noticed that the filenames for the qml
files were wrong

Thanks for checking

Regards,



--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html
_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user