1、测绘程序设计(VC.net)上机试验汇报(Visual C+.Net)班 级: 测绘0901班 学 号: 姓 名: 代娅琴 4月29日试验八 平差程序设计基础一、 试验目标 巩固过程定义和调用 巩固类创建和使用 巩固间接平差模型及平差计算 掌握平差程序设计基础技巧和步骤二、 试验内容水准网平差程序设计。设计一个水准网平差程序,要求数据从文件中读取,计算部分和界面无关。1. 水准网间接平差模型:2. 计算示例:近似高程计算:3. 水准网平差计算通常步骤(1)读取观察数据和已知数据;(2)计算未知点高程近似值;(3)列高差观察值误差方程;(4)依据水准路线长度计算高差观察值权;(5)组成法方程;(
2、6)解法方程,求得未知点高程更正数及平差后高程值;(7)求高差观察值残差及平差后高差观察值;(8)精度评定;(9)输出平差结果。4. 水准网高程近似值计算算法 5. 输入数据格式示例试验代码:#pragma onceclass LevelControlPointpublic:LevelControlPoint(void);LevelControlPoint(void);public:CString strName;/点名CString strID;/点号float H;bool flag;/标识是否已经计算出近似高程值,若计算出则为,不然为;class CDhObspublic:CDhObs(
3、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:LevelControlPoint(void)CDhObs:
4、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_iUnknownPointCount;/未知点个数CDhObs
5、* 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, char split, int& iSubStrs
6、); void ApproHeignt(void);/计算近似值private:LevelControlPoint* SearchKnownPointUsingID(CString ID);LevelControlPoint* SearchUnknownPointUsingID(CString ID);LevelControlPoint* SearchPointUsingID(CString ID); CMatrix LevleWeight(void);/计算权矩阵public:void FormErrorEquation(CMatrix &B, CMatrix &L);/组成误差方程 voi
7、d 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;/已知点数组m_iKnownPointCount=0;/已知点
8、个数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_pDhObs!=NULL)delete m_pDhObs;m
9、_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(int size)m_pDhObs=new CDhObs
10、size;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);/依据已知点数目,创建已知点数组;int n=0;for(int i=0;im_iKnownPo
11、intCount;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.ReadString(strLine);/读取未知点个数SetUnkonwnP
12、ointSize(_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_pUnknownPointi.flag=0;/还没有求得近似高程,故其fl
13、ag设置为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=SearchPointUsingID(pstrData0);/后视点m_pD
14、hObsi.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 iPos = 0; /分割符位置 int iNums = 0; /分割符总数 C
15、String 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 NULL; /子字符串数组 iSubStrs = iNums + 1; /子串数量=
16、分割符数量+ 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 = strRight; pStrSpliti = strLeft; pStrSplitiNum
17、s = 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(CString ID)for(int i=0;im_iUnknownPointCount;i+)
18、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:ApproHeignt(void)/用于计算高程近似值函数for(int i=0;im_iUnkn
19、ownPointCount;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.cpBackObj-H + m_pDhObsj.HObsValue;m_pUnknownPointi.
20、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-H+m_pDhObsi.ObsValue;*/ m_pUnknownPointi.flag
21、=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);p.Unit();double value;for(int i=0;im_iDhObsCoun
22、t;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.cpFrontObj-strID);/找到和第i个观察值相关未知点tmpBack-strID;for(int j=
23、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.Format(_T(%.3f),L(i,0);L(i,0)=_tstof(tmp);L(i,0)=L(i
24、,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_iUnknownPointCount);NBB=BT*P*B;CMatrix NBBl=NBB.Inv();x=NBBl*BT*P
25、*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_iDhObsCount,1);v=B*x-l;CMatrix vT(1,m_iDhObsCount);vT=v;CMa
26、trix 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);NBB=BT*P*B;Qxx=NBB.Inv();void AdjustLevel:CompAdjust(d
27、ouble &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 i=0;im_iUnknownPointCount;i+)/未知点高程中误差Qxi=sqrt(Qxx(i
28、,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; CString strRight; /先计算子字符串数量 while (iPos != -1) iPos = strT
29、emp.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* pStrSplit; pStrSplit = new CStringiSubStrs; strTemp = str; CStr
30、ing 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 pStrSplit;void CIndircLelveDlg:OnBnClickedOpendatafile()/ TOD
31、O: 在此添加控件通知处理程序代码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_ALL,); /设置语言环境CStdioFile sf;if(!sf.Open(strFileName, CF
32、ile: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);void CIndircLelveDlg:OnBnClickedSavedata()/ TODO: 在此添加控件通知处理
33、程序代码 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:modeCreate|CFile:modeWrite) return;sf.WriteString(LevleContent
34、);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.Format(_T(平差后高程值:rn);CString Temp;for(int i=0;iLevelComp
35、ut.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):rn);for(int i=0;i LevelComput.m_iUnknownPointCount;i+)T
36、emp.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),NULL,OFN_EXPLORER,_T(Level格式)|*.txt);if(dlgFile.DoModal(
37、)=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、,感觉很多内容全部不了解。这次试验很大程度上我全部是根据测绘程序设计上面单导线简易计算来编,在加上后面相关水准网间接平差误差方程和法方程,和精度评定相关函数,来完成。而自己关键完成就是水准网数据读取,保留操作,因为这部分关键用知识是文件读取,因为前面做过,所以不是太难。不过这并不意味着这次试验很简单,最少在我心中这确实比较难,因为里面很多东西不是纯粹把代码写上去就能够完成,还要靠自己做对应代码对应,才能够真正得到想要结果。但学好编程并扎实为自己所用是需要更多学习和练习,我知道在掌握课堂知识同时,主动去寻求吸收相关知识,期望经过本门课程学习,掌握学习编程方法,使自己水平能够更深入,循序渐进掌握更多。即使这门课试验已经结束,不过我却深深地知道,我们专业对编程要求很高,而且必需含有很好编程能力,或许这些日子下来,我学到不是很多,不过我或多或少明白,编程是一个循序渐进过程,我想真能够在这方面有所突破,就更要花时间多花工夫。
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100