《测绘程序设计(VC.net)》上机实验报告(VisualC++.Net)班级:测绘0901班学号:0405090204姓名:代娅琴2012年4月29日1实验八平差程序设计基础一、实验目的•巩固过程的定义与调用•巩固类的创建与使用•巩固间接平差模型及平差计算•掌握平差程序设计的基本技巧与步骤二、实验内容水准网平差程序设计。设计一个水准网平差的程序,要求数据从文件中读取,计算部分与界面无关。1.水准网间接平差模型:2.计算示例:2近似高程计算:3.水准网平差计算一般步骤(1)读取观测数据和已知数据;(2)计算未知点高程近似值;(3)列高差观测值误差方程;(4)根据水准路线长度计算高差观测值的权;(5)组成法方程;(6)解法方程,求得未知点高程改正数及平差后高程值;(7)求高差观测值残差及平差后高差观测值;(8)精度评定;(9)输出平差结果。4.水准网高程近似值计算算法35.输入数据格式示例实验代码:#pragmaonceclassLevelControlPoint{public:LevelControlPoint(void);~LevelControlPoint(void);public:CStringstrName;//点名4CStringstrID;//点号floatH;boolflag;//标记是否已经计算出近似高程值,若计算出则为,否则为};classCDhObs{public:CDhObs(void);~CDhObs(void);public:LevelControlPoint*cpBackObj;//后视点LevelControlPoint*cpFrontObj;//前视点doubleObsValue;//高差值doubleDist;//测站的距离};#includeStdAfx.h#includeLevelControlPoint.hLevelControlPoint::LevelControlPoint(void){strName=_T();strID=_T();H=0;flag=0;}LevelControlPoint::~LevelControlPoint(void){}CDhObs::CDhObs(void){}CDhObs::~CDhObs(void){}#pragmaonce#includeLevelControlPoint.h#includeMatrix.hclassAdjustLevel{public:AdjustLevel(void);~AdjustLevel(void);public:LevelControlPoint*m_pKnownPoint;//已知点数组intm_iKnownPointCount;//已知点个数5LevelControlPoint*m_pUnknownPoint;//未知点数组intm_iUnknownPointCount;//未知点个数CDhObs*m_pDhObs;//高差观测值数组intm_iDhObsCount;//高差观测值个数public:voidSetKnownPointSize(intsize);//创建大小为size的已知点数组voidSetUnkonwnPointSize(intsize);//创建大小为size的未知点数组voidSetDhObsSize(intsize);//创建大小为size的观测值数组boolLoadObsData(constCString&strFile);//读入观测文件CString*SplitString(CStringstr,charsplit,int&iSubStrs);voidApproHeignt(void);//计算近似值private:LevelControlPoint*SearchKnownPointUsingID(CStringID);LevelControlPoint*SearchUnknownPointUsingID(CStringID);LevelControlPoint*SearchPointUsingID(CStringID);CMatrixLevleWeight(void);//计算权矩阵public:voidFormErrorEquation(CMatrix&B,CMatrix&L);//组成误差方程voidEquationCompute(CMatrix&x);//计算法方程voidAccuracy_Assessment(double&r0,CMatrix&Qxx);//精度评定voidCompAdjust(double&r0,CMatrixQx[]);};#includeStdAfx.h#includeAdjustLevel.h#includelocale.h#includeLevelControlPoint.h#includemath.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){6delete[]m_pKnownPoint;m_pKnownPoint=NULL;}if(m_pUnknownPoint!=NULL){delete[]m_pUnknownPoint;m_pUnknownPoint=NULL;}if(m_pDhObs!=NULL){delete[]m_pDhObs;m_pDhObs=NULL;}}voidAdjustLevel::SetKnownPointSize(intsize){m_pKnownPoint=newLevelControlPoint[size];//创建动态指针m_iKnownPointCount=size;}voidAdjustLevel::SetUnkonwnPointSize(intsize){m_pUnknownPoint=newLevelControlPoint[size];m_iUnknownPointCount=size;}voidAdjustLevel::SetDhObsSize(intsize){m_pDhObs=newCDhObs[size];m_iDhObsCount=size;//高差观测值个数}boolAdjustLevel::LoadObsData(constCString&strFile){CStdioFilesf;if(!sf.Open(strFile,CFile::modeRead))returnfalse;//创建并打开文件对象CStringstrLine;boolbEOF=sf.ReadString(strLine);//读取第一行,即已知点的数目SetKnownPointSize(_ttoi(strLine));//根据已知点的数目,创建已知点数组;7intn=0;for(inti=0;im_iKnownPointCount;i++)//读取已知点的点名和高程值{sf.ReadString(strLine);CString*pstrData=SplitString(strLine,',',n);m_pKnownPoint[i].strName=pstrData[0];m_pKnownPoint[i].strID=pstrData[0];m_pKnownPoint[i].H=_tstof(pstrData[1]);m_pKnownPoint[i].flag=1;//已知点不用平差,故将其的flag设置为delete[]pstrData;pstrData=NULL;}sf.ReadString(strLine);//读取未知点的个数SetUnkonwnPointSize(_ttoi(strLine));//根据未知点的个数创建未知点数组sf.ReadString(strLine);//读取未知点的点名CString*pstrData=SplitString(strLine,',',n);for(inti=0;im_iUnknownPointCount;i++)//将未知点的点名放入未知点数组{m_pUnknownPoint[i].strName=pstrData[i];m_pUnknownPoint[i].strID=pstrData[i];m_pUnknownPoint[i].H=0;//未知点的高程值设置为m_pUnknownPoint[i].flag=0;//还没有求得近似高程,故其flag设置为}if(pstrData!=NULL){delete[]pstrData;pstrData=NULL;}sf.ReadString(strLine);//读取观测值的个数SetDhObsSize(_ttoi(strLine));//按照观测值的大小,创建观测值数组for(inti=0;im_iDhObsCount;i++)//分行读取观测值的数据,将其存入观测值数组{sf.ReadString(strLine);CString*pstrData=SplitString(strLine,',',n);m_pDhObs[i].cpBackObj=SearchPointUsingID(pstrData[0]);//后视点m_pDhObs[i].cpFrontObj=SearchPointUsingID(pstrData[1]);//前视点m_pDhObs[i].HObsValue=_tstof(pstrData[2]);//高差观测值m_pDhObs[i].Dist=_tstof(pstrData[3]);//距离观测值delete[]pstrData;pstrData=NULL;}sf.Close();return1;}8CString*AdjustLevel::SplitString(CStringstr,charsplit,int&iSubStrs){intiPos=0;//分割符位置intiNums=0;//分割符的总数CStringstrTemp=str;CStringstrRight;//先计算子字符串的数量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;returnNULL;}//子字符串数组iSubStrs=iNums+1;//子串的数量=分割符数量+1CString*pStrSplit;pStrSplit=newCString[iSubStrs];strTemp=str;CStringstrLeft;for(inti=0;iiNums;i++){iPos=strTemp.Find(split);//左子串strLeft=strTemp.Left(iPos);//右子串strRight=strTemp.Mid(iPos+1,strTemp.GetLength());strTemp=strRight;pStrSplit[i]=strLeft;}pStrSplit[iNums]=strTemp;returnpStrSplit;}9//LevelControlPoint*AdjustLevel::SearchKnownPointUsingID(CStringID){for(inti=0;im_iKnownPointCount;i++){if(