We us proj4js ( http://proj4js.org/ ), which is a javascript port of Proj ( https://proj.org/ ) for doing our projections. This is a well known, and use, library. It is the default projection library for GDAL.
All the coordinate system definitions come from http://epsg.io ( you can get it directly with https://epsg.io/[EPSG], so for example NAD50 UTM32 would be : https://epsg.io/23032, and the description we are using : https://epsg.io/23032.proj4 )
The value we get for EPSG:23032 is : +proj=utm +zone=32 +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs
This give Proj4 the information it need for the convertion :
+proj, projection type : UTM ( which give the method for converting the coordinate from cartesian to geocentric ).+ellps, the ellipsoid used ( intl here, for international, which if I remember correcty is Hayford ).+towgs84, the datum shift; to convert the computed geocentric coordinate to wgs84.+unitsthe unit the coordinate are in ( here meters )+no_defs, just tell proj4 to not use default values, and use the one we provided.
For a deeper explenation on the parameters : http://proj.maptools.org/gen_parms.html
( This is a high level overview )
It's actually "fairly" simple. Here we take EPSG:23032 as source, and whatever ( that support convertion ) as the target.
For a convertion of P from source to destination
For EPSG:23032 we use this ellipsoid :
intl = {
a: 6378388.0,
rf: 297.0,
ellipseName: "International 1909 (Hayford)"
}Then we use the code you can find here to convert from "meters" to "lat long" ( same DATUM ) :
- https://github.com/proj4js/proj4js/blob/master/lib/projections/utm.js
- Which is actually using this code : https://github.com/proj4js/proj4js/blob/master/lib/projections/etmerc.js
- ( function name is inverse )
Result from STEP1 -> geodeticToGeocentric(source) -> geocentricToWgs84(source) -> geocentricFromWgs84(destination) -> geocentricToGeodetic(destination)
This is executed :
geocentricFromWgs84https://github.com/proj4js/proj4js/blob/master/lib/datumUtils.js#L214geocentricToWgs84https://github.com/proj4js/proj4js/blob/master/lib/datumUtils.js#L182geocentricToGeodetichttps://github.com/proj4js/proj4js/blob/master/lib/datumUtils.js#L74geodeticToGeocentrichttps://github.com/proj4js/proj4js/blob/master/lib/datumUtils.js#L32
If, for example destination is an UTM, then :
- https://github.com/proj4js/proj4js/blob/master/lib/projections/utm.js
- Which actually call https://github.com/proj4js/proj4js/blob/master/lib/projections/etmerc.js
- ( function name is forward )