PageRenderTime 76ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/webportal/src/main/webapp/scripts/proj4js-combined.js

http://alageospatialportal.googlecode.com/
JavaScript | 4987 lines | 2984 code | 537 blank | 1466 comment | 547 complexity | 4f9fc4de15ecf4ff75223155d283a4c8 MD5 | raw file
  1. /*
  2. proj4js.js -- Javascript reprojection library.
  3. Authors: Mike Adair madairATdmsolutions.ca
  4. Richard Greenwood richATgreenwoodmap.com
  5. Didier Richard didier.richardATign.fr
  6. Stephen Irons
  7. License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
  8. Note: This program is an almost direct port of the C library
  9. Proj4.
  10. */
  11. /* ======================================================================
  12. proj4js.js
  13. ====================================================================== */
  14. /*
  15. Author: Mike Adair madairATdmsolutions.ca
  16. Richard Greenwood rich@greenwoodmap.com
  17. License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
  18. $Id: Proj.js 2956 2007-07-09 12:17:52Z steven $
  19. */
  20. /**
  21. * Namespace: Proj4js
  22. *
  23. * Proj4js is a JavaScript library to transform point coordinates from one
  24. * coordinate system to another, including datum transformations.
  25. *
  26. * This library is a port of both the Proj.4 and GCTCP C libraries to JavaScript.
  27. * Enabling these transformations in the browser allows geographic data stored
  28. * in different projections to be combined in browser-based web mapping
  29. * applications.
  30. *
  31. * Proj4js must have access to coordinate system initialization strings (which
  32. * are the same as for PROJ.4 command line). Thes can be included in your
  33. * application using a <script> tag or Proj4js can load CS initialization
  34. * strings from a local directory or a web service such as spatialreference.org.
  35. *
  36. * Similarly, Proj4js must have access to projection transform code. These can
  37. * be included individually using a <script> tag in your page, built into a
  38. * custom build of Proj4js or loaded dynamically at run-time. Using the
  39. * -combined and -compressed versions of Proj4js includes all projection class
  40. * code by default.
  41. *
  42. * Note that dynamic loading of defs and code happens ascynchrously, check the
  43. * Proj.readyToUse flag before using the Proj object. If the defs and code
  44. * required by your application are loaded through script tags, dynamic loading
  45. * is not required and the Proj object will be readyToUse on return from the
  46. * constructor.
  47. *
  48. * All coordinates are handled as points which have a .x and a .y property
  49. * which will be modified in place.
  50. *
  51. * Override Proj4js.reportError for output of alerts and warnings.
  52. *
  53. * See http://trac.osgeo.org/proj4js/wiki/UserGuide for full details.
  54. */
  55. /**
  56. * Global namespace object for Proj4js library
  57. */
  58. Proj4js = {
  59. /**
  60. * Property: defaultDatum
  61. * The datum to use when no others a specified
  62. */
  63. defaultDatum: 'WGS84', //default datum
  64. /**
  65. * Method: transform(source, dest, point)
  66. * Transform a point coordinate from one map projection to another. This is
  67. * really the only public method you should need to use.
  68. *
  69. * Parameters:
  70. * source - {Proj4js.Proj} source map projection for the transformation
  71. * dest - {Proj4js.Proj} destination map projection for the transformation
  72. * point - {Object} point to transform, may be geodetic (long, lat) or
  73. * projected Cartesian (x,y), but should always have x,y properties.
  74. */
  75. transform: function(source, dest, point) {
  76. if (!source.readyToUse || !dest.readyToUse) {
  77. this.reportError("Proj4js initialization for "+source.srsCode+" not yet complete");
  78. return point;
  79. }
  80. // Workaround for Spherical Mercator
  81. if ((source.srsProjNumber =="900913" && dest.datumCode != "WGS84") ||
  82. (dest.srsProjNumber == "900913" && source.datumCode != "WGS84")) {
  83. var wgs84 = Proj4js.WGS84;
  84. this.transform(source, wgs84, point);
  85. source = wgs84;
  86. }
  87. // Transform source points to long/lat, if they aren't already.
  88. if ( source.projName=="longlat") {
  89. point.x *= Proj4js.common.D2R; // convert degrees to radians
  90. point.y *= Proj4js.common.D2R;
  91. } else {
  92. if (source.to_meter) {
  93. point.x *= source.to_meter;
  94. point.y *= source.to_meter;
  95. }
  96. source.inverse(point); // Convert Cartesian to longlat
  97. }
  98. // Adjust for the prime meridian if necessary
  99. if (source.from_greenwich) {
  100. point.x += source.from_greenwich;
  101. }
  102. // Convert datums if needed, and if possible.
  103. point = this.datum_transform( source.datum, dest.datum, point );
  104. // Adjust for the prime meridian if necessary
  105. if (dest.from_greenwich) {
  106. point.x -= dest.from_greenwich;
  107. }
  108. if( dest.projName=="longlat" ) {
  109. // convert radians to decimal degrees
  110. point.x *= Proj4js.common.R2D;
  111. point.y *= Proj4js.common.R2D;
  112. } else { // else project
  113. dest.forward(point);
  114. if (dest.to_meter) {
  115. point.x /= dest.to_meter;
  116. point.y /= dest.to_meter;
  117. }
  118. }
  119. return point;
  120. }, // transform()
  121. /** datum_transform()
  122. source coordinate system definition,
  123. destination coordinate system definition,
  124. point to transform in geodetic coordinates (long, lat, height)
  125. */
  126. datum_transform : function( source, dest, point ) {
  127. // Short cut if the datums are identical.
  128. if( source.compare_datums( dest ) ) {
  129. return point; // in this case, zero is sucess,
  130. // whereas cs_compare_datums returns 1 to indicate TRUE
  131. // confusing, should fix this
  132. }
  133. // Explicitly skip datum transform by setting 'datum=none' as parameter for either source or dest
  134. if( source.datum_type == Proj4js.common.PJD_NODATUM
  135. || dest.datum_type == Proj4js.common.PJD_NODATUM) {
  136. return point;
  137. }
  138. // If this datum requires grid shifts, then apply it to geodetic coordinates.
  139. if( source.datum_type == Proj4js.common.PJD_GRIDSHIFT )
  140. {
  141. alert("ERROR: Grid shift transformations are not implemented yet.");
  142. /*
  143. pj_apply_gridshift( pj_param(source.params,"snadgrids").s, 0,
  144. point_count, point_offset, x, y, z );
  145. CHECK_RETURN;
  146. src_a = SRS_WGS84_SEMIMAJOR;
  147. src_es = 0.006694379990;
  148. */
  149. }
  150. if( dest.datum_type == Proj4js.common.PJD_GRIDSHIFT )
  151. {
  152. alert("ERROR: Grid shift transformations are not implemented yet.");
  153. /*
  154. dst_a = ;
  155. dst_es = 0.006694379990;
  156. */
  157. }
  158. // Do we need to go through geocentric coordinates?
  159. if( source.es != dest.es || source.a != dest.a
  160. || source.datum_type == Proj4js.common.PJD_3PARAM
  161. || source.datum_type == Proj4js.common.PJD_7PARAM
  162. || dest.datum_type == Proj4js.common.PJD_3PARAM
  163. || dest.datum_type == Proj4js.common.PJD_7PARAM)
  164. {
  165. // Convert to geocentric coordinates.
  166. source.geodetic_to_geocentric( point );
  167. // CHECK_RETURN;
  168. // Convert between datums
  169. if( source.datum_type == Proj4js.common.PJD_3PARAM || source.datum_type == Proj4js.common.PJD_7PARAM ) {
  170. source.geocentric_to_wgs84(point);
  171. // CHECK_RETURN;
  172. }
  173. if( dest.datum_type == Proj4js.common.PJD_3PARAM || dest.datum_type == Proj4js.common.PJD_7PARAM ) {
  174. dest.geocentric_from_wgs84(point);
  175. // CHECK_RETURN;
  176. }
  177. // Convert back to geodetic coordinates
  178. dest.geocentric_to_geodetic( point );
  179. // CHECK_RETURN;
  180. }
  181. // Apply grid shift to destination if required
  182. if( dest.datum_type == Proj4js.common.PJD_GRIDSHIFT )
  183. {
  184. alert("ERROR: Grid shift transformations are not implemented yet.");
  185. // pj_apply_gridshift( pj_param(dest.params,"snadgrids").s, 1, point);
  186. // CHECK_RETURN;
  187. }
  188. return point;
  189. }, // cs_datum_transform
  190. /**
  191. * Function: reportError
  192. * An internal method to report errors back to user.
  193. * Override this in applications to report error messages or throw exceptions.
  194. */
  195. reportError: function(msg) {
  196. //console.log(msg);
  197. },
  198. /**
  199. *
  200. * Title: Private Methods
  201. * The following properties and methods are intended for internal use only.
  202. *
  203. * This is a minimal implementation of JavaScript inheritance methods so that
  204. * Proj4js can be used as a stand-alone library.
  205. * These are copies of the equivalent OpenLayers methods at v2.7
  206. */
  207. /**
  208. * Function: extend
  209. * Copy all properties of a source object to a destination object. Modifies
  210. * the passed in destination object. Any properties on the source object
  211. * that are set to undefined will not be (re)set on the destination object.
  212. *
  213. * Parameters:
  214. * destination - {Object} The object that will be modified
  215. * source - {Object} The object with properties to be set on the destination
  216. *
  217. * Returns:
  218. * {Object} The destination object.
  219. */
  220. extend: function(destination, source) {
  221. destination = destination || {};
  222. if(source) {
  223. for(var property in source) {
  224. var value = source[property];
  225. if(value !== undefined) {
  226. destination[property] = value;
  227. }
  228. }
  229. }
  230. return destination;
  231. },
  232. /**
  233. * Constructor: Class
  234. * Base class used to construct all other classes. Includes support for
  235. * multiple inheritance.
  236. *
  237. */
  238. Class: function() {
  239. var Class = function() {
  240. this.initialize.apply(this, arguments);
  241. };
  242. var extended = {};
  243. var parent;
  244. for(var i=0; i<arguments.length; ++i) {
  245. if(typeof arguments[i] == "function") {
  246. // get the prototype of the superclass
  247. parent = arguments[i].prototype;
  248. } else {
  249. // in this case we're extending with the prototype
  250. parent = arguments[i];
  251. }
  252. Proj4js.extend(extended, parent);
  253. }
  254. Class.prototype = extended;
  255. return Class;
  256. },
  257. /**
  258. * Function: bind
  259. * Bind a function to an object. Method to easily create closures with
  260. * 'this' altered.
  261. *
  262. * Parameters:
  263. * func - {Function} Input function.
  264. * object - {Object} The object to bind to the input function (as this).
  265. *
  266. * Returns:
  267. * {Function} A closure with 'this' set to the passed in object.
  268. */
  269. bind: function(func, object) {
  270. // create a reference to all arguments past the second one
  271. var args = Array.prototype.slice.apply(arguments, [2]);
  272. return function() {
  273. // Push on any additional arguments from the actual function call.
  274. // These will come after those sent to the bind call.
  275. var newArgs = args.concat(
  276. Array.prototype.slice.apply(arguments, [0])
  277. );
  278. return func.apply(object, newArgs);
  279. };
  280. },
  281. /**
  282. * The following properties and methods handle dynamic loading of JSON objects.
  283. *
  284. /**
  285. * Property: scriptName
  286. * {String} The filename of this script without any path.
  287. */
  288. scriptName: "proj4js-combined.js",
  289. /**
  290. * Property: defsLookupService
  291. * AJAX service to retreive projection definition parameters from
  292. */
  293. defsLookupService: 'http://spatialreference.org/ref',
  294. /**
  295. * Property: libPath
  296. * internal: http server path to library code.
  297. */
  298. libPath: null,
  299. /**
  300. * Function: getScriptLocation
  301. * Return the path to this script.
  302. *
  303. * Returns:
  304. * Path to this script
  305. */
  306. getScriptLocation: function () {
  307. if (this.libPath) return this.libPath;
  308. var scriptName = this.scriptName;
  309. var scriptNameLen = scriptName.length;
  310. var scripts = document.getElementsByTagName('script');
  311. for (var i = 0; i < scripts.length; i++) {
  312. var src = scripts[i].getAttribute('src');
  313. if (src) {
  314. var index = src.lastIndexOf(scriptName);
  315. // is it found, at the end of the URL?
  316. if ((index > -1) && (index + scriptNameLen == src.length)) {
  317. this.libPath = src.slice(0, -scriptNameLen);
  318. break;
  319. }
  320. }
  321. }
  322. return this.libPath||"";
  323. },
  324. /**
  325. * Function: loadScript
  326. * Load a JS file from a URL into a <script> tag in the page.
  327. *
  328. * Parameters:
  329. * url - {String} The URL containing the script to load
  330. * onload - {Function} A method to be executed when the script loads successfully
  331. * onfail - {Function} A method to be executed when there is an error loading the script
  332. * loadCheck - {Function} A boolean method that checks to see if the script
  333. * has loaded. Typically this just checks for the existance of
  334. * an object in the file just loaded.
  335. */
  336. loadScript: function(url, onload, onfail, loadCheck) {
  337. var script = document.createElement('script');
  338. script.defer = false;
  339. script.type = "text/javascript";
  340. script.id = url;
  341. script.src = url;
  342. script.onload = onload;
  343. script.onerror = onfail;
  344. script.loadCheck = loadCheck;
  345. if (/MSIE/.test(navigator.userAgent)) {
  346. script.onreadystatechange = this.checkReadyState;
  347. }
  348. document.getElementsByTagName('head')[0].appendChild(script);
  349. },
  350. /**
  351. * Function: checkReadyState
  352. * IE workaround since there is no onerror handler. Calls the user defined
  353. * loadCheck method to determine if the script is loaded.
  354. *
  355. */
  356. checkReadyState: function() {
  357. if (this.readyState == 'loaded') {
  358. if (!this.loadCheck()) {
  359. this.onerror();
  360. } else {
  361. this.onload();
  362. }
  363. }
  364. }
  365. };
  366. /**
  367. * Class: Proj4js.Proj
  368. *
  369. * Proj objects provide transformation methods for point coordinates
  370. * between geodetic latitude/longitude and a projected coordinate system.
  371. * once they have been initialized with a projection code.
  372. *
  373. * Initialization of Proj objects is with a projection code, usually EPSG codes,
  374. * which is the key that will be used with the Proj4js.defs array.
  375. *
  376. * The code passed in will be stripped of colons and converted to uppercase
  377. * to locate projection definition files.
  378. *
  379. * A projection object has properties for units and title strings.
  380. */
  381. Proj4js.Proj = Proj4js.Class({
  382. /**
  383. * Property: readyToUse
  384. * Flag to indicate if initialization is complete for this Proj object
  385. */
  386. readyToUse: false,
  387. /**
  388. * Property: title
  389. * The title to describe the projection
  390. */
  391. title: null,
  392. /**
  393. * Property: projName
  394. * The projection class for this projection, e.g. lcc (lambert conformal conic,
  395. * or merc for mercator). These are exactly equivalent to their Proj4
  396. * counterparts.
  397. */
  398. projName: null,
  399. /**
  400. * Property: units
  401. * The units of the projection. Values include 'm' and 'degrees'
  402. */
  403. units: null,
  404. /**
  405. * Property: datum
  406. * The datum specified for the projection
  407. */
  408. datum: null,
  409. /**
  410. * Property: x0
  411. * The x coordinate origin
  412. */
  413. x0: 0,
  414. /**
  415. * Property: y0
  416. * The y coordinate origin
  417. */
  418. y0: 0,
  419. /**
  420. * Constructor: initialize
  421. * Constructor for Proj4js.Proj objects
  422. *
  423. * Parameters:
  424. * srsCode - a code for map projection definition parameters. These are usually
  425. * (but not always) EPSG codes.
  426. */
  427. initialize: function(srsCode) {
  428. this.srsCodeInput = srsCode;
  429. // DGR 2008-08-03 : support urn and url
  430. if (srsCode.indexOf('urn:') == 0) {
  431. //urn:ORIGINATOR:def:crs:CODESPACE:VERSION:ID
  432. var urn = srsCode.split(':');
  433. if ((urn[1] == 'ogc' || urn[1] =='x-ogc') &&
  434. (urn[2] =='def') &&
  435. (urn[3] =='crs')) {
  436. srsCode = urn[4]+':'+urn[urn.length-1];
  437. }
  438. } else if (srsCode.indexOf('http://') == 0) {
  439. //url#ID
  440. var url = srsCode.split('#');
  441. if (url[0].match(/epsg.org/)) {
  442. // http://www.epsg.org/#
  443. srsCode = 'EPSG:'+url[1];
  444. } else if (url[0].match(/RIG.xml/)) {
  445. //http://librairies.ign.fr/geoportail/resources/RIG.xml#
  446. //http://interop.ign.fr/registers/ign/RIG.xml#
  447. srsCode = 'IGNF:'+url[1];
  448. }
  449. }
  450. this.srsCode = srsCode.toUpperCase();
  451. if (this.srsCode.indexOf("EPSG") == 0) {
  452. this.srsCode = this.srsCode;
  453. this.srsAuth = 'epsg';
  454. this.srsProjNumber = this.srsCode.substring(5);
  455. // DGR 2007-11-20 : authority IGNF
  456. } else if (this.srsCode.indexOf("IGNF") == 0) {
  457. this.srsCode = this.srsCode;
  458. this.srsAuth = 'IGNF';
  459. this.srsProjNumber = this.srsCode.substring(5);
  460. // DGR 2008-06-19 : pseudo-authority CRS for WMS
  461. } else if (this.srsCode.indexOf("CRS") == 0) {
  462. this.srsCode = this.srsCode;
  463. this.srsAuth = 'CRS';
  464. this.srsProjNumber = this.srsCode.substring(4);
  465. } else {
  466. this.srsAuth = '';
  467. this.srsProjNumber = this.srsCode;
  468. }
  469. this.loadProjDefinition();
  470. },
  471. /**
  472. * Function: loadProjDefinition
  473. * Loads the coordinate system initialization string if required.
  474. * Note that dynamic loading happens asynchronously so an application must
  475. * wait for the readyToUse property is set to true.
  476. * To prevent dynamic loading, include the defs through a script tag in
  477. * your application.
  478. *
  479. */
  480. loadProjDefinition: function() {
  481. //check in memory
  482. if (Proj4js.defs[this.srsCode]) {
  483. this.defsLoaded();
  484. return;
  485. }
  486. //else check for def on the server
  487. var url = Proj4js.getScriptLocation() + 'defs/' + this.srsAuth.toUpperCase() + this.srsProjNumber + '.js';
  488. Proj4js.loadScript(url,
  489. Proj4js.bind(this.defsLoaded, this),
  490. Proj4js.bind(this.loadFromService, this),
  491. Proj4js.bind(this.checkDefsLoaded, this) );
  492. },
  493. /**
  494. * Function: loadFromService
  495. * Creates the REST URL for loading the definition from a web service and
  496. * loads it.
  497. *
  498. */
  499. loadFromService: function() {
  500. //else load from web service
  501. var url = Proj4js.defsLookupService +'/' + this.srsAuth +'/'+ this.srsProjNumber + '/proj4js/';
  502. Proj4js.loadScript(url,
  503. Proj4js.bind(this.defsLoaded, this),
  504. Proj4js.bind(this.defsFailed, this),
  505. Proj4js.bind(this.checkDefsLoaded, this) );
  506. },
  507. /**
  508. * Function: defsLoaded
  509. * Continues the Proj object initilization once the def file is loaded
  510. *
  511. */
  512. defsLoaded: function() {
  513. this.parseDefs();
  514. this.loadProjCode(this.projName);
  515. },
  516. /**
  517. * Function: checkDefsLoaded
  518. * This is the loadCheck method to see if the def object exists
  519. *
  520. */
  521. checkDefsLoaded: function() {
  522. if (Proj4js.defs[this.srsCode]) {
  523. return true;
  524. } else {
  525. return false;
  526. }
  527. },
  528. /**
  529. * Function: defsFailed
  530. * Report an error in loading the defs file, but continue on using WGS84
  531. *
  532. */
  533. defsFailed: function() {
  534. Proj4js.reportError('failed to load projection definition for: '+this.srsCode);
  535. Proj4js.defs[this.srsCode] = Proj4js.defs['WGS84']; //set it to something so it can at least continue
  536. this.defsLoaded();
  537. },
  538. /**
  539. * Function: loadProjCode
  540. * Loads projection class code dynamically if required.
  541. * Projection code may be included either through a script tag or in
  542. * a built version of proj4js
  543. *
  544. */
  545. loadProjCode: function(projName) {
  546. if (Proj4js.Proj[projName]) {
  547. this.initTransforms();
  548. return;
  549. }
  550. //the URL for the projection code
  551. var url = Proj4js.getScriptLocation() + 'projCode/' + projName + '.js';
  552. Proj4js.loadScript(url,
  553. Proj4js.bind(this.loadProjCodeSuccess, this, projName),
  554. Proj4js.bind(this.loadProjCodeFailure, this, projName),
  555. Proj4js.bind(this.checkCodeLoaded, this, projName) );
  556. },
  557. /**
  558. * Function: loadProjCodeSuccess
  559. * Loads any proj dependencies or continue on to final initialization.
  560. *
  561. */
  562. loadProjCodeSuccess: function(projName) {
  563. if (Proj4js.Proj[projName].dependsOn){
  564. this.loadProjCode(Proj4js.Proj[projName].dependsOn);
  565. } else {
  566. this.initTransforms();
  567. }
  568. },
  569. /**
  570. * Function: defsFailed
  571. * Report an error in loading the proj file. Initialization of the Proj
  572. * object has failed and the readyToUse flag will never be set.
  573. *
  574. */
  575. loadProjCodeFailure: function(projName) {
  576. Proj4js.reportError("failed to find projection file for: " + projName);
  577. //TBD initialize with identity transforms so proj will still work?
  578. },
  579. /**
  580. * Function: checkCodeLoaded
  581. * This is the loadCheck method to see if the projection code is loaded
  582. *
  583. */
  584. checkCodeLoaded: function(projName) {
  585. if (Proj4js.Proj[projName]) {
  586. return true;
  587. } else {
  588. return false;
  589. }
  590. },
  591. /**
  592. * Function: initTransforms
  593. * Finalize the initialization of the Proj object
  594. *
  595. */
  596. initTransforms: function() {
  597. Proj4js.extend(this, Proj4js.Proj[this.projName]);
  598. this.init();
  599. this.readyToUse = true;
  600. },
  601. /**
  602. * Function: parseDefs
  603. * Parses the PROJ.4 initialization string and sets the associated properties.
  604. *
  605. */
  606. parseDefs: function() {
  607. this.defData = Proj4js.defs[this.srsCode];
  608. var paramName, paramVal;
  609. if (!this.defData) {
  610. return;
  611. }
  612. var paramArray=this.defData.split("+");
  613. for (var prop=0; prop<paramArray.length; prop++) {
  614. var property = paramArray[prop].split("=");
  615. paramName = property[0].toLowerCase();
  616. paramVal = property[1];
  617. switch (paramName.replace(/\s/gi,"")) { // trim out spaces
  618. case "": break; // throw away nameless parameter
  619. case "title": this.title = paramVal; break;
  620. case "proj": this.projName = paramVal.replace(/\s/gi,""); break;
  621. case "units": this.units = paramVal.replace(/\s/gi,""); break;
  622. case "datum": this.datumCode = paramVal.replace(/\s/gi,""); break;
  623. case "nadgrids": this.nagrids = paramVal.replace(/\s/gi,""); break;
  624. case "ellps": this.ellps = paramVal.replace(/\s/gi,""); break;
  625. case "a": this.a = parseFloat(paramVal); break; // semi-major radius
  626. case "b": this.b = parseFloat(paramVal); break; // semi-minor radius
  627. // DGR 2007-11-20
  628. case "rf": this.rf = parseFloat(paramVal); break; // inverse flattening rf= a/(a-b)
  629. case "lat_0": this.lat0 = paramVal*Proj4js.common.D2R; break; // phi0, central latitude
  630. case "lat_1": this.lat1 = paramVal*Proj4js.common.D2R; break; //standard parallel 1
  631. case "lat_2": this.lat2 = paramVal*Proj4js.common.D2R; break; //standard parallel 2
  632. case "lat_ts": this.lat_ts = paramVal*Proj4js.common.D2R; break; // used in merc and eqc
  633. case "lon_0": this.long0 = paramVal*Proj4js.common.D2R; break; // lam0, central longitude
  634. case "alpha": this.alpha = parseFloat(paramVal)*Proj4js.common.D2R; break; //for somerc projection
  635. case "lonc": this.longc = paramVal*Proj4js.common.D2R; break; //for somerc projection
  636. case "x_0": this.x0 = parseFloat(paramVal); break; // false easting
  637. case "y_0": this.y0 = parseFloat(paramVal); break; // false northing
  638. case "k_0": this.k0 = parseFloat(paramVal); break; // projection scale factor
  639. case "k": this.k0 = parseFloat(paramVal); break; // both forms returned
  640. case "r_a": this.R_A = true; break; // sphere--area of ellipsoid
  641. case "zone": this.zone = parseInt(paramVal); break; // UTM Zone
  642. case "south": this.utmSouth = true; break; // UTM north/south
  643. case "towgs84":this.datum_params = paramVal.split(","); break;
  644. case "to_meter": this.to_meter = parseFloat(paramVal); break; // cartesian scaling
  645. case "from_greenwich": this.from_greenwich = paramVal*Proj4js.common.D2R; break;
  646. // DGR 2008-07-09 : if pm is not a well-known prime meridian take
  647. // the value instead of 0.0, then convert to radians
  648. case "pm": paramVal = paramVal.replace(/\s/gi,"");
  649. this.from_greenwich = Proj4js.PrimeMeridian[paramVal] ?
  650. Proj4js.PrimeMeridian[paramVal] : parseFloat(paramVal);
  651. this.from_greenwich *= Proj4js.common.D2R;
  652. break;
  653. case "no_defs": break;
  654. default: //alert("Unrecognized parameter: " + paramName);
  655. } // switch()
  656. } // for paramArray
  657. this.deriveConstants();
  658. },
  659. /**
  660. * Function: deriveConstants
  661. * Sets several derived constant values and initialization of datum and ellipse
  662. * parameters.
  663. *
  664. */
  665. deriveConstants: function() {
  666. if (this.nagrids == '@null') this.datumCode = 'none';
  667. if (this.datumCode && this.datumCode != 'none') {
  668. var datumDef = Proj4js.Datum[this.datumCode];
  669. if (datumDef) {
  670. this.datum_params = datumDef.towgs84 ? datumDef.towgs84.split(',') : null;
  671. this.ellps = datumDef.ellipse;
  672. this.datumName = datumDef.datumName ? datumDef.datumName : this.datumCode;
  673. }
  674. }
  675. if (!this.a) { // do we have an ellipsoid?
  676. var ellipse = Proj4js.Ellipsoid[this.ellps] ? Proj4js.Ellipsoid[this.ellps] : Proj4js.Ellipsoid['WGS84'];
  677. Proj4js.extend(this, ellipse);
  678. }
  679. if (this.rf && !this.b) this.b = (1.0 - 1.0/this.rf) * this.a;
  680. if (Math.abs(this.a - this.b)<Proj4js.common.EPSLN) {
  681. this.sphere = true;
  682. this.b= this.a;
  683. }
  684. this.a2 = this.a * this.a; // used in geocentric
  685. this.b2 = this.b * this.b; // used in geocentric
  686. this.es = (this.a2-this.b2)/this.a2; // e ^ 2
  687. this.e = Math.sqrt(this.es); // eccentricity
  688. if (this.R_A) {
  689. this.a *= 1. - this.es * (Proj4js.common.SIXTH + this.es * (Proj4js.common.RA4 + this.es * Proj4js.common.RA6));
  690. this.a2 = this.a * this.a;
  691. this.b2 = this.b * this.b;
  692. this.es = 0.;
  693. }
  694. this.ep2=(this.a2-this.b2)/this.b2; // used in geocentric
  695. if (!this.k0) this.k0 = 1.0; //default value
  696. this.datum = new Proj4js.datum(this);
  697. }
  698. });
  699. Proj4js.Proj.longlat = {
  700. init: function() {
  701. //no-op for longlat
  702. },
  703. forward: function(pt) {
  704. //identity transform
  705. return pt;
  706. },
  707. inverse: function(pt) {
  708. //identity transform
  709. return pt;
  710. }
  711. };
  712. /**
  713. Proj4js.defs is a collection of coordinate system definition objects in the
  714. PROJ.4 command line format.
  715. Generally a def is added by means of a separate .js file for example:
  716. <SCRIPT type="text/javascript" src="defs/EPSG26912.js"></SCRIPT>
  717. def is a CS definition in PROJ.4 WKT format, for example:
  718. +proj="tmerc" //longlat, etc.
  719. +a=majorRadius
  720. +b=minorRadius
  721. +lat0=somenumber
  722. +long=somenumber
  723. */
  724. Proj4js.defs = {
  725. // These are so widely used, we'll go ahead and throw them in
  726. // without requiring a separate .js file
  727. 'WGS84': "+title=long/lat:WGS84 +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees",
  728. 'EPSG:4326': "+title=long/lat:WGS84 +proj=longlat +a=6378137.0 +b=6356752.31424518 +ellps=WGS84 +datum=WGS84 +units=degrees",
  729. 'EPSG:4269': "+title=long/lat:NAD83 +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees",
  730. 'EPSG:3785': "+title= Google Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"
  731. };
  732. Proj4js.defs['GOOGLE'] = Proj4js.defs['EPSG:3785'];
  733. Proj4js.defs['EPSG:900913'] = Proj4js.defs['EPSG:3785'];
  734. Proj4js.defs['EPSG:102113'] = Proj4js.defs['EPSG:3785'];
  735. Proj4js.common = {
  736. PI : 3.141592653589793238, //Math.PI,
  737. HALF_PI : 1.570796326794896619, //Math.PI*0.5,
  738. TWO_PI : 6.283185307179586477, //Math.PI*2,
  739. FORTPI : 0.78539816339744833,
  740. R2D : 57.29577951308232088,
  741. D2R : 0.01745329251994329577,
  742. SEC_TO_RAD : 4.84813681109535993589914102357e-6, /* SEC_TO_RAD = Pi/180/3600 */
  743. EPSLN : 1.0e-10,
  744. MAX_ITER : 20,
  745. // following constants from geocent.c
  746. COS_67P5 : 0.38268343236508977, /* cosine of 67.5 degrees */
  747. AD_C : 1.0026000, /* Toms region 1 constant */
  748. /* datum_type values */
  749. PJD_UNKNOWN : 0,
  750. PJD_3PARAM : 1,
  751. PJD_7PARAM : 2,
  752. PJD_GRIDSHIFT: 3,
  753. PJD_WGS84 : 4, // WGS84 or equivalent
  754. PJD_NODATUM : 5, // WGS84 or equivalent
  755. SRS_WGS84_SEMIMAJOR : 6378137.0, // only used in grid shift transforms
  756. // ellipoid pj_set_ell.c
  757. SIXTH : .1666666666666666667, /* 1/6 */
  758. RA4 : .04722222222222222222, /* 17/360 */
  759. RA6 : .02215608465608465608, /* 67/3024 */
  760. RV4 : .06944444444444444444, /* 5/72 */
  761. RV6 : .04243827160493827160, /* 55/1296 */
  762. // Function to compute the constant small m which is the radius of
  763. // a parallel of latitude, phi, divided by the semimajor axis.
  764. // -----------------------------------------------------------------
  765. msfnz : function(eccent, sinphi, cosphi) {
  766. var con = eccent * sinphi;
  767. return cosphi/(Math.sqrt(1.0 - con * con));
  768. },
  769. // Function to compute the constant small t for use in the forward
  770. // computations in the Lambert Conformal Conic and the Polar
  771. // Stereographic projections.
  772. // -----------------------------------------------------------------
  773. tsfnz : function(eccent, phi, sinphi) {
  774. var con = eccent * sinphi;
  775. var com = .5 * eccent;
  776. con = Math.pow(((1.0 - con) / (1.0 + con)), com);
  777. return (Math.tan(.5 * (this.HALF_PI - phi))/con);
  778. },
  779. // Function to compute the latitude angle, phi2, for the inverse of the
  780. // Lambert Conformal Conic and Polar Stereographic projections.
  781. // ----------------------------------------------------------------
  782. phi2z : function(eccent, ts) {
  783. var eccnth = .5 * eccent;
  784. var con, dphi;
  785. var phi = this.HALF_PI - 2 * Math.atan(ts);
  786. for (i = 0; i <= 15; i++) {
  787. con = eccent * Math.sin(phi);
  788. dphi = this.HALF_PI - 2 * Math.atan(ts *(Math.pow(((1.0 - con)/(1.0 + con)),eccnth))) - phi;
  789. phi += dphi;
  790. if (Math.abs(dphi) <= .0000000001) return phi;
  791. }
  792. alert("phi2z has NoConvergence");
  793. return (-9999);
  794. },
  795. /* Function to compute constant small q which is the radius of a
  796. parallel of latitude, phi, divided by the semimajor axis.
  797. ------------------------------------------------------------*/
  798. qsfnz : function(eccent,sinphi) {
  799. var con;
  800. if (eccent > 1.0e-7) {
  801. con = eccent * sinphi;
  802. return (( 1.0- eccent * eccent) * (sinphi /(1.0 - con * con) - (.5/eccent)*Math.log((1.0 - con)/(1.0 + con))));
  803. } else {
  804. return(2.0 * sinphi);
  805. }
  806. },
  807. /* Function to eliminate roundoff errors in asin
  808. ----------------------------------------------*/
  809. asinz : function(x) {
  810. if (Math.abs(x)>1.0) {
  811. x=(x>1.0)?1.0:-1.0;
  812. }
  813. return Math.asin(x);
  814. },
  815. // following functions from gctpc cproj.c for transverse mercator projections
  816. e0fn : function(x) {return(1.0-0.25*x*(1.0+x/16.0*(3.0+1.25*x)));},
  817. e1fn : function(x) {return(0.375*x*(1.0+0.25*x*(1.0+0.46875*x)));},
  818. e2fn : function(x) {return(0.05859375*x*x*(1.0+0.75*x));},
  819. e3fn : function(x) {return(x*x*x*(35.0/3072.0));},
  820. mlfn : function(e0,e1,e2,e3,phi) {return(e0*phi-e1*Math.sin(2.0*phi)+e2*Math.sin(4.0*phi)-e3*Math.sin(6.0*phi));},
  821. srat : function(esinp, exp) {
  822. return(Math.pow((1.0-esinp)/(1.0+esinp), exp));
  823. },
  824. // Function to return the sign of an argument
  825. sign : function(x) { if (x < 0.0) return(-1); else return(1);},
  826. // Function to adjust longitude to -180 to 180; input in radians
  827. adjust_lon : function(x) {
  828. x = (Math.abs(x) < this.PI) ? x: (x - (this.sign(x)*this.TWO_PI) );
  829. return x;
  830. },
  831. // IGNF - DGR : algorithms used by IGN France
  832. // Function to adjust latitude to -90 to 90; input in radians
  833. adjust_lat : function(x) {
  834. x= (Math.abs(x) < this.HALF_PI) ? x: (x - (this.sign(x)*this.PI) );
  835. return x;
  836. },
  837. // Latitude Isometrique - close to tsfnz ...
  838. latiso : function(eccent, phi, sinphi) {
  839. if (Math.abs(phi) > this.HALF_PI) return +Number.NaN;
  840. if (phi==this.HALF_PI) return Number.POSITIVE_INFINITY;
  841. if (phi==-1.0*this.HALF_PI) return -1.0*Number.POSITIVE_INFINITY;
  842. var con= eccent*sinphi;
  843. return Math.log(Math.tan((this.HALF_PI+phi)/2.0))+eccent*Math.log((1.0-con)/(1.0+con))/2.0;
  844. },
  845. fL : function(x,L) {
  846. return 2.0*Math.atan(x*Math.exp(L)) - this.HALF_PI;
  847. },
  848. // Inverse Latitude Isometrique - close to ph2z
  849. invlatiso : function(eccent, ts) {
  850. var phi= this.fL(1.0,ts);
  851. var Iphi= 0.0;
  852. var con= 0.0;
  853. do {
  854. Iphi= phi;
  855. con= eccent*Math.sin(Iphi);
  856. phi= this.fL(Math.exp(eccent*Math.log((1.0+con)/(1.0-con))/2.0),ts)
  857. } while (Math.abs(phi-Iphi)>1.0e-12);
  858. return phi;
  859. },
  860. // Needed for Gauss Schreiber
  861. // Original: Denis Makarov (info@binarythings.com)
  862. // Web Site: http://www.binarythings.com
  863. sinh : function(x)
  864. {
  865. var r= Math.exp(x);
  866. r= (r-1.0/r)/2.0;
  867. return r;
  868. },
  869. cosh : function(x)
  870. {
  871. var r= Math.exp(x);
  872. r= (r+1.0/r)/2.0;
  873. return r;
  874. },
  875. tanh : function(x)
  876. {
  877. var r= Math.exp(x);
  878. r= (r-1.0/r)/(r+1.0/r);
  879. return r;
  880. },
  881. asinh : function(x)
  882. {
  883. var s= (x>= 0? 1.0:-1.0);
  884. return s*(Math.log( Math.abs(x) + Math.sqrt(x*x+1.0) ));
  885. },
  886. acosh : function(x)
  887. {
  888. return 2.0*Math.log(Math.sqrt((x+1.0)/2.0) + Math.sqrt((x-1.0)/2.0));
  889. },
  890. atanh : function(x)
  891. {
  892. return Math.log((x-1.0)/(x+1.0))/2.0;
  893. },
  894. // Grande Normale
  895. gN : function(a,e,sinphi)
  896. {
  897. var temp= e*sinphi;
  898. return a/Math.sqrt(1.0 - temp*temp);
  899. }
  900. };
  901. /** datum object
  902. */
  903. Proj4js.datum = Proj4js.Class({
  904. initialize : function(proj) {
  905. this.datum_type = Proj4js.common.PJD_WGS84; //default setting
  906. if (proj.datumCode && proj.datumCode == 'none') {
  907. this.datum_type = Proj4js.common.PJD_NODATUM;
  908. }
  909. if (proj && proj.datum_params) {
  910. for (var i=0; i<proj.datum_params.length; i++) {
  911. proj.datum_params[i]=parseFloat(proj.datum_params[i]);
  912. }
  913. if (proj.datum_params[0] != 0 || proj.datum_params[1] != 0 || proj.datum_params[2] != 0 ) {
  914. this.datum_type = Proj4js.common.PJD_3PARAM;
  915. }
  916. if (proj.datum_params.length > 3) {
  917. if (proj.datum_params[3] != 0 || proj.datum_params[4] != 0 ||
  918. proj.datum_params[5] != 0 || proj.datum_params[6] != 0 ) {
  919. this.datum_type = Proj4js.common.PJD_7PARAM;
  920. proj.datum_params[3] *= Proj4js.common.SEC_TO_RAD;
  921. proj.datum_params[4] *= Proj4js.common.SEC_TO_RAD;
  922. proj.datum_params[5] *= Proj4js.common.SEC_TO_RAD;
  923. proj.datum_params[6] = (proj.datum_params[6]/1000000.0) + 1.0;
  924. }
  925. }
  926. }
  927. if (proj) {
  928. this.a = proj.a; //datum object also uses these values
  929. this.b = proj.b;
  930. this.es = proj.es;
  931. this.ep2 = proj.ep2;
  932. this.datum_params = proj.datum_params;
  933. }
  934. },
  935. /****************************************************************/
  936. // cs_compare_datums()
  937. // Returns 1 (TRUE) if the two datums match, otherwise 0 (FALSE).
  938. compare_datums : function( dest ) {
  939. if( this.datum_type != dest.datum_type ) {
  940. return false; // false, datums are not equal
  941. } else if( this.a != dest.a || Math.abs(this.es-dest.es) > 0.000000000050 ) {
  942. // the tolerence for es is to ensure that GRS80 and WGS84
  943. // are considered identical
  944. return false;
  945. } else if( this.datum_type == Proj4js.common.PJD_3PARAM ) {
  946. return (this.datum_params[0] == dest.datum_params[0]
  947. && this.datum_params[1] == dest.datum_params[1]
  948. && this.datum_params[2] == dest.datum_params[2]);
  949. } else if( this.datum_type == Proj4js.common.PJD_7PARAM ) {
  950. return (this.datum_params[0] == dest.datum_params[0]
  951. && this.datum_params[1] == dest.datum_params[1]
  952. && this.datum_params[2] == dest.datum_params[2]
  953. && this.datum_params[3] == dest.datum_params[3]
  954. && this.datum_params[4] == dest.datum_params[4]
  955. && this.datum_params[5] == dest.datum_params[5]
  956. && this.datum_params[6] == dest.datum_params[6]);
  957. } else if( this.datum_type == Proj4js.common.PJD_GRIDSHIFT ) {
  958. return strcmp( pj_param(this.params,"snadgrids").s,
  959. pj_param(dest.params,"snadgrids").s ) == 0;
  960. } else {
  961. return true; // datums are equal
  962. }
  963. }, // cs_compare_datums()
  964. /*
  965. * The function Convert_Geodetic_To_Geocentric converts geodetic coordinates
  966. * (latitude, longitude, and height) to geocentric coordinates (X, Y, Z),
  967. * according to the current ellipsoid parameters.
  968. *
  969. * Latitude : Geodetic latitude in radians (input)
  970. * Longitude : Geodetic longitude in radians (input)
  971. * Height : Geodetic height, in meters (input)
  972. * X : Calculated Geocentric X coordinate, in meters (output)
  973. * Y : Calculated Geocentric Y coordinate, in meters (output)
  974. * Z : Calculated Geocentric Z coordinate, in meters (output)
  975. *
  976. */
  977. geodetic_to_geocentric : function(p) {
  978. var Longitude = p.x;
  979. var Latitude = p.y;
  980. var Height = p.z ? p.z : 0; //Z value not always supplied
  981. var X; // output
  982. var Y;
  983. var Z;
  984. var Error_Code=0; // GEOCENT_NO_ERROR;
  985. var Rn; /* Earth radius at location */
  986. var Sin_Lat; /* Math.sin(Latitude) */
  987. var Sin2_Lat; /* Square of Math.sin(Latitude) */
  988. var Cos_Lat; /* Math.cos(Latitude) */
  989. /*
  990. ** Don't blow up if Latitude is just a little out of the value
  991. ** range as it may just be a rounding issue. Also removed longitude
  992. ** test, it should be wrapped by Math.cos() and Math.sin(). NFW for PROJ.4, Sep/2001.
  993. */
  994. if( Latitude < -Proj4js.common.HALF_PI && Latitude > -1.001 * Proj4js.common.HALF_PI ) {
  995. Latitude = -Proj4js.common.HALF_PI;
  996. } else if( Latitude > Proj4js.common.HALF_PI && Latitude < 1.001 * Proj4js.common.HALF_PI ) {
  997. Latitude = Proj4js.common.HALF_PI;
  998. } else if ((Latitude < -Proj4js.common.HALF_PI) || (Latitude > Proj4js.common.HALF_PI)) {
  999. /* Latitude out of range */
  1000. Proj4js.reportError('geocent:lat out of range:'+Latitude);
  1001. return null;
  1002. }
  1003. if (Longitude > Proj4js.common.PI) Longitude -= (2*Proj4js.common.PI);
  1004. Sin_Lat = Math.sin(Latitude);
  1005. Cos_Lat = Math.cos(Latitude);
  1006. Sin2_Lat = Sin_Lat * Sin_Lat;
  1007. Rn = this.a / (Math.sqrt(1.0e0 - this.es * Sin2_Lat));
  1008. X = (Rn + Height) * Cos_Lat * Math.cos(Longitude);
  1009. Y = (Rn + Height) * Cos_Lat * Math.sin(Longitude);
  1010. Z = ((Rn * (1 - this.es)) + Height) * Sin_Lat;
  1011. p.x = X;
  1012. p.y = Y;
  1013. p.z = Z;
  1014. return Error_Code;
  1015. }, // cs_geodetic_to_geocentric()
  1016. geocentric_to_geodetic : function (p) {
  1017. /* local defintions and variables */
  1018. /* end-criterium of loop, accuracy of sin(Latitude) */
  1019. var genau = 1.E-12;
  1020. var genau2 = (genau*genau);
  1021. var maxiter = 30;
  1022. var P; /* distance between semi-minor axis and location */
  1023. var RR; /* distance between center and location */
  1024. var CT; /* sin of geocentric latitude */
  1025. var ST; /* cos of geocentric latitude */
  1026. var RX;
  1027. var RK;
  1028. var RN; /* Earth radius at location */
  1029. var CPHI0; /* cos of start or old geodetic latitude in iterations */
  1030. var SPHI0; /* sin of start or old geodetic latitude in iterations */
  1031. var CPHI; /* cos of searched geodetic latitude */
  1032. var SPHI; /* sin of searched geodetic latitude */
  1033. var SDPHI; /* end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1)) */
  1034. var At_Pole; /* indicates location is in polar region */
  1035. var iter; /* # of continous iteration, max. 30 is always enough (s.a.) */
  1036. var X = p.x;
  1037. var Y = p.y;
  1038. var Z = p.z ? p.z : 0.0; //Z value not always supplied
  1039. var Longitude;
  1040. var Latitude;
  1041. var Height;
  1042. At_Pole = false;
  1043. P = Math.sqrt(X*X+Y*Y);
  1044. RR = Math.sqrt(X*X+Y*Y+Z*Z);
  1045. /* special cases for latitude and longitude */
  1046. if (P/this.a < genau) {
  1047. /* special case, if P=0. (X=0., Y=0.) */
  1048. At_Pole = true;
  1049. Longitude = 0.0;
  1050. /* if (X,Y,Z)=(0.,0.,0.) then Height becomes semi-minor axis
  1051. * of ellipsoid (=center of mass), Latitude becomes PI/2 */
  1052. if (RR/this.a < genau) {
  1053. Latitude = Proj4js.common.HALF_PI;
  1054. Height = -this.b;
  1055. return;
  1056. }
  1057. } else {
  1058. /* ellipsoidal (geodetic) longitude
  1059. * interval: -PI < Longitude <= +PI */
  1060. Longitude=Math.atan2(Y,X);
  1061. }
  1062. /* --------------------------------------------------------------
  1063. * Following iterative algorithm was developped by
  1064. * "Institut für Erdmessung", University of Hannover, July 1988.
  1065. * Internet: www.ife.uni-hannover.de
  1066. * Iterative computation of CPHI,SPHI and Height.
  1067. * Iteration of CPHI and SPHI to 10**-12 radian resp.
  1068. * 2*10**-7 arcsec.
  1069. * --------------------------------------------------------------
  1070. */
  1071. CT = Z/RR;
  1072. ST = P/RR;
  1073. RX = 1.0/Math.sqrt(1.0-this.es*(2.0-this.es)*ST*ST);
  1074. CPHI0 = ST*(1.0-this.es)*RX;
  1075. SPHI0 = CT*RX;
  1076. iter = 0;
  1077. /* loop to find sin(Latitude) resp. Latitude
  1078. * until |sin(Latitude(iter)-Latitude(iter-1))| < genau */
  1079. do
  1080. {
  1081. iter++;
  1082. RN = this.a/Math.sqrt(1.0-this.es*SPHI0*SPHI0);
  1083. /* ellipsoidal (geodetic) height */
  1084. Height = P*CPHI0+Z*SPHI0-RN*(1.0-this.es*SPHI0*SPHI0);
  1085. RK = this.es*RN/(RN+Height);
  1086. RX = 1.0/Math.sqrt(1.0-RK*(2.0-RK)*ST*ST);
  1087. CPHI = ST*(1.0-RK)*RX;
  1088. SPHI = CT*RX;
  1089. SDPHI = SPHI*CPHI0-CPHI*SPHI0;
  1090. CPHI0 = CPHI;
  1091. SPHI0 = SPHI;
  1092. }
  1093. while (SDPHI*SDPHI > genau2 && iter < maxiter);
  1094. /* ellipsoidal (geodetic) latitude */
  1095. Latitude=Math.atan(SPHI/Math.abs(CPHI));
  1096. p.x = Longitude;
  1097. p.y = Latitude;
  1098. p.z = Height;
  1099. return p;
  1100. }, // cs_geocentric_to_geodetic()
  1101. /** Convert_Geocentric_To_Geodetic
  1102. * The method used here is derived from 'An Improved Algorithm for
  1103. * Geocentric to Geodetic Coordinate Conversion', by Ralph Toms, Feb 1996
  1104. */
  1105. geocentric_to_geodetic_noniter : function (p) {
  1106. var X = p.x;
  1107. var Y = p.y;
  1108. var Z = p.z ? p.z : 0; //Z value not always supplied
  1109. var Longitude;
  1110. var Latitude;
  1111. var Height;
  1112. var W; /* distance from Z axis */
  1113. var W2; /* square of distance from Z axis */
  1114. var T0; /* initial estimate of vertical component */
  1115. var T1; /* corrected estimate of vertical component */
  1116. var S0; /* initial estimate of horizontal component */
  1117. var S1; /* corrected estimate of horizontal component */
  1118. var Sin_B0; /* Math.sin(B0), B0 is estimate of Bowring aux variable */
  1119. var Sin3_B0; /* cube of Math.sin(B0) */
  1120. var Cos_B0; /* Math.cos(B0) */
  1121. var Sin_p1; /* Math.sin(phi1), phi1 is estimated latitude */
  1122. var Cos_p1; /* Math.cos(phi1) */
  1123. var Rn; /* Earth radius at location */
  1124. var Sum; /* numerator of Math.cos(phi1) */
  1125. var At_Pole; /* indicates location is in polar region */
  1126. X = parseFloat(X); // cast from string to float
  1127. Y = parseFloat(Y);
  1128. Z = parseFloat(Z);
  1129. At_Pole = false;
  1130. if (X != 0.0)
  1131. {
  1132. Longitude = Math.atan2(Y,X);
  1133. }
  1134. else
  1135. {
  1136. if (Y > 0)
  1137. {
  1138. Longitude = Proj4js.common.HALF_PI;
  1139. }
  1140. else if (Y < 0)
  1141. {
  1142. Longitude = -Proj4js.common.HALF_PI;
  1143. }
  1144. else
  1145. {
  1146. At_Pole = true;
  1147. Longitude = 0.0;
  1148. if (Z > 0.0)
  1149. { /* north pole */
  1150. Latitude = Proj4js.common.HALF_PI;
  1151. }
  1152. else if (Z < 0.0)
  1153. { /* south pole */
  1154. Latitude = -Proj4js.common.HALF_PI;
  1155. }
  1156. else
  1157. { /* center of earth */
  1158. Latitude = Proj4js.common.HALF_PI;
  1159. Height = -this.b;
  1160. return;
  1161. }
  1162. }
  1163. }
  1164. W2 = X*X + Y*Y;
  1165. W = Math.sqrt(W2);
  1166. T0 = Z * Proj4js.common.AD_C;
  1167. S0 = Math.sqrt(T0 * T0 + W2);
  1168. Sin_B0 = T0 / S0;
  1169. Cos_B0 = W / S0;
  1170. Sin3_B0 = Sin_B0 * Sin_B0 * Sin_B0;
  1171. T1 = Z + this.b * this.ep2 * Sin3_B0;
  1172. Sum = W - this.a * this.es * Cos_B0 * Cos_B0 * Cos_B0;
  1173. S1 = Math.sqrt(T1*T1 + Sum * Sum);
  1174. Sin_p1 = T1 / S1;
  1175. Cos_p1 = Sum / S1;
  1176. Rn = this.a / Math.sqrt(1.0 - this.es * Sin_p1 * Sin_p1);
  1177. if (Cos_p1 >= Proj4js.common.COS_67P5)
  1178. {
  1179. Height = W / Cos_p1 - Rn;
  1180. }
  1181. else if (Cos_p1 <= -Proj4js.common.COS_67P5)
  1182. {
  1183. Height = W / -Cos_p1 - Rn;
  1184. }
  1185. else
  1186. {
  1187. Height = Z / Sin_p1 + Rn * (this.es - 1.0);
  1188. }
  1189. if (At_Pole == false)
  1190. {
  1191. Latitude = Math.atan(Sin_p1 / Cos_p1);
  1192. }
  1193. p.x = Longitude;
  1194. p.y = Latitude;
  1195. p.z = Height;
  1196. return p;
  1197. }, // geocentric_to_geodetic_noniter()
  1198. /****************************************************************/
  1199. // pj_geocentic_to_wgs84( p )
  1200. // p = point to transform in geocentric coordinates (x,y,z)
  1201. geocentric_to_wgs84 : function ( p ) {
  1202. if( this.datum_type == Proj4js.common.PJD_3PARAM )
  1203. {
  1204. // if( x[io] == HUGE_VAL )
  1205. // continue;
  1206. p.x += this.datum_params[0];
  1207. p.y += this.datum_params[1];
  1208. p.z += this.datum_params[2];
  1209. }
  1210. else if (this.datum_type == Proj4js.common.PJD_7PARAM)
  1211. {
  1212. var Dx_BF =this.datum_params[0];
  1213. var Dy_BF =this.datum_params[1];
  1214. var Dz_BF =this.datum_params[2];
  1215. var Rx_BF =this.datum_params[3];
  1216. var Ry_BF =this.datum_params[4];
  1217. var Rz_BF =this.datum_params[5];
  1218. var M_BF =this.datum_params[6];
  1219. // if( x[io] == HUGE_VAL )
  1220. // continue;
  1221. var x_out = M_BF*( p.x - Rz_BF*p.y + Ry_BF*p.z) + Dx_BF;
  1222. var y_out = M_BF*( Rz_BF*p.x + p.y - Rx_BF*p.z) + Dy_BF;
  1223. var z_out = M_BF*(-Ry_BF*p.x + Rx_BF*p.y + p.z) + Dz_BF;
  1224. p.x = x_out;
  1225. p.y = y_out;
  1226. p.z = z_out;
  1227. }
  1228. }, // cs_geocentric_to_wgs84
  1229. /****************************************************************/
  1230. // pj_geocentic_from_wgs84()
  1231. // coordinate system definition,
  1232. // point to transform in geocentric coordinates (x,y,z)
  1233. geocentric_from_wgs84 : function( p ) {
  1234. if( this.datum_type == Proj4js.common.PJD_3PARAM )
  1235. {
  1236. //if( x[io] == HUGE_VAL )
  1237. // continue;
  1238. p.x -= this.datum_params[0];
  1239. p.y -= this.datum_params[1];
  1240. p.z -= this.datum_params[2];
  1241. }
  1242. else if (this.datum_type == Proj4js.common.PJD_7PARAM)
  1243. {
  1244. var Dx_BF =this.datum_params[0];
  1245. var Dy_BF =this.datum_params[1];
  1246. var Dz_BF =this.datum_params[2];
  1247. var Rx_BF =this.datum_params[3];
  1248. var Ry_BF =this.datum_params[4];
  1249. var Rz_BF =this.datum_params[5];
  1250. var M_BF =this.datum_params[6];
  1251. var x_tmp = (p.x - Dx_BF) / M_BF;
  1252. var y_tmp = (p.y - Dy_BF) / M_BF;
  1253. var z_tmp = (p.z - Dz_BF) / M_BF;
  1254. //if( x[io] == HUGE_VAL )
  1255. // continue;
  1256. p.x = x_tmp + Rz_BF*y_tmp - Ry_BF*z_tmp;
  1257. p.y = -Rz_BF*x_tmp + y_tmp + Rx_BF*z_tmp;
  1258. p.z = Ry_BF*x_tmp - Rx_BF*y_tmp + z_tmp;
  1259. } //cs_geocentric_from_wgs84()
  1260. }
  1261. });
  1262. /** point object, nothing fancy, just allows values to be
  1263. passed back and forth by reference rather than by value.
  1264. Other point classes may be used as long as they have
  1265. x and y properties, which will get modified in the transform method.
  1266. */
  1267. Proj4js.Point = Proj4js.Class({
  1268. /**
  1269. * Constructor: Proj4js.Point
  1270. *
  1271. * Parameters:
  1272. * - x {float} or {Array} either the first coordinates component or
  1273. * the full coordinates
  1274. * - y {float} the second component
  1275. * - z {float} the third component, optional.
  1276. */
  1277. initialize : function(x,y,z) {
  1278. if (typeof x == 'object') {
  1279. this.x = x[0];
  1280. this.y = x[1];
  1281. this.z = x[2] || 0.0;
  1282. } else if (typeof x == 'string') {
  1283. var coords = x.split(',');
  1284. this.x = parseFloat(coords[0]);
  1285. this.y = parseFloat(coords[1]);
  1286. this.z = parseFloat(coords[2]) || 0.0;
  1287. } else {
  1288. this.x = x;
  1289. this.y = y;
  1290. this.z = z || 0.0;
  1291. }
  1292. },
  1293. /**
  1294. * APIMethod: clone
  1295. * Build a copy of a Proj4js.Point object.
  1296. *
  1297. * Return:
  1298. * {Proj4js}.Point the cloned point.
  1299. */
  1300. clone : function() {
  1301. return new Proj4js.Point(this.x, this.y, this.z);
  1302. },
  1303. /**
  1304. * APIMethod: toString
  1305. * Return a readable string version of the point
  1306. *
  1307. * Return:
  1308. * {String} String representation of Proj4js.Point object.
  1309. * (ex. <i>"x=5,y=42"</i>)
  1310. */
  1311. toString : function() {
  1312. return ("x=" + this.x + ",y=" + this.y);
  1313. },
  1314. /**
  1315. * APIMethod: toShortString
  1316. * Return a short string version of the point.
  1317. *
  1318. * Return:
  1319. * {String} Shortened String representation of Proj4js.Point object.
  1320. * (ex. <i>"5, 42"</i>)
  1321. */
  1322. toShortString : function() {
  1323. return (this.x + ", " + this.y);
  1324. }
  1325. });
  1326. Proj4js.PrimeMeridian = {
  1327. "greenwich": 0.0, //"0dE",
  1328. "lisbon": -9.131906111111, //"9d07'54.862\"W",
  1329. "paris": 2.337229166667, //"2d20'14.025\"E",
  1330. "bogota": -74.080916666667, //"74d04'51.3\"W",
  1331. "madrid": -3.687938888889, //"3d41'16.58\"W",
  1332. "rome": 12.452333333333, //"12d27'8.4\"E",
  1333. "bern": 7.439583333333, //"7d26'22.5\"E",
  1334. "jakarta": 106.807719444444, //"106d48'27.79\"E",
  1335. "ferro": -17.666666666667, //"17d40'W",
  1336. "brussels": 4.367975, //"4d22'4.71\"E",
  1337. "stockholm": 18.058277777778, //"18d3'29.8\"E",
  1338. "athens": 23.7163375, //"23d42'58.815\"E",
  1339. "oslo": 10.722916666667 //"10d43'22.5\"E"
  1340. };
  1341. Proj4js.Ellipsoid = {
  1342. "MERIT": {a:6378137.0, rf:298.257, ellipseName:"MERIT 1983"},
  1343. "SGS85": {a:6378136.0, rf:298.257, ellipseName:"Soviet Geodetic System 85"},
  1344. "GRS80": {a:6378137.0, rf:298.257222101, ellipseName:"GRS 1980(IUGG, 1980)"},
  1345. "IAU76": {a:6378140.0, rf:298.257, ellipseName:"IAU 1976"},
  1346. "airy": {a:6377563.396, b:6356256.910, ellipseName:"Airy 1830"},
  1347. "APL4.": {a:6378137, rf:298.25, ellipseName:"Appl. Physics. 1965"},
  1348. "NWL9D": {a:6378145.0, rf:298.25, ellipseName:"Naval Weapons Lab., 1965"},
  1349. "mod_airy": {a:6377340.189, b:6356034.446, ellipseName:"Modified Airy"},
  1350. "andrae": {a:6377104.43, rf:300.0, ellipseName:"Andrae 1876 (Den., Iclnd.)"},
  1351. "aust_SA": {a:6378160.0, rf:298.25, ellipseName:"Australian Natl & S. Amer. 1969"},
  1352. "GRS67": {a:6378160.0, rf:298.2471674270, ellipseName:"GRS 67(IUGG 1967)"},
  1353. "bessel": {a:6377397.155, rf:299.1528128, ellipseName:"Bessel 1841"},
  1354. "bess_nam": {a:6377483.865, rf:299.1528128, ellipseName:"Bessel 1841 (Namibia)"},
  1355. "clrk66": {a:6378206.4, b:6356583.8, ellipseName:"Clarke 1866"},
  1356. "clrk80": {a:6378249.145, rf:293.4663, ellipseName:"Clarke 1880 mod."},
  1357. "CPM": {a:6375738.7, rf:334.29, ellipseName:"Comm. des Poids et Mesures 1799"},
  1358. "delmbr": {a:6376428.0, rf:311.5, ellipseName:"Delambre 1810 (Belgium)"},
  1359. "engelis": {a:6378136.05, rf:298.2566, ellipseName:"Engelis 1985"},
  1360. "evrst30": {a:6377276.345, rf:300.8017, ellipseName:"Everest 1830"},
  1361. "evrst48": {a:6377304.063, rf:300.8017, ellipseName:"Everest 1948"},
  1362. "evrst56": {a:6377301.243, rf:300.8017, ellipseName:"Everest 1956"},
  1363. "evrst69": {a:6377295.664, rf:300.8017, ellipseName:"Everest 1969"},
  1364. "evrstSS": {a:6377298.556, rf:300.8017, ellipseName:"Everest (Sabah & Sarawak)"},
  1365. "fschr60": {a:6378166.0, rf:298.3, ellipseName:"Fischer (Mercury Datum) 1960"},
  1366. "fschr60m": {a:6378155.0, rf:298.3, ellipseName:"Fischer 1960"},
  1367. "fschr68": {a:6378150.0, rf:298.3, ellipseName:"Fischer 1968"},
  1368. "helmert": {a:6378200.0, rf:298.3, ellipseName:"Helmert 1906"},
  1369. "hough": {a:6378270.0, rf:297.0, ellipseName:"Hough"},
  1370. "intl": {a:6378388.0, rf:297.0, ellipseName:"International 1909 (Hayford)"},
  1371. "kaula": {a:6378163.0, rf:298.24, ellipseName:"Kaula 1961"},
  1372. "lerch": {a:6378139.0, rf:298.257, ellipseName:"Lerch 1979"},
  1373. "mprts": {a:6397300.0, rf:191.0, ellipseName:"Maupertius 1738"},
  1374. "new_intl": {a:6378157.5, b:6356772.2, ellipseName:"New International 1967"},
  1375. "plessis": {a:6376523.0, rf:6355863.0, ellipseName:"Plessis 1817 (France)"},
  1376. "krass": {a:6378245.0, rf:298.3, ellipseName:"Krassovsky, 1942"},
  1377. "SEasia": {a:6378155.0, b:6356773.3205, ellipseName:"Southeast Asia"},
  1378. "walbeck": {a:6376896.0, b:6355834.8467, ellipseName:"Walbeck"},
  1379. "WGS60": {a:6378165.0, rf:298.3, ellipseName:"WGS 60"},
  1380. "WGS66": {a:6378145.0, rf:298.25, ellipseName:"WGS 66"},
  1381. "WGS72": {a:6378135.0, rf:298.26, ellipseName:"WGS 72"},
  1382. "WGS84": {a:6378137.0, rf:298.257223563, ellipseName:"WGS 84"},
  1383. "sphere": {a:6370997.0, b:6370997.0, ellipseName:"Normal Sphere (r=6370997)"}
  1384. };
  1385. Proj4js.Datum = {
  1386. "WGS84": {towgs84: "0,0,0", ellipse: "WGS84", datumName: "WGS84"},
  1387. "GGRS87": {towgs84: "-199.87,74.79,246.62", ellipse: "GRS80", datumName: "Greek_Geodetic_Reference_System_1987"},
  1388. "NAD83": {towgs84: "0,0,0", ellipse: "GRS80", datumName: "North_American_Datum_1983"},
  1389. "NAD27": {nadgrids: "@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat", ellipse: "clrk66", datumName: "North_American_Datum_1927"},
  1390. "potsdam": {towgs84: "606.0,23.0,413.0", ellipse: "bessel", datumName: "Potsdam Rauenberg 1950 DHDN"},
  1391. "carthage": {towgs84: "-263.0,6.0,431.0", ellipse: "clark80", datumName: "Carthage 1934 Tunisia"},
  1392. "hermannskogel": {towgs84: "653.0,-212.0,449.0", ellipse: "bessel", datumName: "Hermannskogel"},
  1393. "ire65": {towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15", ellipse: "mod_airy", datumName: "Ireland 1965"},
  1394. "nzgd49": {towgs84: "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993", ellipse: "intl", datumName: "New Zealand Geodetic Datum 1949"},
  1395. "OSGB36": {towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894", ellipse: "airy", datumName: "Airy 1830"}
  1396. };
  1397. Proj4js.WGS84 = new Proj4js.Proj('WGS84');
  1398. Proj4js.Datum['OSB36'] = Proj4js.Datum['OSGB36']; //as returned from spatialreference.org
  1399. /* ======================================================================
  1400. projCode/aea.js
  1401. ====================================================================== */
  1402. /*******************************************************************************
  1403. NAME ALBERS CONICAL EQUAL AREA
  1404. PURPOSE: Transforms input longitude and latitude to Easting and Northing
  1405. for the Albers Conical Equal Area projection. The longitude
  1406. and latitude must be in radians. The Easting and Northing
  1407. values will be returned in meters.
  1408. PROGRAMMER DATE
  1409. ---------- ----
  1410. T. Mittan, Feb, 1992
  1411. ALGORITHM REFERENCES
  1412. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  1413. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  1414. State Government Printing Office, Washington D.C., 1987.
  1415. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  1416. U.S. Geological Survey Professional Paper 1453 , United State Government
  1417. Printing Office, Washington D.C., 1989.
  1418. *******************************************************************************/
  1419. Proj4js.Proj.aea = {
  1420. init : function() {
  1421. if (Math.abs(this.lat1 + this.lat2) < Proj4js.common.EPSLN) {
  1422. Proj4js.reportError("aeaInitEqualLatitudes");
  1423. return;
  1424. }
  1425. this.temp = this.b / this.a;
  1426. this.es = 1.0 - Math.pow(this.temp,2);
  1427. this.e3 = Math.sqrt(this.es);
  1428. this.sin_po=Math.sin(this.lat1);
  1429. this.cos_po=Math.cos(this.lat1);
  1430. this.t1=this.sin_po;
  1431. this.con = this.sin_po;
  1432. this.ms1 = Proj4js.common.msfnz(this.e3,this.sin_po,this.cos_po);
  1433. this.qs1 = Proj4js.common.qsfnz(this.e3,this.sin_po,this.cos_po);
  1434. this.sin_po=Math.sin(this.lat2);
  1435. this.cos_po=Math.cos(this.lat2);
  1436. this.t2=this.sin_po;
  1437. this.ms2 = Proj4js.common.msfnz(this.e3,this.sin_po,this.cos_po);
  1438. this.qs2 = Proj4js.common.qsfnz(this.e3,this.sin_po,this.cos_po);
  1439. this.sin_po=Math.sin(this.lat0);
  1440. this.cos_po=Math.cos(this.lat0);
  1441. this.t3=this.sin_po;
  1442. this.qs0 = Proj4js.common.qsfnz(this.e3,this.sin_po,this.cos_po);
  1443. if (Math.abs(this.lat1 - this.lat2) > Proj4js.common.EPSLN) {
  1444. this.ns0 = (this.ms1 * this.ms1 - this.ms2 *this.ms2)/ (this.qs2 - this.qs1);
  1445. } else {
  1446. this.ns0 = this.con;
  1447. }
  1448. this.c = this.ms1 * this.ms1 + this.ns0 * this.qs1;
  1449. this.rh = this.a * Math.sqrt(this.c - this.ns0 * this.qs0)/this.ns0;
  1450. },
  1451. /* Albers Conical Equal Area forward equations--mapping lat,long to x,y
  1452. -------------------------------------------------------------------*/
  1453. forward: function(p){
  1454. var lon=p.x;
  1455. var lat=p.y;
  1456. this.sin_phi=Math.sin(lat);
  1457. this.cos_phi=Math.cos(lat);
  1458. var qs = Proj4js.common.qsfnz(this.e3,this.sin_phi,this.cos_phi);
  1459. var rh1 =this.a * Math.sqrt(this.c - this.ns0 * qs)/this.ns0;
  1460. var theta = this.ns0 * Proj4js.common.adjust_lon(lon - this.long0);
  1461. var x = rh1 * Math.sin(theta) + this.x0;
  1462. var y = this.rh - rh1 * Math.cos(theta) + this.y0;
  1463. p.x = x;
  1464. p.y = y;
  1465. return p;
  1466. },
  1467. inverse: function(p) {
  1468. var rh1,qs,con,theta,lon,lat;
  1469. p.x -= this.x0;
  1470. p.y = this.rh - p.y + this.y0;
  1471. if (this.ns0 >= 0) {
  1472. rh1 = Math.sqrt(p.x *p.x + p.y * p.y);
  1473. con = 1.0;
  1474. } else {
  1475. rh1 = -Math.sqrt(p.x * p.x + p.y *p.y);
  1476. con = -1.0;
  1477. }
  1478. theta = 0.0;
  1479. if (rh1 != 0.0) {
  1480. theta = Math.atan2(con * p.x, con * p.y);
  1481. }
  1482. con = rh1 * this.ns0 / this.a;
  1483. qs = (this.c - con * con) / this.ns0;
  1484. if (this.e3 >= 1e-10) {
  1485. con = 1 - .5 * (1.0 -this.es) * Math.log((1.0 - this.e3) / (1.0 + this.e3))/this.e3;
  1486. if (Math.abs(Math.abs(con) - Math.abs(qs)) > .0000000001 ) {
  1487. lat = this.phi1z(this.e3,qs);
  1488. } else {
  1489. if (qs >= 0) {
  1490. lat = .5 * PI;
  1491. } else {
  1492. lat = -.5 * PI;
  1493. }
  1494. }
  1495. } else {
  1496. lat = this.phi1z(e3,qs);
  1497. }
  1498. lon = Proj4js.common.adjust_lon(theta/this.ns0 + this.long0);
  1499. p.x = lon;
  1500. p.y = lat;
  1501. return p;
  1502. },
  1503. /* Function to compute phi1, the latitude for the inverse of the
  1504. Albers Conical Equal-Area projection.
  1505. -------------------------------------------*/
  1506. phi1z: function (eccent,qs) {
  1507. var con, com, dphi;
  1508. var phi = Proj4js.common.asinz(.5 * qs);
  1509. if (eccent < Proj4js.common.EPSLN) return phi;
  1510. var eccnts = eccent * eccent;
  1511. for (var i = 1; i <= 25; i++) {
  1512. sinphi = Math.sin(phi);
  1513. cosphi = Math.cos(phi);
  1514. con = eccent * sinphi;
  1515. com = 1.0 - con * con;
  1516. dphi = .5 * com * com / cosphi * (qs / (1.0 - eccnts) - sinphi / com + .5 / eccent * Math.log((1.0 - con) / (1.0 + con)));
  1517. phi = phi + dphi;
  1518. if (Math.abs(dphi) <= 1e-7) return phi;
  1519. }
  1520. Proj4js.reportError("aea:phi1z:Convergence error");
  1521. return null;
  1522. }
  1523. };
  1524. /* ======================================================================
  1525. projCode/sterea.js
  1526. ====================================================================== */
  1527. Proj4js.Proj.sterea = {
  1528. dependsOn : 'gauss',
  1529. init : function() {
  1530. Proj4js.Proj['gauss'].init.apply(this);
  1531. if (!this.rc) {
  1532. Proj4js.reportError("sterea:init:E_ERROR_0");
  1533. return;
  1534. }
  1535. this.sinc0 = Math.sin(this.phic0);
  1536. this.cosc0 = Math.cos(this.phic0);
  1537. this.R2 = 2.0 * this.rc;
  1538. if (!this.title) this.title = "Oblique Stereographic Alternative";
  1539. },
  1540. forward : function(p) {
  1541. p.x = Proj4js.common.adjust_lon(p.x-this.long0); /* adjust del longitude */
  1542. Proj4js.Proj['gauss'].forward.apply(this, [p]);
  1543. sinc = Math.sin(p.y);
  1544. cosc = Math.cos(p.y);
  1545. cosl = Math.cos(p.x);
  1546. k = this.k0 * this.R2 / (1.0 + this.sinc0 * sinc + this.cosc0 * cosc * cosl);
  1547. p.x = k * cosc * Math.sin(p.x);
  1548. p.y = k * (this.cosc0 * sinc - this.sinc0 * cosc * cosl);
  1549. p.x = this.a * p.x + this.x0;
  1550. p.y = this.a * p.y + this.y0;
  1551. return p;
  1552. },
  1553. inverse : function(p) {
  1554. var lon,lat;
  1555. p.x = (p.x - this.x0) / this.a; /* descale and de-offset */
  1556. p.y = (p.y - this.y0) / this.a;
  1557. p.x /= this.k0;
  1558. p.y /= this.k0;
  1559. if ( (rho = Math.sqrt(p.x*p.x + p.y*p.y)) ) {
  1560. c = 2.0 * Math.atan2(rho, this.R2);
  1561. sinc = Math.sin(c);
  1562. cosc = Math.cos(c);
  1563. lat = Math.asin(cosc * this.sinc0 + p.y * sinc * this.cosc0 / rho);
  1564. lon = Math.atan2(p.x * sinc, rho * this.cosc0 * cosc - p.y * this.sinc0 * sinc);
  1565. } else {
  1566. lat = this.phic0;
  1567. lon = 0.;
  1568. }
  1569. p.x = lon;
  1570. p.y = lat;
  1571. Proj4js.Proj['gauss'].inverse.apply(this,[p]);
  1572. p.x = Proj4js.common.adjust_lon(p.x + this.long0); /* adjust longitude to CM */
  1573. return p;
  1574. }
  1575. };
  1576. /* ======================================================================
  1577. projCode/poly.js
  1578. ====================================================================== */
  1579. /* Function to compute, phi4, the latitude for the inverse of the
  1580. Polyconic projection.
  1581. ------------------------------------------------------------*/
  1582. function phi4z (eccent,e0,e1,e2,e3,a,b,c,phi) {
  1583. var sinphi, sin2ph, tanph, ml, mlp, con1, con2, con3, dphi, i;
  1584. phi = a;
  1585. for (i = 1; i <= 15; i++) {
  1586. sinphi = Math.sin(phi);
  1587. tanphi = Math.tan(phi);
  1588. c = tanphi * Math.sqrt (1.0 - eccent * sinphi * sinphi);
  1589. sin2ph = Math.sin (2.0 * phi);
  1590. /*
  1591. ml = e0 * *phi - e1 * sin2ph + e2 * sin (4.0 * *phi);
  1592. mlp = e0 - 2.0 * e1 * cos (2.0 * *phi) + 4.0 * e2 * cos (4.0 * *phi);
  1593. */
  1594. ml = e0 * phi - e1 * sin2ph + e2 * Math.sin (4.0 * phi) - e3 * Math.sin (6.0 * phi);
  1595. mlp = e0 - 2.0 * e1 * Math.cos (2.0 * phi) + 4.0 * e2 * Math.cos (4.0 * phi) - 6.0 * e3 * Math.cos (6.0 * phi);
  1596. con1 = 2.0 * ml + c * (ml * ml + b) - 2.0 * a * (c * ml + 1.0);
  1597. con2 = eccent * sin2ph * (ml * ml + b - 2.0 * a * ml) / (2.0 *c);
  1598. con3 = 2.0 * (a - ml) * (c * mlp - 2.0 / sin2ph) - 2.0 * mlp;
  1599. dphi = con1 / (con2 + con3);
  1600. phi += dphi;
  1601. if (Math.abs(dphi) <= .0000000001 ) return(phi);
  1602. }
  1603. Proj4js.reportError("phi4z: No convergence");
  1604. return null;
  1605. }
  1606. /* Function to compute the constant e4 from the input of the eccentricity
  1607. of the spheroid, x. This constant is used in the Polar Stereographic
  1608. projection.
  1609. --------------------------------------------------------------------*/
  1610. function e4fn(x) {
  1611. var con, com;
  1612. con = 1.0 + x;
  1613. com = 1.0 - x;
  1614. return (Math.sqrt((Math.pow(con,con))*(Math.pow(com,com))));
  1615. }
  1616. /*******************************************************************************
  1617. NAME POLYCONIC
  1618. PURPOSE: Transforms input longitude and latitude to Easting and
  1619. Northing for the Polyconic projection. The
  1620. longitude and latitude must be in radians. The Easting
  1621. and Northing values will be returned in meters.
  1622. PROGRAMMER DATE
  1623. ---------- ----
  1624. T. Mittan Mar, 1993
  1625. ALGORITHM REFERENCES
  1626. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  1627. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  1628. State Government Printing Office, Washington D.C., 1987.
  1629. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  1630. U.S. Geological Survey Professional Paper 1453 , United State Government
  1631. Printing Office, Washington D.C., 1989.
  1632. *******************************************************************************/
  1633. Proj4js.Proj.poly = {
  1634. /* Initialize the POLYCONIC projection
  1635. ----------------------------------*/
  1636. init: function() {
  1637. var temp; /* temporary variable */
  1638. if (this.lat0=0) this.lat0=90;//this.lat0 ca
  1639. /* Place parameters in static storage for common use
  1640. -------------------------------------------------*/
  1641. this.temp = this.b / this.a;
  1642. this.es = 1.0 - Math.pow(this.temp,2);// devait etre dans tmerc.js mais n y est pas donc je commente sinon retour de valeurs nulles
  1643. this.e = Math.sqrt(this.es);
  1644. this.e0 = Proj4js.common.e0fn(this.es);
  1645. this.e1 = Proj4js.common.e1fn(this.es);
  1646. this.e2 = Proj4js.common.e2fn(this.es);
  1647. this.e3 = Proj4js.common.e3fn(this.es);
  1648. this.ml0 = Proj4js.common.mlfn(this.e0, this.e1,this.e2, this.e3, this.lat0);//si que des zeros le calcul ne se fait pas
  1649. //if (!this.ml0) {this.ml0=0;}
  1650. },
  1651. /* Polyconic forward equations--mapping lat,long to x,y
  1652. ---------------------------------------------------*/
  1653. forward: function(p) {
  1654. var sinphi, cosphi; /* sin and cos value */
  1655. var al; /* temporary values */
  1656. var c; /* temporary values */
  1657. var con, ml; /* cone constant, small m */
  1658. var ms; /* small m */
  1659. var x,y;
  1660. var lon=p.x;
  1661. var lat=p.y;
  1662. con = Proj4js.common.adjust_lon(lon - this.long0);
  1663. if (Math.abs(lat) <= .0000001) {
  1664. x = this.x0 + this.a * con;
  1665. y = this.y0 - this.a * this.ml0;
  1666. } else {
  1667. sinphi = Math.sin(lat);
  1668. cosphi = Math.cos(lat);
  1669. ml = Proj4js.common.mlfn(this.e0, this.e1, this.e2, this.e3, lat);
  1670. ms = Proj4js.common.msfnz(this.e,sinphi,cosphi);
  1671. con = sinphi;
  1672. x = this.x0 + this.a * ms * Math.sin(con)/sinphi;
  1673. y = this.y0 + this.a * (ml - this.ml0 + ms * (1.0 - Math.cos(con))/sinphi);
  1674. }
  1675. p.x=x;
  1676. p.y=y;
  1677. return p;
  1678. },
  1679. /* Inverse equations
  1680. -----------------*/
  1681. inverse: function(p) {
  1682. var sin_phi, cos_phi; /* sin and cos value */
  1683. var al; /* temporary values */
  1684. var b; /* temporary values */
  1685. var c; /* temporary values */
  1686. var con, ml; /* cone constant, small m */
  1687. var iflg; /* error flag */
  1688. var lon,lat;
  1689. p.x -= this.x0;
  1690. p.y -= this.y0;
  1691. al = this.ml0 + p.y/this.a;
  1692. iflg = 0;
  1693. if (Math.abs(al) <= .0000001) {
  1694. lon = p.x/this.a + this.long0;
  1695. lat = 0.0;
  1696. } else {
  1697. b = al * al + (p.x/this.a) * (p.x/this.a);
  1698. iflg = phi4z(this.es,this.e0,this.e1,this.e2,this.e3,this.al,b,c,lat);
  1699. if (iflg != 1) return(iflg);
  1700. lon = Proj4js.common.adjust_lon((Proj4js.common.asinz(p.x * c / this.a) / Math.sin(lat)) + this.long0);
  1701. }
  1702. p.x=lon;
  1703. p.y=lat;
  1704. return p;
  1705. }
  1706. };
  1707. /* ======================================================================
  1708. projCode/equi.js
  1709. ====================================================================== */
  1710. /*******************************************************************************
  1711. NAME EQUIRECTANGULAR
  1712. PURPOSE: Transforms input longitude and latitude to Easting and
  1713. Northing for the Equirectangular projection. The
  1714. longitude and latitude must be in radians. The Easting
  1715. and Northing values will be returned in meters.
  1716. PROGRAMMER DATE
  1717. ---------- ----
  1718. T. Mittan Mar, 1993
  1719. ALGORITHM REFERENCES
  1720. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  1721. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  1722. State Government Printing Office, Washington D.C., 1987.
  1723. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  1724. U.S. Geological Survey Professional Paper 1453 , United State Government
  1725. Printing Office, Washington D.C., 1989.
  1726. *******************************************************************************/
  1727. Proj4js.Proj.equi = {
  1728. init: function() {
  1729. if(!this.x0) this.x0=0;
  1730. if(!this.y0) this.y0=0;
  1731. if(!this.lat0) this.lat0=0;
  1732. if(!this.long0) this.long0=0;
  1733. ///this.t2;
  1734. },
  1735. /* Equirectangular forward equations--mapping lat,long to x,y
  1736. ---------------------------------------------------------*/
  1737. forward: function(p) {
  1738. var lon=p.x;
  1739. var lat=p.y;
  1740. var dlon = Proj4js.common.adjust_lon(lon - this.long0);
  1741. var x = this.x0 +this. a * dlon *Math.cos(this.lat0);
  1742. var y = this.y0 + this.a * lat;
  1743. this.t1=x;
  1744. this.t2=Math.cos(this.lat0);
  1745. p.x=x;
  1746. p.y=y;
  1747. return p;
  1748. }, //equiFwd()
  1749. /* Equirectangular inverse equations--mapping x,y to lat/long
  1750. ---------------------------------------------------------*/
  1751. inverse: function(p) {
  1752. p.x -= this.x0;
  1753. p.y -= this.y0;
  1754. var lat = p.y /this. a;
  1755. if ( Math.abs(lat) > Proj4js.common.HALF_PI) {
  1756. Proj4js.reportError("equi:Inv:DataError");
  1757. }
  1758. var lon = Proj4js.common.adjust_lon(this.long0 + p.x / (this.a * Math.cos(this.lat0)));
  1759. p.x=lon;
  1760. p.y=lat;
  1761. }//equiInv()
  1762. };
  1763. /* ======================================================================
  1764. projCode/merc.js
  1765. ====================================================================== */
  1766. /*******************************************************************************
  1767. NAME MERCATOR
  1768. PURPOSE: Transforms input longitude and latitude to Easting and
  1769. Northing for the Mercator projection. The
  1770. longitude and latitude must be in radians. The Easting
  1771. and Northing values will be returned in meters.
  1772. PROGRAMMER DATE
  1773. ---------- ----
  1774. D. Steinwand, EROS Nov, 1991
  1775. T. Mittan Mar, 1993
  1776. ALGORITHM REFERENCES
  1777. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  1778. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  1779. State Government Printing Office, Washington D.C., 1987.
  1780. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  1781. U.S. Geological Survey Professional Paper 1453 , United State Government
  1782. Printing Office, Washington D.C., 1989.
  1783. *******************************************************************************/
  1784. //static double r_major = a; /* major axis */
  1785. //static double r_minor = b; /* minor axis */
  1786. //static double lon_center = long0; /* Center longitude (projection center) */
  1787. //static double lat_origin = lat0; /* center latitude */
  1788. //static double e,es; /* eccentricity constants */
  1789. //static double m1; /* small value m */
  1790. //static double false_northing = y0; /* y offset in meters */
  1791. //static double false_easting = x0; /* x offset in meters */
  1792. //scale_fact = k0
  1793. Proj4js.Proj.merc = {
  1794. init : function() {
  1795. //?this.temp = this.r_minor / this.r_major;
  1796. //this.temp = this.b / this.a;
  1797. //this.es = 1.0 - Math.sqrt(this.temp);
  1798. //this.e = Math.sqrt( this.es );
  1799. //?this.m1 = Math.cos(this.lat_origin) / (Math.sqrt( 1.0 - this.es * Math.sin(this.lat_origin) * Math.sin(this.lat_origin)));
  1800. //this.m1 = Math.cos(0.0) / (Math.sqrt( 1.0 - this.es * Math.sin(0.0) * Math.sin(0.0)));
  1801. if (this.lat_ts) {
  1802. if (this.sphere) {
  1803. this.k0 = Math.cos(this.lat_ts);
  1804. } else {
  1805. this.k0 = Proj4js.common.msfnz(this.es, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
  1806. }
  1807. }
  1808. },
  1809. /* Mercator forward equations--mapping lat,long to x,y
  1810. --------------------------------------------------*/
  1811. forward : function(p) {
  1812. //alert("ll2m coords : "+coords);
  1813. var lon = p.x;
  1814. var lat = p.y;
  1815. // convert to radians
  1816. if ( lat*Proj4js.common.R2D > 90.0 &&
  1817. lat*Proj4js.common.R2D < -90.0 &&
  1818. lon*Proj4js.common.R2D > 180.0 &&
  1819. lon*Proj4js.common.R2D < -180.0) {
  1820. Proj4js.reportError("merc:forward: llInputOutOfRange: "+ lon +" : " + lat);
  1821. return null;
  1822. }
  1823. var x,y;
  1824. if(Math.abs( Math.abs(lat) - Proj4js.common.HALF_PI) <= Proj4js.common.EPSLN) {
  1825. Proj4js.reportError("merc:forward: ll2mAtPoles");
  1826. return null;
  1827. } else {
  1828. if (this.sphere) {
  1829. x = this.x0 + this.a * this.k0 * Proj4js.common.adjust_lon(lon - this.long0);
  1830. y = this.y0 + this.a * this.k0 * Math.log(Math.tan(Proj4js.common.FORTPI + 0.5*lat));
  1831. } else {
  1832. var sinphi = Math.sin(lat);
  1833. var ts = Proj4js.common.tsfnz(this.e,lat,sinphi);
  1834. x = this.x0 + this.a * this.k0 * Proj4js.common.adjust_lon(lon - this.long0);
  1835. y = this.y0 - this.a * this.k0 * Math.log(ts);
  1836. }
  1837. p.x = x;
  1838. p.y = y;
  1839. return p;
  1840. }
  1841. },
  1842. /* Mercator inverse equations--mapping x,y to lat/long
  1843. --------------------------------------------------*/
  1844. inverse : function(p) {
  1845. var x = p.x - this.x0;
  1846. var y = p.y - this.y0;
  1847. var lon,lat;
  1848. if (this.sphere) {
  1849. lat = Proj4js.common.HALF_PI - 2.0 * Math.atan(Math.exp(-y / this.a * this.k0));
  1850. } else {
  1851. var ts = Math.exp(-y / (this.a * this.k0));
  1852. lat = Proj4js.common.phi2z(this.e,ts);
  1853. if(lat == -9999) {
  1854. Proj4js.reportError("merc:inverse: lat = -9999");
  1855. return null;
  1856. }
  1857. }
  1858. lon = Proj4js.common.adjust_lon(this.long0+ x / (this.a * this.k0));
  1859. p.x = lon;
  1860. p.y = lat;
  1861. return p;
  1862. }
  1863. };
  1864. /* ======================================================================
  1865. projCode/utm.js
  1866. ====================================================================== */
  1867. /*******************************************************************************
  1868. NAME TRANSVERSE MERCATOR
  1869. PURPOSE: Transforms input longitude and latitude to Easting and
  1870. Northing for the Transverse Mercator projection. The
  1871. longitude and latitude must be in radians. The Easting
  1872. and Northing values will be returned in meters.
  1873. ALGORITHM REFERENCES
  1874. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  1875. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  1876. State Government Printing Office, Washington D.C., 1987.
  1877. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  1878. U.S. Geological Survey Professional Paper 1453 , United State Government
  1879. Printing Office, Washington D.C., 1989.
  1880. *******************************************************************************/
  1881. /**
  1882. Initialize Transverse Mercator projection
  1883. */
  1884. Proj4js.Proj.utm = {
  1885. dependsOn : 'tmerc',
  1886. init : function() {
  1887. if (!this.zone) {
  1888. Proj4js.reportError("utm:init: zone must be specified for UTM");
  1889. return;
  1890. }
  1891. this.lat0 = 0.0;
  1892. this.long0 = ((6 * Math.abs(this.zone)) - 183) * Proj4js.common.D2R;
  1893. this.x0 = 500000.0;
  1894. this.y0 = this.utmSouth ? 10000000.0 : 0.0;
  1895. this.k0 = 0.9996;
  1896. Proj4js.Proj['tmerc'].init.apply(this);
  1897. this.forward = Proj4js.Proj['tmerc'].forward;
  1898. this.inverse = Proj4js.Proj['tmerc'].inverse;
  1899. }
  1900. };
  1901. /* ======================================================================
  1902. projCode/eqdc.js
  1903. ====================================================================== */
  1904. /*******************************************************************************
  1905. NAME EQUIDISTANT CONIC
  1906. PURPOSE: Transforms input longitude and latitude to Easting and Northing
  1907. for the Equidistant Conic projection. The longitude and
  1908. latitude must be in radians. The Easting and Northing values
  1909. will be returned in meters.
  1910. PROGRAMMER DATE
  1911. ---------- ----
  1912. T. Mittan Mar, 1993
  1913. ALGORITHM REFERENCES
  1914. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  1915. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  1916. State Government Printing Office, Washington D.C., 1987.
  1917. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  1918. U.S. Geological Survey Professional Paper 1453 , United State Government
  1919. Printing Office, Washington D.C., 1989.
  1920. *******************************************************************************/
  1921. /* Variables common to all subroutines in this code file
  1922. -----------------------------------------------------*/
  1923. Proj4js.Proj.eqdc = {
  1924. /* Initialize the Equidistant Conic projection
  1925. ------------------------------------------*/
  1926. init: function() {
  1927. /* Place parameters in static storage for common use
  1928. -------------------------------------------------*/
  1929. if(!this.mode) this.mode=0;//chosen default mode
  1930. this.temp = this.b / this.a;
  1931. this.es = 1.0 - Math.pow(this.temp,2);
  1932. this.e = Math.sqrt(this.es);
  1933. this.e0 = Proj4js.common.e0fn(this.es);
  1934. this.e1 = Proj4js.common.e1fn(this.es);
  1935. this.e2 = Proj4js.common.e2fn(this.es);
  1936. this.e3 = Proj4js.common.e3fn(this.es);
  1937. this.sinphi=Math.sin(this.lat1);
  1938. this.cosphi=Math.cos(this.lat1);
  1939. this.ms1 = Proj4js.common.msfnz(this.e,this.sinphi,this.cosphi);
  1940. this.ml1 = Proj4js.common.mlfn(this.e0, this.e1, this.e2,this.e3, this.lat1);
  1941. /* format B
  1942. ---------*/
  1943. if (this.mode != 0) {
  1944. if (Math.abs(this.lat1 + this.lat2) < Proj4js.common.EPSLN) {
  1945. Proj4js.reportError("eqdc:Init:EqualLatitudes");
  1946. //return(81);
  1947. }
  1948. this.sinphi=Math.sin(this.lat2);
  1949. this.cosphi=Math.cos(this.lat2);
  1950. this.ms2 = Proj4js.common.msfnz(this.e,this.sinphi,this.cosphi);
  1951. this.ml2 = Proj4js.common.mlfn(this.e0, this.e1, this.e2, this.e3, this.lat2);
  1952. if (Math.abs(this.lat1 - this.lat2) >= Proj4js.common.EPSLN) {
  1953. this.ns = (this.ms1 - this.ms2) / (this.ml2 - this.ml1);
  1954. } else {
  1955. this.ns = this.sinphi;
  1956. }
  1957. } else {
  1958. this.ns = this.sinphi;
  1959. }
  1960. this.g = this.ml1 + this.ms1/this.ns;
  1961. this.ml0 = Proj4js.common.mlfn(this.e0, this.e1,this. e2, this.e3, this.lat0);
  1962. this.rh = this.a * (this.g - this.ml0);
  1963. },
  1964. /* Equidistant Conic forward equations--mapping lat,long to x,y
  1965. -----------------------------------------------------------*/
  1966. forward: function(p) {
  1967. var lon=p.x;
  1968. var lat=p.y;
  1969. /* Forward equations
  1970. -----------------*/
  1971. var ml = Proj4js.common.mlfn(this.e0, this.e1, this.e2, this.e3, lat);
  1972. var rh1 = this.a * (this.g - ml);
  1973. var theta = this.ns * Proj4js.common.adjust_lon(lon - this.long0);
  1974. var x = this.x0 + rh1 * Math.sin(theta);
  1975. var y = this.y0 + this.rh - rh1 * Math.cos(theta);
  1976. p.x=x;
  1977. p.y=y;
  1978. return p;
  1979. },
  1980. /* Inverse equations
  1981. -----------------*/
  1982. inverse: function(p) {
  1983. p.x -= this.x0;
  1984. p.y = this.rh - p.y + this.y0;
  1985. var con, rh1;
  1986. if (this.ns >= 0) {
  1987. var rh1 = Math.sqrt(p.x *p.x + p.y * p.y);
  1988. var con = 1.0;
  1989. } else {
  1990. rh1 = -Math.sqrt(p.x *p. x +p. y * p.y);
  1991. con = -1.0;
  1992. }
  1993. var theta = 0.0;
  1994. if (rh1 != 0.0) theta = Math.atan2(con *p.x, con *p.y);
  1995. var ml = this.g - rh1 /this.a;
  1996. var lat = this.phi3z(this.ml,this.e0,this.e1,this.e2,this.e3);
  1997. var lon = Proj4js.common.adjust_lon(this.long0 + theta / this.ns);
  1998. p.x=lon;
  1999. p.y=lat;
  2000. return p;
  2001. },
  2002. /* Function to compute latitude, phi3, for the inverse of the Equidistant
  2003. Conic projection.
  2004. -----------------------------------------------------------------*/
  2005. phi3z: function(ml,e0,e1,e2,e3) {
  2006. var phi;
  2007. var dphi;
  2008. phi = ml;
  2009. for (var i = 0; i < 15; i++) {
  2010. dphi = (ml + e1 * Math.sin(2.0 * phi) - e2 * Math.sin(4.0 * phi) + e3 * Math.sin(6.0 * phi))/ e0 - phi;
  2011. phi += dphi;
  2012. if (Math.abs(dphi) <= .0000000001) {
  2013. return phi;
  2014. }
  2015. }
  2016. Proj4js.reportError("PHI3Z-CONV:Latitude failed to converge after 15 iterations");
  2017. return null;
  2018. }
  2019. };
  2020. /* ======================================================================
  2021. projCode/tmerc.js
  2022. ====================================================================== */
  2023. /*******************************************************************************
  2024. NAME TRANSVERSE MERCATOR
  2025. PURPOSE: Transforms input longitude and latitude to Easting and
  2026. Northing for the Transverse Mercator projection. The
  2027. longitude and latitude must be in radians. The Easting
  2028. and Northing values will be returned in meters.
  2029. ALGORITHM REFERENCES
  2030. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  2031. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  2032. State Government Printing Office, Washington D.C., 1987.
  2033. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  2034. U.S. Geological Survey Professional Paper 1453 , United State Government
  2035. Printing Office, Washington D.C., 1989.
  2036. *******************************************************************************/
  2037. /**
  2038. Initialize Transverse Mercator projection
  2039. */
  2040. Proj4js.Proj.tmerc = {
  2041. init : function() {
  2042. this.e0 = Proj4js.common.e0fn(this.es);
  2043. this.e1 = Proj4js.common.e1fn(this.es);
  2044. this.e2 = Proj4js.common.e2fn(this.es);
  2045. this.e3 = Proj4js.common.e3fn(this.es);
  2046. this.ml0 = this.a * Proj4js.common.mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
  2047. },
  2048. /**
  2049. Transverse Mercator Forward - long/lat to x/y
  2050. long/lat in radians
  2051. */
  2052. forward : function(p) {
  2053. var lon = p.x;
  2054. var lat = p.y;
  2055. var delta_lon = Proj4js.common.adjust_lon(lon - this.long0); // Delta longitude
  2056. var con; // cone constant
  2057. var x, y;
  2058. var sin_phi=Math.sin(lat);
  2059. var cos_phi=Math.cos(lat);
  2060. if (this.sphere) { /* spherical form */
  2061. var b = cos_phi * Math.sin(delta_lon);
  2062. if ((Math.abs(Math.abs(b) - 1.0)) < .0000000001) {
  2063. Proj4js.reportError("tmerc:forward: Point projects into infinity");
  2064. return(93);
  2065. } else {
  2066. x = .5 * this.a * this.k0 * Math.log((1.0 + b)/(1.0 - b));
  2067. con = Math.acos(cos_phi * Math.cos(delta_lon)/Math.sqrt(1.0 - b*b));
  2068. if (lat < 0) con = - con;
  2069. y = this.a * this.k0 * (con - this.lat0);
  2070. }
  2071. } else {
  2072. var al = cos_phi * delta_lon;
  2073. var als = Math.pow(al,2);
  2074. var c = this.ep2 * Math.pow(cos_phi,2);
  2075. var tq = Math.tan(lat);
  2076. var t = Math.pow(tq,2);
  2077. con = 1.0 - this.es * Math.pow(sin_phi,2);
  2078. var n = this.a / Math.sqrt(con);
  2079. var ml = this.a * Proj4js.common.mlfn(this.e0, this.e1, this.e2, this.e3, lat);
  2080. x = this.k0 * n * al * (1.0 + als / 6.0 * (1.0 - t + c + als / 20.0 * (5.0 - 18.0 * t + Math.pow(t,2) + 72.0 * c - 58.0 * this.ep2))) + this.x0;
  2081. y = this.k0 * (ml - this.ml0 + n * tq * (als * (0.5 + als / 24.0 * (5.0 - t + 9.0 * c + 4.0 * Math.pow(c,2) + als / 30.0 * (61.0 - 58.0 * t + Math.pow(t,2) + 600.0 * c - 330.0 * this.ep2))))) + this.y0;
  2082. }
  2083. p.x = x; p.y = y;
  2084. return p;
  2085. }, // tmercFwd()
  2086. /**
  2087. Transverse Mercator Inverse - x/y to long/lat
  2088. */
  2089. inverse : function(p) {
  2090. var con, phi; /* temporary angles */
  2091. var delta_phi; /* difference between longitudes */
  2092. var i;
  2093. var max_iter = 6; /* maximun number of iterations */
  2094. var lat, lon;
  2095. if (this.sphere) { /* spherical form */
  2096. var f = Math.exp(p.x/(this.a * this.k0));
  2097. var g = .5 * (f - 1/f);
  2098. var temp = this.lat0 + p.y/(this.a * this.k0);
  2099. var h = Math.cos(temp);
  2100. con = Math.sqrt((1.0 - h * h)/(1.0 + g * g));
  2101. lat = Proj4js.common.asinz(con);
  2102. if (temp < 0)
  2103. lat = -lat;
  2104. if ((g == 0) && (h == 0)) {
  2105. lon = this.long0;
  2106. } else {
  2107. lon = Proj4js.common.adjust_lon(Math.atan2(g,h) + this.long0);
  2108. }
  2109. } else { // ellipsoidal form
  2110. var x = p.x - this.x0;
  2111. var y = p.y - this.y0;
  2112. con = (this.ml0 + y / this.k0) / this.a;
  2113. phi = con;
  2114. for (i=0;true;i++) {
  2115. delta_phi=((con + this.e1 * Math.sin(2.0*phi) - this.e2 * Math.sin(4.0*phi) + this.e3 * Math.sin(6.0*phi)) / this.e0) - phi;
  2116. phi += delta_phi;
  2117. if (Math.abs(delta_phi) <= Proj4js.common.EPSLN) break;
  2118. if (i >= max_iter) {
  2119. Proj4js.reportError("tmerc:inverse: Latitude failed to converge");
  2120. return(95);
  2121. }
  2122. } // for()
  2123. if (Math.abs(phi) < Proj4js.common.HALF_PI) {
  2124. // sincos(phi, &sin_phi, &cos_phi);
  2125. var sin_phi=Math.sin(phi);
  2126. var cos_phi=Math.cos(phi);
  2127. var tan_phi = Math.tan(phi);
  2128. var c = this.ep2 * Math.pow(cos_phi,2);
  2129. var cs = Math.pow(c,2);
  2130. var t = Math.pow(tan_phi,2);
  2131. var ts = Math.pow(t,2);
  2132. con = 1.0 - this.es * Math.pow(sin_phi,2);
  2133. var n = this.a / Math.sqrt(con);
  2134. var r = n * (1.0 - this.es) / con;
  2135. var d = x / (n * this.k0);
  2136. var ds = Math.pow(d,2);
  2137. lat = phi - (n * tan_phi * ds / r) * (0.5 - ds / 24.0 * (5.0 + 3.0 * t + 10.0 * c - 4.0 * cs - 9.0 * this.ep2 - ds / 30.0 * (61.0 + 90.0 * t + 298.0 * c + 45.0 * ts - 252.0 * this.ep2 - 3.0 * cs)));
  2138. lon = Proj4js.common.adjust_lon(this.long0 + (d * (1.0 - ds / 6.0 * (1.0 + 2.0 * t + c - ds / 20.0 * (5.0 - 2.0 * c + 28.0 * t - 3.0 * cs + 8.0 * this.ep2 + 24.0 * ts))) / cos_phi));
  2139. } else {
  2140. lat = Proj4js.common.HALF_PI * Proj4js.common.sign(y);
  2141. lon = this.long0;
  2142. }
  2143. }
  2144. p.x = lon;
  2145. p.y = lat;
  2146. return p;
  2147. } // tmercInv()
  2148. };
  2149. /* ======================================================================
  2150. defs/GOOGLE.js
  2151. ====================================================================== */
  2152. Proj4js.defs["GOOGLE"]="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs";
  2153. Proj4js.defs["EPSG:900913"]=Proj4js.defs["GOOGLE"];
  2154. /* ======================================================================
  2155. projCode/gstmerc.js
  2156. ====================================================================== */
  2157. Proj4js.Proj.gstmerc = {
  2158. init : function() {
  2159. // array of: a, b, lon0, lat0, k0, x0, y0
  2160. var temp= this.b / this.a;
  2161. this.e= Math.sqrt(1.0 - temp*temp);
  2162. this.lc= this.long0;
  2163. this.rs= Math.sqrt(1.0+this.e*this.e*Math.pow(Math.cos(this.lat0),4.0)/(1.0-this.e*this.e));
  2164. var sinz= Math.sin(this.lat0);
  2165. var pc= Math.asin(sinz/this.rs);
  2166. var sinzpc= Math.sin(pc);
  2167. this.cp= Proj4js.common.latiso(0.0,pc,sinzpc)-this.rs*Proj4js.common.latiso(this.e,this.lat0,sinz);
  2168. this.n2= this.k0*this.a*Math.sqrt(1.0-this.e*this.e)/(1.0-this.e*this.e*sinz*sinz);
  2169. this.xs= this.x0;
  2170. this.ys= this.y0-this.n2*pc;
  2171. if (!this.title) this.title = "Gauss Schreiber transverse mercator";
  2172. },
  2173. // forward equations--mapping lat,long to x,y
  2174. // -----------------------------------------------------------------
  2175. forward : function(p) {
  2176. var lon= p.x;
  2177. var lat= p.y;
  2178. var L= this.rs*(lon-this.lc);
  2179. var Ls= this.cp+(this.rs*Proj4js.common.latiso(this.e,lat,Math.sin(lat)));
  2180. var lat1= Math.asin(Math.sin(L)/Proj4js.common.cosh(Ls));
  2181. var Ls1= Proj4js.common.latiso(0.0,lat1,Math.sin(lat1));
  2182. p.x= this.xs+(this.n2*Ls1);
  2183. p.y= this.ys+(this.n2*Math.atan(Proj4js.common.sinh(Ls)/Math.cos(L)));
  2184. return p;
  2185. },
  2186. // inverse equations--mapping x,y to lat/long
  2187. // -----------------------------------------------------------------
  2188. inverse : function(p) {
  2189. var x= p.x;
  2190. var y= p.y;
  2191. var L= Math.atan(Proj4js.common.sinh((x-this.xs)/this.n2)/Math.cos((y-this.ys)/this.n2));
  2192. var lat1= Math.asin(Math.sin((y-this.ys)/this.n2)/Proj4js.common.cosh((x-this.xs)/this.n2));
  2193. var LC= Proj4js.common.latiso(0.0,lat1,Math.sin(lat1));
  2194. p.x= this.lc+L/this.rs;
  2195. p.y= Proj4js.common.invlatiso(this.e,(LC-this.cp)/this.rs);
  2196. return p;
  2197. }
  2198. };
  2199. /* ======================================================================
  2200. projCode/ortho.js
  2201. ====================================================================== */
  2202. /*******************************************************************************
  2203. NAME ORTHOGRAPHIC
  2204. PURPOSE: Transforms input longitude and latitude to Easting and
  2205. Northing for the Orthographic projection. The
  2206. longitude and latitude must be in radians. The Easting
  2207. and Northing values will be returned in meters.
  2208. PROGRAMMER DATE
  2209. ---------- ----
  2210. T. Mittan Mar, 1993
  2211. ALGORITHM REFERENCES
  2212. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  2213. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  2214. State Government Printing Office, Washington D.C., 1987.
  2215. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  2216. U.S. Geological Survey Professional Paper 1453 , United State Government
  2217. Printing Office, Washington D.C., 1989.
  2218. *******************************************************************************/
  2219. Proj4js.Proj.ortho = {
  2220. /* Initialize the Orthographic projection
  2221. -------------------------------------*/
  2222. init: function(def) {
  2223. //double temp; /* temporary variable */
  2224. /* Place parameters in static storage for common use
  2225. -------------------------------------------------*/;
  2226. this.sin_p14=Math.sin(this.lat0);
  2227. this.cos_p14=Math.cos(this.lat0);
  2228. },
  2229. /* Orthographic forward equations--mapping lat,long to x,y
  2230. ---------------------------------------------------*/
  2231. forward: function(p) {
  2232. var sinphi, cosphi; /* sin and cos value */
  2233. var dlon; /* delta longitude value */
  2234. var coslon; /* cos of longitude */
  2235. var ksp; /* scale factor */
  2236. var g;
  2237. var lon=p.x;
  2238. var lat=p.y;
  2239. /* Forward equations
  2240. -----------------*/
  2241. dlon = Proj4js.common.adjust_lon(lon - this.long0);
  2242. sinphi=Math.sin(lat);
  2243. cosphi=Math.cos(lat);
  2244. coslon = Math.cos(dlon);
  2245. g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
  2246. ksp = 1.0;
  2247. if ((g > 0) || (Math.abs(g) <= Proj4js.common.EPSLN)) {
  2248. var x = this.a * ksp * cosphi * Math.sin(dlon);
  2249. var y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
  2250. } else {
  2251. Proj4js.reportError("orthoFwdPointError");
  2252. }
  2253. p.x=x;
  2254. p.y=y;
  2255. return p;
  2256. },
  2257. inverse: function(p) {
  2258. var rh; /* height above ellipsoid */
  2259. var z; /* angle */
  2260. var sinz,cosz; /* sin of z and cos of z */
  2261. var temp;
  2262. var con;
  2263. var lon , lat;
  2264. /* Inverse equations
  2265. -----------------*/
  2266. p.x -= this.x0;
  2267. p.y -= this.y0;
  2268. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  2269. if (rh > this.a + .0000001) {
  2270. Proj4js.reportError("orthoInvDataError");
  2271. }
  2272. z = Proj4js.common.asinz(rh / this.a);
  2273. sinz=Math.sin(z);
  2274. cosz=Math.cos(z);
  2275. lon = this.long0;
  2276. if (Math.abs(rh) <= Proj4js.common.EPSLN) {
  2277. lat = this.lat0;
  2278. }
  2279. lat = Proj4js.common.asinz(cosz * this.sin_p14 + (p.y * sinz * this.cos_p14)/rh);
  2280. con = Math.abs(lat0) - Proj4js.common.HALF_PI;
  2281. if (Math.abs(con) <= Proj4js.common.EPSLN) {
  2282. if (this.lat0 >= 0) {
  2283. lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2(p.x, -p.y));
  2284. } else {
  2285. lon = Proj4js.common.adjust_lon(this.long0 -Math.atan2(-p.x, p.y));
  2286. }
  2287. }
  2288. con = cosz - this.sin_p14 * Math.sin(lat);
  2289. if ((Math.abs(con) >= Proj4js.common.EPSLN) || (Math.abs(x) >= Proj4js.common.EPSLN)) {
  2290. lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p14), (con * rh)));
  2291. }
  2292. p.x=lon;
  2293. p.y=lat;
  2294. return p;
  2295. }
  2296. };
  2297. /* ======================================================================
  2298. projCode/somerc.js
  2299. ====================================================================== */
  2300. /*******************************************************************************
  2301. NAME SWISS OBLIQUE MERCATOR
  2302. PURPOSE: Swiss projection.
  2303. WARNING: X and Y are inverted (weird) in the swiss coordinate system. Not
  2304. here, since we want X to be horizontal and Y vertical.
  2305. ALGORITHM REFERENCES
  2306. 1. "Formules et constantes pour le Calcul pour la
  2307. projection cylindrique conforme ?  axe oblique et pour la transformation entre
  2308. des syst?¨mes de r?Šf?Šrence".
  2309. http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey/sys/refsys/switzerland.parsysrelated1.31216.downloadList.77004.DownloadFile.tmp/swissprojectionfr.pdf
  2310. *******************************************************************************/
  2311. Proj4js.Proj.somerc = {
  2312. init: function() {
  2313. var phy0 = this.lat0;
  2314. this.lambda0 = this.long0;
  2315. var sinPhy0 = Math.sin(phy0);
  2316. var semiMajorAxis = this.a;
  2317. var invF = this.rf;
  2318. var flattening = 1 / invF;
  2319. var e2 = 2 * flattening - Math.pow(flattening, 2);
  2320. var e = this.e = Math.sqrt(e2);
  2321. this.R = semiMajorAxis * Math.sqrt(1 - e2) / (1 - e2 * Math.pow(sinPhy0, 2.0));
  2322. this.alpha = Math.sqrt(1 + e2 / (1 - e2) * Math.pow(Math.cos(phy0), 4.0));
  2323. this.b0 = Math.asin(sinPhy0 / this.alpha);
  2324. this.K = Math.log(Math.tan(Math.PI / 4.0 + this.b0 / 2.0))
  2325. - this.alpha
  2326. * Math.log(Math.tan(Math.PI / 4.0 + phy0 / 2.0))
  2327. + this.alpha
  2328. * e / 2
  2329. * Math.log((1 + e * sinPhy0)
  2330. / (1 - e * sinPhy0));
  2331. },
  2332. forward: function(p) {
  2333. var Sa1 = Math.log(Math.tan(Math.PI / 4.0 - p.y / 2.0));
  2334. var Sa2 = this.e / 2.0
  2335. * Math.log((1 + this.e * Math.sin(p.y))
  2336. / (1 - this.e * Math.sin(p.y)));
  2337. var S = -this.alpha * (Sa1 + Sa2) + this.K;
  2338. // spheric latitude
  2339. var b = 2.0 * (Math.atan(Math.exp(S)) - Math.PI / 4.0);
  2340. // spheric longitude
  2341. var I = this.alpha * (p.x - this.lambda0);
  2342. // psoeudo equatorial rotation
  2343. var rotI = Math.atan(Math.sin(I)
  2344. / (Math.sin(this.b0) * Math.tan(b) +
  2345. Math.cos(this.b0) * Math.cos(I)));
  2346. var rotB = Math.asin(Math.cos(this.b0) * Math.sin(b) -
  2347. Math.sin(this.b0) * Math.cos(b) * Math.cos(I));
  2348. p.y = this.R / 2.0
  2349. * Math.log((1 + Math.sin(rotB)) / (1 - Math.sin(rotB)))
  2350. + this.y0;
  2351. p.x = this.R * rotI + this.x0;
  2352. return p;
  2353. },
  2354. inverse: function(p) {
  2355. var Y = p.x - this.x0;
  2356. var X = p.y - this.y0;
  2357. var rotI = Y / this.R;
  2358. var rotB = 2 * (Math.atan(Math.exp(X / this.R)) - Math.PI / 4.0);
  2359. var b = Math.asin(Math.cos(this.b0) * Math.sin(rotB)
  2360. + Math.sin(this.b0) * Math.cos(rotB) * Math.cos(rotI));
  2361. var I = Math.atan(Math.sin(rotI)
  2362. / (Math.cos(this.b0) * Math.cos(rotI) - Math.sin(this.b0)
  2363. * Math.tan(rotB)));
  2364. var lambda = this.lambda0 + I / this.alpha;
  2365. var S = 0.0;
  2366. var phy = b;
  2367. var prevPhy = -1000.0;
  2368. var iteration = 0;
  2369. while (Math.abs(phy - prevPhy) > 0.0000001)
  2370. {
  2371. if (++iteration > 20)
  2372. {
  2373. Proj4js.reportError("omercFwdInfinity");
  2374. return;
  2375. }
  2376. //S = Math.log(Math.tan(Math.PI / 4.0 + phy / 2.0));
  2377. S = 1.0
  2378. / this.alpha
  2379. * (Math.log(Math.tan(Math.PI / 4.0 + b / 2.0)) - this.K)
  2380. + this.e
  2381. * Math.log(Math.tan(Math.PI / 4.0
  2382. + Math.asin(this.e * Math.sin(phy))
  2383. / 2.0));
  2384. prevPhy = phy;
  2385. phy = 2.0 * Math.atan(Math.exp(S)) - Math.PI / 2.0;
  2386. }
  2387. p.x = lambda;
  2388. p.y = phy;
  2389. return p;
  2390. }
  2391. };
  2392. /* ======================================================================
  2393. projCode/stere.js
  2394. ====================================================================== */
  2395. // Initialize the Stereographic projection
  2396. Proj4js.Proj.stere = {
  2397. ssfn_: function(phit, sinphi, eccen) {
  2398. sinphi *= eccen;
  2399. return (Math.tan (.5 * (Proj4js.common.HALF_PI + phit)) * Math.pow((1. - sinphi) / (1. + sinphi), .5 * eccen));
  2400. },
  2401. TOL: 1.e-8,
  2402. NITER: 8,
  2403. CONV: 1.e-10,
  2404. S_POLE: 0,
  2405. N_POLE: 1,
  2406. OBLIQ: 2,
  2407. EQUIT: 3,
  2408. init : function() {
  2409. this.phits = this.lat_ts ? this.lat_ts : Proj4js.common.HALF_PI;
  2410. var t = Math.abs(this.lat0);
  2411. if ((Math.abs(t) - Proj4js.common.HALF_PI) < Proj4js.common.EPSLN) {
  2412. this.mode = this.lat0 < 0. ? this.S_POLE : this.N_POLE;
  2413. } else {
  2414. this.mode = t > Proj4js.common.EPSLN ? this.OBLIQ : this.EQUIT;
  2415. }
  2416. this.phits = Math.abs(this.phits);
  2417. if (this.es) {
  2418. var X;
  2419. switch (this.mode) {
  2420. case this.N_POLE:
  2421. case this.S_POLE:
  2422. if (Math.abs(this.phits - Proj4js.common.HALF_PI) < Proj4js.common.EPSLN) {
  2423. this.akm1 = 2. * this.k0 / Math.sqrt(Math.pow(1+this.e,1+this.e)*Math.pow(1-this.e,1-this.e));
  2424. } else {
  2425. t = Math.sin(this.phits);
  2426. this.akm1 = Math.cos(this.phits) / Proj4js.common.tsfnz(this.e, this.phits, t);
  2427. t *= this.e;
  2428. this.akm1 /= Math.sqrt(1. - t * t);
  2429. }
  2430. break;
  2431. case this.EQUIT:
  2432. this.akm1 = 2. * this.k0;
  2433. break;
  2434. case this.OBLIQ:
  2435. t = Math.sin(this.lat0);
  2436. X = 2. * Math.atan(this.ssfn_(this.lat0, t, this.e)) - Proj4js.common.HALF_PI;
  2437. t *= this.e;
  2438. this.akm1 = 2. * this.k0 * Math.cos(this.lat0) / Math.sqrt(1. - t * t);
  2439. this.sinX1 = Math.sin(X);
  2440. this.cosX1 = Math.cos(X);
  2441. break;
  2442. }
  2443. } else {
  2444. switch (this.mode) {
  2445. case this.OBLIQ:
  2446. this.sinph0 = Math.sin(this.lat0);
  2447. this.cosph0 = Math.cos(this.lat0);
  2448. case this.EQUIT:
  2449. this.akm1 = 2. * this.k0;
  2450. break;
  2451. case this.S_POLE:
  2452. case this.N_POLE:
  2453. this.akm1 = Math.abs(this.phits - Proj4js.common.HALF_PI) >= Proj4js.common.EPSLN ?
  2454. Math.cos(this.phits) / Math.tan(Proj4js.common.FORTPI - .5 * this.phits) :
  2455. 2. * this.k0 ;
  2456. break;
  2457. }
  2458. }
  2459. },
  2460. // Stereographic forward equations--mapping lat,long to x,y
  2461. forward: function(p) {
  2462. var lon = p.x;
  2463. lon = Proj4js.common.adjust_lon(lon - this.long0);
  2464. var lat = p.y;
  2465. var x, y;
  2466. if (this.sphere) {
  2467. var sinphi, cosphi, coslam, sinlam;
  2468. sinphi = Math.sin(lat);
  2469. cosphi = Math.cos(lat);
  2470. coslam = Math.cos(lon);
  2471. sinlam = Math.sin(lon);
  2472. switch (this.mode) {
  2473. case this.EQUIT:
  2474. y = 1. + cosphi * coslam;
  2475. if (y <= Proj4js.common.EPSLN) {
  2476. F_ERROR;
  2477. }
  2478. y = this.akm1 / y;
  2479. x = y * cosphi * sinlam;
  2480. y *= sinphi;
  2481. break;
  2482. case this.OBLIQ:
  2483. y = 1. + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
  2484. if (y <= Proj4js.common.EPSLN) {
  2485. F_ERROR;
  2486. }
  2487. y = this.akm1 / y;
  2488. x = y * cosphi * sinlam;
  2489. y *= this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
  2490. break;
  2491. case this.N_POLE:
  2492. coslam = -coslam;
  2493. lat = -lat;
  2494. //Note no break here so it conitnues through S_POLE
  2495. case this.S_POLE:
  2496. if (Math.abs(lat - Proj4js.common.HALF_PI) < this.TOL) {
  2497. F_ERROR;
  2498. }
  2499. y = this.akm1 * Math.tan(Proj4js.common.FORTPI + .5 * lat);
  2500. x = sinlam * y;
  2501. y *= coslam;
  2502. break;
  2503. }
  2504. } else {
  2505. coslam = Math.cos(lon);
  2506. sinlam = Math.sin(lon);
  2507. sinphi = Math.sin(lat);
  2508. if (this.mode == this.OBLIQ || this.mode == this.EQUIT) {
  2509. X = 2. * Math.atan(this.ssfn_(lat, sinphi, this.e));
  2510. sinX = Math.sin(X - Proj4js.common.HALF_PI);
  2511. cosX = Math.cos(X);
  2512. }
  2513. switch (this.mode) {
  2514. case this.OBLIQ:
  2515. A = this.akm1 / (this.cosX1 * (1. + this.sinX1 * sinX + this.cosX1 * cosX * coslam));
  2516. y = A * (this.cosX1 * sinX - this.sinX1 * cosX * coslam);
  2517. x = A * cosX;
  2518. break;
  2519. case this.EQUIT:
  2520. A = 2. * this.akm1 / (1. + cosX * coslam);
  2521. y = A * sinX;
  2522. x = A * cosX;
  2523. break;
  2524. case this.S_POLE:
  2525. lat = -lat;
  2526. coslam = - coslam;
  2527. sinphi = -sinphi;
  2528. case this.N_POLE:
  2529. x = this.akm1 * Proj4js.common.tsfnz(this.e, lat, sinphi);
  2530. y = - x * coslam;
  2531. break;
  2532. }
  2533. x = x * sinlam;
  2534. }
  2535. p.x = x*this.a + this.x0;
  2536. p.y = y*this.a + this.y0;
  2537. return p;
  2538. },
  2539. //* Stereographic inverse equations--mapping x,y to lat/long
  2540. inverse: function(p) {
  2541. var x = (p.x - this.x0)/this.a; /* descale and de-offset */
  2542. var y = (p.y - this.y0)/this.a;
  2543. var lon, lat;
  2544. var cosphi, sinphi, tp=0.0, phi_l=0.0, rho, halfe=0.0, pi2=0.0;
  2545. var i;
  2546. if (this.sphere) {
  2547. var c, rh, sinc, cosc;
  2548. rh = Math.sqrt(x*x + y*y);
  2549. c = 2. * Math.atan(rh / this.akm1);
  2550. sinc = Math.sin(c);
  2551. cosc = Math.cos(c);
  2552. lon = 0.;
  2553. switch (this.mode) {
  2554. case this.EQUIT:
  2555. if (Math.abs(rh) <= Proj4js.common.EPSLN) {
  2556. lat = 0.;
  2557. } else {
  2558. lat = Math.asin(y * sinc / rh);
  2559. }
  2560. if (cosc != 0. || x != 0.) lon = Math.atan2(x * sinc, cosc * rh);
  2561. break;
  2562. case this.OBLIQ:
  2563. if (Math.abs(rh) <= Proj4js.common.EPSLN) {
  2564. lat = this.phi0;
  2565. } else {
  2566. lat = Math.asin(cosc * sinph0 + y * sinc * cosph0 / rh);
  2567. }
  2568. c = cosc - sinph0 * Math.sin(lat);
  2569. if (c != 0. || x != 0.) {
  2570. lon = Math.atan2(x * sinc * cosph0, c * rh);
  2571. }
  2572. break;
  2573. case this.N_POLE:
  2574. y = -y;
  2575. case this.S_POLE:
  2576. if (Math.abs(rh) <= Proj4js.common.EPSLN) {
  2577. lat = this.phi0;
  2578. } else {
  2579. lat = Math.asin(this.mode == this.S_POLE ? -cosc : cosc);
  2580. }
  2581. lon = (x == 0. && y == 0.) ? 0. : Math.atan2(x, y);
  2582. break;
  2583. }
  2584. } else {
  2585. rho = Math.sqrt(x*x + y*y);
  2586. switch (this.mode) {
  2587. case this.OBLIQ:
  2588. case this.EQUIT:
  2589. tp = 2. * Math.atan2(rho * this.cosX1 , this.akm1);
  2590. cosphi = Math.cos(tp);
  2591. sinphi = Math.sin(tp);
  2592. if( rho == 0.0 ) {
  2593. phi_l = Math.asin(cosphi * this.sinX1);
  2594. } else {
  2595. phi_l = Math.asin(cosphi * this.sinX1 + (y * sinphi * this.cosX1 / rho));
  2596. }
  2597. tp = Math.tan(.5 * (Proj4js.common.HALF_PI + phi_l));
  2598. x *= sinphi;
  2599. y = rho * this.cosX1 * cosphi - y * this.sinX1* sinphi;
  2600. pi2 = Proj4js.common.HALF_PI;
  2601. halfe = .5 * this.e;
  2602. break;
  2603. case this.N_POLE:
  2604. y = -y;
  2605. case this.S_POLE:
  2606. tp = - rho / this.akm1;
  2607. phi_l = Proj4js.common.HALF_PI - 2. * Math.atan(tp);
  2608. pi2 = -Proj4js.common.HALF_PI;
  2609. halfe = -.5 * this.e;
  2610. break;
  2611. }
  2612. for (i = this.NITER; i--; phi_l = lat) { //check this
  2613. sinphi = this.e * Math.sin(phi_l);
  2614. lat = 2. * Math.atan(tp * Math.pow((1.+sinphi)/(1.-sinphi), halfe)) - pi2;
  2615. if (Math.abs(phi_l - lat) < this.CONV) {
  2616. if (this.mode == this.S_POLE) lat = -lat;
  2617. lon = (x == 0. && y == 0.) ? 0. : Math.atan2(x, y);
  2618. p.x = Proj4js.common.adjust_lon(lon + this.long0);
  2619. p.y = lat;
  2620. return p;
  2621. }
  2622. }
  2623. }
  2624. }
  2625. };
  2626. /* ======================================================================
  2627. projCode/nzmg.js
  2628. ====================================================================== */
  2629. /*******************************************************************************
  2630. NAME NEW ZEALAND MAP GRID
  2631. PURPOSE: Transforms input longitude and latitude to Easting and
  2632. Northing for the New Zealand Map Grid projection. The
  2633. longitude and latitude must be in radians. The Easting
  2634. and Northing values will be returned in meters.
  2635. ALGORITHM REFERENCES
  2636. 1. Department of Land and Survey Technical Circular 1973/32
  2637. http://www.linz.govt.nz/docs/miscellaneous/nz-map-definition.pdf
  2638. 2. OSG Technical Report 4.1
  2639. http://www.linz.govt.nz/docs/miscellaneous/nzmg.pdf
  2640. IMPLEMENTATION NOTES
  2641. The two references use different symbols for the calculated values. This
  2642. implementation uses the variable names similar to the symbols in reference [1].
  2643. The alogrithm uses different units for delta latitude and delta longitude.
  2644. The delta latitude is assumed to be in units of seconds of arc x 10^-5.
  2645. The delta longitude is the usual radians. Look out for these conversions.
  2646. The algorithm is described using complex arithmetic. There were three
  2647. options:
  2648. * find and use a Javascript library for complex arithmetic
  2649. * write my own complex library
  2650. * expand the complex arithmetic by hand to simple arithmetic
  2651. This implementation has expanded the complex multiplication operations
  2652. into parallel simple arithmetic operations for the real and imaginary parts.
  2653. The imaginary part is way over to the right of the display; this probably
  2654. violates every coding standard in the world, but, to me, it makes it much
  2655. more obvious what is going on.
  2656. The following complex operations are used:
  2657. - addition
  2658. - multiplication
  2659. - division
  2660. - complex number raised to integer power
  2661. - summation
  2662. A summary of complex arithmetic operations:
  2663. (from http://en.wikipedia.org/wiki/Complex_arithmetic)
  2664. addition: (a + bi) + (c + di) = (a + c) + (b + d)i
  2665. subtraction: (a + bi) - (c + di) = (a - c) + (b - d)i
  2666. multiplication: (a + bi) x (c + di) = (ac - bd) + (bc + ad)i
  2667. division: (a + bi) / (c + di) = [(ac + bd)/(cc + dd)] + [(bc - ad)/(cc + dd)]i
  2668. The algorithm needs to calculate summations of simple and complex numbers. This is
  2669. implemented using a for-loop, pre-loading the summed value to zero.
  2670. The algorithm needs to calculate theta^2, theta^3, etc while doing a summation.
  2671. There are three possible implementations:
  2672. - use Math.pow in the summation loop - except for complex numbers
  2673. - precalculate the values before running the loop
  2674. - calculate theta^n = theta^(n-1) * theta during the loop
  2675. This implementation uses the third option for both real and complex arithmetic.
  2676. For example
  2677. psi_n = 1;
  2678. sum = 0;
  2679. for (n = 1; n <=6; n++) {
  2680. psi_n1 = psi_n * psi; // calculate psi^(n+1)
  2681. psi_n = psi_n1;
  2682. sum = sum + A[n] * psi_n;
  2683. }
  2684. TEST VECTORS
  2685. NZMG E, N: 2487100.638 6751049.719 metres
  2686. NZGD49 long, lat: 172.739194 -34.444066 degrees
  2687. NZMG E, N: 2486533.395 6077263.661 metres
  2688. NZGD49 long, lat: 172.723106 -40.512409 degrees
  2689. NZMG E, N: 2216746.425 5388508.765 metres
  2690. NZGD49 long, lat: 169.172062 -46.651295 degrees
  2691. Note that these test vectors convert from NZMG metres to lat/long referenced
  2692. to NZGD49, not the more usual WGS84. The difference is about 70m N/S and about
  2693. 10m E/W.
  2694. These test vectors are provided in reference [1]. Many more test
  2695. vectors are available in
  2696. http://www.linz.govt.nz/docs/topography/topographicdata/placenamesdatabase/nznamesmar08.zip
  2697. which is a catalog of names on the 260-series maps.
  2698. EPSG CODES
  2699. NZMG EPSG:27200
  2700. NZGD49 EPSG:4272
  2701. http://spatialreference.org/ defines these as
  2702. Proj4js.defs["EPSG:4272"] = "+proj=longlat +ellps=intl +datum=nzgd49 +no_defs ";
  2703. Proj4js.defs["EPSG:27200"] = "+proj=nzmg +lat_0=-41 +lon_0=173 +x_0=2510000 +y_0=6023150 +ellps=intl +datum=nzgd49 +units=m +no_defs ";
  2704. LICENSE
  2705. Copyright: Stephen Irons 2008
  2706. Released under terms of the LGPL as per: http://www.gnu.org/copyleft/lesser.html
  2707. *******************************************************************************/
  2708. /**
  2709. Initialize New Zealand Map Grip projection
  2710. */
  2711. Proj4js.Proj.nzmg = {
  2712. /**
  2713. * iterations: Number of iterations to refine inverse transform.
  2714. * 0 -> km accuracy
  2715. * 1 -> m accuracy -- suitable for most mapping applications
  2716. * 2 -> mm accuracy
  2717. */
  2718. iterations: 1,
  2719. init : function() {
  2720. this.A = new Array();
  2721. this.A[1] = +0.6399175073;
  2722. this.A[2] = -0.1358797613;
  2723. this.A[3] = +0.063294409;
  2724. this.A[4] = -0.02526853;
  2725. this.A[5] = +0.0117879;
  2726. this.A[6] = -0.0055161;
  2727. this.A[7] = +0.0026906;
  2728. this.A[8] = -0.001333;
  2729. this.A[9] = +0.00067;
  2730. this.A[10] = -0.00034;
  2731. this.B_re = new Array(); this.B_im = new Array();
  2732. this.B_re[1] = +0.7557853228; this.B_im[1] = 0.0;
  2733. this.B_re[2] = +0.249204646; this.B_im[2] = +0.003371507;
  2734. this.B_re[3] = -0.001541739; this.B_im[3] = +0.041058560;
  2735. this.B_re[4] = -0.10162907; this.B_im[4] = +0.01727609;
  2736. this.B_re[5] = -0.26623489; this.B_im[5] = -0.36249218;
  2737. this.B_re[6] = -0.6870983; this.B_im[6] = -1.1651967;
  2738. this.C_re = new Array(); this.C_im = new Array();
  2739. this.C_re[1] = +1.3231270439; this.C_im[1] = 0.0;
  2740. this.C_re[2] = -0.577245789; this.C_im[2] = -0.007809598;
  2741. this.C_re[3] = +0.508307513; this.C_im[3] = -0.112208952;
  2742. this.C_re[4] = -0.15094762; this.C_im[4] = +0.18200602;
  2743. this.C_re[5] = +1.01418179; this.C_im[5] = +1.64497696;
  2744. this.C_re[6] = +1.9660549; this.C_im[6] = +2.5127645;
  2745. this.D = new Array();
  2746. this.D[1] = +1.5627014243;
  2747. this.D[2] = +0.5185406398;
  2748. this.D[3] = -0.03333098;
  2749. this.D[4] = -0.1052906;
  2750. this.D[5] = -0.0368594;
  2751. this.D[6] = +0.007317;
  2752. this.D[7] = +0.01220;
  2753. this.D[8] = +0.00394;
  2754. this.D[9] = -0.0013;
  2755. },
  2756. /**
  2757. New Zealand Map Grid Forward - long/lat to x/y
  2758. long/lat in radians
  2759. */
  2760. forward : function(p) {
  2761. var lon = p.x;
  2762. var lat = p.y;
  2763. var delta_lat = lat - this.lat0;
  2764. var delta_lon = lon - this.long0;
  2765. // 1. Calculate d_phi and d_psi ... // and d_lambda
  2766. // For this algorithm, delta_latitude is in seconds of arc x 10-5, so we need to scale to those units. Longitude is radians.
  2767. var d_phi = delta_lat / Proj4js.common.SEC_TO_RAD * 1E-5; var d_lambda = delta_lon;
  2768. var d_phi_n = 1; // d_phi^0
  2769. var d_psi = 0;
  2770. for (n = 1; n <= 10; n++) {
  2771. d_phi_n = d_phi_n * d_phi;
  2772. d_psi = d_psi + this.A[n] * d_phi_n;
  2773. }
  2774. // 2. Calculate theta
  2775. var th_re = d_psi; var th_im = d_lambda;
  2776. // 3. Calculate z
  2777. var th_n_re = 1; var th_n_im = 0; // theta^0
  2778. var th_n_re1; var th_n_im1;
  2779. var z_re = 0; var z_im = 0;
  2780. for (n = 1; n <= 6; n++) {
  2781. th_n_re1 = th_n_re*th_re - th_n_im*th_im; th_n_im1 = th_n_im*th_re + th_n_re*th_im;
  2782. th_n_re = th_n_re1; th_n_im = th_n_im1;
  2783. z_re = z_re + this.B_re[n]*th_n_re - this.B_im[n]*th_n_im; z_im = z_im + this.B_im[n]*th_n_re + this.B_re[n]*th_n_im;
  2784. }
  2785. // 4. Calculate easting and northing
  2786. x = (z_im * this.a) + this.x0;
  2787. y = (z_re * this.a) + this.y0;
  2788. p.x = x; p.y = y;
  2789. return p;
  2790. },
  2791. /**
  2792. New Zealand Map Grid Inverse - x/y to long/lat
  2793. */
  2794. inverse : function(p) {
  2795. var x = p.x;
  2796. var y = p.y;
  2797. var delta_x = x - this.x0;
  2798. var delta_y = y - this.y0;
  2799. // 1. Calculate z
  2800. var z_re = delta_y / this.a; var z_im = delta_x / this.a;
  2801. // 2a. Calculate theta - first approximation gives km accuracy
  2802. var z_n_re = 1; var z_n_im = 0; // z^0
  2803. var z_n_re1; var z_n_im1;
  2804. var th_re = 0; var th_im = 0;
  2805. for (n = 1; n <= 6; n++) {
  2806. z_n_re1 = z_n_re*z_re - z_n_im*z_im; z_n_im1 = z_n_im*z_re + z_n_re*z_im;
  2807. z_n_re = z_n_re1; z_n_im = z_n_im1;
  2808. th_re = th_re + this.C_re[n]*z_n_re - this.C_im[n]*z_n_im; th_im = th_im + this.C_im[n]*z_n_re + this.C_re[n]*z_n_im;
  2809. }
  2810. // 2b. Iterate to refine the accuracy of the calculation
  2811. // 0 iterations gives km accuracy
  2812. // 1 iteration gives m accuracy -- good enough for most mapping applications
  2813. // 2 iterations bives mm accuracy
  2814. for (i = 0; i < this.iterations; i++) {
  2815. var th_n_re = th_re; var th_n_im = th_im;
  2816. var th_n_re1; var th_n_im1;
  2817. var num_re = z_re; var num_im = z_im;
  2818. for (n = 2; n <= 6; n++) {
  2819. th_n_re1 = th_n_re*th_re - th_n_im*th_im; th_n_im1 = th_n_im*th_re + th_n_re*th_im;
  2820. th_n_re = th_n_re1; th_n_im = th_n_im1;
  2821. num_re = num_re + (n-1)*(this.B_re[n]*th_n_re - this.B_im[n]*th_n_im); num_im = num_im + (n-1)*(this.B_im[n]*th_n_re + this.B_re[n]*th_n_im);
  2822. }
  2823. th_n_re = 1; th_n_im = 0;
  2824. var den_re = this.B_re[1]; var den_im = this.B_im[1];
  2825. for (n = 2; n <= 6; n++) {
  2826. th_n_re1 = th_n_re*th_re - th_n_im*th_im; th_n_im1 = th_n_im*th_re + th_n_re*th_im;
  2827. th_n_re = th_n_re1; th_n_im = th_n_im1;
  2828. den_re = den_re + n * (this.B_re[n]*th_n_re - this.B_im[n]*th_n_im); den_im = den_im + n * (this.B_im[n]*th_n_re + this.B_re[n]*th_n_im);
  2829. }
  2830. // Complex division
  2831. var den2 = den_re*den_re + den_im*den_im;
  2832. th_re = (num_re*den_re + num_im*den_im) / den2; th_im = (num_im*den_re - num_re*den_im) / den2;
  2833. }
  2834. // 3. Calculate d_phi ... // and d_lambda
  2835. var d_psi = th_re; var d_lambda = th_im;
  2836. var d_psi_n = 1; // d_psi^0
  2837. var d_phi = 0;
  2838. for (n = 1; n <= 9; n++) {
  2839. d_psi_n = d_psi_n * d_psi;
  2840. d_phi = d_phi + this.D[n] * d_psi_n;
  2841. }
  2842. // 4. Calculate latitude and longitude
  2843. // d_phi is calcuated in second of arc * 10^-5, so we need to scale back to radians. d_lambda is in radians.
  2844. var lat = this.lat0 + (d_phi * Proj4js.common.SEC_TO_RAD * 1E5);
  2845. var lon = this.long0 + d_lambda;
  2846. p.x = lon;
  2847. p.y = lat;
  2848. return p;
  2849. }
  2850. };
  2851. /* ======================================================================
  2852. projCode/mill.js
  2853. ====================================================================== */
  2854. /*******************************************************************************
  2855. NAME MILLER CYLINDRICAL
  2856. PURPOSE: Transforms input longitude and latitude to Easting and
  2857. Northing for the Miller Cylindrical projection. The
  2858. longitude and latitude must be in radians. The Easting
  2859. and Northing values will be returned in meters.
  2860. PROGRAMMER DATE
  2861. ---------- ----
  2862. T. Mittan March, 1993
  2863. This function was adapted from the Lambert Azimuthal Equal Area projection
  2864. code (FORTRAN) in the General Cartographic Transformation Package software
  2865. which is available from the U.S. Geological Survey National Mapping Division.
  2866. ALGORITHM REFERENCES
  2867. 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
  2868. The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
  2869. 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  2870. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  2871. State Government Printing Office, Washington D.C., 1987.
  2872. 3. "Software Documentation for GCTP General Cartographic Transformation
  2873. Package", U.S. Geological Survey National Mapping Division, May 1982.
  2874. *******************************************************************************/
  2875. Proj4js.Proj.mill = {
  2876. /* Initialize the Miller Cylindrical projection
  2877. -------------------------------------------*/
  2878. init: function() {
  2879. //no-op
  2880. },
  2881. /* Miller Cylindrical forward equations--mapping lat,long to x,y
  2882. ------------------------------------------------------------*/
  2883. forward: function(p) {
  2884. var lon=p.x;
  2885. var lat=p.y;
  2886. /* Forward equations
  2887. -----------------*/
  2888. var dlon = Proj4js.common.adjust_lon(lon -this.long0);
  2889. var x = this.x0 + this.a * dlon;
  2890. var y = this.y0 + this.a * Math.log(Math.tan((Proj4js.common.PI / 4.0) + (lat / 2.5))) * 1.25;
  2891. p.x=x;
  2892. p.y=y;
  2893. return p;
  2894. },//millFwd()
  2895. /* Miller Cylindrical inverse equations--mapping x,y to lat/long
  2896. ------------------------------------------------------------*/
  2897. inverse: function(p) {
  2898. p.x -= this.x0;
  2899. p.y -= this.y0;
  2900. var lon = Proj4js.common.adjust_lon(this.long0 + p.x /this.a);
  2901. var lat = 2.5 * (Math.atan(Math.exp(0.8*p.y/this.a)) - Proj4js.common.PI / 4.0);
  2902. p.x=lon;
  2903. p.y=lat;
  2904. return p;
  2905. }//millInv()
  2906. };
  2907. /* ======================================================================
  2908. projCode/gnom.js
  2909. ====================================================================== */
  2910. /*****************************************************************************
  2911. NAME GNOMONIC
  2912. PURPOSE: Transforms input longitude and latitude to Easting and
  2913. Northing for the Gnomonic Projection.
  2914. Implementation based on the existing sterea and ortho
  2915. implementations.
  2916. PROGRAMMER DATE
  2917. ---------- ----
  2918. Richard Marsden November 2009
  2919. ALGORITHM REFERENCES
  2920. 1. Snyder, John P., "Flattening the Earth - Two Thousand Years of Map
  2921. Projections", University of Chicago Press 1993
  2922. 2. Wolfram Mathworld "Gnomonic Projection"
  2923. http://mathworld.wolfram.com/GnomonicProjection.html
  2924. Accessed: 12th November 2009
  2925. ******************************************************************************/
  2926. Proj4js.Proj.gnom = {
  2927. /* Initialize the Gnomonic projection
  2928. -------------------------------------*/
  2929. init: function(def) {
  2930. /* Place parameters in static storage for common use
  2931. -------------------------------------------------*/
  2932. this.sin_p14=Math.sin(this.lat0);
  2933. this.cos_p14=Math.cos(this.lat0);
  2934. // Approximation for projecting points to the horizon (infinity)
  2935. this.infinity_dist = 1000 * this.a;
  2936. },
  2937. /* Gnomonic forward equations--mapping lat,long to x,y
  2938. ---------------------------------------------------*/
  2939. forward: function(p) {
  2940. var sinphi, cosphi; /* sin and cos value */
  2941. var dlon; /* delta longitude value */
  2942. var coslon; /* cos of longitude */
  2943. var ksp; /* scale factor */
  2944. var g;
  2945. var lon=p.x;
  2946. var lat=p.y;
  2947. /* Forward equations
  2948. -----------------*/
  2949. dlon = Proj4js.common.adjust_lon(lon - this.long0);
  2950. sinphi=Math.sin(lat);
  2951. cosphi=Math.cos(lat);
  2952. coslon = Math.cos(dlon);
  2953. g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
  2954. ksp = 1.0;
  2955. if ((g > 0) || (Math.abs(g) <= Proj4js.common.EPSLN)) {
  2956. x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon) / g;
  2957. y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon) / g;
  2958. } else {
  2959. Proj4js.reportError("orthoFwdPointError");
  2960. // Point is in the opposing hemisphere and is unprojectable
  2961. // We still need to return a reasonable point, so we project
  2962. // to infinity, on a bearing
  2963. // equivalent to the northern hemisphere equivalent
  2964. // This is a reasonable approximation for short shapes and lines that
  2965. // straddle the horizon.
  2966. x = this.x0 + this.infinity_dist * cosphi * Math.sin(dlon);
  2967. y = this.y0 + this.infinity_dist * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
  2968. }
  2969. p.x=x;
  2970. p.y=y;
  2971. return p;
  2972. },
  2973. inverse: function(p) {
  2974. var rh; /* Rho */
  2975. var z; /* angle */
  2976. var sinc, cosc;
  2977. var c;
  2978. var lon , lat;
  2979. /* Inverse equations
  2980. -----------------*/
  2981. p.x = (p.x - this.x0) / this.a;
  2982. p.y = (p.y - this.y0) / this.a;
  2983. p.x /= this.k0;
  2984. p.y /= this.k0;
  2985. if ( (rh = Math.sqrt(p.x * p.x + p.y * p.y)) ) {
  2986. c = Math.atan2(rh, this.rc);
  2987. sinc = Math.sin(c);
  2988. cosc = Math.cos(c);
  2989. lat = Proj4js.common.asinz(cosc*this.sin_p14 + (p.y*sinc*this.cos_p14) / rh);
  2990. lon = Math.atan2(p.x*sinc, rh*this.cos_p14*cosc - p.y*this.sin_p14*sinc);
  2991. lon = Proj4js.common.adjust_lon(this.long0+lon);
  2992. } else {
  2993. lat = this.phic0;
  2994. lon = 0.0;
  2995. }
  2996. p.x=lon;
  2997. p.y=lat;
  2998. return p;
  2999. }
  3000. };
  3001. /* ======================================================================
  3002. projCode/sinu.js
  3003. ====================================================================== */
  3004. /*******************************************************************************
  3005. NAME SINUSOIDAL
  3006. PURPOSE: Transforms input longitude and latitude to Easting and
  3007. Northing for the Sinusoidal projection. The
  3008. longitude and latitude must be in radians. The Easting
  3009. and Northing values will be returned in meters.
  3010. PROGRAMMER DATE
  3011. ---------- ----
  3012. D. Steinwand, EROS May, 1991
  3013. This function was adapted from the Sinusoidal projection code (FORTRAN) in the
  3014. General Cartographic Transformation Package software which is available from
  3015. the U.S. Geological Survey National Mapping Division.
  3016. ALGORITHM REFERENCES
  3017. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3018. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3019. State Government Printing Office, Washington D.C., 1987.
  3020. 2. "Software Documentation for GCTP General Cartographic Transformation
  3021. Package", U.S. Geological Survey National Mapping Division, May 1982.
  3022. *******************************************************************************/
  3023. Proj4js.Proj.sinu = {
  3024. /* Initialize the Sinusoidal projection
  3025. ------------------------------------*/
  3026. init: function() {
  3027. /* Place parameters in static storage for common use
  3028. -------------------------------------------------*/
  3029. this.R = 6370997.0; //Radius of earth
  3030. },
  3031. /* Sinusoidal forward equations--mapping lat,long to x,y
  3032. -----------------------------------------------------*/
  3033. forward: function(p) {
  3034. var x,y,delta_lon;
  3035. var lon=p.x;
  3036. var lat=p.y;
  3037. /* Forward equations
  3038. -----------------*/
  3039. delta_lon = Proj4js.common.adjust_lon(lon - this.long0);
  3040. x = this.R * delta_lon * Math.cos(lat) + this.x0;
  3041. y = this.R * lat + this.y0;
  3042. p.x=x;
  3043. p.y=y;
  3044. return p;
  3045. },
  3046. inverse: function(p) {
  3047. var lat,temp,lon;
  3048. /* Inverse equations
  3049. -----------------*/
  3050. p.x -= this.x0;
  3051. p.y -= this.y0;
  3052. lat = p.y / this.R;
  3053. if (Math.abs(lat) > Proj4js.common.HALF_PI) {
  3054. Proj4js.reportError("sinu:Inv:DataError");
  3055. }
  3056. temp = Math.abs(lat) - Proj4js.common.HALF_PI;
  3057. if (Math.abs(temp) > Proj4js.common.EPSLN) {
  3058. temp = this.long0+ p.x / (this.R *Math.cos(lat));
  3059. lon = Proj4js.common.adjust_lon(temp);
  3060. } else {
  3061. lon = this.long0;
  3062. }
  3063. p.x=lon;
  3064. p.y=lat;
  3065. return p;
  3066. }
  3067. };
  3068. /* ======================================================================
  3069. projCode/vandg.js
  3070. ====================================================================== */
  3071. /*******************************************************************************
  3072. NAME VAN DER GRINTEN
  3073. PURPOSE: Transforms input Easting and Northing to longitude and
  3074. latitude for the Van der Grinten projection. The
  3075. Easting and Northing must be in meters. The longitude
  3076. and latitude values will be returned in radians.
  3077. PROGRAMMER DATE
  3078. ---------- ----
  3079. T. Mittan March, 1993
  3080. This function was adapted from the Van Der Grinten projection code
  3081. (FORTRAN) in the General Cartographic Transformation Package software
  3082. which is available from the U.S. Geological Survey National Mapping Division.
  3083. ALGORITHM REFERENCES
  3084. 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
  3085. The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
  3086. 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3087. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3088. State Government Printing Office, Washington D.C., 1987.
  3089. 3. "Software Documentation for GCTP General Cartographic Transformation
  3090. Package", U.S. Geological Survey National Mapping Division, May 1982.
  3091. *******************************************************************************/
  3092. Proj4js.Proj.vandg = {
  3093. /* Initialize the Van Der Grinten projection
  3094. ----------------------------------------*/
  3095. init: function() {
  3096. this.R = 6370997.0; //Radius of earth
  3097. },
  3098. forward: function(p) {
  3099. var lon=p.x;
  3100. var lat=p.y;
  3101. /* Forward equations
  3102. -----------------*/
  3103. var dlon = Proj4js.common.adjust_lon(lon - this.long0);
  3104. var x,y;
  3105. if (Math.abs(lat) <= Proj4js.common.EPSLN) {
  3106. x = this.x0 + this.R * dlon;
  3107. y = this.y0;
  3108. }
  3109. var theta = Proj4js.common.asinz(2.0 * Math.abs(lat / Proj4js.common.PI));
  3110. if ((Math.abs(dlon) <= Proj4js.common.EPSLN) || (Math.abs(Math.abs(lat) - Proj4js.common.HALF_PI) <= Proj4js.common.EPSLN)) {
  3111. x = this.x0;
  3112. if (lat >= 0) {
  3113. y = this.y0 + Proj4js.common.PI * this.R * Math.tan(.5 * theta);
  3114. } else {
  3115. y = this.y0 + Proj4js.common.PI * this.R * - Math.tan(.5 * theta);
  3116. }
  3117. // return(OK);
  3118. }
  3119. var al = .5 * Math.abs((Proj4js.common.PI / dlon) - (dlon / Proj4js.common.PI));
  3120. var asq = al * al;
  3121. var sinth = Math.sin(theta);
  3122. var costh = Math.cos(theta);
  3123. var g = costh / (sinth + costh - 1.0);
  3124. var gsq = g * g;
  3125. var m = g * (2.0 / sinth - 1.0);
  3126. var msq = m * m;
  3127. var con = Proj4js.common.PI * this.R * (al * (g - msq) + Math.sqrt(asq * (g - msq) * (g - msq) - (msq + asq) * (gsq - msq))) / (msq + asq);
  3128. if (dlon < 0) {
  3129. con = -con;
  3130. }
  3131. x = this.x0 + con;
  3132. con = Math.abs(con / (Proj4js.common.PI * this.R));
  3133. if (lat >= 0) {
  3134. y = this.y0 + Proj4js.common.PI * this.R * Math.sqrt(1.0 - con * con - 2.0 * al * con);
  3135. } else {
  3136. y = this.y0 - Proj4js.common.PI * this.R * Math.sqrt(1.0 - con * con - 2.0 * al * con);
  3137. }
  3138. p.x = x;
  3139. p.y = y;
  3140. return p;
  3141. },
  3142. /* Van Der Grinten inverse equations--mapping x,y to lat/long
  3143. ---------------------------------------------------------*/
  3144. inverse: function(p) {
  3145. var dlon;
  3146. var xx,yy,xys,c1,c2,c3;
  3147. var al,asq;
  3148. var a1;
  3149. var m1;
  3150. var con;
  3151. var th1;
  3152. var d;
  3153. /* inverse equations
  3154. -----------------*/
  3155. p.x -= this.x0;
  3156. p.y -= this.y0;
  3157. con = Proj4js.common.PI * this.R;
  3158. xx = p.x / con;
  3159. yy =p.y / con;
  3160. xys = xx * xx + yy * yy;
  3161. c1 = -Math.abs(yy) * (1.0 + xys);
  3162. c2 = c1 - 2.0 * yy * yy + xx * xx;
  3163. c3 = -2.0 * c1 + 1.0 + 2.0 * yy * yy + xys * xys;
  3164. d = yy * yy / c3 + (2.0 * c2 * c2 * c2 / c3 / c3 / c3 - 9.0 * c1 * c2 / c3 /c3) / 27.0;
  3165. a1 = (c1 - c2 * c2 / 3.0 / c3) / c3;
  3166. m1 = 2.0 * Math.sqrt( -a1 / 3.0);
  3167. con = ((3.0 * d) / a1) / m1;
  3168. if (Math.abs(con) > 1.0) {
  3169. if (con >= 0.0) {
  3170. con = 1.0;
  3171. } else {
  3172. con = -1.0;
  3173. }
  3174. }
  3175. th1 = Math.acos(con) / 3.0;
  3176. if (p.y >= 0) {
  3177. lat = (-m1 *Math.cos(th1 + Proj4js.common.PI / 3.0) - c2 / 3.0 / c3) * Proj4js.common.PI;
  3178. } else {
  3179. lat = -(-m1 * Math.cos(th1 + PI / 3.0) - c2 / 3.0 / c3) * Proj4js.common.PI;
  3180. }
  3181. if (Math.abs(xx) < Proj4js.common.EPSLN) {
  3182. lon = this.long0;
  3183. }
  3184. lon = Proj4js.common.adjust_lon(this.long0 + Proj4js.common.PI * (xys - 1.0 + Math.sqrt(1.0 + 2.0 * (xx * xx - yy * yy) + xys * xys)) / 2.0 / xx);
  3185. p.x=lon;
  3186. p.y=lat;
  3187. return p;
  3188. }
  3189. };
  3190. /* ======================================================================
  3191. projCode/cea.js
  3192. ====================================================================== */
  3193. /*******************************************************************************
  3194. NAME LAMBERT CYLINDRICAL EQUAL AREA
  3195. PURPOSE: Transforms input longitude and latitude to Easting and
  3196. Northing for the Lambert Cylindrical Equal Area projection.
  3197. This class of projection includes the Behrmann and
  3198. Gall-Peters Projections. The
  3199. longitude and latitude must be in radians. The Easting
  3200. and Northing values will be returned in meters.
  3201. PROGRAMMER DATE
  3202. ---------- ----
  3203. R. Marsden August 2009
  3204. Winwaed Software Tech LLC, http://www.winwaed.com
  3205. This function was adapted from the Miller Cylindrical Projection in the Proj4JS
  3206. library.
  3207. Note: This implementation assumes a Spherical Earth. The (commented) code
  3208. has been included for the ellipsoidal forward transform, but derivation of
  3209. the ellispoidal inverse transform is beyond me. Note that most of the
  3210. Proj4JS implementations do NOT currently support ellipsoidal figures.
  3211. Therefore this is not seen as a problem - especially this lack of support
  3212. is explicitly stated here.
  3213. ALGORITHM REFERENCES
  3214. 1. "Cartographic Projection Procedures for the UNIX Environment -
  3215. A User's Manual" by Gerald I. Evenden, USGS Open File Report 90-284
  3216. and Release 4 Interim Reports (2003)
  3217. 2. Snyder, John P., "Flattening the Earth - Two Thousand Years of Map
  3218. Projections", Univ. Chicago Press, 1993
  3219. *******************************************************************************/
  3220. Proj4js.Proj.cea = {
  3221. /* Initialize the Cylindrical Equal Area projection
  3222. -------------------------------------------*/
  3223. init: function() {
  3224. //no-op
  3225. },
  3226. /* Cylindrical Equal Area forward equations--mapping lat,long to x,y
  3227. ------------------------------------------------------------*/
  3228. forward: function(p) {
  3229. var lon=p.x;
  3230. var lat=p.y;
  3231. /* Forward equations
  3232. -----------------*/
  3233. dlon = Proj4js.common.adjust_lon(lon -this.long0);
  3234. var x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
  3235. var y = this.y0 + this.a * Math.sin(lat) / Math.cos(this.lat_ts);
  3236. /* Elliptical Forward Transform
  3237. Not implemented due to a lack of a matchign inverse function
  3238. {
  3239. var Sin_Lat = Math.sin(lat);
  3240. var Rn = this.a * (Math.sqrt(1.0e0 - this.es * Sin_Lat * Sin_Lat ));
  3241. x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
  3242. y = this.y0 + Rn * Math.sin(lat) / Math.cos(this.lat_ts);
  3243. }
  3244. */
  3245. p.x=x;
  3246. p.y=y;
  3247. return p;
  3248. },//ceaFwd()
  3249. /* Cylindrical Equal Area inverse equations--mapping x,y to lat/long
  3250. ------------------------------------------------------------*/
  3251. inverse: function(p) {
  3252. p.x -= this.x0;
  3253. p.y -= this.y0;
  3254. var lon = Proj4js.common.adjust_lon( this.long0 + (p.x / this.a) / Math.cos(this.lat_ts) );
  3255. var lat = Math.asin( (p.y/this.a) * Math.cos(this.lat_ts) );
  3256. p.x=lon;
  3257. p.y=lat;
  3258. return p;
  3259. }//ceaInv()
  3260. };
  3261. /* ======================================================================
  3262. projCode/eqc.js
  3263. ====================================================================== */
  3264. /* similar to equi.js FIXME proj4 uses eqc */
  3265. Proj4js.Proj.eqc = {
  3266. init : function() {
  3267. if(!this.x0) this.x0=0;
  3268. if(!this.y0) this.y0=0;
  3269. if(!this.lat0) this.lat0=0;
  3270. if(!this.long0) this.long0=0;
  3271. if(!this.lat_ts) this.lat_ts=0;
  3272. if (!this.title) this.title = "Equidistant Cylindrical (Plate Carre)";
  3273. this.rc= Math.cos(this.lat_ts);
  3274. },
  3275. // forward equations--mapping lat,long to x,y
  3276. // -----------------------------------------------------------------
  3277. forward : function(p) {
  3278. var lon= p.x;
  3279. var lat= p.y;
  3280. var dlon = Proj4js.common.adjust_lon(lon - this.long0);
  3281. var dlat = Proj4js.common.adjust_lat(lat - this.lat0 );
  3282. p.x= this.x0 + (this.a*dlon*this.rc);
  3283. p.y= this.y0 + (this.a*dlat );
  3284. return p;
  3285. },
  3286. // inverse equations--mapping x,y to lat/long
  3287. // -----------------------------------------------------------------
  3288. inverse : function(p) {
  3289. var x= p.x;
  3290. var y= p.y;
  3291. p.x= Proj4js.common.adjust_lon(this.long0 + ((x - this.x0)/(this.a*this.rc)));
  3292. p.y= Proj4js.common.adjust_lat(this.lat0 + ((y - this.y0)/(this.a )));
  3293. return p;
  3294. }
  3295. };
  3296. /* ======================================================================
  3297. projCode/cass.js
  3298. ====================================================================== */
  3299. /*******************************************************************************
  3300. NAME CASSINI
  3301. PURPOSE: Transforms input longitude and latitude to Easting and
  3302. Northing for the Cassini projection. The
  3303. longitude and latitude must be in radians. The Easting
  3304. and Northing values will be returned in meters.
  3305. Ported from PROJ.4.
  3306. ALGORITHM REFERENCES
  3307. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3308. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3309. State Government Printing Office, Washington D.C., 1987.
  3310. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  3311. U.S. Geological Survey Professional Paper 1453 , United State Government
  3312. *******************************************************************************/
  3313. //Proj4js.defs["EPSG:28191"] = "+proj=cass +lat_0=31.73409694444445 +lon_0=35.21208055555556 +x_0=170251.555 +y_0=126867.909 +a=6378300.789 +b=6356566.435 +towgs84=-275.722,94.7824,340.894,-8.001,-4.42,-11.821,1 +units=m +no_defs";
  3314. // Initialize the Cassini projection
  3315. // -----------------------------------------------------------------
  3316. Proj4js.Proj.cass = {
  3317. init : function() {
  3318. if (!this.sphere) {
  3319. this.en = this.pj_enfn(this.es)
  3320. this.m0 = this.pj_mlfn(this.lat0, Math.sin(this.lat0), Math.cos(this.lat0), this.en);
  3321. }
  3322. },
  3323. C1: .16666666666666666666,
  3324. C2: .00833333333333333333,
  3325. C3: .04166666666666666666,
  3326. C4: .33333333333333333333,
  3327. C5: .06666666666666666666,
  3328. /* Cassini forward equations--mapping lat,long to x,y
  3329. -----------------------------------------------------------------------*/
  3330. forward: function(p) {
  3331. /* Forward equations
  3332. -----------------*/
  3333. var x,y;
  3334. var lam=p.x;
  3335. var phi=p.y;
  3336. lam = Proj4js.common.adjust_lon(lam - this.long0);
  3337. if (this.sphere) {
  3338. x = Math.asin(Math.cos(phi) * Math.sin(lam));
  3339. y = Math.atan2(Math.tan(phi) , Math.cos(lam)) - this.phi0;
  3340. } else {
  3341. //ellipsoid
  3342. this.n = Math.sin(phi);
  3343. this.c = Math.cos(phi);
  3344. y = this.pj_mlfn(phi, this.n, this.c, this.en);
  3345. this.n = 1./Math.sqrt(1. - this.es * this.n * this.n);
  3346. this.tn = Math.tan(phi);
  3347. this.t = this.tn * this.tn;
  3348. this.a1 = lam * this.c;
  3349. this.c *= this.es * this.c / (1 - this.es);
  3350. this.a2 = this.a1 * this.a1;
  3351. x = this.n * this.a1 * (1. - this.a2 * this.t * (this.C1 - (8. - this.t + 8. * this.c) * this.a2 * this.C2));
  3352. y -= this.m0 - this.n * this.tn * this.a2 * (.5 + (5. - this.t + 6. * this.c) * this.a2 * this.C3);
  3353. }
  3354. p.x = this.a*x + this.x0;
  3355. p.y = this.a*y + this.y0;
  3356. return p;
  3357. },//cassFwd()
  3358. /* Inverse equations
  3359. -----------------*/
  3360. inverse: function(p) {
  3361. p.x -= this.x0;
  3362. p.y -= this.y0;
  3363. var x = p.x/this.a;
  3364. var y = p.y/this.a;
  3365. if (this.sphere) {
  3366. this.dd = y + this.lat0;
  3367. phi = Math.asin(Math.sin(this.dd) * Math.cos(x));
  3368. lam = Math.atan2(Math.tan(x), Math.cos(this.dd));
  3369. } else {
  3370. /* ellipsoid */
  3371. ph1 = this.pj_inv_mlfn(this.m0 + y, this.es, this.en);
  3372. this.tn = Math.tan(ph1);
  3373. this.t = this.tn * this.tn;
  3374. this.n = Math.sin(ph1);
  3375. this.r = 1. / (1. - this.es * this.n * this.n);
  3376. this.n = Math.sqrt(this.r);
  3377. this.r *= (1. - this.es) * this.n;
  3378. this.dd = x / this.n;
  3379. this.d2 = this.dd * this.dd;
  3380. phi = ph1 - (this.n * this.tn / this.r) * this.d2 * (.5 - (1. + 3. * this.t) * this.d2 * this.C3);
  3381. lam = this.dd * (1. + this.t * this.d2 * (-this.C4 + (1. + 3. * this.t) * this.d2 * this.C5)) / Math.cos(ph1);
  3382. }
  3383. p.x = Proj4js.common.adjust_lon(this.long0+lam);
  3384. p.y = phi;
  3385. return p;
  3386. },//lamazInv()
  3387. //code from the PROJ.4 pj_mlfn.c file; this may be useful for other projections
  3388. pj_enfn: function(es) {
  3389. en = new Array();
  3390. en[0] = this.C00 - es * (this.C02 + es * (this.C04 + es * (this.C06 + es * this.C08)));
  3391. en[1] = es * (this.C22 - es * (this.C04 + es * (this.C06 + es * this.C08)));
  3392. var t = es * es;
  3393. en[2] = t * (this.C44 - es * (this.C46 + es * this.C48));
  3394. t *= es;
  3395. en[3] = t * (this.C66 - es * this.C68);
  3396. en[4] = t * es * this.C88;
  3397. return en;
  3398. },
  3399. pj_mlfn: function(phi, sphi, cphi, en) {
  3400. cphi *= sphi;
  3401. sphi *= sphi;
  3402. return(en[0] * phi - cphi * (en[1] + sphi*(en[2]+ sphi*(en[3] + sphi*en[4]))));
  3403. },
  3404. pj_inv_mlfn: function(arg, es, en) {
  3405. k = 1./(1.-es);
  3406. phi = arg;
  3407. for (i = Proj4js.common.MAX_ITER; i ; --i) { /* rarely goes over 2 iterations */
  3408. s = Math.sin(phi);
  3409. t = 1. - es * s * s;
  3410. //t = this.pj_mlfn(phi, s, Math.cos(phi), en) - arg;
  3411. //phi -= t * (t * Math.sqrt(t)) * k;
  3412. t = (this.pj_mlfn(phi, s, Math.cos(phi), en) - arg) * (t * Math.sqrt(t)) * k;
  3413. phi -= t;
  3414. if (Math.abs(t) < Proj4js.common.EPSLN)
  3415. return phi;
  3416. }
  3417. Proj4js.reportError("cass:pj_inv_mlfn: Convergence error");
  3418. return phi;
  3419. },
  3420. /* meridinal distance for ellipsoid and inverse
  3421. ** 8th degree - accurate to < 1e-5 meters when used in conjuction
  3422. ** with typical major axis values.
  3423. ** Inverse determines phi to EPS (1e-11) radians, about 1e-6 seconds.
  3424. */
  3425. C00: 1.0,
  3426. C02: .25,
  3427. C04: .046875,
  3428. C06: .01953125,
  3429. C08: .01068115234375,
  3430. C22: .75,
  3431. C44: .46875,
  3432. C46: .01302083333333333333,
  3433. C48: .00712076822916666666,
  3434. C66: .36458333333333333333,
  3435. C68: .00569661458333333333,
  3436. C88: .3076171875
  3437. }
  3438. /* ======================================================================
  3439. projCode/gauss.js
  3440. ====================================================================== */
  3441. Proj4js.Proj.gauss = {
  3442. init : function() {
  3443. sphi = Math.sin(this.lat0);
  3444. cphi = Math.cos(this.lat0);
  3445. cphi *= cphi;
  3446. this.rc = Math.sqrt(1.0 - this.es) / (1.0 - this.es * sphi * sphi);
  3447. this.C = Math.sqrt(1.0 + this.es * cphi * cphi / (1.0 - this.es));
  3448. this.phic0 = Math.asin(sphi / this.C);
  3449. this.ratexp = 0.5 * this.C * this.e;
  3450. this.K = Math.tan(0.5 * this.phic0 + Proj4js.common.FORTPI) / (Math.pow(Math.tan(0.5*this.lat0 + Proj4js.common.FORTPI), this.C) * Proj4js.common.srat(this.e*sphi, this.ratexp));
  3451. },
  3452. forward : function(p) {
  3453. var lon = p.x;
  3454. var lat = p.y;
  3455. p.y = 2.0 * Math.atan( this.K * Math.pow(Math.tan(0.5 * lat + Proj4js.common.FORTPI), this.C) * Proj4js.common.srat(this.e * Math.sin(lat), this.ratexp) ) - Proj4js.common.HALF_PI;
  3456. p.x = this.C * lon;
  3457. return p;
  3458. },
  3459. inverse : function(p) {
  3460. var DEL_TOL = 1e-14;
  3461. var lon = p.x / this.C;
  3462. var lat = p.y;
  3463. num = Math.pow(Math.tan(0.5 * lat + Proj4js.common.FORTPI)/this.K, 1./this.C);
  3464. for (var i = Proj4js.common.MAX_ITER; i>0; --i) {
  3465. lat = 2.0 * Math.atan(num * Proj4js.common.srat(this.e * Math.sin(p.y), -0.5 * this.e)) - Proj4js.common.HALF_PI;
  3466. if (Math.abs(lat - p.y) < DEL_TOL) break;
  3467. p.y = lat;
  3468. }
  3469. /* convergence failed */
  3470. if (!i) {
  3471. Proj4js.reportError("gauss:inverse:convergence failed");
  3472. return null;
  3473. }
  3474. p.x = lon;
  3475. p.y = lat;
  3476. return p;
  3477. }
  3478. };
  3479. /* ======================================================================
  3480. projCode/omerc.js
  3481. ====================================================================== */
  3482. /*******************************************************************************
  3483. NAME OBLIQUE MERCATOR (HOTINE)
  3484. PURPOSE: Transforms input longitude and latitude to Easting and
  3485. Northing for the Oblique Mercator projection. The
  3486. longitude and latitude must be in radians. The Easting
  3487. and Northing values will be returned in meters.
  3488. PROGRAMMER DATE
  3489. ---------- ----
  3490. T. Mittan Mar, 1993
  3491. ALGORITHM REFERENCES
  3492. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3493. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3494. State Government Printing Office, Washington D.C., 1987.
  3495. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  3496. U.S. Geological Survey Professional Paper 1453 , United State Government
  3497. Printing Office, Washington D.C., 1989.
  3498. *******************************************************************************/
  3499. Proj4js.Proj.omerc = {
  3500. /* Initialize the Oblique Mercator projection
  3501. ------------------------------------------*/
  3502. init: function() {
  3503. if (!this.mode) this.mode=0;
  3504. if (!this.lon1) {this.lon1=0;this.mode=1;}
  3505. if (!this.lon2) this.lon2=0;
  3506. if (!this.lat2) this.lat2=0;
  3507. /* Place parameters in static storage for common use
  3508. -------------------------------------------------*/
  3509. var temp = this.b/ this.a;
  3510. var es = 1.0 - Math.pow(temp,2);
  3511. var e = Math.sqrt(es);
  3512. this.sin_p20=Math.sin(this.lat0);
  3513. this.cos_p20=Math.cos(this.lat0);
  3514. this.con = 1.0 - this.es * this.sin_p20 * this.sin_p20;
  3515. this.com = Math.sqrt(1.0 - es);
  3516. this.bl = Math.sqrt(1.0 + this.es * Math.pow(this.cos_p20,4.0)/(1.0 - es));
  3517. this.al = this.a * this.bl * this.k0 * this.com / this.con;
  3518. if (Math.abs(this.lat0) < Proj4js.common.EPSLN) {
  3519. this.ts = 1.0;
  3520. this.d = 1.0;
  3521. this.el = 1.0;
  3522. } else {
  3523. this.ts = Proj4js.common.tsfnz(this.e,this.lat0,this.sin_p20);
  3524. this.con = Math.sqrt(this.con);
  3525. this.d = this.bl * this.com / (this.cos_p20 * this.con);
  3526. if ((this.d * this.d - 1.0) > 0.0) {
  3527. if (this.lat0 >= 0.0) {
  3528. this.f = this.d + Math.sqrt(this.d * this.d - 1.0);
  3529. } else {
  3530. this.f = this.d - Math.sqrt(this.d * this.d - 1.0);
  3531. }
  3532. } else {
  3533. this.f = this.d;
  3534. }
  3535. this.el = this.f * Math.pow(this.ts,this.bl);
  3536. }
  3537. //this.longc=52.60353916666667;
  3538. if (this.mode != 0) {
  3539. this.g = .5 * (this.f - 1.0/this.f);
  3540. this.gama = Proj4js.common.asinz(Math.sin(this.alpha) / this.d);
  3541. this.longc= this.longc - Proj4js.common.asinz(this.g * Math.tan(this.gama))/this.bl;
  3542. /* Report parameters common to format B
  3543. -------------------------------------*/
  3544. //genrpt(azimuth * R2D,"Azimuth of Central Line: ");
  3545. //cenlon(lon_origin);
  3546. // cenlat(lat_origin);
  3547. this.con = Math.abs(this.lat0);
  3548. if ((this.con > Proj4js.common.EPSLN) && (Math.abs(this.con - Proj4js.common.HALF_PI) > Proj4js.common.EPSLN)) {
  3549. this.singam=Math.sin(this.gama);
  3550. this.cosgam=Math.cos(this.gama);
  3551. this.sinaz=Math.sin(this.alpha);
  3552. this.cosaz=Math.cos(this.alpha);
  3553. if (this.lat0>= 0) {
  3554. this.u = (this.al / this.bl) * Math.atan(Math.sqrt(this.d*this.d - 1.0)/this.cosaz);
  3555. } else {
  3556. this.u = -(this.al / this.bl) *Math.atan(Math.sqrt(this.d*this.d - 1.0)/this.cosaz);
  3557. }
  3558. } else {
  3559. Proj4js.reportError("omerc:Init:DataError");
  3560. }
  3561. } else {
  3562. this.sinphi =Math. sin(this.at1);
  3563. this.ts1 = Proj4js.common.tsfnz(this.e,this.lat1,this.sinphi);
  3564. this.sinphi = Math.sin(this.lat2);
  3565. this.ts2 = Proj4js.common.tsfnz(this.e,this.lat2,this.sinphi);
  3566. this.h = Math.pow(this.ts1,this.bl);
  3567. this.l = Math.pow(this.ts2,this.bl);
  3568. this.f = this.el/this.h;
  3569. this.g = .5 * (this.f - 1.0/this.f);
  3570. this.j = (this.el * this.el - this.l * this.h)/(this.el * this.el + this.l * this.h);
  3571. this.p = (this.l - this.h) / (this.l + this.h);
  3572. this.dlon = this.lon1 - this.lon2;
  3573. if (this.dlon < -Proj4js.common.PI) this.lon2 = this.lon2 - 2.0 * Proj4js.common.PI;
  3574. if (this.dlon > Proj4js.common.PI) this.lon2 = this.lon2 + 2.0 * Proj4js.common.PI;
  3575. this.dlon = this.lon1 - this.lon2;
  3576. this.longc = .5 * (this.lon1 + this.lon2) -Math.atan(this.j * Math.tan(.5 * this.bl * this.dlon)/this.p)/this.bl;
  3577. this.dlon = Proj4js.common.adjust_lon(this.lon1 - this.longc);
  3578. this.gama = Math.atan(Math.sin(this.bl * this.dlon)/this.g);
  3579. this.alpha = Proj4js.common.asinz(this.d * Math.sin(this.gama));
  3580. /* Report parameters common to format A
  3581. -------------------------------------*/
  3582. if (Math.abs(this.lat1 - this.lat2) <= Proj4js.common.EPSLN) {
  3583. Proj4js.reportError("omercInitDataError");
  3584. //return(202);
  3585. } else {
  3586. this.con = Math.abs(this.lat1);
  3587. }
  3588. if ((this.con <= Proj4js.common.EPSLN) || (Math.abs(this.con - HALF_PI) <= Proj4js.common.EPSLN)) {
  3589. Proj4js.reportError("omercInitDataError");
  3590. //return(202);
  3591. } else {
  3592. if (Math.abs(Math.abs(this.lat0) - Proj4js.common.HALF_PI) <= Proj4js.common.EPSLN) {
  3593. Proj4js.reportError("omercInitDataError");
  3594. //return(202);
  3595. }
  3596. }
  3597. this.singam=Math.sin(this.gam);
  3598. this.cosgam=Math.cos(this.gam);
  3599. this.sinaz=Math.sin(this.alpha);
  3600. this.cosaz=Math.cos(this.alpha);
  3601. if (this.lat0 >= 0) {
  3602. this.u = (this.al/this.bl) * Math.atan(Math.sqrt(this.d * this.d - 1.0)/this.cosaz);
  3603. } else {
  3604. this.u = -(this.al/this.bl) * Math.atan(Math.sqrt(this.d * this.d - 1.0)/this.cosaz);
  3605. }
  3606. }
  3607. },
  3608. /* Oblique Mercator forward equations--mapping lat,long to x,y
  3609. ----------------------------------------------------------*/
  3610. forward: function(p) {
  3611. var theta; /* angle */
  3612. var sin_phi, cos_phi;/* sin and cos value */
  3613. var b; /* temporary values */
  3614. var c, t, tq; /* temporary values */
  3615. var con, n, ml; /* cone constant, small m */
  3616. var q,us,vl;
  3617. var ul,vs;
  3618. var s;
  3619. var dlon;
  3620. var ts1;
  3621. var lon=p.x;
  3622. var lat=p.y;
  3623. /* Forward equations
  3624. -----------------*/
  3625. sin_phi = Math.sin(lat);
  3626. dlon = Proj4js.common.adjust_lon(lon - this.longc);
  3627. vl = Math.sin(this.bl * dlon);
  3628. if (Math.abs(Math.abs(lat) - Proj4js.common.HALF_PI) > Proj4js.common.EPSLN) {
  3629. ts1 = Proj4js.common.tsfnz(this.e,lat,sin_phi);
  3630. q = this.el / (Math.pow(ts1,this.bl));
  3631. s = .5 * (q - 1.0 / q);
  3632. t = .5 * (q + 1.0/ q);
  3633. ul = (s * this.singam - vl * this.cosgam) / t;
  3634. con = Math.cos(this.bl * dlon);
  3635. if (Math.abs(con) < .0000001) {
  3636. us = this.al * this.bl * dlon;
  3637. } else {
  3638. us = this.al * Math.atan((s * this.cosgam + vl * this.singam) / con)/this.bl;
  3639. if (con < 0) us = us + Proj4js.common.PI * this.al / this.bl;
  3640. }
  3641. } else {
  3642. if (lat >= 0) {
  3643. ul = this.singam;
  3644. } else {
  3645. ul = -this.singam;
  3646. }
  3647. us = this.al * lat / this.bl;
  3648. }
  3649. if (Math.abs(Math.abs(ul) - 1.0) <= Proj4js.common.EPSLN) {
  3650. //alert("Point projects into infinity","omer-for");
  3651. Proj4js.reportError("omercFwdInfinity");
  3652. //return(205);
  3653. }
  3654. vs = .5 * this.al * Math.log((1.0 - ul)/(1.0 + ul)) / this.bl;
  3655. us = us - this.u;
  3656. var x = this.x0 + vs * this.cosaz + us * this.sinaz;
  3657. var y = this.y0 + us * this.cosaz - vs * this.sinaz;
  3658. p.x=x;
  3659. p.y=y;
  3660. return p;
  3661. },
  3662. inverse: function(p) {
  3663. var delta_lon; /* Delta longitude (Given longitude - center */
  3664. var theta; /* angle */
  3665. var delta_theta; /* adjusted longitude */
  3666. var sin_phi, cos_phi;/* sin and cos value */
  3667. var b; /* temporary values */
  3668. var c, t, tq; /* temporary values */
  3669. var con, n, ml; /* cone constant, small m */
  3670. var vs,us,q,s,ts1;
  3671. var vl,ul,bs;
  3672. var dlon;
  3673. var flag;
  3674. /* Inverse equations
  3675. -----------------*/
  3676. p.x -= this.x0;
  3677. p.y -= this.y0;
  3678. flag = 0;
  3679. vs = p.x * this.cosaz - p.y * this.sinaz;
  3680. us = p.y * this.cosaz + p.x * this.sinaz;
  3681. us = us + this.u;
  3682. q = Math.exp(-this.bl * vs / this.al);
  3683. s = .5 * (q - 1.0/q);
  3684. t = .5 * (q + 1.0/q);
  3685. vl = Math.sin(this.bl * us / this.al);
  3686. ul = (vl * this.cosgam + s * this.singam)/t;
  3687. if (Math.abs(Math.abs(ul) - 1.0) <= Proj4js.common.EPSLN)
  3688. {
  3689. lon = this.longc;
  3690. if (ul >= 0.0) {
  3691. lat = Proj4js.common.HALF_PI;
  3692. } else {
  3693. lat = -Proj4js.common.HALF_PI;
  3694. }
  3695. } else {
  3696. con = 1.0 / this.bl;
  3697. ts1 =Math.pow((this.el / Math.sqrt((1.0 + ul) / (1.0 - ul))),con);
  3698. lat = Proj4js.common.phi2z(this.e,ts1);
  3699. //if (flag != 0)
  3700. //return(flag);
  3701. //~ con = Math.cos(this.bl * us /al);
  3702. theta = this.longc - Math.atan2((s * this.cosgam - vl * this.singam) , con)/this.bl;
  3703. lon = Proj4js.common.adjust_lon(theta);
  3704. }
  3705. p.x=lon;
  3706. p.y=lat;
  3707. return p;
  3708. }
  3709. };
  3710. /* ======================================================================
  3711. projCode/lcc.js
  3712. ====================================================================== */
  3713. /*******************************************************************************
  3714. NAME LAMBERT CONFORMAL CONIC
  3715. PURPOSE: Transforms input longitude and latitude to Easting and
  3716. Northing for the Lambert Conformal Conic projection. The
  3717. longitude and latitude must be in radians. The Easting
  3718. and Northing values will be returned in meters.
  3719. ALGORITHM REFERENCES
  3720. 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3721. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3722. State Government Printing Office, Washington D.C., 1987.
  3723. 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  3724. U.S. Geological Survey Professional Paper 1453 , United State Government
  3725. *******************************************************************************/
  3726. //<2104> +proj=lcc +lat_1=10.16666666666667 +lat_0=10.16666666666667 +lon_0=-71.60561777777777 +k_0=1 +x0=-17044 +x0=-23139.97 +ellps=intl +units=m +no_defs no_defs
  3727. // Initialize the Lambert Conformal conic projection
  3728. // -----------------------------------------------------------------
  3729. //Proj4js.Proj.lcc = Class.create();
  3730. Proj4js.Proj.lcc = {
  3731. init : function() {
  3732. // array of: r_maj,r_min,lat1,lat2,c_lon,c_lat,false_east,false_north
  3733. //double c_lat; /* center latitude */
  3734. //double c_lon; /* center longitude */
  3735. //double lat1; /* first standard parallel */
  3736. //double lat2; /* second standard parallel */
  3737. //double r_maj; /* major axis */
  3738. //double r_min; /* minor axis */
  3739. //double false_east; /* x offset in meters */
  3740. //double false_north; /* y offset in meters */
  3741. if (!this.lat2){this.lat2=this.lat0;}//if lat2 is not defined
  3742. if (!this.k0) this.k0 = 1.0;
  3743. // Standard Parallels cannot be equal and on opposite sides of the equator
  3744. if (Math.abs(this.lat1+this.lat2) < Proj4js.common.EPSLN) {
  3745. Proj4js.reportError("lcc:init: Equal Latitudes");
  3746. return;
  3747. }
  3748. var temp = this.b / this.a;
  3749. this.e = Math.sqrt(1.0 - temp*temp);
  3750. var sin1 = Math.sin(this.lat1);
  3751. var cos1 = Math.cos(this.lat1);
  3752. var ms1 = Proj4js.common.msfnz(this.e, sin1, cos1);
  3753. var ts1 = Proj4js.common.tsfnz(this.e, this.lat1, sin1);
  3754. var sin2 = Math.sin(this.lat2);
  3755. var cos2 = Math.cos(this.lat2);
  3756. var ms2 = Proj4js.common.msfnz(this.e, sin2, cos2);
  3757. var ts2 = Proj4js.common.tsfnz(this.e, this.lat2, sin2);
  3758. var ts0 = Proj4js.common.tsfnz(this.e, this.lat0, Math.sin(this.lat0));
  3759. if (Math.abs(this.lat1 - this.lat2) > Proj4js.common.EPSLN) {
  3760. this.ns = Math.log(ms1/ms2)/Math.log(ts1/ts2);
  3761. } else {
  3762. this.ns = sin1;
  3763. }
  3764. this.f0 = ms1 / (this.ns * Math.pow(ts1, this.ns));
  3765. this.rh = this.a * this.f0 * Math.pow(ts0, this.ns);
  3766. if (!this.title) this.title = "Lambert Conformal Conic";
  3767. },
  3768. // Lambert Conformal conic forward equations--mapping lat,long to x,y
  3769. // -----------------------------------------------------------------
  3770. forward : function(p) {
  3771. var lon = p.x;
  3772. var lat = p.y;
  3773. // convert to radians
  3774. if ( lat <= 90.0 && lat >= -90.0 && lon <= 180.0 && lon >= -180.0) {
  3775. //lon = lon * Proj4js.common.D2R;
  3776. //lat = lat * Proj4js.common.D2R;
  3777. } else {
  3778. Proj4js.reportError("lcc:forward: llInputOutOfRange: "+ lon +" : " + lat);
  3779. return null;
  3780. }
  3781. var con = Math.abs( Math.abs(lat) - Proj4js.common.HALF_PI);
  3782. var ts, rh1;
  3783. if (con > Proj4js.common.EPSLN) {
  3784. ts = Proj4js.common.tsfnz(this.e, lat, Math.sin(lat) );
  3785. rh1 = this.a * this.f0 * Math.pow(ts, this.ns);
  3786. } else {
  3787. con = lat * this.ns;
  3788. if (con <= 0) {
  3789. Proj4js.reportError("lcc:forward: No Projection");
  3790. return null;
  3791. }
  3792. rh1 = 0;
  3793. }
  3794. var theta = this.ns * Proj4js.common.adjust_lon(lon - this.long0);
  3795. p.x = this.k0 * (rh1 * Math.sin(theta)) + this.x0;
  3796. p.y = this.k0 * (this.rh - rh1 * Math.cos(theta)) + this.y0;
  3797. return p;
  3798. },
  3799. // Lambert Conformal Conic inverse equations--mapping x,y to lat/long
  3800. // -----------------------------------------------------------------
  3801. inverse : function(p) {
  3802. var rh1, con, ts;
  3803. var lat, lon;
  3804. x = (p.x - this.x0)/this.k0;
  3805. y = (this.rh - (p.y - this.y0)/this.k0);
  3806. if (this.ns > 0) {
  3807. rh1 = Math.sqrt (x * x + y * y);
  3808. con = 1.0;
  3809. } else {
  3810. rh1 = -Math.sqrt (x * x + y * y);
  3811. con = -1.0;
  3812. }
  3813. var theta = 0.0;
  3814. if (rh1 != 0) {
  3815. theta = Math.atan2((con * x),(con * y));
  3816. }
  3817. if ((rh1 != 0) || (this.ns > 0.0)) {
  3818. con = 1.0/this.ns;
  3819. ts = Math.pow((rh1/(this.a * this.f0)), con);
  3820. lat = Proj4js.common.phi2z(this.e, ts);
  3821. if (lat == -9999) return null;
  3822. } else {
  3823. lat = -Proj4js.common.HALF_PI;
  3824. }
  3825. lon = Proj4js.common.adjust_lon(theta/this.ns + this.long0);
  3826. p.x = lon;
  3827. p.y = lat;
  3828. return p;
  3829. }
  3830. };
  3831. /* ======================================================================
  3832. projCode/laea.js
  3833. ====================================================================== */
  3834. /*******************************************************************************
  3835. NAME LAMBERT AZIMUTHAL EQUAL-AREA
  3836. PURPOSE: Transforms input longitude and latitude to Easting and
  3837. Northing for the Lambert Azimuthal Equal-Area projection. The
  3838. longitude and latitude must be in radians. The Easting
  3839. and Northing values will be returned in meters.
  3840. PROGRAMMER DATE
  3841. ---------- ----
  3842. D. Steinwand, EROS March, 1991
  3843. This function was adapted from the Lambert Azimuthal Equal Area projection
  3844. code (FORTRAN) in the General Cartographic Transformation Package software
  3845. which is available from the U.S. Geological Survey National Mapping Division.
  3846. ALGORITHM REFERENCES
  3847. 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
  3848. The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
  3849. 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  3850. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  3851. State Government Printing Office, Washington D.C., 1987.
  3852. 3. "Software Documentation for GCTP General Cartographic Transformation
  3853. Package", U.S. Geological Survey National Mapping Division, May 1982.
  3854. *******************************************************************************/
  3855. Proj4js.Proj.laea = {
  3856. S_POLE: 1,
  3857. N_POLE: 2,
  3858. EQUIT: 3,
  3859. OBLIQ: 4,
  3860. /* Initialize the Lambert Azimuthal Equal Area projection
  3861. ------------------------------------------------------*/
  3862. init: function() {
  3863. var t = Math.abs(this.lat0);
  3864. if (Math.abs(t - Proj4js.common.HALF_PI) < Proj4js.common.EPSLN) {
  3865. this.mode = this.lat0 < 0. ? this.S_POLE : this.N_POLE;
  3866. } else if (Math.abs(t) < Proj4js.common.EPSLN) {
  3867. this.mode = this.EQUIT;
  3868. } else {
  3869. this.mode = this.OBLIQ;
  3870. }
  3871. if (this.es > 0) {
  3872. var sinphi;
  3873. this.qp = Proj4js.common.qsfnz(this.e, 1.0);
  3874. this.mmf = .5 / (1. - this.es);
  3875. this.apa = this.authset(this.es);
  3876. switch (this.mode) {
  3877. case this.N_POLE:
  3878. case this.S_POLE:
  3879. this.dd = 1.;
  3880. break;
  3881. case this.EQUIT:
  3882. this.rq = Math.sqrt(.5 * this.qp);
  3883. this.dd = 1. / this.rq;
  3884. this.xmf = 1.;
  3885. this.ymf = .5 * this.qp;
  3886. break;
  3887. case this.OBLIQ:
  3888. this.rq = Math.sqrt(.5 * this.qp);
  3889. sinphi = Math.sin(this.lat0);
  3890. this.sinb1 = Proj4js.common.qsfnz(this.e, sinphi) / this.qp;
  3891. this.cosb1 = Math.sqrt(1. - this.sinb1 * this.sinb1);
  3892. this.dd = Math.cos(this.lat0) / (Math.sqrt(1. - this.es * sinphi * sinphi) * this.rq * this.cosb1);
  3893. this.ymf = (this.xmf = this.rq) / this.dd;
  3894. this.xmf *= this.dd;
  3895. break;
  3896. }
  3897. } else {
  3898. if (this.mode == this.OBLIQ) {
  3899. this.sinph0 = Math.sin(this.lat0);
  3900. this.cosph0 = Math.cos(this.lat0);
  3901. }
  3902. }
  3903. },
  3904. /* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
  3905. -----------------------------------------------------------------------*/
  3906. forward: function(p) {
  3907. /* Forward equations
  3908. -----------------*/
  3909. var x,y;
  3910. var lam=p.x;
  3911. var phi=p.y;
  3912. lam = Proj4js.common.adjust_lon(lam - this.long0);
  3913. if (this.sphere) {
  3914. var coslam, cosphi, sinphi;
  3915. sinphi = Math.sin(phi);
  3916. cosphi = Math.cos(phi);
  3917. coslam = Math.cos(lam);
  3918. switch (this.mode) {
  3919. case this.EQUIT:
  3920. y = (this.mode == this.EQUIT) ? 1. + cosphi * coslam : 1. + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
  3921. if (y <= Proj4js.common.EPSLN) {
  3922. Proj4js.reportError("laea:fwd:y less than eps");
  3923. return null;
  3924. }
  3925. y = Math.sqrt(2. / y);
  3926. x = y * cosphi * Math.sin(lam);
  3927. y *= (this.mode == this.EQUIT) ? sinphi : this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
  3928. break;
  3929. case this.N_POLE:
  3930. coslam = -coslam;
  3931. case this.S_POLE:
  3932. if (Math.abs(phi + this.phi0) < Proj4js.common.EPSLN) {
  3933. Proj4js.reportError("laea:fwd:phi < eps");
  3934. return null;
  3935. }
  3936. y = Proj4js.common.FORTPI - phi * .5;
  3937. y = 2. * ((this.mode == this.S_POLE) ? Math.cos(y) : Math.sin(y));
  3938. x = y * Math.sin(lam);
  3939. y *= coslam;
  3940. break;
  3941. }
  3942. } else {
  3943. var coslam, sinlam, sinphi, q, sinb=0.0, cosb=0.0, b=0.0;
  3944. coslam = Math.cos(lam);
  3945. sinlam = Math.sin(lam);
  3946. sinphi = Math.sin(phi);
  3947. q = Proj4js.common.qsfnz(this.e, sinphi);
  3948. if (this.mode == this.OBLIQ || this.mode == this.EQUIT) {
  3949. sinb = q / this.qp;
  3950. cosb = Math.sqrt(1. - sinb * sinb);
  3951. }
  3952. switch (this.mode) {
  3953. case this.OBLIQ:
  3954. b = 1. + this.sinb1 * sinb + this.cosb1 * cosb * coslam;
  3955. break;
  3956. case this.EQUIT:
  3957. b = 1. + cosb * coslam;
  3958. break;
  3959. case this.N_POLE:
  3960. b = Proj4js.common.HALF_PI + phi;
  3961. q = this.qp - q;
  3962. break;
  3963. case this.S_POLE:
  3964. b = phi - Proj4js.common.HALF_PI;
  3965. q = this.qp + q;
  3966. break;
  3967. }
  3968. if (Math.abs(b) < Proj4js.common.EPSLN) {
  3969. Proj4js.reportError("laea:fwd:b < eps");
  3970. return null;
  3971. }
  3972. switch (this.mode) {
  3973. case this.OBLIQ:
  3974. case this.EQUIT:
  3975. b = Math.sqrt(2. / b);
  3976. if (this.mode == this.OBLIQ) {
  3977. y = this.ymf * b * (this.cosb1 * sinb - this.sinb1 * cosb * coslam);
  3978. } else {
  3979. y = (b = Math.sqrt(2. / (1. + cosb * coslam))) * sinb * this.ymf;
  3980. }
  3981. x = this.xmf * b * cosb * sinlam;
  3982. break;
  3983. case this.N_POLE:
  3984. case this.S_POLE:
  3985. if (q >= 0.) {
  3986. x = (b = Math.sqrt(q)) * sinlam;
  3987. y = coslam * ((this.mode == this.S_POLE) ? b : -b);
  3988. } else {
  3989. x = y = 0.;
  3990. }
  3991. break;
  3992. }
  3993. }
  3994. //v 1.0
  3995. /*
  3996. var sin_lat=Math.sin(lat);
  3997. var cos_lat=Math.cos(lat);
  3998. var sin_delta_lon=Math.sin(delta_lon);
  3999. var cos_delta_lon=Math.cos(delta_lon);
  4000. var g =this.sin_lat_o * sin_lat +this.cos_lat_o * cos_lat * cos_delta_lon;
  4001. if (g == -1.0) {
  4002. Proj4js.reportError("laea:fwd:Point projects to a circle of radius "+ 2.0 * R);
  4003. return null;
  4004. }
  4005. var ksp = this.a * Math.sqrt(2.0 / (1.0 + g));
  4006. var x = ksp * cos_lat * sin_delta_lon + this.x0;
  4007. var y = ksp * (this.cos_lat_o * sin_lat - this.sin_lat_o * cos_lat * cos_delta_lon) + this.y0;
  4008. */
  4009. p.x = this.a*x + this.x0;
  4010. p.y = this.a*y + this.y0;
  4011. return p;
  4012. },//lamazFwd()
  4013. /* Inverse equations
  4014. -----------------*/
  4015. inverse: function(p) {
  4016. p.x -= this.x0;
  4017. p.y -= this.y0;
  4018. var x = p.x/this.a;
  4019. var y = p.y/this.a;
  4020. if (this.sphere) {
  4021. var cosz=0.0, rh, sinz=0.0;
  4022. rh = Math.sqrt(x*x + y*y);
  4023. var phi = rh * .5;
  4024. if (phi > 1.) {
  4025. Proj4js.reportError("laea:Inv:DataError");
  4026. return null;
  4027. }
  4028. phi = 2. * Math.asin(phi);
  4029. if (this.mode == this.OBLIQ || this.mode == this.EQUIT) {
  4030. sinz = Math.sin(phi);
  4031. cosz = Math.cos(phi);
  4032. }
  4033. switch (this.mode) {
  4034. case this.EQUIT:
  4035. phi = (Math.abs(rh) <= Proj4js.common.EPSLN) ? 0. : Math.asin(y * sinz / rh);
  4036. x *= sinz;
  4037. y = cosz * rh;
  4038. break;
  4039. case this.OBLIQ:
  4040. phi = (Math.abs(rh) <= Proj4js.common.EPSLN) ? this.phi0 : Math.asin(cosz * sinph0 + y * sinz * cosph0 / rh);
  4041. x *= sinz * cosph0;
  4042. y = (cosz - Math.sin(phi) * sinph0) * rh;
  4043. break;
  4044. case this.N_POLE:
  4045. y = -y;
  4046. phi = Proj4js.common.HALF_PI - phi;
  4047. break;
  4048. case this.S_POLE:
  4049. phi -= Proj4js.common.HALF_PI;
  4050. break;
  4051. }
  4052. lam = (y == 0. && (this.mode == this.EQUIT || this.mode == this.OBLIQ)) ? 0. : Math.atan2(x, y);
  4053. } else {
  4054. var cCe, sCe, q, rho, ab=0.0;
  4055. switch (this.mode) {
  4056. case this.EQUIT:
  4057. case this.OBLIQ:
  4058. x /= this.dd;
  4059. y *= this.dd;
  4060. rho = Math.sqrt(x*x + y*y);
  4061. if (rho < Proj4js.common.EPSLN) {
  4062. p.x = 0.;
  4063. p.y = this.phi0;
  4064. return p;
  4065. }
  4066. sCe = 2. * Math.asin(.5 * rho / this.rq);
  4067. cCe = Math.cos(sCe);
  4068. x *= (sCe = Math.sin(sCe));
  4069. if (this.mode == this.OBLIQ) {
  4070. ab = cCe * this.sinb1 + y * sCe * this.cosb1 / rho
  4071. q = this.qp * ab;
  4072. y = rho * this.cosb1 * cCe - y * this.sinb1 * sCe;
  4073. } else {
  4074. ab = y * sCe / rho;
  4075. q = this.qp * ab;
  4076. y = rho * cCe;
  4077. }
  4078. break;
  4079. case this.N_POLE:
  4080. y = -y;
  4081. case this.S_POLE:
  4082. q = (x * x + y * y);
  4083. if (!q ) {
  4084. p.x = 0.;
  4085. p.y = this.phi0;
  4086. return p;
  4087. }
  4088. /*
  4089. q = this.qp - q;
  4090. */
  4091. ab = 1. - q / this.qp;
  4092. if (this.mode == this.S_POLE) {
  4093. ab = - ab;
  4094. }
  4095. break;
  4096. }
  4097. lam = Math.atan2(x, y);
  4098. phi = this.authlat(Math.asin(ab), this.apa);
  4099. }
  4100. /*
  4101. var Rh = Math.Math.sqrt(p.x *p.x +p.y * p.y);
  4102. var temp = Rh / (2.0 * this.a);
  4103. if (temp > 1) {
  4104. Proj4js.reportError("laea:Inv:DataError");
  4105. return null;
  4106. }
  4107. var z = 2.0 * Proj4js.common.asinz(temp);
  4108. var sin_z=Math.sin(z);
  4109. var cos_z=Math.cos(z);
  4110. var lon =this.long0;
  4111. if (Math.abs(Rh) > Proj4js.common.EPSLN) {
  4112. var lat = Proj4js.common.asinz(this.sin_lat_o * cos_z +this. cos_lat_o * sin_z *p.y / Rh);
  4113. var temp =Math.abs(this.lat0) - Proj4js.common.HALF_PI;
  4114. if (Math.abs(temp) > Proj4js.common.EPSLN) {
  4115. temp = cos_z -this.sin_lat_o * Math.sin(lat);
  4116. if(temp!=0.0) lon=Proj4js.common.adjust_lon(this.long0+Math.atan2(p.x*sin_z*this.cos_lat_o,temp*Rh));
  4117. } else if (this.lat0 < 0.0) {
  4118. lon = Proj4js.common.adjust_lon(this.long0 - Math.atan2(-p.x,p.y));
  4119. } else {
  4120. lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2(p.x, -p.y));
  4121. }
  4122. } else {
  4123. lat = this.lat0;
  4124. }
  4125. */
  4126. //return(OK);
  4127. p.x = Proj4js.common.adjust_lon(this.long0+lam);
  4128. p.y = phi;
  4129. return p;
  4130. },//lamazInv()
  4131. /* determine latitude from authalic latitude */
  4132. P00: .33333333333333333333,
  4133. P01: .17222222222222222222,
  4134. P02: .10257936507936507936,
  4135. P10: .06388888888888888888,
  4136. P11: .06640211640211640211,
  4137. P20: .01641501294219154443,
  4138. authset: function(es) {
  4139. var t;
  4140. var APA = new Array();
  4141. APA[0] = es * this.P00;
  4142. t = es * es;
  4143. APA[0] += t * this.P01;
  4144. APA[1] = t * this.P10;
  4145. t *= es;
  4146. APA[0] += t * this.P02;
  4147. APA[1] += t * this.P11;
  4148. APA[2] = t * this.P20;
  4149. return APA;
  4150. },
  4151. authlat: function(beta, APA) {
  4152. var t = beta+beta;
  4153. return(beta + APA[0] * Math.sin(t) + APA[1] * Math.sin(t+t) + APA[2] * Math.sin(t+t+t));
  4154. }
  4155. };
  4156. /* ======================================================================
  4157. projCode/aeqd.js
  4158. ====================================================================== */
  4159. Proj4js.Proj.aeqd = {
  4160. init : function() {
  4161. this.sin_p12=Math.sin(this.lat0);
  4162. this.cos_p12=Math.cos(this.lat0);
  4163. },
  4164. forward: function(p) {
  4165. var lon=p.x;
  4166. var lat=p.y;
  4167. var ksp;
  4168. var sinphi=Math.sin(p.y);
  4169. var cosphi=Math.cos(p.y);
  4170. var dlon = Proj4js.common.adjust_lon(lon - this.long0);
  4171. var coslon = Math.cos(dlon);
  4172. var g = this.sin_p12 * sinphi + this.cos_p12 * cosphi * coslon;
  4173. if (Math.abs(Math.abs(g) - 1.0) < Proj4js.common.EPSLN) {
  4174. ksp = 1.0;
  4175. if (g < 0.0) {
  4176. Proj4js.reportError("aeqd:Fwd:PointError");
  4177. return;
  4178. }
  4179. } else {
  4180. var z = Math.acos(g);
  4181. ksp = z/Math.sin(z);
  4182. }
  4183. p.x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon);
  4184. p.y = this.y0 + this.a * ksp * (this.cos_p12 * sinphi - this.sin_p12 * cosphi * coslon);
  4185. return p;
  4186. },
  4187. inverse: function(p){
  4188. p.x -= this.x0;
  4189. p.y -= this.y0;
  4190. var rh = Math.sqrt(p.x * p.x + p.y *p.y);
  4191. if (rh > (2.0 * Proj4js.common.HALF_PI * this.a)) {
  4192. Proj4js.reportError("aeqdInvDataError");
  4193. return;
  4194. }
  4195. var z = rh / this.a;
  4196. var sinz=Math.sin(z);
  4197. var cosz=Math.cos(z);
  4198. var lon = this.long0;
  4199. var lat;
  4200. if (Math.abs(rh) <= Proj4js.common.EPSLN) {
  4201. lat = this.lat0;
  4202. } else {
  4203. lat = Proj4js.common.asinz(cosz * this.sin_p12 + (p.y * sinz * this.cos_p12) / rh);
  4204. var con = Math.abs(this.lat0) - Proj4js.common.HALF_PI;
  4205. if (Math.abs(con) <= Proj4js.common.EPSLN) {
  4206. if (lat0 >= 0.0) {
  4207. lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2(p.x , -p.y));
  4208. } else {
  4209. lon = Proj4js.common.adjust_lon(this.long0 - Math.atan2(-p.x , p.y));
  4210. }
  4211. } else {
  4212. con = cosz - this.sin_p12 * Math.sin(lat);
  4213. if ((Math.abs(con) < Proj4js.common.EPSLN) && (Math.abs(p.x) < Proj4js.common.EPSLN)) {
  4214. //no-op, just keep the lon value as is
  4215. } else {
  4216. var temp = Math.atan2((p.x * sinz * this.cos_p12), (con * rh));
  4217. lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p12), (con * rh)));
  4218. }
  4219. }
  4220. }
  4221. p.x = lon;
  4222. p.y = lat;
  4223. return p;
  4224. }
  4225. };
  4226. /* ======================================================================
  4227. projCode/moll.js
  4228. ====================================================================== */
  4229. /*******************************************************************************
  4230. NAME MOLLWEIDE
  4231. PURPOSE: Transforms input longitude and latitude to Easting and
  4232. Northing for the MOllweide projection. The
  4233. longitude and latitude must be in radians. The Easting
  4234. and Northing values will be returned in meters.
  4235. PROGRAMMER DATE
  4236. ---------- ----
  4237. D. Steinwand, EROS May, 1991; Updated Sept, 1992; Updated Feb, 1993
  4238. S. Nelson, EDC Jun, 2993; Made corrections in precision and
  4239. number of iterations.
  4240. ALGORITHM REFERENCES
  4241. 1. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
  4242. U.S. Geological Survey Professional Paper 1453 , United State Government
  4243. Printing Office, Washington D.C., 1989.
  4244. 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
  4245. Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
  4246. State Government Printing Office, Washington D.C., 1987.
  4247. *******************************************************************************/
  4248. Proj4js.Proj.moll = {
  4249. /* Initialize the Mollweide projection
  4250. ------------------------------------*/
  4251. init: function(){
  4252. //no-op
  4253. },
  4254. /* Mollweide forward equations--mapping lat,long to x,y
  4255. ----------------------------------------------------*/
  4256. forward: function(p) {
  4257. /* Forward equations
  4258. -----------------*/
  4259. var lon=p.x;
  4260. var lat=p.y;
  4261. var delta_lon = Proj4js.common.adjust_lon(lon - this.long0);
  4262. var theta = lat;
  4263. var con = Proj4js.common.PI * Math.sin(lat);
  4264. /* Iterate using the Newton-Raphson method to find theta
  4265. -----------------------------------------------------*/
  4266. for (var i=0;true;i++) {
  4267. var delta_theta = -(theta + Math.sin(theta) - con)/ (1.0 + Math.cos(theta));
  4268. theta += delta_theta;
  4269. if (Math.abs(delta_theta) < Proj4js.common.EPSLN) break;
  4270. if (i >= 50) {
  4271. Proj4js.reportError("moll:Fwd:IterationError");
  4272. //return(241);
  4273. }
  4274. }
  4275. theta /= 2.0;
  4276. /* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
  4277. this is done here because of precision problems with "cos(theta)"
  4278. --------------------------------------------------------------------------*/
  4279. if (Proj4js.common.PI/2 - Math.abs(lat) < Proj4js.common.EPSLN) delta_lon =0;
  4280. var x = 0.900316316158 * this.a * delta_lon * Math.cos(theta) + this.x0;
  4281. var y = 1.4142135623731 * this.a * Math.sin(theta) + this.y0;
  4282. p.x=x;
  4283. p.y=y;
  4284. return p;
  4285. },
  4286. inverse: function(p){
  4287. var theta;
  4288. var arg;
  4289. /* Inverse equations
  4290. -----------------*/
  4291. p.x-= this.x0;
  4292. //~ p.y -= this.y0;
  4293. var arg = p.y / (1.4142135623731 * this.a);
  4294. /* Because of division by zero problems, 'arg' can not be 1.0. Therefore
  4295. a number very close to one is used instead.
  4296. -------------------------------------------------------------------*/
  4297. if(Math.abs(arg) > 0.999999999999) arg=0.999999999999;
  4298. var theta =Math.asin(arg);
  4299. var lon = Proj4js.common.adjust_lon(this.long0 + (p.x / (0.900316316158 * this.a * Math.cos(theta))));
  4300. if(lon < (-Proj4js.common.PI)) lon= -Proj4js.common.PI;
  4301. if(lon > Proj4js.common.PI) lon= Proj4js.common.PI;
  4302. arg = (2.0 * theta + Math.sin(2.0 * theta)) / Proj4js.common.PI;
  4303. if(Math.abs(arg) > 1.0)arg=1.0;
  4304. var lat = Math.asin(arg);
  4305. //return(OK);
  4306. p.x=lon;
  4307. p.y=lat;
  4308. return p;
  4309. }
  4310. };