TransWikia.com

Boolean fields from PostGIS data type changed to QString in QQIS

Geographic Information Systems Asked by George of all trades on June 16, 2021

I have a layer in QGIS loaded from a PostGIS database. In the layer properties dialog in QGIS, under the fields tab, layers with a typename of ‘bool’ (which are boolean fields in the PostGIS database) appear as type ‘QString’. The values then behave as strings in QGIS. Is there a way to bring the layer in so that the boolean fields are treated as booleans in QGIS?

3 Answers

I think it's impossible. But you can use the field like a boolean with the selection box (ex: myfield = 't' ). Result will be same as myfield is true in Postgresql.

Answered by Mathieu D on June 16, 2021

I solved my problem with the following approach:

In the field which holds the boolean value, I defined a checkbox as edit widget under layer properties -> fieöds and set the representation for checked as t and for unchecked as f ( see image) enter image description here

Another but similar approach is to use a value map field and use the two options (image 2)

enter image description here

I then defined a standard layer style for my layer in QGIS and saved this style into the database with properties -> style(the button down left) -> Save as default -> Save to datasource database

So every time I load the layer the bool field is shown as checkbox which is either t or f and which is understood by Postgres as a boolean value and if I query the field inside postgres with:

SELECT bool_field from my_table 

I get something like

bool_field: false, false. true, ...

Answered by LaughU on June 16, 2021

Actually it is possible to doubleclick to the boolean field in the QGIS attribute table to get a checkbox where it is possible to change the value from true to false or vice versa. One must know this, since it isn't possible to edit this field otherwise. No chance to change the text from 'true' to 'false'. enter image description here

Answered by geom on June 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP