[Qgis-developer] How to load a QLR file with pyQGIS ?
Gary Sherman
gsherman at geoapt.com
Thu Apr 16 07:53:24 PDT 2015
On 4/15/15 10:55 PM, Nathan Woodrow wrote:
> Hey,
>
> QLR files are not style files they can't be loaded like that.
OH :) My brain read QML...
> 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
>
>
> On Thu, 16 Apr 2015 at 16:51 Geo DrinX <geodrinx at gmail.com
> <mailto:geodrinx at gmail.com>> wrote:
>
> 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?
>
>
> 2015-04-15 18:39 GMT+02:00 Gary Sherman <gsherman at geoapt.com
> <mailto:gsherman at geoapt.com>>:
>
> On 4/15/15 2:24 AM, Geo DrinX wrote:
>
> 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
>
>
> Thank you
>
> Roberto
>
>
> _________________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> <mailto:Qgis-developer at lists.osgeo.org>
> 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
> Qgis-developer at lists.osgeo.org
> <mailto:Qgis-developer at lists.osgeo.org>
> http://lists.osgeo.org/__mailman/listinfo/qgis-__developer
> <http://lists.osgeo.org/mailman/listinfo/qgis-developer>
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org <mailto:Qgis-developer at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Gary Sherman
Founder, QGIS Project
Consulting: geoapt.com
Publishing: locatepress.com
We work virtually anywhere
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
More information about the Qgis-developer
mailing list