gstmerc.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var latiso = require('../common/latiso');
  2. var sinh = require('../common/sinh');
  3. var cosh = require('../common/cosh');
  4. var invlatiso = require('../common/invlatiso');
  5. exports.init = function() {
  6. // array of: a, b, lon0, lat0, k0, x0, y0
  7. var temp = this.b / this.a;
  8. this.e = Math.sqrt(1 - temp * temp);
  9. this.lc = this.long0;
  10. this.rs = Math.sqrt(1 + this.e * this.e * Math.pow(Math.cos(this.lat0), 4) / (1 - this.e * this.e));
  11. var sinz = Math.sin(this.lat0);
  12. var pc = Math.asin(sinz / this.rs);
  13. var sinzpc = Math.sin(pc);
  14. this.cp = latiso(0, pc, sinzpc) - this.rs * latiso(this.e, this.lat0, sinz);
  15. this.n2 = this.k0 * this.a * Math.sqrt(1 - this.e * this.e) / (1 - this.e * this.e * sinz * sinz);
  16. this.xs = this.x0;
  17. this.ys = this.y0 - this.n2 * pc;
  18. if (!this.title) {
  19. this.title = "Gauss Schreiber transverse mercator";
  20. }
  21. };
  22. // forward equations--mapping lat,long to x,y
  23. // -----------------------------------------------------------------
  24. exports.forward = function(p) {
  25. var lon = p.x;
  26. var lat = p.y;
  27. var L = this.rs * (lon - this.lc);
  28. var Ls = this.cp + (this.rs * latiso(this.e, lat, Math.sin(lat)));
  29. var lat1 = Math.asin(Math.sin(L) / cosh(Ls));
  30. var Ls1 = latiso(0, lat1, Math.sin(lat1));
  31. p.x = this.xs + (this.n2 * Ls1);
  32. p.y = this.ys + (this.n2 * Math.atan(sinh(Ls) / Math.cos(L)));
  33. return p;
  34. };
  35. // inverse equations--mapping x,y to lat/long
  36. // -----------------------------------------------------------------
  37. exports.inverse = function(p) {
  38. var x = p.x;
  39. var y = p.y;
  40. var L = Math.atan(sinh((x - this.xs) / this.n2) / Math.cos((y - this.ys) / this.n2));
  41. var lat1 = Math.asin(Math.sin((y - this.ys) / this.n2) / cosh((x - this.xs) / this.n2));
  42. var LC = latiso(0, lat1, Math.sin(lat1));
  43. p.x = this.lc + L / this.rs;
  44. p.y = invlatiso(this.e, (LC - this.cp) / this.rs);
  45. return p;
  46. };
  47. exports.names = ["gstmerg"];