《测绘程序设计实验八_水准网平差程序设计报告.pdf》由会员分享,可在线阅读,更多相关《测绘程序设计实验八_水准网平差程序设计报告.pdf(19页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、误差理论与测量平差基础课程设计(VC.net)实习报告(Visual C+.Net)班 级:学 号:姓 名:12014 年 2 月 17 日至 2 月 28 日水准网水准网平差程序设计平差程序设计一、一、 实验目的实验目的 巩固过程的定义与调用 巩固类的创建与使用 巩固间接平差模型及平差计算 掌握平差程序设计的基本技巧与步骤二、二、 实验内容实验内容水准网平差程序设计。设计一个水准网平差的程序,要求数据从文件中读取,计算部分与界面无关。1. 水准网间接平差模型:2.2. 计算示例:近似高程计算:23. 水准网平差计算一般步骤(1)读取观测数据和已知数据;(2)计算未知点高程近似值;(3)列高差
2、观测值误差方程;(4)根据水准路线长度计算高差观测值的权;(5)组成法方程;(6)解法方程,求得未知点高程改正数及平差后高程值;(7)求高差观测值残差及平差后高差观测值;3(8)精度评定;(9)输出平差结果。4. 水准网高程近似值计算算法5. 输入数据格式示例3已知点数A,151.5664B,144.5684已知点号及高程C,144.31949未知数P1,P2,P3,P4,P5,P6,P7,P8,P9未知点号15高差观测数据个数B,P4,1.4966,0.4B,P1,1.7881,0.5P1,A,5.2065,0.7P4,P2,2.0850,0.9P2,A,3.4175,0.4C,P3,1.2
3、081,1.0P3,A,6.0372,0.6C,P5,4.3306,0.7高差观测数据:起点,终点,高差,路线长度P6,P5,3.6513,0.6P7,P6,2.5122,0.34P7,P9,2.0415,0.8P9,P4,1.5366,0.7C,P4,1.7450,0.8P8,P5,2.7436,0.4P9,P8,1.3783,0,5实验代码:实验代码:#pragma onceclassclass LevelControlPointLevelControlPointpublic:LevelControlPoint(void);LevelControlPoint(void);public:CS
4、tring strName;/点名CString strID;/点号float H;bool flag;/标记是否已经计算出近似高程值,若计算出则为,否则为;class CDhObspublic:CDhObs(void);CDhObs(void);public:LevelControlPoint* cpBackObj;/后视点LevelControlPoint* cpFrontObj;/前视点double ObsValue;/高差值double Dist;/测站的距离;#include StdAfx.h#include LevelControlPoint.hLevelControlPoint:
5、LevelControlPoint(void)strName=_T();strID=_T();H=0;flag=0;5LevelControlPoint:LevelControlPoint(void)CDhObs:CDhObs(void)CDhObs:CDhObs(void)#pragma once#includeLevelControlPoint.h#include Matrix.hclassclass AdjustLevelAdjustLevelpublic:AdjustLevel(void);AdjustLevel(void);public:LevelControlPoint* m_pK
6、nownPoint;/已知点数组int m_iKnownPointCount;/已知点个数LevelControlPoint* m_pUnknownPoint;/未知点数组int m_iUnknownPointCount;/未知点个数CDhObs* m_pDhObs;/高差观测值数组int m_iDhObsCount;/高差观测值个数public:void SetKnownPointSize(int size);/创建大小为size的已知点数组void SetUnkonwnPointSize(int size);/创建大小为size的未知点数组void SetDhObsSize(int siz
7、e);/创建大小为size的观测值数组bool LoadObsData(const CString& strFile);/读入观测文件CString* SplitString(CString str, char split, int& iSubStrs);void ApproHeignt(void);/计算近似值private:LevelControlPoint* SearchKnownPointUsingID(CString ID);LevelControlPoint* SearchUnknownPointUsingID(CString ID);LevelControlPoint* Sear
8、chPointUsingID(CString ID);CMatrix LevleWeight(void);/计算权矩阵public:void FormErrorEquation(CMatrix &B, CMatrix &L);/组成误差方程void EquationCompute(CMatrix &x);/计算法方程void Accuracy_Assessment(double &r0,CMatrix &Qxx);/精度评定void CompAdjust(double &r0,CMatrix Qx);6#include StdAfx.h#include AdjustLevel.h#includ
9、e #include LevelControlPoint.h#include math.hAdjustLevel:AdjustLevel(void)m_pKnownPoint=NULL;/已知点数组m_iKnownPointCount=0;/已知点个数m_pUnknownPoint=NULL;/未知点数组m_iUnknownPointCount=0;/未知点个数m_pDhObs=NULL;/高差观测值数组m_iDhObsCount=0;/高差观测值个数AdjustLevel:AdjustLevel(void)if(m_pKnownPoint!=NULL)delete m_pKnownPoint
10、;m_pKnownPoint=NULL;if(m_pUnknownPoint!=NULL)delete m_pUnknownPoint;m_pUnknownPoint=NULL;if(m_pDhObs!=NULL)delete m_pDhObs;m_pDhObs=NULL;void AdjustLevel:SetKnownPointSize(int size)m_pKnownPoint=new LevelControlPointsize;/创建动态指针m_iKnownPointCount=size;7void AdjustLevel:SetUnkonwnPointSize(int size)m
11、_pUnknownPoint=new LevelControlPointsize;m_iUnknownPointCount=size;void AdjustLevel:SetDhObsSize(int size)m_pDhObs=new CDhObssize;m_iDhObsCount=size;/高差观测值个数bool AdjustLevel:LoadObsData(const CString& strFile)CStdioFile sf;if(!sf.Open(strFile,CFile:modeRead) return false;/创建并打开文件对象CString strLine;bo
12、ol bEOF=sf.ReadString(strLine);/读取第一行,即已知点的数目SetKnownPointSize(_ttoi(strLine);/根据已知点的数目,创建已知点数组;int n=0;for(int i=0;im_iKnownPointCount;i+)/读取已知点的点名和高程值sf.ReadString(strLine);CString *pstrData=SplitString(strLine,n);m_pKnownPointi.strName=pstrData0;m_pKnownPointi.strID=pstrData0;m_pKnownPointi.H=_ts
13、tof(pstrData1);m_pKnownPointi.flag=1;/已知点不用平差,故将其的flag设置为delete pstrData;pstrData=NULL;sf.ReadString(strLine);/读取未知点的个数SetUnkonwnPointSize(_ttoi(strLine);/根据未知点的个数创建未知点数组sf.ReadString(strLine);/读取未知点的点名CString *pstrData=SplitString(strLine,n);for(int i=0;im_iUnknownPointCount;i+)/将未知点的点名放入未知点数组m_pUn
14、knownPointi.strName=pstrDatai;m_pUnknownPointi.strID=pstrDatai;m_pUnknownPointi.H=0;/未知点的高程值设置为m_pUnknownPointi.flag=0;/还没有求得近似高程,故其flag设置为8if(pstrData!=NULL)delete pstrData;pstrData=NULL;sf.ReadString(strLine);/读取观测值的个数SetDhObsSize(_ttoi(strLine);/按照观测值的大小,创建观测值数组for(int i=0;im_iDhObsCount;i+)/分行读取
15、观测值的数据,将其存入观测值数组sf.ReadString(strLine);CString *pstrData=SplitString(strLine,n);m_pDhObsi.cpBackObj=SearchPointUsingID(pstrData0);/后视点m_pDhObsi.cpFrontObj=SearchPointUsingID(pstrData1);/前视点m_pDhObsi.HObsValue=_tstof(pstrData2);/高差观测值m_pDhObsi.Dist=_tstof(pstrData3);/距离观测值delete pstrData;pstrData=NUL
16、L;sf.Close();return 1;CString* AdjustLevel:SplitString(CString str, char split, int& iSubStrs)int iPos = 0; /分割符位置int iNums = 0; /分割符的总数CString strTemp = str;CString strRight;/先计算子字符串的数量while (iPos != -1)iPos = strTemp.Find(split);if (iPos = -1)break;strRight = strTemp.Mid(iPos + 1, str.GetLength();
17、strTemp = strRight;iNums+;if (iNums = 0) /没有找到分割符/子字符串数就是字符串本身iSubStrs = 1;9return NULL;/子字符串数组iSubStrs = iNums + 1; /子串的数量= 分割符数量+ 1CString* pStrSplit;pStrSplit = new CStringiSubStrs;strTemp = str;CString strLeft;for (int i = 0; i iNums; i+)iPos = strTemp.Find(split);/左子串strLeft = strTemp.Left(iPos
18、);/右子串strRight = strTemp.Mid(iPos + 1, strTemp.GetLength();strTemp = strRight;pStrSpliti = strLeft;pStrSplitiNums = strTemp;return pStrSplit;/LevelControlPoint* AdjustLevel:SearchKnownPointUsingID(CString ID)for(int i=0;im_iKnownPointCount;i+)if(m_pKnownPointi.strID=ID)return &m_pKnownPointi;return
19、NULL;/LevelControlPoint* AdjustLevel:SearchUnknownPointUsingID(CString ID)for(int i=0;im_iUnknownPointCount;i+)if(m_pUnknownPointi.strID=ID)return &m_pUnknownPointi;return NULL;LevelControlPoint* AdjustLevel:SearchPointUsingID(CString ID)10LevelControlPoint* cp;cp=SearchKnownPointUsingID(ID);if(cp=N
20、ULL)cp=SearchUnknownPointUsingID(ID);return cp;void AdjustLevel:ApproHeignt(void)/用于计算高程近似值的函数for(int i=0;im_iUnknownPointCount;i+)/计算未知点高程值if(m_pUnknownPointi.flag!=1)/先在未知点作为观测值的前视点的情况for(int j=0;jstrID=m_pUnknownPointi.strID)& m_pDhObsj.cpBackObj-flag=1 )/前视点=后视点-高差/*m_pUnknownPointi.H=m_pDhObsi.
21、cpBackObj-H -m_pDhObsi.ObsValue;*/m_pUnknownPointi.H=m_pDhObsj.cpBackObj-H + m_pDhObsj.HObsValue;m_pUnknownPointi.flag=1;break;if(m_pUnknownPointi.flag!=1)/如果经过上一步骤未知点仍没有计算出近似值for(int j=0;jstrID=m_pUnknownPointi.strID)& m_pDhObsj.cpFrontObj-flag=1 )/后视点=前视点+高差m_pUnknownPointi.H=m_pDhObsj.cpFrontObj-
22、H-m_pDhObsj.HObsValue;/*m_pUnknownPointi.H=m_pDhObsi.cpFrontObj-H+m_pDhObsi.ObsValue;*/m_pUnknownPointi.flag=1;break;11if(i=m_iUnknownPointCount-1)/如果已经计算到最后一个未知点for(int a=0;am_iUnknownPointCount;a+)if(m_pUnknownPointi.flag!=1)/只要有一个未知点的近似高程直没有计算/则要重新进行上面的步骤直到所有的未知点的近似高程值都计算出i=-1;break;CMatrix Adjus
23、tLevel:LevleWeight(void)CMatrix p(m_iDhObsCount,m_iDhObsCount);p.Unit();double value;for(int i=0;im_iDhObsCount;i+)value=(1.0/m_pDhObsi.Dist);p(i,i)=value;return p;void AdjustLevel:FormErrorEquation(CMatrix &B, CMatrix &L)B.SetSize(m_iDhObsCount,m_iUnknownPointCount);L.SetSize(m_iDhObsCount,1);for(i
24、nt i=0;istrID);tmpFront=SearchPointUsingID(m_pDhObsi.cpFrontObj-strID);/找到与第i个观测值有关的未知点tmpBack-strID;for(int j=0;jstrID)/如果是后视点则前面的系数为-1 B(i,j)=-1;continue;12if(m_pUnknownPointj.strID=tmpFront-strID)/如果是前视点则前面的系数为B(i,j)=1;/建立L矩阵CString tmp;for(int i=0;iH-m_pDhObsi.cpFrontObj-H);*/L(i,0)=m_pDhObsi.HO
25、bsValue-(m_pDhObsi.cpFrontObj-H -m_pDhObsi.cpBackObj-H);tmp.Format(_T(%.3f),L(i,0);L(i,0)=_tstof(tmp);L(i,0)=L(i,0)*1000;/将单位化为mmvoidAdjustLevel:EquationCompute(CMatrix &x)/计算法方程CMatrix P,B,l;P=LevleWeight(); /P为权矩阵FormErrorEquation(B,l);ApproHeignt();CMatrix BT(m_iUnknownPointCount,m_iDhObsCount);B
26、T=B;/B的转置矩阵CMatrix NBB(m_iUnknownPointCount,m_iUnknownPointCount);NBB=BT*P*B;CMatrix NBBl=NBB.Inv();x=NBBl*BT*P*l;for(int i=0;im_iUnknownPointCount;i+)m_pUnknownPointi.H+=x(i,0);/未知点高程值=近似值+改正数voidAdjustLevel:Accuracy_Assessment(double &r0,CMatrix &Qxx)/精度评定CMatrix B,l,P,x;P=LevleWeight(); /P为权矩阵For
27、mErrorEquation(B,l);EquationCompute(x);13CMatrix v(m_iDhObsCount,1);v=B*x-l;CMatrix vT(1,m_iDhObsCount);vT=v;CMatrix r/*(1,l)*/;r=vT*P*v;r0=sqrt(r(0,0)/(m_iDhObsCount-m_iUnknownPointCount);/单位权中误差Qxx.SetSize(m_iUnknownPointCount,m_iUnknownPointCount);CMatrix BT(m_iUnknownPointCount,m_iDhObsCount);BT
28、=B;CMatrix NBB(m_iUnknownPointCount,m_iUnknownPointCount);NBB=BT*P*B;Qxx=NBB.Inv();void AdjustLevel:CompAdjust(double &r0,CMatrix Qx)ApproHeignt();/计算未知点的近似高程值并且存入数组CMatrix P(m_iDhObsCount,m_iDhObsCount);P=LevleWeight();/p为权矩阵CMatrix B,L;CMatrix x,Qxx;FormErrorEquation(B,L);/组成误差方程,B为系数矩阵,l为常数项Equat
29、ionCompute(x);/计算法方程Accuracy_Assessment(r0,Qxx);/精度评定for(int i=0;im_iUnknownPointCount;i+)/未知点高程中误差Qxi=sqrt(Qxx(i,i)*r0;#include Matrix.h#include locale.h#include LevelControlPoint.h#include AdjustLevel.hAdjustLevel LevelComput;CString* SplitString(CString str, char split, int& iSubStrs)int iPos = 0
30、; /分割符位置int iNums = 0; /分割符的总数CString strTemp = str;CString strRight;/先计算子字符串的数量while (iPos != -1)14iPos = strTemp.Find(split);if (iPos = -1)break;strRight = strTemp.Mid(iPos + 1, str.GetLength();strTemp = strRight;iNums+;if (iNums = 0) /没有找到分割符/子字符串数就是字符串本身iSubStrs = 1;return NULL;/子字符串数组iSubStrs =
31、 iNums + 1; /子串的数量= 分割符数量+ 1CString* pStrSplit;pStrSplit = new CStringiSubStrs;strTemp = str;CString strLeft;for (int i = 0; i iNums; i+)iPos = strTemp.Find(split);/左子串strLeft = strTemp.Left(iPos);/右子串strRight = strTemp.Mid(iPos + 1, strTemp.GetLength();strTemp = strRight;pStrSpliti = strLeft;pStrSp
32、litiNums = strTemp;return pStrSplit;void CIndircLelveDlg:OnBnClickedOpendatafile()/ TODO: 在此添加控件通知处理程序代码UpdateData(TRUE);CFileDialog dlgFile(TRUE,_T(txt),NULL,OFN_ALLOWMULTISELECT|OFN_EXPLORER,_T(文本文件)|*.txt);/创建文件对话框if(dlgFile.DoModal()=IDCANCEL) return;/如果选择取消按钮则返回CString strFileName=dlgFile.GetPa
33、thName();/打开获取文件文件名setlocale(LC_ALL,); /设置语言环境15CStdioFile sf;if(!sf.Open(strFileName, CFile:modeRead) return;InputContent.Empty();/清空字符串str_openContent中的内容CString strLine;BOOL bEOF=sf.ReadString(strLine);/读取第一行数据while(bEOF)/开始读取顶点数据bEOF=sf.ReadString(strLine);if(bEOF)InputContent+=strLine+_T(rn);sf
34、.Close();UpdateData(FALSE);void CIndircLelveDlg:OnBnClickedSavedata()/ TODO: 在此添加控件通知处理程序代码UpdateData(TRUE);CFileDialog dlgFile(FALSE,_T(txt),NULL,OFN_EXPLORER,_T(Level格式)|*.txt);if(dlgFile.DoModal()=IDCANCEL) return;CString strFileName=dlgFile.GetPathName();setlocale(LC_ALL,);CStdioFile sf;if(!sf.O
35、pen(strFileName, CFile:modeCreate|CFile:modeWrite) return;sf.WriteString(LevleContent);sf.Close();UpdateData(FALSE);void CIndircLelveDlg:OnBnClickedComputelevel()/ TODO: 在此添加控件通知处理程序代码UpdateData(TRUE);setlocale(LC_ALL,);double *Qx=new doubleLevelComput.m_iUnknownPointCount;double r0;LevelComput.Comp
36、Adjust(r0,Qx);LevleContent.Format(_T(平差后高程值:rn);CString Temp;for(int i=0;iLevelComput.m_iUnknownPointCount;i+)16Temp.Empty();Temp.Format(_T(%s,%.4frn),LevelComput.m_pUnknownPointi.strID,LevelComput.m_pUnknownPointi.H);LevleContent+=Temp;Temp.Format(_T(单位权中误差:%.1f mmrn),r0*1000);LevleContent+=Temp;Le
37、vleContent+=_T(未知点高程中误差(mm):rn);for(int i=0;i LevelComput.m_iUnknownPointCount;i+)Temp.Empty();Temp.Format(_T(%s,%.1frn),LevelComput.m_pUnknownPointi.strName,Qxi*1000);LevleContent+=Temp;UpdateData(false);void CIndircLelveDlg:OnBnClickedSavelevleresult()/ TODO: 在此添加控件通知处理程序代码UpdateData(TRUE);CFileDi
38、alog dlgFile(FALSE,_T(txt),NULL,OFN_EXPLORER,_T(Level格式)|*.txt);if(dlgFile.DoModal()=IDCANCEL) return;CString strFileName=dlgFile.GetPathName();setlocale(LC_ALL,);CStdioFile sf;if(!sf.Open(strFileName, CFile:modeCreate|CFile:modeWrite) return;sf.WriteString(LevleContent);sf.Close();UpdateData(FALSE)
39、;三、三、 实验结果实验结果打开文件数据:17平差结果:四、四、实验心得实验心得这从实验是我们测绘程序设计的最后一次实验, 虽然这个学期我们做了18好几次相关的实验,但是我却发现自己学的东西也越来越模糊,感觉很多内容都不理解。这次的实验很大程度上我都是按照测绘程序设计上面单导线简易计算来编的,在加上后面的关于水准网间接平差的误差方程和法方程,以及精度评定的相关函数,来完成的。而自己主要完成的就是水准网的数据读取,保存的操作,由于这部分主要用的知识是文件的读取的,因为前面做过,所以不是太难。但是这并不意味着这次实验很简单,至少在我心中这的确比较难,因为里面很多东西不是纯粹的把代码写上去就可以完成,还要靠自己做相应的代码对应,才能够真正的得到想要的结果。但学好编程并扎实的为自己所用是需要更多的学习和练习的,我知道在掌握课堂知识的同时,主动的去寻找吸收相关的知识,希望通过本门课程的学习,掌握学习编程的方法,使自己的水平能够更进一步,循序渐进的掌握更多。虽然这门课的实验已经结束,但是我却深深地知道,我们专业对编程的要求很高,而且必须具备较好的编程能力,或许这些日子下来,我学到的不是很多,但是我或多或少明白,编程是一个循序渐进的过程,我想真的能够在这方面有所突破,就更要花时间多花工夫。