高斯投影正反算-c#代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

高斯投影正反算程序设计一.程序设计流程本程序的设计思路如下:(1),程序采用VS08版本作为开发平台,并采用C#语言作为开发语言,设计为WindowsForm窗体程序形式。(2),程序主要的算法来自于教材。但是本程序为了更加实用,添加了更多的解算基准,包括:WGS-84,国际椭球1975,克氏椭球,和2000国家大地坐标系。(3),程序为了更方便的读取数据和输出数据,故需要自己定义了固定的数据输入格式和数据输出格式或形式,请老师注意查看。二.代码usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceGauss{publicpartialclassForm1:Form{//大地坐标//GeodeticCoordinatepublicstructCRDGEODETIC{publicdoubledLongitude;publicdoubledLatitude;publicdoubledHeight;}//笛卡尔坐标//CartesianCoordinatepublicstructCRDCARTESIAN{publicdoublex;publicdoubley;publicdoublez;}publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){doubleee=0;doublea=0;stringtt;try{tt=this.comboBox1.Items[this.comboBox1.SelectedIndex].ToString();}catch{MessageBox.Show(GaussInverse:Choosedatumerror!);return;}if(tt.CompareTo(克氏椭球)==0){a=6378245.00;ee=Math.Sqrt(0.006693421622);}if(tt.CompareTo(WGS-84)==0){a=6378137.00;ee=Math.Sqrt(0.00669437999013);}if(tt.CompareTo(1975国际椭球)==0){a=6378140.00;ee=Math.Sqrt(0.006694384999588);}if(tt.CompareTo(2000国家大地坐标系)==0){a=6378137.0;ee=Math.Sqrt(0.0066943802290);}constdoublepai=3.1415926;doubleb=Math.Sqrt(a*a*(1-ee*ee));doublec=a*a/b;doubleepp=Math.Sqrt((a*a-b*b)/b/b);CRDGEODETICpcrdGeo;CRDCARTESIANpcrdCar;doublemidlong;//求纬度string[]temp;temp=textBox1.Text.Split('');double[]tempradius=newdouble[3];for(inti=0;i3;i++){tempradius[i]=Convert.ToDouble(temp[i]);}pcrdGeo.dLatitude=tempradius[0]/180.0*pai+tempradius[1]/180.0/60.0*pai+tempradius[2]/180/60.0/60*pai;//求经度temp=textBox2.Text.Split('');for(inti=0;i3;i++){tempradius[i]=Convert.ToDouble(temp[i]);}pcrdGeo.dLongitude=tempradius[0]/180.0*pai+tempradius[1]/180.0/60.0*pai+tempradius[2]/180/60.0/60*pai;intdeglon=Convert.ToInt32(pcrdGeo.dLongitude*180/pai);//求中央经度intnum;//带号midlong=0;//默认值,需要制定分带try{tt=this.comboBox3.Items[this.comboBox3.SelectedIndex].ToString();}catch{MessageBox.Show(Choose3/6error!);return;}if(tt.CompareTo(3度带)==0){num=Convert.ToInt32(deglon/6+1);midlong=(6*num-3)/180.0*pai;}if(tt.CompareTo(6度带)==0){num=Convert.ToInt32((deglon+1.5)/3);midlong=num*3*pai/180;}doublelp=pcrdGeo.dLongitude-midlong;doubleN=c/Math.Sqrt(1+epp*epp*Math.Cos(pcrdGeo.dLatitude)*Math.Cos(pcrdGeo.dLatitude));doubleM=c/Math.Pow(1+epp*epp*Math.Cos(pcrdGeo.dLatitude)*Math.Cos(pcrdGeo.dLatitude),1.5);doubleita=epp*Math.Cos(pcrdGeo.dLatitude);doublet=Math.Tan(pcrdGeo.dLatitude);doubleNscnb=N*Math.Sin(pcrdGeo.dLatitude)*Math.Cos(pcrdGeo.dLatitude);doubleNcosb=N*Math.Cos(pcrdGeo.dLatitude);doublecosb=Math.Cos(pcrdGeo.dLatitude);doubleX;doublem0,m2,m4,m6,m8;doublea0,a2,a4,a6,a8;m0=a*(1-ee*ee);m2=3.0/2.0*m0*ee*ee;m4=5.0/4.0*ee*ee*m2;m6=7.0/6.0*ee*ee*m4;m8=9.0/8.0*ee*ee*m6;a0=m0+m2/2.0+3.0/8.0*m4+5.0/16.0*m6+35.0/128.0*m8;a2=m2/2+m4/2+15.0/32.0*m6+7.0/16.0*m8;a4=m4/8.0+3.0/16.0*m6+7.0/32.0*m8;a6=m6/32.0+m8/16.0;a8=m8/128.0;doubleB=pcrdGeo.dLatitude;doublesb=Math.Sin(B);doublecb=Math.Cos(B);doubles2b=sb*cb*2;doubles4b=s2b*(1-2*sb*sb)*2;doubles6b=s2b*Math.Sqrt(1-s4b*s4b)+s4b*Math.Sqrt(1-s2b*s2b);X=a0*B-a2/2.0*s2b+a4*s4b/4.0-a6/6.0*s6b;pcrdCar.x=Nscnb*lp*lp/2.0+Nscnb*cosb*cosb*Math.Pow(lp,4)*(5-t*t+9*ita*ita+4*Math.Pow(ita,4))/24.0+Nscnb*Math.Pow(cosb,4)*Math.Pow(lp,6)*(61-58*t*t+Math.Pow(t,4))/720.0+X;pcrdCar.y=Ncosb*Math.Pow(lp,1)+Ncosb*cosb*cosb*(1-t*t+ita*ita)/6.0*Math.Pow(lp,3)+Ncosb*Math.Pow(lp,5)*Math.Pow(cosb,4)*(5-18*t*t+Math.Pow(t,4)+14*ita*ita-58*ita*ita*t*t)/120.0;if(pcrdCar.y0)pcrdCar.y+=500000;richTextBox1.Text=Results:\nX:\t+Convert.ToString(pcrdCar.x)+\nY:\t+Convert.ToString(pcrdCar.y);}privatevoidbutton2_Click(objectsender,EventArgse){doubleee=0;doublea=0;stringtt;intnum;//带号stringytext;//利用y值求带号和中央经线try{tt=this.comboBox2.Items[this.comboBox2.SelectedIndex].ToString();}catch{MessageBox.Show(GaussInverse:Choosedatumerror!);return;}if(tt.CompareTo(克氏椭球)==0){a=6378245.00;ee=Math.Sqrt(0.006693421622);}if(tt.CompareTo(WGS-84)==0){a=6378137.00;ee=Math.Sqrt(0.00669437999013);}if(tt.CompareTo(1975国际椭球)==0){a=6378140.00;ee=Math.Sqrt(0.006694384999588);}if(tt.CompareTo(2000国家大地坐标系)==0){a=6378137.0;ee=Math.Sqrt(0.0066943802290);}constdoublepai=3.1415926535898;doubleb=Math.Sqrt(a*a*(1-ee*ee));doublec=a*a/b;doubleepp=Math.Sqrt((a*a-b*b)/b/b);CRDGEODETICpcrdGeo;CRDCARTESIANpcrdCar;doublemidlong=0;//求X,Y和带号pcrdCar.x=Convert.ToDouble(textBox4.Text);ytext=textBox5.Text;stringtemp=ytext.Substring(0,2);num=Convert.ToInt32(temp);ytext=ytext.Remove(0,2);pcrdCar.y=Convert.ToDouble(ytext)-500000;try{tt=this.comboBox4.Items[this.comboBox4.SelectedIndex].ToString();}catch{MessageBox.Show(Choose3/6error!);return;}if(tt.CompareTo(3度带)==0){midlong=num*3*pai/180;}if(tt.CompareTo(6度带)==0){midlong=(6*num-3)*pai/180;}b=Math.Sqrt(a*a*(1-ee*ee));c=a*a/b;epp=Math.Sqrt(a*a-b*b)/b;doublem0,m2,m4,m6,m8;doublea0,a2,a4,a6,a8;m0=a*(1-ee*ee);m2=3.0/2.0*m0*ee*ee;m4=5.0/4.0*ee*ee*m2;m6=7.0/6.0*ee*ee*m4;m8=9.0/8.0*ee*ee*m6;a0=m0+m2/2.0+3.0/8.0*m4+5.0/16.0*m6+35.0/128.0*m8;a2=m2/2+m4/2+15.0/32.0*m6+7.0/16.0*m8;a4=m4/8.

1 / 11
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功