I try to make a script which changes the coordinates given in format DMS (like N54 24 04.50, E018 34 17.20 to 18.6889, 54.3320) to DD format which is suitable for working in QGIS. The conversion is pretty easy but what I want to really do is to change a point position basing on coordinates given in columns. Like here:enter image description here

So I want to create a feature, then type in LAT and LON columns the desired position, columns 'x' and 'y' shall take these coordinates and convert them to DD format. And the last step is to change the feature position basing on columns 'x' and 'y'.

I know that I can retype the coordinates or recalculate them in csv. sheet and load again to QGIS but it's time consuming. So is there a possibility to 'set' a columns from which the feature will take the $x and $y of geometry directly in QGIS?

1 Answer 1


Absolutely, via Field calculator in your attribute table. First, you need to create a text field that includes both the Lat Long values as a WKT Text Point input, such as "Point (-40.7 15.397)". As you noted, these can't be inputted as variables directly to the geom_from_wkt function call. Create a new field, of type Text, and populate with your X and Y columns, with the expression concat( 'Point ( ',"X",' ',"Y", ' )') like this:

enter image description here

Be sure to set the field length to 40 to avoid cutting off the statement. Then, you'll want to check the box for "Update existing field", and pass this WKT field to the geometry function. Select geometry from the drop down list. Then, you can either type the function directly into the Expression box or select it from the Geometry function drop-down menu: geom_from_wkt. You'll enter:

geom_from_wkt( "WKT" )

After updating this, you'll need to save edits, as this will open an edit session and update all the features directly. Here's a view of what your Field Calculation should be: enter image description here

Now, if you want to bypass the attribute table directly, you can use the NODE tool, with your QGIS editor toolbar: enter image description here When you click a point with this tool, it will bring up the Vertex Editor window that will allow you to manipulate positions directly by typing values. However, this is a tedious process, and I would suggest using the Field Calculator. enter image description here

  • OK. Seems to be working. But: when I type column names in expression which You gave me instead of 'raw' coordinates (like 18.9123 45.2345) the position of point will be 0,0. Is there any way to put a column or expression (I wrote a function in python which converts DMS to DD) inside this: geom_from_wkt( 'POINT(X Y)' )?
    – muszynov
    Jan 10, 2018 at 21:56
  • I see what you mean - check the corrected solution, this should work fine. An intermediate step was necessary, but it should now update without issue.
    – AlecZ
    Jan 10, 2018 at 22:43
  • 1
    Thank You very very much! You've helped me a lot. It could be also done with one step less: it's possible to put 'concat' inside geometry expression: geom_from_wkt( ( concat( 'POINT (',"x",' ',"y", ')') )
    – muszynov
    Jan 12, 2018 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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