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
35.7k5 gold badges77 silver badges151 bronze badges
asked Jun 8, 2018 at 0:27

3 Answers 3

13

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"||')')
answered Jun 8, 2018 at 1:54
5
  • Awesome - I would never have figured out the || by myself... Thank you for the quick response. Commented Jun 8, 2018 at 4:28
  • Great! Thanks @Benoit_W :) You would have found out that sooner or later. Commented 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. Commented Jan 24, 2019 at 12:50
  • 2
    @15Step This syntax is reading values from "x" and "y" fields, such field names were set by OP. Commented 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. Commented Jan 24, 2019 at 14:24
3

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

answered May 13, 2022 at 5:52
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
79.7k15 gold badges96 silver badges244 bronze badges
answered Feb 8, 2021 at 17:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.