gstmerc.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import latiso from '../common/latiso';
  2. import sinh from '../common/sinh';
  3. import cosh from '../common/cosh';
  4. import invlatiso from '../common/invlatiso';
  5. export function init() {
  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. export function forward(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. export function inverse(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. export var names = ["gstmerg", "gstmerc"];
  48. export default {
  49. init: init,
  50. forward: forward,
  51. inverse: inverse,
  52. names: names
  53. };