4

I need to create in a point layer attribute table new fields with the points coordinates converted in different geographic CRS through an expression like:

x(transform($geometry, 'EPSG:xxxxx', 'EPSG:xxxxx'))

Is it possible (and how) to integrate in this expression the function to_dms() in order to convert directly the decimal degrees output to DMS degrees?

Taras
  • 32,823
  • 4
  • 66
  • 137
Andrew-63
  • 643
  • 4
  • 15

1 Answers1

3

I have a layer in OSGB coordinates (EPSG code 27700) and I can use:

to_dms(x(transform($geometry, 'EPSG:4326', 'epsg:4326')), 'x', 3)

to get a DMS representation of the point coordinates.

For example, I can use this expression in the labelling engine:

enter image description here

and my points get labelled with the DMS longitude, even though their coordinate system is still OSGB metres:

enter image description here

You can use that expression to add a DMS longitude column to the attribute table (and with slight modification, latitude too).

Taras
  • 32,823
  • 4
  • 66
  • 137
Spacedman
  • 63,755
  • 5
  • 81
  • 115