Skip to content

Instantly share code, notes, and snippets.

@esutton
Created January 11, 2023 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esutton/8b47d4857d458aad4fa558bbd4952b8d to your computer and use it in GitHub Desktop.
Save esutton/8b47d4857d458aad4fa558bbd4952b8d to your computer and use it in GitHub Desktop.
NAD83 to WGS84 - JavaScript NodeJs
// - https://www.getbounds.com/blog/rtk-to-wgs84/
//
// Output:
// nad83: https://www.google.com/maps?q=36.2929067,-97.308243
// wgs84: https://www.google.com/maps?q=36.29291304405147,-97.30825093744994
import proj4 from 'proj4';
// The transformation in this example (known as the ITRF00 transformation) came from ArcGIS Desktop 10.7
function coordRTKtoWGS84(point) {
const nad83ITRF00 = "+proj=longLat +ellps=GRS80 +towgs84=-0.9956,1.9013,0.5215,0.025915,0.009246,0.011599,-0.00062 +units=degrees +no_defs";
const nad83NoTransform = "+proj=longLat +ellps=GRS80 +towgs84=0,0,0 +units=degrees +no_defs";
var pointInNAD83 = proj4(nad83NoTransform, point);
return proj4(nad83ITRF00, 'WGS84', pointInNAD83)
}
try {
const latitude = 36.2929067;
const longitude = -97.308243;
const nad83Point = [longitude, latitude];
// How fast is it?
// Pretty fast without console.logs
const countRepeat = 1;
for (let i = 0; i < countRepeat; i++) {
var wgs84 = coordRTKtoWGS84(nad83Point);
console.log(i);
console.log(`nad83: `, nad83Point);
console.log(`wgs84: `, wgs84);
const urlNad83 = pointToGooleMapsUrl(nad83Point);;
console.log(`urlNad83: `, urlNad83);
const urlWgs84 = pointToGooleMapsUrl(wgs84);;
console.log(`urlWgs84: `, urlWgs84);
}
} catch (error) {
console.log('Exception:', error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment