Tuesday, 7 May 2019

Connect to local file or PostGIS layer in field calculator QGIS


I'm trying to make query from field calculator so that it would be possible to connect to PostGIS layer (or local file on computer) and select data according to condition so that use this selection afterwards for layer in project.


Is it possible?


I've found great functions in Reffunctions plugin - e.g. dbvalue, that retrieve first targetField value from targetLayer when keyField is equal to conditionValue;


dbquery, that retrieve first targetField value from targetLayer when whereClause is true (for file in project) - this function seems to not work


But all these functions require a layer in a project, altough I wonder to connect to PostGIS layer or local file in a query. I suppose I will need to create custom function in function builder, but I don't know how turn to local or PostGIS layer from QGIS via python.


This post and cookbook gives information about adding PostGIS layer in QGIS project, but still unsuccessfully - What's wrong? It gives me an error


"NameError: name 'self' is not defined"



here is my code


other variant


other variant


also don't add a PostGIS layer


I tried single quotes instead of double, but it doesn't help. Local file adds successfully after replacing single delimiter to double in path to file.


Any ideas?)




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...