Skip to content

Instantly share code, notes, and snippets.

@olivierchatry
Last active March 23, 2022 14:03
Show Gist options
  • Select an option

  • Save olivierchatry/75bc73d398e3dd0c9365f73d30662f0a to your computer and use it in GitHub Desktop.

Select an option

Save olivierchatry/75bc73d398e3dd0c9365f73d30662f0a to your computer and use it in GitHub Desktop.

Library

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.

Parameters, datum shift, etc.

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.
  • +units the 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

Convertion

( 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

STEP1: Convert P to latlong ( in the same datum ) using source transformation.

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 ) :

STEP2: If not the same DATUM

Result from STEP1 -> geodeticToGeocentric(source) -> geocentricToWgs84(source) -> geocentricFromWgs84(destination) -> geocentricToGeodetic(destination) This is executed :

STEP3: Use the "forward" function from the destination coordinate system code.

If, for example destination is an UTM, then :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment