7

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.

3 Answers 3

10

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"||')')
5
  • Awesome - I would never have figured out the || by myself... Thank you for the quick response. Jun 8, 2018 at 4:28
  • Great! Thanks @Benoit_W :) You would have found out that sooner or later.
    – Kazuhito
    Jun 8, 2018 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, 2019 at 12:50
  • @15Step This syntax is reading values from "x" and "y" fields, such field names were set by OP.
    – Kazuhito
    Jan 24, 2019 at 13:17
  • I misunderstood the question, sorry about that! I think the comment could still be useful for updating numerical coordinates in the <geometry> field.
    – 15Step
    Jan 24, 2019 at 14:24
1

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.