cea.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import adjust_lon from '../common/adjust_lon';
  2. import qsfnz from '../common/qsfnz';
  3. import msfnz from '../common/msfnz';
  4. import iqsfnz from '../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. export function init() {
  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. export function forward(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. export function inverse(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. export var names = ["cea"];
  58. export default {
  59. init: init,
  60. forward: forward,
  61. inverse: inverse,
  62. names: names
  63. };