3

I need to know how to get a geographic coordinate from a point, extracting it from EPSG:31982 in degrees, minutes and seconds.

MrXsquared
  • 34,292
  • 21
  • 67
  • 117

1 Answers1

8

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:

enter image description here

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.

hgb
  • 1,174
  • 7
  • 11
  • Great! I was to post a similar answer, but you were faster. Nice to include layer_property so that you can transform without even knowing from what CRS you transform! – Babel Mar 28 '22 at 15:17
  • 1
    There is also the named variable @layer_crs for an even tidier expression. – Matt Mar 28 '22 at 17:07
  • 1
    @Matt, thanks for the suggestion. I did notice @layer_crs when looking up to_dms(). Edited to add the alternative expression . – hgb Mar 28 '22 at 17:16