Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading