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
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"||')')
-
Awesome - I would never have figured out the || by myself... Thank you for the quick response.benny the spaceman– benny the spaceman2018年06月08日 04:28:40 +00:00Commented Jun 8, 2018 at 4:28
-
Great! Thanks @Benoit_W :) You would have found out that sooner or later.Kazuhito– Kazuhito2018年06月08日 12:48:06 +00:00Commented 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– 15Step2019年01月24日 12:50:21 +00:00Commented 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.Kazuhito– Kazuhito2019年01月24日 13:17:40 +00:00Commented 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– 15Step2019年01月24日 14:24:45 +00:00Commented Jan 24, 2019 at 14:24
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
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.
Explore related questions
See similar questions with these tags.