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.

Vince
  • 20,017
  • 15
  • 45
  • 64

2 Answers2

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

Babel
  • 71,072
  • 14
  • 78
  • 208
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

Taras
  • 32,823
  • 4
  • 66
  • 137