3

I have a shapefile of a 10km grid that is in UTM projection but I would like to convert all coordinates to Degrees, Minutes, and Seconds. The attribute table has corners (Top, Bottom, left, and right). These are the ones I would like to convert to DMS. How can I do that in QGIS?

I tried to save as CSV but I did not get the coordinates of all corners. I have also used 'add geometry attribute' but it also did not give the DMS coordinates.

Here is how the grid looks like: Attribute table of the grids

2
  • 2
    Please decide which software you want to use. Please add what you researched, as well was what you tried so far and where you're stuck.
    – Erik
    Aug 3, 2021 at 14:25
  • Thank you for adding the details. Are you aware that add geometry attributes uses the current CRS of the layer? So you either need to reproject your data to EPSG:4326, or use the field calculator expression transform() in order to add the coordinates as decimal degrees.
    – Erik
    Aug 3, 2021 at 15:26

1 Answer 1

5

You can use these expressions:

left:

to_dms(x_min(transform($geometry,layer_property(@layer,'crs'),'EPSG:4326')),'x',3)

top:

to_dms(y_max(transform($geometry,layer_property(@layer,'crs'),'EPSG:4326')),'y',3)

right:

to_dms(x_max(transform($geometry,layer_property(@layer,'crs'),'EPSG:4326')),'x',3)

bottom:

to_dms(y_min(transform($geometry,layer_property(@layer,'crs'),'EPSG:4326')),'y',3)
  • The last number (3 in my example) specifies the coordinate precision. Change that if you want to.
  • You can also add ,'aligned' or ,'suffix' behind the coordinate precision to format your output. E.g. to_dms(y_min(transform($geometry,layer_property(@layer,'crs'),'EPSG:4326')),'y',3,'suffix')
  • Note that your output field must be of type string

Further explanation: First we get the geometry by using $geometry and transform() it from the layers source CRS (layer_property(@layer,'crs')) to WGS84 ('EPSG:4326'). Then we get the max or min coordinates by using x_min(), y_max() and so on, which are equal to left, top, etc.. Finally we convert the transformed coordinate to degree, minute and second by using to_dms(). See QGIS docs for information about this expression: https://docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/functions_list.html#to-dms

1
  • Works Completely well. Thank you. Aug 4, 2021 at 8:15

Your Answer

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

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