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

Enrico Ferreguti enricofer at gmail.com
Wed Jun 17 12:56:39 PDT 2015


Hi Olivier,
datasource changing is a feature that I really miss and wait from longtime.
Every Qgis new release I checked without success if the properties
datasource string is editable. I recently found the hack you report (
https://geogear.wordpress.som/2015/05/15/changing-qgis-layer-datasource-with-python/)
that I verify to be working up to Wien 2.8.2. Till 2.9 the code crash qgis.
Reading your post I realized that a new QgsVectorLayer method has appeared:
setDatasource. Wow! Perhaps the waiting is going to be over....

Regards,

Enrico Ferreguti.

2015-06-17 16:45 GMT+02:00 Olivier Dalang <olivier.dalang at gmail.com>:

> Hi Enrico,
>
> Hmm I didn't think of that, thanks for the idea ! But I can't use it since
> I may have several user at once.
>
> Best,
>
> Olivier
>
> 2015-06-17 16:03 GMT+02:00 enricofer <enricofer at gmail.com>:
>
>> Hi Olivier,
>> In your case, I think that the best way to do this is to create a view
>> from the sql query and load it as layer, than, when qslider changes, change
>> the view definition with "ALTER VIEW"  and reload the layer.
>>
>> Regards,
>>
>> Enrico Ferreguti
>>
>> Il giorno 17/giu/2015, alle ore 14:29, olivier [via OSGeo.org] <[hidden
>> email] <http:///user/SendEmail.jtp?type=node&node=5211452&i=0>> ha
>> scritto:
>>
>> 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
>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5211424&i=0>
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>> ------------------------------
>>  If you reply to this email, your message will be added to the
>> discussion below:
>>
>> http://osgeo-org.1560.x6.nabble.com/Change-the-query-of-a-query-layer-postgis-tp5211424.html
>>  To unsubscribe from Quantum GIS - Developer, click here.
>> 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: Re: Change the query of a query layer
>> (postgis)
>> <http://osgeo-org.1560.x6.nabble.com/Change-the-query-of-a-query-layer-postgis-tp5211424p5211452.html>
>> Sent from the Quantum GIS - Developer mailing list archive
>> <http://osgeo-org.1560.x6.nabble.com/Quantum-GIS-Developer-f4099106.html>
>> at Nabble.com.
>>
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150617/aa17c6ec/attachment.html>


More information about the Qgis-developer mailing list