0

This problem may sound trivial but I don't understand it. I changed my project's CRS from EPSG 31256 to 25833. When I change the layer' CRS it appears on a different location. So the changes are not applied on the geometry. I can see that because in the attribute table I have a column for X and one for Y in the old system (EPSG: 31256) and the values don't change. How can I transform these coordinates into the new CRS?

2
  • Use the processing tool Reproject to project's the layer's CRS.
    – 15Step
    Commented Jun 29, 2021 at 8:05
  • 2
    See here for conceptual background - to understand why you have to reproject and why you should not set (change) the CRS of your layer: gis.stackexchange.com/a/383437/88814
    – Babel
    Commented Jun 29, 2021 at 8:21

1 Answer 1

4

As said in the comments, you should reproject your data - if necessary. Most times it is not necessary, unless e.g. you're exporting your data to a file format which doesn't know about CRS, e.g. dxf.

If you only need to add the reprojected coordinates to the attribute table, you may use the field calculator expression transform().

You need to hand the expression a geometry. In your case the geometry of the current feature, $geometry. You also need to tell it, which CRS you're starting from ('EPSG:31256'), as well as where you're "going" ('EPSG:25833').

So you end up with: transform($geometry,'EPSG:31256','EPSG:25833') - this gives you a coordinate pair for each point. If you have lines or polygons, you should have said so earlier, you're now in for points.

Since you probably want to have separate columns for x and y, you need to tell the calculator to only grab that part of the coordinate pair. This can be done by adding x(...) respectively y(...) around your expression. So, x(transform($geometry,'EPSG:31256','EPSG:25833')) will return you the x-coordinate of the current geometry/point, which orignially is in 31256, transformed to 25833.


You also could simply transform your data, and then use $x and $y to write the transformed coordinates to the attribute table. But that would produce probably redundant data.

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.