forked from systemed/potlatch2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjProjection.as
executable file
·282 lines (250 loc) · 12.5 KB
/
ProjProjection.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
package com.gradoservice.proj4as
{
import com.gradoservice.proj4as.proj.*;
public class ProjProjection
{
/**
* Property: readyToUse
* Flag to indicate if initialization is complete for this Proj object
*/
public var readyToUse:Boolean = false;
/**
* Property: title
* The title to describe the projection
*/
protected var projParams:ProjParams = new ProjParams();
static public const defs:Object = {
'EPSG:900913': "+title=Google Mercator EPSG:900913 +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",
'WGS84': "+title=long/lat:WGS84 +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees",
'EPSG:4326': "+title=long/lat:WGS84 +proj=longlat +a=6378137.0 +b=6356752.31424518 +ellps=WGS84 +datum=WGS84 +units=degrees",
'EPSG:4269': "+title=long/lat:NAD83 +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees",
'EPSG:32639': "+title=WGS 84 / UTM zone 39N +proj=utm +zone=39 +ellps=WGS84 +datum=WGS84 +units=m +no_defs",
'EPSG:27700': "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs"
}
protected var proj:IProjection;
public function get srsCode():String
{
return projParams.srsCode;
}
public function get srsProjNumber():String
{
return projParams.srsProjNumber;
}
public function get projName():String
{
return projParams.projName;
}
public function get datum():Datum
{
return projParams.datum;
}
public function get datumCode():String
{
return projParams.datumCode;
}
public function get from_greenwich():Number
{
return projParams.from_greenwich;
}
public function get to_meter():Number
{
return projParams.to_meter;
}
public function get a():Number
{
return projParams.a;
}
public function get b():Number
{
return projParams.b;
}
public function get ep2():Number
{
return projParams.ep2;
}
public function get es():Number
{
return projParams.es;
}
public function get datum_params():Array
{
return projParams.datum_params;
}
public function ProjProjection(srsCode:String)
{
this.projParams.srsCode = srsCode.toUpperCase();
if (this.projParams.srsCode.indexOf("EPSG") == 0) {
this.projParams.srsAuth = 'epsg';
this.projParams.srsProjNumber = this.projParams.srsCode.substring(5);
// DGR 2007-11-20 : authority IGNF
} else if (this.projParams.srsCode.indexOf("IGNF") == 0) {
this.projParams.srsAuth = 'IGNF';
this.projParams.srsProjNumber = this.projParams.srsCode.substring(5);
// DGR 2008-06-19 : pseudo-authority CRS for WMS
} else if (this.projParams.srsCode.indexOf("CRS") == 0) {
this.projParams.srsAuth = 'CRS';
this.projParams.srsProjNumber = this.projParams.srsCode.substring(4);
} else {
this.projParams.srsAuth = '';
this.projParams.srsProjNumber = this.projParams.srsCode;
}
this.loadProjDefinition();
}
private function loadProjDefinition():void
{
if (this.srsCode!=null && ProjProjection.defs[this.srsCode]!=null)
{
this.parseDef(ProjProjection.defs[this.projParams.srsCode]);
this.initTransforms();
}
}
protected function initTransforms():void
{
switch (this.projParams.projName)
{
case "aea": this.proj = new ProjAea(this.projParams); break;
case "aeqd": this.proj = new ProjAeqd(this.projParams); break;
case "eqc": this.proj = new ProjEqc(this.projParams); break;
case "eqdc": this.proj = new ProjEqdc(this.projParams); break;
case "equi": this.proj = new ProjEqui(this.projParams); break;
case "gauss": this.proj = new ProjGauss(this.projParams); break;
case "gstmerc": this.proj = new ProjGstmerc(this.projParams); break;
case "laea": this.proj = new ProjLaea(this.projParams); break;
case "lcc": this.proj = new ProjLcc(this.projParams); break;
case "longlat": this.proj = new ProjLonglat(this.projParams); break;
case "merc": this.proj = new ProjMerc(this.projParams); break;
case "mill": this.proj = new ProjMill(this.projParams); break;
case "moll": this.proj = new ProjMoll(this.projParams); break;
case "nzmg": this.proj = new ProjNzmg(this.projParams); break;
case "omerc": this.proj = new ProjOmerc(this.projParams); break;
case "ortho": this.proj = new ProjOrtho(this.projParams); break;
case "sinu": this.proj = new ProjSinu(this.projParams); break;
case "omerc": this.proj = new ProjOmerc(this.projParams); break;
case "stere": this.proj = new ProjStere(this.projParams); break;
case "sterea": this.proj = new ProjSterea(this.projParams); break;
case "tmerc": this.proj = new ProjTmerc(this.projParams); break;
case "utm": this.proj = new ProjUtm(this.projParams); break;
case "vandg": this.proj = new ProjVandg(this.projParams); break;
}
if (this.proj!=null) {
this.proj.init();
this.readyToUse = true;
}
}
private function parseDef(definition:String):void
{
var paramName:String = '';
var paramVal:String = '';
var paramArray:Array=definition.split("+");
for (var prop:int=0; prop<paramArray.length; prop++) {
var property:Array = paramArray[prop].split("=");
paramName = property[0].toLowerCase();
paramVal = property[1];
switch (paramName.replace(/\s/gi,"")) { // trim out spaces
case "": break; // throw away nameless parameter
case "title": this.projParams.title = paramVal; break;
case "proj": this.projParams.projName = paramVal.replace(/\s/gi,""); break;
case "units": this.projParams.units = paramVal.replace(/\s/gi,""); break;
case "datum": this.projParams.datumCode = paramVal.replace(/\s/gi,""); break;
case "nadgrids": this.projParams.nagrids = paramVal.replace(/\s/gi,""); break;
case "ellps": this.projParams.ellps = paramVal.replace(/\s/gi,""); break;
case "a": this.projParams.a = parseFloat(paramVal); break; // semi-major radius
case "b": this.projParams.b = parseFloat(paramVal); break; // semi-minor radius
// DGR 2007-11-20
case "rf": this.projParams.rf = parseFloat(paramVal); break; // inverse flattening rf= a/(a-b)
case "lat_0": this.projParams.lat0 = parseFloat(paramVal)*ProjConstants.D2R; break; // phi0, central latitude
case "lat_1": this.projParams.lat1 = parseFloat(paramVal)*ProjConstants.D2R; break; //standard parallel 1
case "lat_2": this.projParams.lat2 = parseFloat(paramVal)*ProjConstants.D2R; break; //standard parallel 2
case "lat_ts": this.projParams.lat_ts = parseFloat(paramVal)*ProjConstants.D2R; break; // used in merc and eqc
case "lon_0": this.projParams.long0 = parseFloat(paramVal)*ProjConstants.D2R; break; // lam0, central longitude
case "alpha": this.projParams.alpha = parseFloat(paramVal)*ProjConstants.D2R; break; //for somerc projection
case "lonc": this.projParams.longc = parseFloat(paramVal)*ProjConstants.D2R; break; //for somerc projection
case "x_0": this.projParams.x0 = parseFloat(paramVal); break; // false easting
case "y_0": this.projParams.y0 = parseFloat(paramVal); break; // false northing
case "k_0": this.projParams.k0 = parseFloat(paramVal); break; // projection scale factor
case "k": this.projParams.k0 = parseFloat(paramVal); break; // both forms returned
case "R_A": this.projParams.R_A = true; break; //Spheroid radius
case "zone": this.projParams.zone = parseInt(paramVal); break; // UTM Zone
case "south": this.projParams.utmSouth = true; break; // UTM north/south
case "towgs84":this.projParams.datum_params = paramVal.split(","); break;
case "to_meter": this.projParams.to_meter = parseFloat(paramVal); break; // cartesian scaling
case "from_greenwich": this.projParams.from_greenwich = parseFloat(paramVal)*ProjConstants.D2R; break;
// DGR 2008-07-09 : if pm is not a well-known prime meridian take
// the value instead of 0.0, then convert to radians
case "pm": paramVal = paramVal.replace(/\s/gi,"");
this.projParams.from_greenwich = ProjConstants.PrimeMeridian[paramVal] ?
ProjConstants.PrimeMeridian[paramVal] : parseFloat(paramVal);
this.projParams.from_greenwich *= ProjConstants.D2R;
break;
case "no_defs": break;
default: trace("Unrecognized parameter: " + paramName); break;
} // switch()
} // for paramArray
this.deriveConstants();
}
private function deriveConstants():void
{
if (this.projParams.nagrids == '@null') this.projParams.datumCode = 'none';
if (this.projParams.datumCode && this.projParams.datumCode != 'none')
{
var datumDef:Object = ProjConstants.Datum[this.projParams.datumCode];
if (datumDef)
{
this.projParams.datum_params = datumDef.towgs84.split(',');
this.projParams.ellps = datumDef.ellipse;
this.projParams.datumName = datumDef.datumName ? datumDef.datumName : this.projParams.datumCode;
}
}
if (!this.projParams.a) { // do we have an ellipsoid?
var ellipse:Object = ProjConstants.Ellipsoid[this.projParams.ellps] ? ProjConstants.Ellipsoid[this.projParams.ellps] : ProjConstants.Ellipsoid['WGS84'];
extend(this.projParams, ellipse);
}
if (this.projParams.rf && !this.projParams.b) this.projParams.b = (1.0 - 1.0/this.projParams.rf) * this.projParams.a;
if (Math.abs(this.projParams.a - this.projParams.b)<ProjConstants.EPSLN) {
this.projParams.sphere = true;
this.projParams.b= this.projParams.a;
}
this.projParams.a2 = this.projParams.a * this.projParams.a; // used in geocentric
this.projParams.b2 = this.projParams.b * this.projParams.b; // used in geocentric
this.projParams.es = (this.projParams.a2-this.projParams.b2)/this.projParams.a2; // e ^ 2
this.projParams.e = Math.sqrt(this.projParams.es); // eccentricity
if (this.projParams.R_A) {
this.projParams.a *= 1. - this.projParams.es * (ProjConstants.SIXTH + this.projParams.es * (ProjConstants.RA4 + this.projParams.es * ProjConstants.RA6));
this.projParams.a2 = this.projParams.a * this.projParams.a;
this.projParams.b2 = this.projParams.b * this.projParams.b;
this.projParams.es = 0.;
}
this.projParams.ep2=(this.projParams.a2-this.projParams.b2)/this.projParams.b2; // used in geocentric
if (!this.projParams.k0) this.projParams.k0 = 1.0; //default value
this.projParams.datum = new Datum(this);
}
private function extend(destination:Object, source:Object):void
{
destination = destination || {};
if(source) {
for(var property:String in source) {
var value:Object = source[property];
if(value != null) {
destination[property] = value;
}
}
}
}
public function forward(p:ProjPoint):ProjPoint
{
if (this.proj!=null)
{
return this.proj.forward(p);
}
return p;
}
public function inverse(p:ProjPoint):ProjPoint
{
if (this.proj!=null)
{
return this.proj.inverse(p);
}
return p;
}
}
}