2

I’m new using QGIS with PostgreSQL I have imported layers via QGIS via the DBA plugin. The fields in PostgreSQL are encoded, example:

ID   NAME
1   GRASS
2   SAND
3   PAVEMENT

My question resides in the possibility of express the values in the output table as text instead of plain numbers is there a way to do this, should I use some kind of external plugin or there is a way to do it via the console.

2

If I understood the comment correctly, you want to replace the numbers 1,2,3 with the words GRASS, SAND, PAVEMENT.

Yo would do the following:

  • Load your Postgis Table into QGIS
  • Change into editing mode
  • Add a new Field (e.x. "bar") with typ char
  • Open the Attribute Table and go to the field calculator
  • Use this snipped to alter the content of the new field

    if( "id" = 1, 'GRASS', "bar")

  • With this you ensures, that you only alter this rows of "bar", where the id Field equals 1.

  • You repeat that for you other classes and when saved the table is also updated.

Keep in mind, that double quotes indicates field names while single quotes are strings

0

You can create a table holding the encoded values, for example the table landusecode having the fields ID and CLASSNAME.

In QGIS, you load both the layer and the lookup table, then make a join based on the ID field. That way, you see both the ID and the ClassName. It has the benefit of reducing the DB size (no need to repeat text on every row) and it ensure ALL entries of the same type have the exact same attribute value (no typo, no casing issue etc)

Alternatively, you can create a view in PostGres linking the layer and the lookup table, and display this spatial view directly in QGIS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.