This repository has been archived by the owner on Jan 1, 2021. It is now read-only.
forked from openstreetmap/potlatch2
-
Notifications
You must be signed in to change notification settings - Fork 23
/
ProjAeqd.as
executable file
·93 lines (82 loc) · 2.75 KB
/
ProjAeqd.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.gradoservice.proj4as.proj
{
import com.gradoservice.proj4as.ProjPoint;
import com.gradoservice.proj4as.ProjConstants;
import com.gradoservice.proj4as.Datum;
public class ProjAeqd extends AbstractProjProjection
{
public function ProjAeqd(data:ProjParams)
{
super(data);
}
override public function init():void
{
this.sin_p12=Math.sin(this.lat0)
this.cos_p12=Math.cos(this.lat0)
}
override public function forward(p:ProjPoint):ProjPoint
{
var lon:Number=p.x;
var lat:Number=p.y;
var ksp:Number;
var sinphi:Number=Math.sin(p.y);
var cosphi:Number=Math.cos(p.y);
var dlon:Number = ProjConstants.adjust_lon(lon - this.long0);
var coslon:Number = Math.cos(dlon);
var g:Number = this.sin_p12 * sinphi + this.cos_p12 * cosphi * coslon;
if (Math.abs(Math.abs(g) - 1.0) < ProjConstants.EPSLN) {
ksp = 1.0;
if (g < 0.0) {
trace("aeqd:Fwd:PointError");
return null;
}
} else {
var z:Number = Math.acos(g);
ksp = z/Math.sin(z);
}
p.x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon);
p.y = this.y0 + this.a * ksp * (this.cos_p12 * sinphi - this.sin_p12 * cosphi * coslon);
return p;
}
override public function inverse(p:ProjPoint):ProjPoint
{
p.x -= this.x0;
p.y -= this.y0;
var rh:Number = Math.sqrt(p.x * p.x + p.y *p.y);
if (rh > (2.0 * ProjConstants.HALF_PI * this.a))
{
trace("aeqdInvDataError");
return null;
}
var z:Number = rh / this.a;
var sinz:Number=Math.sin(z)
var cosz:Number=Math.cos(z)
var lon:Number = this.long0;
var lat:Number;
if (Math.abs(rh) <= ProjConstants.EPSLN) {
lat = this.lat0;
} else {
lat = ProjConstants.asinz(cosz * this.sin_p12 + (p.y * sinz * this.cos_p12) / rh);
var con:Number = Math.abs(this.lat0) - ProjConstants.HALF_PI;
if (Math.abs(con) <= ProjConstants.EPSLN) {
if (lat0 >= 0.0) {
lon = ProjConstants.adjust_lon(this.long0 + Math.atan2(p.x , -p.y));
} else {
lon = ProjConstants.adjust_lon(this.long0 - Math.atan2(-p.x , p.y));
}
} else {
con = cosz - this.sin_p12 * Math.sin(lat);
if ((Math.abs(con) < ProjConstants.EPSLN) && (Math.abs(p.x) < ProjConstants.EPSLN)) {
//no-op, just keep the lon value as is
} else {
var temp:Number = Math.atan2((p.x * sinz * this.cos_p12), (con * rh));
lon = ProjConstants.adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p12), (con * rh)));
}
}
}
p.x = lon;
p.y = lat;
return p;
}
}
}