3

I have a entities layer in projection A with positionned labels coordinates based on X,Y and Rotation angle in the attribute table :

ETIKT_X, ETIKT_Y, ETIKT_ROTA

Labels

Labels_2

Those labels are defined into the geometry displayed, I have positionned manually those labels with QGIS label tools and data defined attributes.

Now, I wish to reproject my layer in projection B but, if I do that, my labels will still be in projection A and therefore will not appear correctly.

My actual manual solution is :

  • Use "Point from table" tool to create points in my label position in projection A
  • Project my label point layer from projection A to B
  • Calculate $x and $y of my projected points into my attribute table
  • Project my layer from projection A to B
  • Join my label point layer to my layer and update the label X and Y field with my proj B calculated values.

Is there a already-made tool in QGIS that can do that without doing all this manipulation ?

If not, I think I'll try to make a processing script that will take as argument : "X field", "Y field", "proj A code" and "proj B code", optionnaly X and Y new Proj B field and do the automation of my process. I'll put it into a solution if I manage to do it.

1 Answer 1

5

The calculation was quite simple in fact, thanks to the wonderful field calculator. I did some research and below the solution I found :

  • In the Field Calculator, add a new field X_ProjB or Y_ProjB for example and enter as a parameter the following codes for each attribute column :

    x(transform( make_point( "ETIKT_X" , "ETIKT_Y" ) ,'EPSG:27572','EPSG:2154'))

    y(transform( make_point( "ETIKT_X" , "ETIKT_Y" ) ,'EPSG:27572','EPSG:2154'))

Explanation :

  1. make_point() : creates a point geometry from my 2 fields X and Y in proj A.
  2. transform() projects the geometry generated in (1) from EPSG:proj A to EPSG:proj B
  3. x() and y() gets the coordinates of the projected point generated in (2)

The result is the projection B coordinates values. So simple !

0

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.