Discussion:
How to load a QLR file with pyQGIS ?
(too old to reply)
Geo DrinX
2015-04-15 10:24:54 UTC
Permalink
Hello,


there is a way to load a QLR file with pyQGIS ?

I tried using vlayer.loadNamedStyle(qlrFileName) but it seems not
to work.


What is the correct way ?


Thank you

Roberto
Gary Sherman
2015-04-15 16:39:21 UTC
Permalink
Post by Geo DrinX
Hello,
there is a way to load a QLR file with pyQGIS ?
I tried using vlayer.loadNamedStyle(qlrFileName) but it seems
not to work.
What is the correct way ?
That is the correct way. Have you done the following after applying the
style?:

vlayer.triggerRepaint()

You can test the result of applying the style using:

result = vlayer.loadNamedStyle(qlrFileName)

If result if False, the style was not loaded/applied.

-gary
Post by Geo DrinX
Thank you
Roberto
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Gary Sherman

Founder, QGIS Project
Consulting: geoapt.com
Publishing: locatepress.com

We work virtually anywhere
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Geo DrinX
2015-04-16 06:50:56 UTC
Permalink
Very strange :(

I inserted also the triggerRepaint() but nothing changes.

This is my sourcecode:

https://github.com/geodrinx/smartroadsense/blob/master/smartroadsense.py


If I drag and drop in QGIS my "srs_data.qlr" file, it works.

Instead, from python code, the style is not applied.

Could be because my data file is a CSV ?
Post by Gary Sherman
Post by Geo DrinX
Hello,
there is a way to load a QLR file with pyQGIS ?
I tried using vlayer.loadNamedStyle(qlrFileName) but it seems
not to work.
What is the correct way ?
That is the correct way. Have you done the following after applying the
vlayer.triggerRepaint()
result = vlayer.loadNamedStyle(qlrFileName)
If result if False, the style was not loaded/applied.
-gary
Post by Geo DrinX
Thank you
Roberto
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Gary Sherman
Founder, QGIS Project
Consulting: geoapt.com
Publishing: locatepress.com
We work virtually anywhere
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Nathan Woodrow
2015-04-16 06:55:41 UTC
Permalink
Hey,

QLR files are not style files they can't be loaded like that.
Unfortunately the API for loading a QLR is broken in 2.8.1 but will be
fixed in 2.8.2, however the logic isn't very complex and you can translate
it to Python from C++. The source is here
https://github.com/qgis/QGIS/blob/master/src/core/qgslayerdefinition.cpp#L36
.

If you don't need to support loading groups from the QLR you can use this:

QList<QgsMapLayer*> layers = QgsMapLayer::fromLayerDefinition( doc );
QgsMapLayerRegistry::instance()->addMapLayers( layers, True);

- Nathan
Post by Geo DrinX
Very strange :(
I inserted also the triggerRepaint() but nothing changes.
https://github.com/geodrinx/smartroadsense/blob/master/smartroadsense.py
If I drag and drop in QGIS my "srs_data.qlr" file, it works.
Instead, from python code, the style is not applied.
Could be because my data file is a CSV ?
Post by Gary Sherman
Post by Geo DrinX
Hello,
there is a way to load a QLR file with pyQGIS ?
I tried using vlayer.loadNamedStyle(qlrFileName) but it seems
not to work.
What is the correct way ?
That is the correct way. Have you done the following after applying the
vlayer.triggerRepaint()
result = vlayer.loadNamedStyle(qlrFileName)
If result if False, the style was not loaded/applied.
-gary
Post by Geo DrinX
Thank you
Roberto
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Gary Sherman
Founder, QGIS Project
Consulting: geoapt.com
Publishing: locatepress.com
We work virtually anywhere
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Geo DrinX
2015-04-16 07:35:15 UTC
Permalink
Post by Nathan Woodrow
QLR files are not style files
I am trying with a .qml file, but the result is the same : no style
applied using a CSV and python.

Instead, if I use SHP and QML, the style is applied immediately after
loading the SHP.

But, for do this, I should need convert my CSV into SHP every time, before.

Well, I'll do this if there is no alternative.

Or, I will try to define the style of the level directly through python.
Is possible to do this ? I will study.


- Roberto
Nathan Woodrow
2015-04-16 07:38:52 UTC
Permalink
Ok but your said QLR in your message hence my answer.

Natham
Post by Nathan Woodrow
QLR files are not style files
I am trying with a .qml file, but the result is the same : no style
applied using a CSV and python.
Instead, if I use SHP and QML, the style is applied immediately after
loading the SHP.
But, for do this, I should need convert my CSV into SHP every time, before.
Well, I'll do this if there is no alternative.
Or, I will try to define the style of the level directly through python.
Is possible to do this ? I will study.
- Roberto
Gary Sherman
2015-04-16 14:53:24 UTC
Permalink
Post by Nathan Woodrow
Hey,
QLR files are not style files they can't be loaded like that.
OH :) My brain read QML...
Post by Nathan Woodrow
Unfortunately the API for loading a QLR is broken in 2.8.1 but will be
fixed in 2.8.2, however the logic isn't very complex and you can
translate it to Python from C++. The source is here
https://github.com/qgis/QGIS/blob/master/src/core/qgslayerdefinition.cpp#L36.
QList<QgsMapLayer*> layers = QgsMapLayer::fromLayerDefinition( doc );
QgsMapLayerRegistry::instance()->addMapLayers( layers, True);
- Nathan
Very strange :(
I inserted also the triggerRepaint() but nothing changes.
https://github.com/geodrinx/smartroadsense/blob/master/smartroadsense.py
If I drag and drop in QGIS my "srs_data.qlr" file, it works.
Instead, from python code, the style is not applied.
Could be because my data file is a CSV?
Hello,
there is a way to load a QLR file with pyQGIS ?
I tried using vlayer.loadNamedStyle(__qlrFileName)
but it seems
not to work.
What is the correct way ?
That is the correct way. Have you done the following after
vlayer.triggerRepaint()
result = vlayer.loadNamedStyle(__qlrFileName)
If result if False, the style was not loaded/applied.
-gary
Thank you
Roberto
_________________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/__mailman/listinfo/qgis-__developer
<http://lists.osgeo.org/mailman/listinfo/qgis-developer>
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Gary Sherman
Founder, QGIS Project
Consulting: geoapt.com <http://geoapt.com>
Publishing: locatepress.com <http://locatepress.com>
We work virtually anywhere
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
_________________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/__mailman/listinfo/qgis-__developer
<http://lists.osgeo.org/mailman/listinfo/qgis-developer>
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Gary Sherman

Founder, QGIS Project
Consulting: geoapt.com
Publishing: locatepress.com

We work virtually anywhere
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Alain
2016-05-12 06:58:44 UTC
Permalink
Hello,


There is any way, in the new QGIS versions, to load the .qrl ,Definition
Layer Files, with python ?

Thanks,
Alain



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/How-to-load-a-QLR-file-with-pyQGIS-tp5201428p5265951.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
Alain
2016-05-12 06:59:38 UTC
Permalink
Hello

2016-05-12 8:58 GMT+02:00 Alain [via OSGeo.org] <
Post by Geo DrinX
Hello,
There is any way, in the new QGIS versions, to load the .qrl ,Definition
Layer Files, with python ?
Thanks,
Alain
------------------------------
If you reply to this email, your message will be added to the discussion
http://osgeo-org.1560.x6.nabble.com/How-to-load-a-QLR-file-with-pyQGIS-tp5201428p5265951.html
To unsubscribe from How to load a QLR file with pyQGIS ?, click here
<http://osgeo-org.1560.x6.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5201428&code=YWxhZ295YUBnbWFpbC5jb218NTIwMTQyOHwzMDA0MTAyNzc=>
.
NAML
<http://osgeo-org.1560.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/How-to-load-a-QLR-file-with-pyQGIS-tp5201428p5265952.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
Loading...