usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacemrp{ Public classCLASSMCT {Static Public int__iterativetimes =Ten;//number of iterations in the reverse conversion program Static Public Double__iterativevalue =0;//iterative initial values in a reverse translator Static Public Double__a =6378137.0;//ellipsoid length axis, m Static Public Double__b =6356752.314;//ellipsoid Short axis, M Static Public Double__b0 =0;//standard latitude, radians Static Public Double__l0 =0;//origin longitude, radians//Angle-to-radian conversion Static Public DoubleDegreetorad (Doubledegree) { returnMath.PI * (Double) Degree/(Double) the); } //arc-to-angle conversion Static Public DoubleRadtodegree (Doublerad) { return( the* rad)/Math.PI; } //the setting of the above parameters is done by the following public functions//setting __a and __b Static Public voidSetab (DoubleADoubleb) {if(A <=0|| b <=0) { return; } __a=A; __b=b; } //Set __b0 Static Public voidSetB0 (DoubleB0) {B0=Degreetorad (B0); if(B0 <-MATH.PI/2|| B0 > Math.PI/2) { return; } __b0=B0; } //Set __l0 Static Public voidSetL0 (Doublel0) {L0=Degreetorad (l0); if(L0 <-math.pi | | l0 >Math.PI) {return; } __l0=L0; } /******************************************* projection forward translator double B: latitude, Angle double L: longitude, Angle double & X: longitudinal cartesian double& Y: transverse cartesian *******************************************/ //static public int toproj (double B, double L, ref double X, ref double Y) Static Publicpointxy lbtoxy (pointlb pmtLonLat0, pointlb pmtLonLat1) {SetB0 (Pmtlonlat0.lat); SetL0 (Pmtlonlat0.lon); DoubleB =Degreetorad (Pmtlonlat1.lat); DoubleL =Degreetorad (Pmtlonlat1.lon); POINTXY XY=NewPointxy (); Xy.x=0; XY.Y =0; DoubleF/*Flat Rate*/E/*first bias heart rate*/, E_/*Second eccentricity*/, NB0/*radius of curvature of the unitary circle of Mao*/, K, dtemp; DoubleE = Math.exp (1); if(L <-math.pi | | L > Math.PI | | B <-MATH.PI/2|| B > Math.PI/2) { returnXY; } if(__a <=0|| __b <=0) { returnXY; } f= (__a-__b)/__a; Dtemp=1-(__b/__a) * (__b/__a); if(Dtemp <0) { returnXY; } e=math.sqrt (dtemp); Dtemp= (__a/__b) * (__a/__b)-1; if(Dtemp <0) { returnXY; } e_=math.sqrt (dtemp); NB0= ((__a * __a)/__b)/MATH.SQRT (1+ e_ * e_ * MATH.COS (__b0) *Math.Cos (__b0)); K= NB0 *Math.Cos (__b0); Xy.x= K * (L-__l0); Xy.y= K * Math.Log (Math.tan (Math.PI/4+ B/2) * MATH.POW ((1-E * Math.sin (B))/(1+ E * Math.sin (B)), E/2)); returnXY; } /******************************************* projection Reverse translator double X: Vertical rectangular coordinate double Y: transverse cartesian Doub le& B: Dimensions, radians double& L: Longitude, radian *******************************************/ //static public int fromproj (double X, double Y, ref double B, ref double L) Static Publicpointlb Xytolb (pointlb pmtLB0, Pointxy pmtxy) {SetB0 (Pmtlb0.lat); SetL0 (Pmtlb0.lon); DoubleX =pmtxy.x; DoubleY =pmtxy.y; DoubleB =0, L =0; pointlb lb=Newpointlb (); Lb.lat=0; Lb.lon =0; DoubleF/*Flat Rate*/E/*first bias heart rate*/, E_/*Second eccentricity*/, NB0/*radius of curvature of the unitary circle of Mao*/, K, dtemp; DoubleE = Math.exp (1); if(__a <=0|| __b <=0) { returnlb; } f= (__a-__b)/__a; Dtemp=1-(__b/__a) * (__b/__a); if(Dtemp <0) { returnlb; } e=math.sqrt (dtemp); Dtemp= (__a/__b) * (__a/__b)-1; if(Dtemp <0) { returnlb; } e_=math.sqrt (dtemp); NB0= ((__a * __a)/__b)/MATH.SQRT (1+ e_ * e_ * MATH.COS (__b0) *Math.Cos (__b0)); K= NB0 *Math.Cos (__b0); L= x/k +__l0; B=__iterativevalue; for(inti =0; i < __iterativetimes; i++) {B= Math.PI/2-2* Math.atan (Math.pow (E, (-y/k)) * MATH.POW (E, (E/2) * MATH.LOG ((1-E * Math.sin (B))/(1+ E *Math.sin (B)))); } Lb.lon=Radtodegree (L); Lb.lat=Radtodegree (B); returnlb; } }}
Mercator Projection C # implementation