Saturday 25 February 2017

field calculator - Filling column with consecutive numbers in QGIS?


I make a new column in my attribute table and it has a default value (for example 0). I want to (probably using the field calculator) have the result that row 1 has the value 1, row 2=2 and so on, just like a numbered index.


I'd be thankful for a code example for the field calculator (including the use of $rownum (I think I need this for switching to the line)).



Answer



Just put $rownum (QGIS 2) or @row_number (QGIS 3+) as the expression. Simple as that. :)


An up-to-date list of all the field calculator functions can be read in the official docs.


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