pythonlatitude-longitudecartesian-coordinates

Convert from Cartesian grid to Lat Lon python


I have a cartesian square grid in meters with (-3600, -3600), (3600, -3600), (-3600, 3600) and (3600, 3600) as the boundary points. I know the latitude and longitude corresponding to the central point (0,0). I would like to convert this cartesian grid to latitude longitude based on the central reference latitude and longitude.

import numpy as np

x = np.linspace(-3600,3600,7201)
y = np.linspace(-3600,3600,7201)
yy, xx = np.meshgrid(y,x)

referenceLatitude = 48.85865
referenceLongitude = 2.33811

I would like to convert this resulting grid into lat lon coordinates

Any help would be appreciated

I have tried with WGS84 projections using pyproj, but I am not able to get in the reference latitude and longitude, so it is not correct


Solution

  • This function would do the trick:

    import math
    
    def cartesian_to_latlon(x, y, central_lat, central_lon):
        # Earth radius in meters
        earth_radius = 6378137
    
        # Convert x and y distances to radians
        lat_offset = y / earth_radius
        lon_offset = x / (earth_radius * math.cos(math.pi * central_lat / 180))
    
        # Convert radians to degrees
        new_lat = central_lat + (lat_offset * 180 / math.pi)
        new_lon = central_lon + (lon_offset * 180 / math.pi)
    
        return new_lat, new_lon
    
    

    Here you can replace x,y with your points