Monday 25 March 2019

qgis - unable to append zero into id when updating attribute table


I want to update attribute table BID column using below line


($id +002)


but it is not adding 00 at beginning. instead adding 2,3,4,5,...... I am very beginner and this is my first try to append zero zero into features table column. I am somehow manage to write this


'0000' || ($id + 5)

it adding zeros but changing exceeding the id length limits



Answer



You have to decide whether you want to have an integer or text field. If you want to do any arithemetics on the field, take integer, if you want trailing zeros, take a text field.


As a workaround, you can use an integer field, and use the field calculator to add a new, virtual field of type text, with this formula:


lpad( "" ,4,0)

This will make the field auto-updateable.



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...