《测绘程序设计—实验八-水准网平差程序设计报告(共18页).doc》由会员分享,可在线阅读,更多相关《测绘程序设计—实验八-水准网平差程序设计报告(共18页).doc(18页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上测绘程序设计(VC.net)上机实验报告(Visual C+.Net)班 级: 测绘0901班 学 号: 姓 名: 代娅琴 2012年4月29日实验八 平差程序设计基础一、 实验目的 巩固过程的定义与调用 巩固类的创建与使用 巩固间接平差模型及平差计算 掌握平差程序设计的基本技巧与步骤二、 实验内容水准网平差程序设计。设计一个水准网平差的程序,要求数据从文件中读取,计算部分与界面无关。1. 水准网间接平差模型:2. 计算示例:近似高程计算:3. 水准网平差计算一般步骤(1)读取观测数据和已知数据;(2)计算未知点高程近似值;(3)列高差观测值误差方程;(4)根据水准路
2、线长度计算高差观测值的权;(5)组成法方程;(6)解法方程,求得未知点高程改正数及平差后高程值;(7)求高差观测值残差及平差后高差观测值;(8)精度评定;(9)输出平差结果。4. 水准网高程近似值计算算法 5. 输入数据格式示例实验代码:#pragma onceclass LevelControlPointpublic:LevelControlPoint(void);LevelControlPoint(void);public:CString strName;/点名CString strID;/点号float H;bool flag;/标记是否已经计算出近似高程值,若计算出则为,否则为;cla
3、ss CDhObspublic:CDhObs(void);CDhObs(void);public:LevelControlPoint* cpBackObj;/后视点LevelControlPoint* cpFrontObj;/前视点double ObsValue;/高差值double Dist;/测站的距离;#include StdAfx.h#include LevelControlPoint.hLevelControlPoint:LevelControlPoint(void)strName=_T();strID=_T();H=0;flag=0;LevelControlPoint:LevelC
4、ontrolPoint(void)CDhObs:CDhObs(void)CDhObs:CDhObs(void)#pragma once#includeLevelControlPoint.h#include Matrix.hclass AdjustLevelpublic:AdjustLevel(void);AdjustLevel(void);public:LevelControlPoint* m_pKnownPoint;/已知点数组int m_iKnownPointCount;/已知点个数LevelControlPoint* m_pUnknownPoint;/未知点数组int m_iUnknow
5、nPointCount;/未知点个数CDhObs* m_pDhObs;/高差观测值数组int m_iDhObsCount;/高差观测值个数public:void SetKnownPointSize(int size);/创建大小为size的已知点数组void SetUnkonwnPointSize(int size);/创建大小为size的未知点数组void SetDhObsSize(int size);/创建大小为size的观测值数组bool LoadObsData(const CString& strFile);/读入观测文件CString* SplitString(CString str
6、, char split, int& iSubStrs); void ApproHeignt(void);/计算近似值private:LevelControlPoint* SearchKnownPointUsingID(CString ID);LevelControlPoint* SearchUnknownPointUsingID(CString ID);LevelControlPoint* SearchPointUsingID(CString ID); CMatrix LevleWeight(void);/计算权矩阵public:void FormErrorEquation(CMatrix
7、&B, CMatrix &L);/组成误差方程 void EquationCompute(CMatrix &x);/计算法方程void Accuracy_Assessment(double &r0,CMatrix &Qxx);/精度评定void CompAdjust(double &r0,CMatrix Qx);#include StdAfx.h#include AdjustLevel.h#include #include LevelControlPoint.h#include math.hAdjustLevel:AdjustLevel(void)m_pKnownPoint=NULL;/已知点
8、数组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;m_pKnownPoint=NULL;if(m_pUnknownPoint!=NULL)delete m_pUnknownPoint;m_pUnknownPoint=NULL;if(m_pDh
9、Obs!=NULL)delete m_pDhObs;m_pDhObs=NULL;void AdjustLevel:SetKnownPointSize(int size)m_pKnownPoint=new LevelControlPointsize;/创建动态指针m_iKnownPointCount=size;void AdjustLevel:SetUnkonwnPointSize(int size)m_pUnknownPoint=new LevelControlPointsize;m_iUnknownPointCount=size;void AdjustLevel:SetDhObsSize(i
10、nt 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;bool bEOF=sf.ReadString(strLine);/读取第一行,即已知点的数目SetKnownPointSize(_ttoi(strLine);/根据已知点的数目,创建已知点数组;in
11、t 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=_tstof(pstrData1);m_pKnownPointi.flag=1;/已知点不用平差,故将其的flag设置为delete pstrData;pstrData=NULL;sf.ReadStri
12、ng(strLine);/读取未知点的个数SetUnkonwnPointSize(_ttoi(strLine);/根据未知点的个数创建未知点数组sf.ReadString(strLine);/读取未知点的点名CString *pstrData=SplitString(strLine,n);for(int i=0;im_iUnknownPointCount;i+)/将未知点的点名放入未知点数组m_pUnknownPointi.strName=pstrDatai;m_pUnknownPointi.strID=pstrDatai;m_pUnknownPointi.H=0;/未知点的高程值设置为m_p
13、UnknownPointi.flag=0;/还没有求得近似高程,故其flag设置为if(pstrData!=NULL)delete pstrData;pstrData=NULL;sf.ReadString(strLine);/读取观测值的个数SetDhObsSize(_ttoi(strLine);/按照观测值的大小,创建观测值数组for(int i=0;im_iDhObsCount;i+)/分行读取观测值的数据,将其存入观测值数组sf.ReadString(strLine);CString *pstrData=SplitString(strLine,n);m_pDhObsi.cpBackObj
14、=SearchPointUsingID(pstrData0);/后视点m_pDhObsi.cpFrontObj=SearchPointUsingID(pstrData1);/前视点m_pDhObsi.HObsValue=_tstof(pstrData2);/高差观测值m_pDhObsi.Dist=_tstof(pstrData3);/距离观测值delete pstrData;pstrData=NULL;sf.Close();return 1;CString* AdjustLevel:SplitString(CString str, char split, int& iSubStrs)int i
15、Pos = 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(); strTemp = strRight; iNums+; if (iNums = 0) /没有找到分割符 /子字符串数就是字符串本身 iSubStrs = 1; return NU
16、LL; /子字符串数组 iSubStrs = iNums + 1; /子串的数量= 分割符数量+ 1 CString* 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 = str
17、Right; 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 NULL;/LevelControlPoint* AdjustLevel:SearchUnknownPointUsingID(CStrin
18、g ID)for(int i=0;im_iUnknownPointCount;i+)if(m_pUnknownPointi.strID=ID)return &m_pUnknownPointi;return NULL;LevelControlPoint* AdjustLevel:SearchPointUsingID(CString ID)LevelControlPoint* cp;cp=SearchKnownPointUsingID(ID);if(cp=NULL)cp=SearchUnknownPointUsingID(ID);return cp;void AdjustLevel:ApproHe
19、ignt(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.cpBackObj-H - m_pDhObsi.ObsValue;*/m_pUnknownPointi.H=m_pDhObsj.cpBack
20、Obj-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-H-m_pDhObsj.HObsValue; /* m_pUnknownPointi.H=m_pDhObsi.cpFrontObj-
21、H+m_pDhObsi.ObsValue;*/ m_pUnknownPointi.flag=1; break; if(i=m_iUnknownPointCount-1)/如果已经计算到最后一个未知点for(int a=0;am_iUnknownPointCount;a+)if(m_pUnknownPointi.flag!=1)/只要有一个未知点的近似高程直没有计算 /则要重新进行上面的步骤直到所有的未知点的近似高程值都计算出i=-1;break;CMatrix AdjustLevel:LevleWeight(void)CMatrix p(m_iDhObsCount,m_iDhObsCount)
22、;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(int i=0;istrID);tmpFront=SearchPointUsingID(m_pDhObsi.cpFrontOb
23、j-strID);/找到与第i个观测值有关的未知点tmpBack-strID;for(int j=0;jstrID)/如果是后视点则前面的系数为-1 B(i,j)=-1;continue;if(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.HObsValue-(m_pDhObsi.cpFrontObj-H - m_pDhObsi.cpBackObj-H);tmp.F
24、ormat(_T(%.3f),L(i,0);L(i,0)=_tstof(tmp);L(i,0)=L(i,0)*1000;/将单位化为mmvoid AdjustLevel:EquationCompute(CMatrix &x)/计算法方程CMatrix P,B,l;P=LevleWeight(); /P为权矩阵FormErrorEquation(B,l);ApproHeignt();CMatrix BT(m_iUnknownPointCount,m_iDhObsCount);BT=B; /B的转置矩阵CMatrix NBB(m_iUnknownPointCount,m_iUnknownPoint
25、Count);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);/未知点高程值=近似值+改正数void AdjustLevel:Accuracy_Assessment(double &r0,CMatrix &Qxx)/精度评定CMatrix B,l,P,x;P=LevleWeight(); /P为权矩阵FormErrorEquation(B,l);EquationCompute(x);CMatrix v(m_iDhObsC
26、ount,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=B;CMatrix NBB(m_iUnknownPointCount,m_iUnknownPointCount);NB
27、B=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为常数项EquationCompute(x);/计算法方程Accuracy_Assessment(r0,Qxx);/精度评定for(int
28、 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; /分割符位置 int iNums = 0; /分割符的总数 CString strTemp = str; CStri
29、ng strRight; /先计算子字符串的数量 while (iPos != -1) iPos = 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 = iNums + 1; /子串的数量= 分割符数量+ 1 CString* pStrSpl
30、it; 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; pStrSplitiNums = strTemp; return pStrS
31、plit;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.GetPathName();/打开获取文件文件名setlocale(LC
32、_ALL,); /设置语言环境CStdioFile 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.Close();UpdateData(FALSE);voi
33、d 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.Open(strFileName, CFile:modeC
34、reate|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.CompAdjust(r0,Qx);LevleContent
35、.Format(_T(平差后高程值:rn);CString Temp;for(int i=0;iLevelComput.m_iUnknownPointCount;i+) Temp.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;LevleContent+=_T(未知点高程中误差(mm
36、):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);CFileDialog dlgFile(FALSE,_T(txt)
37、,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);三、 实验结果打开文件数据:平差结果:四、实验心
38、得 这从实验是我们测绘程序设计的最后一次实验,虽然这个学期我们做了好几次相关的实验,但是我却发现自己学的东西也越来越模糊,感觉很多内容都不理解。这次的实验很大程度上我都是按照测绘程序设计上面单导线简易计算来编的,在加上后面的关于水准网间接平差的误差方程和法方程,以及精度评定的相关函数,来完成的。而自己主要完成的就是水准网的数据读取,保存的操作,由于这部分主要用的知识是文件的读取的,因为前面做过,所以不是太难。但是这并不意味着这次实验很简单,至少在我心中这的确比较难,因为里面很多东西不是纯粹的把代码写上去就可以完成,还要靠自己做相应的代码对应,才能够真正的得到想要的结果。但学好编程并扎实的为自己所用是需要更多的学习和练习的,我知道在掌握课堂知识的同时,主动的去寻找吸收相关的知识,希望通过本门课程的学习,掌握学习编程的方法,使自己的水平能够更进一步,循序渐进的掌握更多。虽然这门课的实验已经结束,但是我却深深地知道,我们专业对编程的要求很高,而且必须具备较好的编程能力,或许这些日子下来,我学到的不是很多,但是我或多或少明白,编程是一个循序渐进的过程,我想真的能够在这方面有所突破,就更要花时间多花工夫。专心-专注-专业