projection conversion equations
Martin Weinelt
mweinelt at PLANIGLOBE.COM
Tue Jun 7 00:11:33 PDT 2005
On Tuesday 07 June 2005 08:09, Dylan Beaudette wrote:
> Hi,
>
> I would like to re-implement some functionality in the DHTML mapserver
> interface for converting between Lat/Lon to an Albers Equal Area
> Projection.
>
> Currently, I have the proj library doing this for single coordinate
> pairs, but I would like to integrate this functionality in the form of
> a JS routine for on-the-fly conversion: much like the existing UTM
> <->lat/lon conversion.
>
> Does anyone have any ideas on where to get started?
>
> thanks in advance!
Dylan,
start with " Snyder, J.P, 1987: Map Projections - A Working Manual".
There you find the formulas for the projections and you can translate
this to JS and boil it down. I did two for a project lately which I attach
to give you an idea: Mercator invers and Lambert Azimuthal Equal Area
invers:
function refSys(radius) { // some useful constants
var t=this;
t.R=radius;
t.halfpi=Math.PI/2;
t.R2=t.R*2;
t.d2r= Math.PI/180;
}
var sphere=new refSys(6371000);
function invMerc(xn,yn) {
var eyr,phi,lam;
eyr = Math.pow(Math.E, (yn * -1)/sphere.R);
phi = (sphere.halfpi - (2*Math.atan(eyr)))/sphere.d2r;
lam = (xn/sphere.R)/sphere.d2r;
return [phi,lam];
}
function invLaea(xn,yn,asp) { // sphere, polar aspect, lon0=0
var p,c,phi,lam,adj;
if (asp=='N') yn*=-1;
p = Math.sqrt(Math.pow(xn,2) + Math.pow(yn,2));
if (p==0) return([90,0]);
c = 2* Math.asin(p/sphere.R2);
phi = Math.asin(Math.cos(c)) / sphere.d2r;
(yn<=0&&xn>0)?adj=180:adj=0; // ad-hoc quadrant adjustment
(yn<=0&&xn<0)?adj=-180:adj=adj;
var lam = Math.atan(xn/yn) / sphere.d2r + adj;
return [phi,lam];
}
Cheers, Martin
More information about the MapServer-users
mailing list