中线桩地质体桩号计算记录

最近,做了一段输水管道桩号计算的数据处理。

其中涉及,根据桩号计算坐标,在地质体中加入中线转点坐标的问题。

数据量有1500多条。一个个计算比较麻烦。所以考虑编程批量计算。




第一步:数据准备

1.中线转点坐标值(转点桩号里程,转点X,转点Y)

2.地质体信息(地质体桩号里程,待求X,待求Y,高程h,s1上地层编号,s2下地层编号,s1上地层属性,s2下地层属性,s1编码,s2编码)

第二步:编码


#include <iostream>
#include <fstream>
#include <string>
#include "vector3.h"
#include<iterator>
#include<iomanip>
#include <list>
#include <sstream>
#include <string>
#include <ctype.h>
using namespace std;
typedef struct CzHstuct
{
bool tf;//是否是中线点
int Id;
int linenumb;
double x,y,h,Length;
string s1,s2,stmp1,stmp2,s1zw,s2zw;
 
bool operator < (CzHstuct & b) {
       return Length < b.Length;
}


};




//桩号坐标计算,x,y,z;z代表桩距
typedef struct CIrrPostion
{
int posnum;
POSTION *positionlist;



};
//计算输入数据


typedef struct CzjPosIndex
{
int Indexnum;
double *zjIndexlist;


};


//定义已知地质体信息
typedef struct CzHPosDataList
{
int Indexnum;
CzHstuct *posIndexlist;


};


//定义已知地质体信息
typedef struct CRecordxlList
{
int Indexnum;
    string Nameofline;
int LineId;


};




char  gEnergyFile[30];


 
typedef list<CRecordxlList> LISTRECORDLINE;  
typedef list<CzHstuct> LISTCZHSTUCT;






全局变量记录桩号信息//线路I信息
  LISTRECORDLINE meRecordCountNamelist;
  LISTCZHSTUCT meListzhstruct;
  //中线桩数据
  LISTCZHSTUCT mezxzdataList;


   LISTCZHSTUCT :: iterator iterzhst;//指针桩号
   LISTCZHSTUCT :: iterator iterzxst;//指针中线桩号
   LISTRECORDLINE::iterator iterxlst;//指针线路




//读取桩距列表
 CzjPosIndex ReadposIndex()
{
CzjPosIndex PosIndexlist;
FILE    *fp;
    char    stemp[50];

strcpy(gEnergyFile,"zjlist.txt");
//cinployfloat
fp = fopen( gEnergyFile, "r" );
    if ( fp == NULL ) 
    {  
 printf( "\n Can not open energy data file:%s\n", gEnergyFile);
          exit(0);
         // AfxMessageBox( "\n Can not open energy data,没有找到屋顶参数!提示!默认设置:(30,5) ");
// return  Poslist;
        
    }  
    fseek( fp, 0, SEEK_SET);
fscanf( fp, "%s", stemp);


    while( strcmp( stemp,"Zjlist:" ) != 0)  fscanf( fp, "%s", stemp);
fscanf( fp, "%d", &(PosIndexlist.Indexnum));
PosIndexlist.zjIndexlist =(double*)malloc(sizeof(double)* PosIndexlist.Indexnum);


for(int i=0;i<PosIndexlist.Indexnum;i++)
{
fscanf( fp, "%lf", &(PosIndexlist.zjIndexlist[i]));
}
 fclose( fp );
   return PosIndexlist;




}


 //读取桩距坐标类表
CIrrPostion ReadPosdatas()
{
CIrrPostion Poslist;
FILE    *fp;
    char    stemp[50];

strcpy(gEnergyFile,"zhzb.txt");
//cinploydouble
fp = fopen( gEnergyFile, "r" );
    if ( fp == NULL ) 
    {  
 printf( "\n Can not open energy data file:%s\n", gEnergyFile);
          exit(0);
         // AfxMessageBox( "\n Can not open energy data,没有找到屋顶参数!提示!默认设置:(30,5) ");
// return  Poslist;
        
    }  
    fseek( fp, 0, SEEK_SET);
fscanf( fp, "%s", stemp);


    while( strcmp( stemp,"Zhzbdata:" ) != 0)  fscanf( fp, "%s", stemp);
fscanf( fp, "%d", &(Poslist.posnum));
Poslist.positionlist =(POSTION*)malloc(sizeof(POSTION)* Poslist.posnum);


for(int i=0;i<Poslist.posnum;i++)
{
fscanf( fp, "%lf%lf%lf", &(Poslist.positionlist[i].z),&(Poslist.positionlist[i].x),&(Poslist.positionlist[i].y));
}
 fclose( fp );
   return Poslist;
}






//读取需要计算的桩号地质体信息
void  Preadzhdata()
 {
  // CzHPosDataList  zHdataList;
  //临时变量桩号信息
   CzHstuct sengleCzhstruct;
   CRecordxlList  sengleCRecordline;
int mecount=0;
int melinenumb=0;
cout << setprecision(4) << fixed;
// LISTINT::iterator plist;  //读取数据
std::ifstream fin("newformatread.txt", std::ios::in);
char line[1024]={0};


while(fin.getline(line, sizeof(line)))
{
std::stringstream word(line);




if(isdigit(line[0])||isdigit(line[1]))//如果是数字
{
mecount++;
///
word >> sengleCzhstruct.Length >> sengleCzhstruct.x >> sengleCzhstruct.y>> sengleCzhstruct.h>> sengleCzhstruct.s1>> sengleCzhstruct.stmp1>> sengleCzhstruct.s1zw>> sengleCzhstruct.s2>>sengleCzhstruct.stmp2>>sengleCzhstruct.s2zw;






sengleCzhstruct.Id=mecount;
sengleCzhstruct.tf=false;
sengleCzhstruct.linenumb=melinenumb;
meListzhstruct.push_back(sengleCzhstruct);

std::cout <<setw(6)<< mecount << "  " << sengleCzhstruct.Length <<"  " << sengleCzhstruct.x <<"  " << sengleCzhstruct.y <<"  " << sengleCzhstruct.h <<"  " << sengleCzhstruct.s1 <<"  " << sengleCzhstruct.s2 <<"  " << sengleCzhstruct.stmp1 <<"  " << sengleCzhstruct.s2 <<" "<<sengleCzhstruct.stmp2<<" "<<sengleCzhstruct.s2zw<< std::endl;


}
else
{
word >> sengleCRecordline.Nameofline;
sengleCRecordline.Indexnum=mecount;
sengleCRecordline.LineId=melinenumb;
    std::cout << "线名:  " << sengleCRecordline.Nameofline << " 个数: "<<sengleCRecordline.Indexnum <<std::endl;


meRecordCountNamelist.push_back(sengleCRecordline);


    mecount=0;
melinenumb++;
}


}
fin.clear();
fin.close();


}
//读取中线桩信息


void  Readzxlistdata()
 {
  //临时变量桩号信息中线点
   CzHstuct zxdCzhstruct;
   cout << setprecision(4) << fixed;
int mecount=0;
// LISTINT::iterator plist;  //读取数据
std::ifstream fin("xinjianzxdata.txt", std::ios::in);
char line[524]={0};


while(fin.getline(line, sizeof(line)))
{
std::stringstream word(line);
if(isdigit(line[0])||isdigit(line[1]))//如果是数字
{
mecount++;


word >> zxdCzhstruct.Length >>  zxdCzhstruct.x >> zxdCzhstruct.y;


zxdCzhstruct.Id=1000000+mecount;
zxdCzhstruct.tf=true;
mezxzdataList.push_back(zxdCzhstruct);

///std::cout << mecount << " " << zxdCzhstruct.Length <<" " << zxdCzhstruct.x <<" " << zxdCzhstruct.y <<" " << zxdCzhstruct.h <<" " << zxdCzhstruct.s1 <<" " << zxdCzhstruct.s2 <<" " << zxdCzhstruct.stmp1 <<" " << zxdCzhstruct.stmp2 << std::endl;
std::cout<<setw(6) << mecount << " : " << zxdCzhstruct.Length <<"  " << zxdCzhstruct.x <<"  " << zxdCzhstruct.y << std::endl;
}
else
{



    std::cout << "错误:  " << " 第几???: "<<mecount <<std::endl;





}


}
fin.clear();
fin.close();


}








int main()
{


//读取待测桩号数据数据得到所有线路的桩号点信息和路线信息
 printf( "\n ----------------读取桩号地质体信息--------------------\n");


 Preadzhdata();


 printf( "\n ----------------读取中线坐标信息---------------------\n");


 Readzxlistdata();


  printf( "\n----------------------------------------------\n");
 printf( "\n                  开始计算\n----------------------------------------------\n");
 ///
 // LISTRECORDLINE meRecordCountNamelist;
 // LISTCZHSTUCT meListzhstruct;
  //中线桩数据
 // LISTCZHSTUCT mezxzdataList;
 //  LISTCZHSTUCT :: iterator iterzhst;//指针桩号
 //  LISTCZHSTUCT :: iterator iterzxst;//指针中线桩号
 //  LISTRECORDLINE::iterator iterxlst;//指针线路
 //私有指针
  LISTCZHSTUCT :: iterator iterzhstper;//指针桩号
  LISTCZHSTUCT :: iterator iterzhstnext;//指针桩号
   ofstream outfile("NewZhzbZHresult.txt", ios_base::out);
 if (!outfile)
 {
  cerr<<"error: can not open \"NewZhzbZHresult.txt\" for output\n";
  exit(-1);
 }
  outfile.precision(4);
    outfile.setf(ios::fixed);
cout << setprecision(4) << fixed;
int Errorcount=0;
double tmpzj;
double tempA,tempB;
    int perId;
int pnextId=0;
double a=0,b=0,zhzbx=0,zhzby=0;


//首先计算地质体桩号坐标信息


for (iterzhst=meListzhstruct.begin();iterzhst!=meListzhstruct.end();iterzhst++)
{
        perId=mezxzdataList.size();//获得中线点的个数
   pnextId=0;
   tempA=500000000;
tempB=500000000;
tmpzj=iterzhst->Length;




//实现插入
for (iterzxst=mezxzdataList.begin();iterzxst!=mezxzdataList.end();iterzxst++)
{


if(iterzxst->Length<=tmpzj)
{
if (tmpzj-iterzxst->Length <tempA)

tempA=tmpzj-iterzxst->Length ;
perId=iterzxst->Id;
iterzhstper=iterzxst;
}


}
if(iterzxst->Length>tmpzj)
{

if (iterzxst->Length-tmpzj <tempB)

tempB=iterzxst->Length-tmpzj;
   pnextId=iterzxst->Id;
iterzhstnext=iterzxst;
}


}


}




if( perId!=mezxzdataList.size()&&pnextId!=0&& iterzhstper->Length  <=tmpzj && iterzhstnext->Length>tmpzj )
{


a=tmpzj-iterzhstper->Length;
b=iterzhstnext->Length-tmpzj;


           /* zhzbx = mIrrpos.positionlist[perId].x+ (mIrrpos.positionlist[pnextId].x-mIrrpos.positionlist[perId].x)*a /(a+b)  ;
zhzby = mIrrpos.positionlist[perId].y+ (mIrrpos.positionlist[pnextId].y-mIrrpos.positionlist[perId].y)*a /(a+b)  ;*/


if (a<0||b<0){ cout<<"我去!Error 出现异常!"<< std::endl ;}



           /* zhzbx = (a*iterzhstnext->x+ b*iterzhstper->x )/(a+b)  ;
zhzby = (a*iterzhstnext->y + b*iterzhstper->y )/(a+b)  ;*/
iterzhst->x = (a*iterzhstnext->x+ b*iterzhstper->x )/(a+b)  ;
iterzhst->y= (a*iterzhstnext->y + b*iterzhstper->y )/(a+b)  ;

        outfile<< iterzhst->Id <<" "<<iterzhst->Length<<" "<<iterzhst->x<<" "<<iterzhst->y<<" "<<iterzhst->h<<" "<<iterzhst->s1<<" "<<iterzhst->stmp1<<" "<<iterzhst->s1zw<<" "<<iterzhst->s2<<" "<<iterzhst->stmp2<<" "<<iterzhst->s2zw<<std::endl ;
   cout<< iterzhst->Id <<" "<<iterzhst->Length<<" "<<iterzhst->x<<" "<<iterzhst->y<<" "<<iterzhst->h<<" "<<iterzhst->s1<<" "<<iterzhst->s2<<" "<<iterzhst->stmp1<<" "<<iterzhst->stmp2<<std::endl ;




}
else
{
   outfile<< iterzhst->Id <<" "<<iterzhst->Length<<" "<<iterzhst->x<<" "<<iterzhst->y<<" "<<iterzhst->h<<" "<<iterzhst->s1<<" "<<iterzhst->stmp1<<" "<<iterzhst->s1zw<<" "<<iterzhst->s2<<" "<<iterzhst->stmp2<<" "<<iterzhst->s2zw<<std::endl ;
 //  outfile<< iterzhst->Id <<" "<<iterzhst->Length<<" "<<iterzhst->x<<" "<<iterzhst->y<<" "<<iterzhst->h<<" "<<iterzhst->s1<<" "<<iterzhst->s2<<" "<<iterzhst->stmp1<<" "<<iterzhst->stmp2<<std::endl ;
cout<< iterzhst->Id <<" Error 出现异常!"<< std::endl ;


Errorcount++;

}


}


outfile.close();
printf( "\n -------------------------------------\n");
printf( "\n 计算结束生成文件:Zhzbresult.txt");
if (Errorcount>0)
{  
cout<<"Error 出现异常个数 : "<<Errorcount << std::endl ;


}








逐线插值生成中线点信息。


// LISTRECORDLINE meRecordCountNamelist;
 // LISTCZHSTUCT meListzhstruct;
  //中线桩数据
 // LISTCZHSTUCT mezxzdataList;
 //  LISTCZHSTUCT :: iterator iterzhst;//指针桩号
 //  LISTCZHSTUCT :: iterator iterzxst;//指针中线桩号
 //  LISTRECORDLINE::iterator iterxlst;//指针线路
// LISTCZHSTUCT :: iterator iterzhstper;//指针下面新含义
  //LISTCZHSTUCT :: iterator iterzhstnext;//指针下面新含义
//临时中线


 ofstream Lastoutfile("LastZhRresult.txt", ios_base::out);
 if (!Lastoutfile)
 {
  cerr<<"error: can not open \"LastZhRresult.txt\" for output\n";
  exit(-1);
 }
  Lastoutfile.precision(4);
    Lastoutfile.setf(ios::fixed);
cout << setprecision(4) << fixed;








    LISTCZHSTUCT tmplist;//临时桩号
    LISTCZHSTUCT tmpzxlist;//临时中线桩号






   CzHstuct lnewzxdCzhstruct;//临时桩号定义
  double tmplengthmin,tmplengthmax;//最大最小临时








  for (iterxlst=meRecordCountNamelist.begin();iterxlst!=meRecordCountNamelist.end();iterxlst++)//循环逐条地层
  {
 tmpzxlist.clear();
 tmplist.clear();//清空上条地层信息
 //首先读取已有地址体线路信息
 for(iterzhst=meListzhstruct.begin();iterzhst!=meListzhstruct.end(); iterzhst++)//循环所有的地层逐条选取
 {


 if(iterzhst->linenumb==iterxlst->LineId )
 {
 lnewzxdCzhstruct.Length=iterzhst->Length;
 lnewzxdCzhstruct.x=iterzhst->x;
 lnewzxdCzhstruct.y=iterzhst->y;
 lnewzxdCzhstruct.h=iterzhst->h;
 lnewzxdCzhstruct.Id=iterzhst->Id;
              lnewzxdCzhstruct.linenumb=iterzhst->linenumb;
 lnewzxdCzhstruct.s1=iterzhst->s1;
 lnewzxdCzhstruct.s2=iterzhst->s2;
 lnewzxdCzhstruct.stmp1=iterzhst->stmp1;
 lnewzxdCzhstruct.stmp2=iterzhst->stmp2;
 lnewzxdCzhstruct.s1zw=iterzhst->s1zw;
 lnewzxdCzhstruct.s2zw=iterzhst->s2zw;
     lnewzxdCzhstruct.tf=iterzhst->tf;


 tmplist.push_back(lnewzxdCzhstruct);


 }


 }


 ///找到已有线路的最大桩号,最小桩号
 tmplist.sort();//按桩号长度排序
 iterzhstper= tmplist.begin();//第一个
 tmplengthmin=iterzhstper->Length;//最近
 iterzhstnext=tmplist.end();//最后一个
 iterzhstnext--;//最远
 tmplengthmax=iterzhstnext->Length;//最大值


 //插入中线点
   for(iterzxst=mezxzdataList.begin();iterzxst!=mezxzdataList.end(); iterzxst++)
 {


 if(iterzxst->Length< tmplengthmax &&iterzxst->Length>tmplengthmin )
 {
   tempA=500000000;
       tempB=500000000;
       tmpzj=iterzxst->Length;
///******查找最邻近的桩号指针
       for(iterzhst=tmplist.begin();iterzhst!=tmplist.end(); iterzhst++)
{


  if(iterzhst->Length<=tmpzj)
         {
       if (tmpzj-iterzhst->Length <tempA)
       { 
       tempA=tmpzj-iterzhst->Length ;
       perId=iterzhst->Id;
       iterzhstper=iterzhst;
       }


  }
      if(iterzhst->Length>tmpzj)
      {

    if (iterzhst->Length-tmpzj <tempB)
    { 
  tempB=iterzhst->Length-tmpzj;
      pnextId=iterzhst->Id;
  iterzhstnext=iterzhst;
    }


  }


}




 lnewzxdCzhstruct.Length=iterzxst->Length;
 lnewzxdCzhstruct.x=iterzxst->x;
 lnewzxdCzhstruct.y=iterzxst->y;
 lnewzxdCzhstruct.h= ((iterzhstper->h)*tempB+(iterzhstnext->h)*tempA)/(tempA+tempB) ;
 lnewzxdCzhstruct.Id=iterzxst->Id;
              lnewzxdCzhstruct.linenumb=iterxlst->LineId;


 if (tempA<tempB)
 {
lnewzxdCzhstruct.s1=iterzhstper->s1;
   lnewzxdCzhstruct.s2=iterzhstper->s2;
   lnewzxdCzhstruct.stmp1=iterzhstper->stmp1;
   lnewzxdCzhstruct.stmp2=iterzhstper->stmp2;
lnewzxdCzhstruct.s1zw=iterzhstper->s1zw;
   lnewzxdCzhstruct.s2zw=iterzhstper->s2zw;


 }
 else
 {
lnewzxdCzhstruct.s1=iterzhstnext->s1;
   lnewzxdCzhstruct.s2=iterzhstnext->s2;
   lnewzxdCzhstruct.stmp1=iterzhstnext->stmp1;
   lnewzxdCzhstruct.stmp2=iterzhstnext->stmp2;
lnewzxdCzhstruct.s1zw=iterzhstnext->s1zw;
   lnewzxdCzhstruct.s2zw=iterzhstnext->s2zw;


 }

     lnewzxdCzhstruct.tf=iterzxst->tf;
 tmpzxlist.push_back(lnewzxdCzhstruct);


 }


}
//开始以中线长度排序

for(iterzhst=tmpzxlist.begin();iterzhst!=tmpzxlist.end();iterzhst++ )
{
lnewzxdCzhstruct.Length=iterzhst->Length;
 lnewzxdCzhstruct.x=iterzhst->x;
 lnewzxdCzhstruct.y=iterzhst->y;
 lnewzxdCzhstruct.h=iterzhst->h;
 lnewzxdCzhstruct.Id=iterzhst->Id;
              lnewzxdCzhstruct.linenumb=iterzhst->linenumb;
 lnewzxdCzhstruct.s1=iterzhst->s1;
 lnewzxdCzhstruct.s2=iterzhst->s2;
 lnewzxdCzhstruct.stmp1=iterzhst->stmp1;
 lnewzxdCzhstruct.stmp2=iterzhst->stmp2;
 lnewzxdCzhstruct.s1zw=iterzhst->s1zw;
 lnewzxdCzhstruct.s2zw=iterzhst->s2zw;


     lnewzxdCzhstruct.tf=iterzhst->tf;
 tmplist.push_back(lnewzxdCzhstruct);
}





tmplist.sort();//再次排序


for(iterzhst=tmplist.begin();iterzhst!=tmplist.end();iterzhst++ )
{
         Lastoutfile<< iterzhst->Id <<" "<<iterzhst->Length<<" "<<iterzhst->x<<" "<<iterzhst->y<<" "<<iterzhst->h<<" "<<iterzhst->s1<<" "<<iterzhst->stmp1<<" "<<iterzhst->s1zw<<" "<<iterzhst->s2<<" "<<iterzhst->stmp2<<" "<<iterzhst->s2zw<<" "<<iterzhst->linenumb<<" "<<iterzhst->tf<<std::endl ;
cout<< iterzhst->linenumb << std::endl ;


}
Lastoutfile<<iterxlst->Nameofline<<" "<<iterxlst->LineId<<" "<<tmplist.size() <<std::endl ;
        cout<< "--------------------------------------" << std::endl ;


}




     Lastoutfile.close();
printf( "\n -------------------------------------\n");
printf( "\n 计算结束生成文件:LastZhRresult.txt");


printf( "\n -------------------------------------\n");
int pouse;
cin >>pouse;



return 0 ;
}

最终解决。批量生成

代码在这里http://download.csdn.net/detail/sun19890716/8645779

没有项目工程文件,只有两个代码和实例文件,程序小白就不要下了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值