I need to know how to get a geographic coordinate from a point, extracting it from EPSG:31982 in degrees, minutes and seconds.
1 Answers
You can reproject the longitude and latitude coordinates from the layer's geometry directly to create a new column for each using the QGIS field calculator.
This is explained here: https://gis.stackexchange.com/a/375071/110158
The field calculator dialogue for the longitude column is shown below:
That gets you to the longitude coordinate in decimal degrees. To get to degrees-minutes-seconds, as you requested, take the result from above and pass it into to_dms(). The complete field expression becomes:
to_dms(x(transform($geometry, layer_property(@layer, 'crs'),'EPSG:4326')), 'x', 3)
Or, as Matt suggested, layer_property(@layer, 'crs') can be shortened to @layer_crs making the full expression:
to_dms(x(transform($geometry, @layer_crs,'EPSG:4326')), 'x', 3)
Documentation for to_dms. This will return a text value so make sure you create a new text field or update an existing text field with space for the text.
- 1,174
- 7
- 11
-
Great! I was to post a similar answer, but you were faster. Nice to include
layer_propertyso that you can transform without even knowing from what CRS you transform! – Babel Mar 28 '22 at 15:17 -
1There is also the named variable
@layer_crsfor an even tidier expression. – Matt Mar 28 '22 at 17:07 -
1@Matt, thanks for the suggestion. I did notice
@layer_crswhen looking upto_dms(). Edited to add the alternative expression . – hgb Mar 28 '22 at 17:16

transform-expression? – Erik Mar 28 '22 at 13:14