qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.32k stars 2.97k forks source link

use variable in layer source #26826

Open qgib opened 6 years ago

qgib commented 6 years ago

Author Name: Pranas Slezas (Pranas Slezas) Original Redmine Issue: 18995

Redmine category:gui


use variable in layer source

We using qGis layer and can not use variable in source. We would use this feature for authentication. User can add project variables and then this variables can be used in layer source (connection)

Example dbname='pvz1' host=biomon.com port=5432 user=@user password=@password sslmode=disable key='pkuid' srid=3346 type=Point table="public"."dirvinis_sejikas" (geometrija) sql=

qgib commented 6 years ago

Author Name: jd lom (@lejedi76)


A better solution is to use the authentication system with basic authentication:

https://docs.qgis.org/2.14/fr/docs/user_manual/auth_system/auth_overview.html

Change the id of the autentication with something like 0000000

Your layer source should be :

dbname='pvz1' biomon.com port=5432 sslmode=disable authcfg=0000000 key='pkuid' srid=3346 type=Point table="public"."dirvinis_sejikas" (geometrija) sql=

Do this on every client.

Best regards,

ar-siddiqui commented 1 year ago

In our workflow, this will be useful as we have multiple PostgreSQL layers defined based on WHERE county_name = 'some_text' and to do analysis for a different county, currently we have to swap the county name in each layer individually or through python. If project variables are allowed in SQL query, we can just change the variable value in the project setting and switch analysis and all layers to a different county.

andreasneumann commented 1 year ago

@ar-siddiqui - there is a QGIS plugin available for that:

https://plugins.qgis.org/plugins/qgis-subset-expression-plugin/

Description at https://github.com/elpaso/qgis-subset-expression-plugin