cea.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var adjust_lon = require('../common/adjust_lon');
  2. var qsfnz = require('../common/qsfnz');
  3. var msfnz = require('../common/msfnz');
  4. var iqsfnz = require('../common/iqsfnz');
  5. /*
  6. reference:
  7. "Cartographic Projection Procedures for the UNIX Environment-
  8. A User's Manual" by Gerald I. Evenden,
  9. USGS Open File Report 90-284and Release 4 Interim Reports (2003)
  10. */
  11. exports.init = function() {
  12. //no-op
  13. if (!this.sphere) {
  14. this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
  15. }
  16. };
  17. /* Cylindrical Equal Area forward equations--mapping lat,long to x,y
  18. ------------------------------------------------------------*/
  19. exports.forward = function(p) {
  20. var lon = p.x;
  21. var lat = p.y;
  22. var x, y;
  23. /* Forward equations
  24. -----------------*/
  25. var dlon = adjust_lon(lon - this.long0);
  26. if (this.sphere) {
  27. x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
  28. y = this.y0 + this.a * Math.sin(lat) / Math.cos(this.lat_ts);
  29. }
  30. else {
  31. var qs = qsfnz(this.e, Math.sin(lat));
  32. x = this.x0 + this.a * this.k0 * dlon;
  33. y = this.y0 + this.a * qs * 0.5 / this.k0;
  34. }
  35. p.x = x;
  36. p.y = y;
  37. return p;
  38. };
  39. /* Cylindrical Equal Area inverse equations--mapping x,y to lat/long
  40. ------------------------------------------------------------*/
  41. exports.inverse = function(p) {
  42. p.x -= this.x0;
  43. p.y -= this.y0;
  44. var lon, lat;
  45. if (this.sphere) {
  46. lon = adjust_lon(this.long0 + (p.x / this.a) / Math.cos(this.lat_ts));
  47. lat = Math.asin((p.y / this.a) * Math.cos(this.lat_ts));
  48. }
  49. else {
  50. lat = iqsfnz(this.e, 2 * p.y * this.k0 / this.a);
  51. lon = adjust_lon(this.long0 + p.x / (this.a * this.k0));
  52. }
  53. p.x = lon;
  54. p.y = lat;
  55. return p;
  56. };
  57. exports.names = ["cea"];