Search code examples
leafletcoordinate-systems

Convert coordinate between projections of different bounds


I have markers that were plotted in a legacy system on a EPSG4326 map with a bounds of -180 to 180 latitude and -180 to 180 longitude. I'm now trying to plot these onto a EPSG4326 map that has a bounds of -90 to 90 latitude and -180 to 180 longitude. How can I convert the original coordinate to the new coordinate system so it appears on the new map at the same location? I'm trying to tackle this within a JavaScript application using the Leaflet mapping library. Any pointers or insight would be greatly appreciated.

As an example, the location of London on the source map that represents latitude in -180 to 180 range is approximately (Lat: 61.8750, Lon: 0.1278) and on destination map where latitude is -90 to 90 it would be about (Lat: 51.5074, Lon: 0.1278).


Solution

  • I figured it out!

    newlat = (180.0/Math.PI*(2.0*Math.atan(Math.exp(oldlat*Math.PI/180.0))-Math.PI/2.0))
    

    Thus if oldlat = 61.8750, newlat = 52.482780222078226 which is what I needed and solves my problem perfectly, converting a latitude with different extents into the new extents.

    The reverse (if needing to reconvert) formula is:

    oldlat = ((180.0/Math.PI)*Math.log(Math.tan((90.0+newlat)*Math.PI/360.0)))