[Qgis-developer] Change the query of a query layer (postgis)

Nyall Dawson nyall.dawson at gmail.com
Mon Jun 22 03:17:35 PDT 2015


On 18 June 2015 at 00:06, Olivier Dalang <olivier.dalang at gmail.com> wrote:
> Actually it seems the layer.setDataSource() method works, sorry for the
> noise !
>
> But then it resets the style of the layer to default (uniform random color),
> as if the layer was freshly added...

No, you're right. It was crashy. It's been fixed in master, and I've
also made it now retain the layer's renderer and legend if the
geometry type has not changed.

Hope that helps!
Nyall

>
>
>
>
> 2015-06-17 14:29 GMT+02:00 Olivier Dalang <olivier.dalang at gmail.com>:
>>
>> Hi !
>>
>> Is it possible to change the query of a postgis query layer in python
>> without reloading the project ?
>>
>> The goal is to have a parameter in my query that I'd be able to change
>> with a slider.
>>
>> I tried the QgsVectorLayer.setDataSource() method, but it makes QGis
>> crash.
>> I tried the workaround described here (
>> http://gis.stackexchange.com/questions/62610/changing-data-source-of-layer-in-qgis
>> ), writing and reading the XML file, but it also makes QGis crash.
>>
>> If not possible, is there a serious limitation behind this, or is the
>> feature just missing/bugged ?
>>
>> Example :
>>
>> I have this query loaded as a layer:
>>
>> "SELECT id, name, ST_Buffer(geom,25) as geom FROM my_table"
>>
>> But I want to be able to change the hardcoded buffer from 25 to some value
>> from a QSlider.
>>
>> Thanks!
>>
>> Olivier
>
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the Qgis-developer mailing list