[GIS] How to add geometry columns to a layer in QGIS 2.16

fields-attributesgeometryqgis

I want to add geometry columns to a shapefile. I use the tool called Export/Add Geometry Columns. The tool automatically creates a new layer with the input layer's attributes and the new geometry columns. In previous versions this tool (very usefully) allowed to add (or update) the columns to the existing shapefile instead of creating a new one. How can this be done in the 2.16 and 2.18 versions? I tried by selecting the curved arrow icon labelled ("Iterate over this layer") but the program crashes ("An error occurred while executing Python code").

Best Answer

You could use the field calculator and the expression:

 geom_to_wkt(  $geometry )

For point data you can create X and Y columns and use the field calculator with:

$x

and

$y