QGIS – Using Expressions to Edit Columns Automatically in QGIS

attribute-tableexcelexpressionqgis

I have a geoJSON file with 4,500 rows. I need to edit this file as follow:

  • if plot_num starts with 2 -> rep = 2
  • first 11 rows of line = 1
  • second 11 rows of line = 2

I have been updating the fields manually, but it is taking me for ever and I have 8 files that need the same. How can I use the Expression Dialog tool in QGIS to do so? I wish it was like Excel where I can just copy and paste or use the corner dropdown tool. Can you write a QGIS expression or a Python function to be used in QGIS?

Example (24 rows/4,500 rows):

line    rep     plot_num
1       2       256
1       2       256
1       2       256
1       2       256
1       2       256
1       2       256
1       2       256
1       2       256
1       2       256
1       2       256
1       2       256
2       2       256
2       2       256
2       2       256
2       2       256
2       2       256
2       2       256
2       2       256
2       2       256
2       2       256
2       2       256
2       2       256
1       3       356
1       3       356

Best Answer

I figure it out that you can use the tool "Select features using an expression" and then update the fields using "Open field calculator". On the "Select features using an expression" I used the following to find the empty "rep" fields where "plot_num" was 1.

CASE
WHEN left("plot_num",1) IS 1 THEN "rep" is NULL
END

Once those where selected, I updated their values using "Open field calculator" by selecting the field that needed to be updated and setting the desired value.

Related Question