eqdc.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. var e0fn = require('../common/e0fn');
  2. var e1fn = require('../common/e1fn');
  3. var e2fn = require('../common/e2fn');
  4. var e3fn = require('../common/e3fn');
  5. var msfnz = require('../common/msfnz');
  6. var mlfn = require('../common/mlfn');
  7. var adjust_lon = require('../common/adjust_lon');
  8. var adjust_lat = require('../common/adjust_lat');
  9. var imlfn = require('../common/imlfn');
  10. var EPSLN = 1.0e-10;
  11. exports.init = function() {
  12. /* Place parameters in static storage for common use
  13. -------------------------------------------------*/
  14. // Standard Parallels cannot be equal and on opposite sides of the equator
  15. if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
  16. return;
  17. }
  18. this.lat2 = this.lat2 || this.lat1;
  19. this.temp = this.b / this.a;
  20. this.es = 1 - Math.pow(this.temp, 2);
  21. this.e = Math.sqrt(this.es);
  22. this.e0 = e0fn(this.es);
  23. this.e1 = e1fn(this.es);
  24. this.e2 = e2fn(this.es);
  25. this.e3 = e3fn(this.es);
  26. this.sinphi = Math.sin(this.lat1);
  27. this.cosphi = Math.cos(this.lat1);
  28. this.ms1 = msfnz(this.e, this.sinphi, this.cosphi);
  29. this.ml1 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat1);
  30. if (Math.abs(this.lat1 - this.lat2) < EPSLN) {
  31. this.ns = this.sinphi;
  32. }
  33. else {
  34. this.sinphi = Math.sin(this.lat2);
  35. this.cosphi = Math.cos(this.lat2);
  36. this.ms2 = msfnz(this.e, this.sinphi, this.cosphi);
  37. this.ml2 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat2);
  38. this.ns = (this.ms1 - this.ms2) / (this.ml2 - this.ml1);
  39. }
  40. this.g = this.ml1 + this.ms1 / this.ns;
  41. this.ml0 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
  42. this.rh = this.a * (this.g - this.ml0);
  43. };
  44. /* Equidistant Conic forward equations--mapping lat,long to x,y
  45. -----------------------------------------------------------*/
  46. exports.forward = function(p) {
  47. var lon = p.x;
  48. var lat = p.y;
  49. var rh1;
  50. /* Forward equations
  51. -----------------*/
  52. if (this.sphere) {
  53. rh1 = this.a * (this.g - lat);
  54. }
  55. else {
  56. var ml = mlfn(this.e0, this.e1, this.e2, this.e3, lat);
  57. rh1 = this.a * (this.g - ml);
  58. }
  59. var theta = this.ns * adjust_lon(lon - this.long0);
  60. var x = this.x0 + rh1 * Math.sin(theta);
  61. var y = this.y0 + this.rh - rh1 * Math.cos(theta);
  62. p.x = x;
  63. p.y = y;
  64. return p;
  65. };
  66. /* Inverse equations
  67. -----------------*/
  68. exports.inverse = function(p) {
  69. p.x -= this.x0;
  70. p.y = this.rh - p.y + this.y0;
  71. var con, rh1, lat, lon;
  72. if (this.ns >= 0) {
  73. rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
  74. con = 1;
  75. }
  76. else {
  77. rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
  78. con = -1;
  79. }
  80. var theta = 0;
  81. if (rh1 !== 0) {
  82. theta = Math.atan2(con * p.x, con * p.y);
  83. }
  84. if (this.sphere) {
  85. lon = adjust_lon(this.long0 + theta / this.ns);
  86. lat = adjust_lat(this.g - rh1 / this.a);
  87. p.x = lon;
  88. p.y = lat;
  89. return p;
  90. }
  91. else {
  92. var ml = this.g - rh1 / this.a;
  93. lat = imlfn(ml, this.e0, this.e1, this.e2, this.e3);
  94. lon = adjust_lon(this.long0 + theta / this.ns);
  95. p.x = lon;
  96. p.y = lat;
  97. return p;
  98. }
  99. };
  100. exports.names = ["Equidistant_Conic", "eqdc"];