8

I know how to get the geometry (x,y) into Attribute fields with the Calculator, but I can't figure out how to update the geometry from values contained in attributes.

I am trying Field Calculator > Update existing field > <geometry>, but I can't find how to assign my "x" and "y" fields to the actual feature geometry.

I don't want to manually drag each point with the vertex editor, or type in each coordinate. I have to update many points.

Taras
  • 32,823
  • 4
  • 66
  • 137

3 Answers3

12

Assuming you have chosen <geometry> field in the Update existing field drop down list, the expression you need would be:

geom_from_wkt('POINT('||"x"||' '||"y"||')')
Kazuhito
  • 30,746
  • 5
  • 69
  • 149
  • Awesome - I would never have figured out the || by myself... Thank you for the quick response. – benny the spaceman Jun 08 '18 at 04:28
  • Great! Thanks @Benoit_W :) You would have found out that sooner or later. – Kazuhito Jun 08 '18 at 12:48
  • The syntax is actually quite misleading. Here is the correct one with example coordinates:

    geom_from_wkt('POINT('||'31.797788'||' '||'30.729471'||')')

    Notice the single quotes. Using double quotes in QGIS 2/3 will cause an error as it mistakens the x and y values as field names.

    – 15Step Jan 24 '19 at 12:50
  • 1
    @15Step This syntax is reading values from "x" and "y" fields, such field names were set by OP. – Kazuhito Jan 24 '19 at 13:17
  • I misunderstood the question, sorry about that! I think the comment could still be useful for updating numerical coordinates in the field. – 15Step Jan 24 '19 at 14:24
2

Another option is to use the make_point() function together with updated fields "x" and "y".

before change :
case1_before

window :
window

after change :
case1_after

Taras
  • 32,823
  • 4
  • 66
  • 137
1

I modified this a bit to move a selection of points into a spread out line along a vertical axis.

geom_from_wkt('POINT('||$x||' '||((@row_number*100)+$y)||')')

The 100 can be changed to whatever is appropriate for your area and scale. I imagine that this could be further modified to create a grid, but I didn't have time to try.

Babel
  • 71,072
  • 14
  • 78
  • 208
hillibilli
  • 11
  • 1