1

I have data for Danish administrative areas. So far I have calculated centroids and added y and x coordinates for them. However, I have not been able to convert them to decimal degrees when exporting as CSV. In the "Save Vector Layer as..." I tried changing the CRS to EPSG:4326 which was what I read would do it. But when I export the CSV, the format is not as such (between -180 and 180 for the y coordinate for example).

I have read several forum posts about this exact issue without result.

5
  • Save to 4326 first, then add coordinates, then export.
    – Erik
    Commented Sep 9, 2021 at 10:46
  • Thank you for your reply. Can you elaborate "Save to 4326 first"? I'm not sure I understand what you mean. Commented Sep 9, 2021 at 11:05
  • 2
    To re-project the layer "save to 4326" see: gis.stackexchange.com/questions/35590/… Selecting EPSG:4326 as the CRS. Commented Sep 9, 2021 at 11:11
  • When you say "I tried changing the CRS to EPSG:4326" how did you do this? I would try re-projecting the data then doing the save. Commented Sep 9, 2021 at 11:12
  • Thank you so much. It helped! Commented Sep 9, 2021 at 11:32

2 Answers 2

3

Use the following expression to (internally) transform a layer in any CRS to EPSG:4326 and from there get lat/lon values - no need to actually reproject as long as you only want to get coordinate values in another CRS than the one the layer is defined in. The variable @layer_crs automatically gets the CRS of the layer, so even without knowing what CRS it has, you can use the expression.

This expression is for longitude, for latitude simply replace x by y:

 x (transform( $geometry,  @layer_crs, 'EPSG:4326'))

Layer in EPSG:32032 (UTM zone 32N), coordinate values calculated in lat/lon, based on EPSG:4326. First two columns are in layer's UTM coordinates for comparison: enter image description here

2

Additionally the "Add X/Y fields to layer" geoalgorithm can be used, where the 'Coordinate reference system to use for the generated x and y fields' can be specified.

window

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