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
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 expressiontransform()
in order to add the coordinates as decimal degrees.