Closed noelmas closed 10 years ago
Above problem was appearing in Google Chrome, also tried in Firefox, kept telling me the script was unresponsive.
@noelmas it will be slow to load on that much data but looks like it has worked - when i look at http://explorer.okfnlabs.org/#noelmas/5f2bf36b37418bcf5ff8/view/grid there is 104210 records and they all seem to be convered. Note you can download the complete csv using the link at the top right called "Data"
Great, looks like it did complete. I assume the script continues to run even if you close your browser? That would be useful info to have for people working with larger datasets.
@noelmas in theory it should not continue to run if you close that window - but it does run in the background.
INVALID.
Web page freezes on execution of script for converting OSGR coordinates to lat/long. Worked on one occasion, now freezes. Also appeared to create duplicate projects on one attempt. Dataset possibly too large.
Data: http://explorer.okfnlabs.org/#noelmas/5f2bf36b37418bcf5ff8/view/grid
Script: // ============================================================ // Library stuff // // For real "meat" see loadDataset function below
// From http://www.movable-type.co.uk/scripts/latlong-convert-coords.html var CoordTransform = {}; // CoordTransform namespace, representing static class
function toRad(num) { // convert degrees to radians return num * Math.PI / 180; }
// ellipse parameters CoordTransform.ellipse = { WGS84: { a: 6378137, b: 6356752.3142, f: 1/298.257223563 }, GRS80: { a: 6378137, b: 6356752.314140, f: 1/298.257222101 }, Airy1830: { a: 6377563.396, b: 6356256.910, f: 1/299.3249646 }, AiryModified: { a: 6377340.189, b: 6356034.448, f: 1/299.32496 }, Intl1924: { a: 6378388.000, b: 6356911.946, f: 1/297.0 } };
// helmert transform parameters from WGS84 to other datums CoordTransform.datumTransform = { toOSGB36: { tx: -446.448, ty: 125.157, tz: -542.060, // m rx: -0.1502, ry: -0.2470, rz: -0.8421, // sec s: 20.4894 }, // ppm toED50: { tx: 89.5, ty: 93.8, tz: 123.1, // m rx: 0.0, ry: 0.0, rz: 0.156, // sec s: -1.2 }, // ppm toIrl1975: { tx: -482.530, ty: 130.596, tz: -564.557, // m rx: -1.042, ry: -0.214, rz: -0.631, // sec s: -8.150 } }; // ppm // ED50: og.decc.gov.uk/en/olgs/cms/pons_and_cop/pons/pon4/pon4.aspx // strictly, Ireland 1975 is from ETRF89: qv // www.osi.ie/OSI/media/OSI/Content/Publications/transformations_booklet.pdf // www.ordnancesurvey.co.uk/oswebsite/gps/information/coordinatesystemsinfo/guidecontents/guide6.html#6.5
/**
/**
@return {Coord} lat/lon in target reference frame */ CoordTransform.convertEllipsoid = function(point, e1, t, e2) {
// -- 1: convert polar to cartesian coordinates (using ellipse 1)
var lat = toRad(point.lat); var lon = toRad(point.lon);
var a = e1.a, b = e1.b;
var sinPhi = Math.sin(lat); var cosPhi = Math.cos(lat); var sinLambda = Math.sin(lon); var cosLambda = Math.cos(lon); var H = 24.7; // for the moment
var eSq = (a_a - b_b) / (a_a); var nu = a / Math.sqrt(1 - eSq_sinPhi*sinPhi);
var x1 = (nu+H) * cosPhi * cosLambda; var y1 = (nu+H) * cosPhi * sinLambda; var z1 = ((1-eSq)nu + H) \ sinPhi;
// -- 2: apply helmert transform using appropriate params
var tx = t.tx, ty = t.ty, tz = t.tz; var rx = toRad(t.rx/3600); // normalise seconds to radians var ry = toRad(t.ry/3600); var rz = toRad(t.rz/3600); var s1 = t.s/1e6 + 1; // normalise ppm to (s+1)
// apply transform var x2 = tx + x1_s1 - y1_rz + z1_ry; var y2 = ty + x1_rz + y1_s1 - z1_rx; var z2 = tz - x1_ry + y1_rx + z1*s1;
// -- 3: convert cartesian to polar coordinates (using ellipse 2)
a = e2.a, b = e2.b; var precision = 4 / a; // results accurate to around 4 metres
eSq = (a_a - b_b) / (a_a); var p = Math.sqrt(x2_x2 + y2y2); var phi = Math.atan2(z2, p(1-eSq)), phiP = 2_Math.PI; while (Math.abs(phi-phiP) > precision) { nu = a / Math.sqrt(1 - eSq_Math.sin(phi)_Math.sin(phi)); phiP = phi; phi = Math.atan2(z2 + eSq_nu*Math.sin(phi), p); } var lambda = Math.atan2(y2, x2); H = p/Math.cos(phi) - nu;
return {lat: toDeg(phi), lon: toDeg(lambda)}; }
// taken from http://www.movable-type.co.uk/scripts/latlong-gridref.html /**
@return {LatLon} latitude/longitude (in OSGB36) of supplied grid reference */ function osGridToOSGB36(easting, northing) { var E = easting; var N = northing;
var a = 6377563.396, b = 6356256.910; // Airy 1830 major & minor semi-axes var F0 = 0.9996012717; // NatGrid scale factor on central meridian var lat0 = 49_Math.PI/180, lon0 = -2_Math.PI/180; // NatGrid true origin var N0 = -100000, E0 = 400000; // northing & easting of true origin, metres var e2 = 1 - (b_b)/(a_a); // eccentricity squared var n = (a-b)/(a+b), n2 = n_n, n3 = n_n*n;
var lat=lat0, M=0; do { lat = (N-N0-M)/(a*F0) + lat;
var Ma = (1 + n + (5/4)_n2 + (5/4)_n3) * (lat-lat0); var Mb = (3_n + 3_n_n + (21/8)_n3) * Math.sin(lat-lat0) * Math.cos(lat+lat0); var Mc = ((15/8)_n2 + (15/8)n3) * Math.sin(2(lat-lat0)) * Math.cos(2_(lat+lat0)); var Md = (35/24)n3 * Math.sin(3(lat-lat0)) * Math.cos(3(lat+lat0)); M = b * F0 \ (Ma - Mb + Mc - Md); // meridional arc
} while (N-N0-M >= 0.00001); // ie until < 0.01mm
var cosLat = Math.cos(lat), sinLat = Math.sin(lat); var nu = a_F0/Math.sqrt(1-e2_sinLat_sinLat); // transverse radius of curvature var rho = aF0(1-e2)/Math.pow(1-e2_sinLat*sinLat, 1.5); // meridional radius of curvature var eta2 = nu/rho-1;
var tanLat = Math.tan(lat); var tan2lat = tanLat_tanLat, tan4lat = tan2lat_tan2lat, tan6lat = tan4lat_tan2lat; var secLat = 1/cosLat; var nu3 = nu_nu_nu, nu5 = nu3_nu_nu, nu7 = nu5_nu_nu; var VII = tanLat/(2_rho_nu); var VIII = tanLat/(24_rhonu3)(5+3_tan2lat+eta2-9_tan2lat_eta2); var IX = tanLat/(720_rhonu5)(61+90_tan2lat+45_tan4lat); var X = secLat/nu; var XI = secLat/(6nu3)(nu/rho+2_tan2lat); var XII = secLat/(120nu5)(5+28_tan2lat+24_tan4lat); var XIIA = secLat/(5040nu7)(61+662_tan2lat+1320_tan4lat+720_tan6lat);
var dE = (E-E0), dE2 = dE_dE, dE3 = dE2_dE, dE4 = dE2_dE2, dE5 = dE3_dE2, dE6 = dE4_dE2, dE7 = dE5_dE2; lat = lat - VII_dE2 + VIII_dE4 - IX_dE6; var lon = lon0 + X_dE - XI_dE3 + XII_dE5 - XIIA*dE7;
lat = lat * 180 / Math.PI; lon = lon * 180 / Math.PI;
return {lat: lat, lon: lon}; }
function toDeg(num) { return num * 180 / Math.PI; }
// ============================================= // Our main function where we use the library to transform the data
loadDataset("original", function (error, dataset) { // error will be null unless there is an error // dataset is a Recline memory store (http://reclinejs.com//docs/src/backend.memory.html). // console.log(dataset); dataset.fields.splice(3, 0, {id: 'Latitude'}); dataset.fields.splice(3, 0, {id: 'Longitude'}); dataset.records = dataset.records.map(function(rec) { var out = transform(rec.Location_Easting_OSGR, rec.Location_Northing_OSGR); rec.Latitude = out.lat; rec.Longitude = out.lon; return rec; }); saveDataset(dataset); });
function transform(easting, northing) { var out = osGridToOSGB36(easting, northing); out = CoordTransform.convertOSGB36toWGS84(out); // console.log(out); return out; }