projection conversion equations

Dylan Beaudette dylan at IICI.NO-IP.ORG
Tue Jun 7 12:20:38 EDT 2005


On Jun 7, 2005, at 12:11 AM, Martin Weinelt wrote:

> 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
>
>


Martin,

thank you very much for the literature reference, this is exactly what 
i was looking for. I have located the book in my school's library, and 
will pour over it this week.

thanks again for the example code as well!

--
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341



More information about the mapserver-users mailing list