0

I'm trying to use pyProj to convert UTM coordinates from WGS84 UTM 30N (epsg 36230) to ED50 (epsg 23030).

My WGS 85 coordinate is 456859.248 E, 6212329.347 N. When I convert using this online convertor [https://tool-online.com/en/coordinate-converter.php] I should get this: 456961.342 E, 6212551.085 N. Instead I get this: 456959.3405 E, 6212550.44 N, which as you can see is around 2 metres from where it should be.

In my code, I import a simple CSV with two columns called 'Easting' and 'Northing'. The CSV has one row which is the Easting and Northing values I posted above.

CODE BELOW

import pandas as pd
from pyproj import Transformer


class Transform:
    def __init__(self, in_epsg, out_epsg, input_file):
        self.in_epsg = in_epsg
        self.out_epsg = out_epsg
        self.transformer = Transformer.from_crs(f"epsg:{self.in_epsg}", f"epsg:{self.out_epsg}")
        self.df = pd.read_csv(input_file)
        self.x_list, self.y_list = [], []

    def iterate_rows(self, column1, column2):
        for index, row in self.df.iterrows():
            x = (row[column1])
            y = (row[column2])
            x_new, y_new = self.transformer.transform(x, y)
            self.x_list.append(x_new)
            self.y_list.append(y_new)
        self.df[f'Easting_converted'], self.df[f'Northing_converted'] = self.x_list, self.y_list
        self.df.to_csv('converted.csv')


test = Transform(32630, 23030, 'small.csv')
test.iterate_rows('Easting', 'Northing')

enter image description here

Dave Stark
  • 107
  • 8
  • It's probably different definitions at some point, what makes you think the online tool is correct? You can use `gdaltransform` (also boils down to proj) to confirm that it isn't your own code. Unrelated, you can call the transformer with arrays, so no need to loop over the rows, that should improve performance a bit. – Rutger Kassies Oct 17 '22 at 06:36
  • Thanks Rutger. I've checked the transformation with 3x programs in total and they all give the same results. The only one that doesn't tie in is PyProj. I'll take a look with GDAL now. Also, thanks for the heads up on arrays. I'll try that too. – Dave Stark Oct 17 '22 at 07:10
  • I get the same result as you with `gdaltransform` which is expected given that it also uses `proj`. You can export the GDAL definition to WKT, which might given some insight in how it's defined. Since the EPSG number is "just" a lookup, it could be something like different versions/definitions in the end. – Rutger Kassies Oct 17 '22 at 07:15
  • Is is possible to do a custom transformation? Could I create a custom WKT file, and transform that way? As in putting in my own 7-parameter shift? - Shift Tx - Shift Ty - Shift Tz - Rotation Rx - Rotation Ry - Rotation Rz - Scale Factor – Dave Stark Oct 17 '22 at 08:31

0 Answers0