proj4
Version:
Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.
75 lines (67 loc) • 1.94 kB
JavaScript
import gauss from './gauss';
import adjust_lon from '../common/adjust_lon';
import hypot from '../common/hypot';
/**
* @typedef {Object} LocalThis
* @property {number} sinc0
* @property {number} cosc0
* @property {number} R2
* @property {number} rc
* @property {number} phic0
*/
/** @this {import('../defs.js').ProjectionDefinition & LocalThis} */
export function init() {
gauss.init.apply(this);
if (!this.rc) {
return;
}
this.sinc0 = Math.sin(this.phic0);
this.cosc0 = Math.cos(this.phic0);
this.R2 = 2 * this.rc;
if (!this.title) {
this.title = 'Oblique Stereographic Alternative';
}
}
export function forward(p) {
var sinc, cosc, cosl, k;
p.x = adjust_lon(p.x - this.long0, this.over);
gauss.forward.apply(this, [p]);
sinc = Math.sin(p.y);
cosc = Math.cos(p.y);
cosl = Math.cos(p.x);
k = this.k0 * this.R2 / (1 + this.sinc0 * sinc + this.cosc0 * cosc * cosl);
p.x = k * cosc * Math.sin(p.x);
p.y = k * (this.cosc0 * sinc - this.sinc0 * cosc * cosl);
p.x = this.a * p.x + this.x0;
p.y = this.a * p.y + this.y0;
return p;
}
export function inverse(p) {
var sinc, cosc, lon, lat, rho;
p.x = (p.x - this.x0) / this.a;
p.y = (p.y - this.y0) / this.a;
p.x /= this.k0;
p.y /= this.k0;
if ((rho = hypot(p.x, p.y))) {
var c = 2 * Math.atan2(rho, this.R2);
sinc = Math.sin(c);
cosc = Math.cos(c);
lat = Math.asin(cosc * this.sinc0 + p.y * sinc * this.cosc0 / rho);
lon = Math.atan2(p.x * sinc, rho * this.cosc0 * cosc - p.y * this.sinc0 * sinc);
} else {
lat = this.phic0;
lon = 0;
}
p.x = lon;
p.y = lat;
gauss.inverse.apply(this, [p]);
p.x = adjust_lon(p.x + this.long0, this.over);
return p;
}
export var names = ['Stereographic_North_Pole', 'Oblique_Stereographic', 'sterea', 'Oblique Stereographic Alternative', 'Double_Stereographic'];
export default {
init: init,
forward: forward,
inverse: inverse,
names: names
};