⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgcoordtrans.cpp

📁 GPS坐标转换软件与源程序 支持世界上大多数坐标框架下
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		u1 bfind=0;
		while(ReadLine(fp,str) != -1)
		{
			if(strstr(str,"LanguageID=") != NULL){//LanguageID
				//strtmp.find("LanguageID=",0) == 0
				int langid;
				sscanf_s(str,"LanguageID=%d",&langid);
				theLang.SetLanguageID(langid);
				bfind =1;
			}
			if (strstr(str,"Datum Transformation=") != NULL)//Datum transformation para
			{//in form: Datum Transformation=modelID,srcellip,destellip,factor,tx,ty,tz,wx,wy,wz
				sscanf_s(str,"Datum Transformation=%d,%d,%d,%f,%f,%f,%f,%f,%f,%f\n",
					&(_datumtran.model),&(_datumtran.srcellip),&(_datumtran.destellip),&(_datumtran.factor),
					&(_datumtran.tx),&(_datumtran.ty),&(_datumtran.tz),
					&(_datumtran.wx),&(_datumtran.wy),&(_datumtran.wz));
			}
		}
		if(!bfind)
			theLang.SetLanguageID(LANGID_ZH_CN); //default is zh_cn
		fclose(fp);
	}
	else{
		theLang.SetLanguageID(LANGID_ZH_CN);
	}

	//evaluate the global variance _refellip;
	_refellip.clear();
	path=theLang.GetDirectory(EXECUTABLEDIR)+ "Ellipse.csv.bak";
	if(fopen_s(&fp,path,"r") == 0){
		_refellipsoid ellip;
		//first line
		ReadLine(fp,str);
		while(ReadLine(fp,str) != -1){//str in format:"str,str,double,double,str,\n"
			string strtmp(str);
			u1 pos1=0,pos2=0;
			//first.
			pos2=strtmp.find(',',pos1);	
			strtmp.copy(ellip.name_coor,pos2-pos1,pos1);ellip.name_coor[pos2-pos1]=0;
			//second
			pos1=pos2+1;		pos2=strtmp.find(',',pos1);
			strtmp.copy(ellip.name_ellip,pos2-pos1,pos1);ellip.name_ellip[pos2-pos1]=0;
			pos1 = pos2+1;
			sscanf_s(str+pos1,"%lf,%lf",&(ellip.semimajor),&(ellip.invflattening));
			_refellip.push_back(ellip);			
		}
		fclose(fp);
	}
	
	//Initialize the checkbutton and the lables of coords.
	SetCheckState();
	//Initialize CCombox.
	PopulateCombo();
	
	theLang.SetLanguage();
	Localize(1);
	
	m_edtsrc1.SetWindowText("0.0");
	m_edtsrc2.SetWindowText("0.0");
	m_edtsrc3.SetWindowText("0.0");
	m_edtdest1.SetWindowText("0.0");
	m_edtdest2.SetWindowText("0.0");
	m_edtdest3.SetWindowText("0.0");
	m_edtSrcZone.EnableWindow(FALSE);
	m_edtDestZone.EnableWindow(FALSE);


	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgCoordTrans::OnCoordTrans() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	LLA blh;
	GRID utm;
	ECEF ecef;

	//evaluation
	CString tmp;
	RetrieveDataFromCtrl(1);	
	//src=grid ,must set zone first.
	if(2 == m_SrcCoordType)
		if (!m_bProject) {
			AfxMessageBox("Projection parameter error\
				\nYou must set Projection parameter first in Set/Projection menu");
			return;
		}
//		if(m_srczone.GetLength() != 3){
//			AfxMessageBox("You must set zone first!\neg:01C,02X,31S,60W\nlongitude zone:01-60,\
//				latitude zone C-X,exlude I,O");
//			return;
// 		}

	//DatumTran = 0: m_SrcEllip == m_DestEllip; =1:m_SrcEllip != m_DestEllip
	BOOL DatumTran = m_chkDatum.GetState() & 0x0003;
	//ecef2ecef
	if ( 0 == m_SrcCoordType && 0 == m_DestCoordType) {
		if (!DatumTran)
			m_dest1=m_src1,m_dest2=m_src2,m_dest3=m_src3;
		else{
			;
		}
	}
	//ecef2geodetic
	else if ( 0 == m_SrcCoordType && 1 == m_DestCoordType) {
		ecef.Set(m_src1,m_src2,m_src3);
		if (!DatumTran){
			blh = ECEFtoLLA(ecef,m_SrcEllip);
			blh.Get(m_dest1,m_dest2,m_dest3,2);
		}
		else{
			;
		}
//		blh.GetInDegrees(m_dest1,m_dest2,m_dest3);
	}
	//ecef2projection grid
	else if ( 0 == m_SrcCoordType && 2 == m_DestCoordType) {
		char zone;
		ecef.Set(m_src1,m_src2,m_src3);
		if (!DatumTran){
			utm = ECEFtoGRID(ecef,m_k0,m_SrcEllip);
		}
		else{
			;
		}
		utm.Get(m_dest1,m_dest2,zone,m_dest3);		
		m_destzone.Format("%d%C",zone,utm.designator());
	}
	
	//Geodetic2ecef
	else if ( 1 == m_SrcCoordType && 0 == m_DestCoordType) {	
		if (!DatumTran) {
			blh.Set(m_src1,m_src2,m_src3);
			ecef = LLAtoECEF(blh,m_SrcEllip);
			ecef.Get(m_dest1,m_dest2,m_dest3);
		}
		else{
			;
		}
	}
	//GeotoGeo
	else if ( 1 == m_SrcCoordType && 1 == m_DestCoordType) {	
		if (!DatumTran) {
			m_dest1=m_src1,m_dest2=m_src2,m_dest3=m_src3;
		}
		else{
			;
		}
	}

	//Geodetic2grid
	else if ( 1 == m_SrcCoordType && 2 == m_DestCoordType ) {
		char zone;
		if (!DatumTran) {
			blh.Set(m_src1,m_src2,m_src3);
			utm =  LLAtoGRID(blh,m_k0,m_SrcEllip);
			utm.Get(m_dest1,m_dest2,zone,m_dest3);
		}
		m_destzone.Format("%d%C",zone,utm.designator());
	}
	//grid2ecef
	else if ( 2 == m_SrcCoordType && 0 == m_DestCoordType) {
		utm.Set(m_src1,m_src2,m_lon0,m_src3,m_NorS);
		if (!DatumTran) {
			ecef =  GRIDtoECEF(utm,m_k0,m_SrcEllip);
		}
		ecef.Get(m_dest1,m_dest2,m_dest3);
	}
	//grid2Geodetic
	else if ( 2 == m_SrcCoordType && 1 == m_DestCoordType) {
		utm.Set(m_src1,m_src2,m_lon0,m_src3,m_NorS);
		if (!DatumTran) {
			blh =  GRIDtoLLA(utm,m_k0,m_SrcEllip);
			blh.Get(m_dest1,m_dest2,m_dest3,2);
		}
//		blh.GetInDegrees(m_dest1,m_dest2,m_dest3);
	}
	
	//grid2grid
	else if ( 2 == m_SrcCoordType && 2 == m_DestCoordType) {	
		if (!DatumTran) {
			m_dest1=m_src1,m_dest2=m_src2,m_dest3=m_src3;m_destzone=m_srczone;
		}
		else{
			;
		}
	}
	InitializeDataToCtrl(2);
	_bwsmodify =TRUE;
	UpdateData(FALSE);
}

void CDlgCoordTrans::OnSelchangeDestEllip() 
{
	// TODO: Add your control notification handler code here
	int nDestIndex=m_cmbDestEllip.GetCurSel();
	switch(nDestIndex) {
	case 0:
		m_DestEllip=GeoRef::Krassolvsky1990;
		break;
	case 1:
		m_DestEllip=GeoRef::Clarke1866;
		break;
	case 2:
		m_DestEllip=GeoRef::WGS84;
		break;
	}	

}

void CDlgCoordTrans::OnSelchangeSrcEllip() 
{
	// TODO: Add your control notification handler code here
	//retrieve the index of the selected item.
	int nSrcIndex=m_cmbSrcEllip.GetCurSel();
	switch(nSrcIndex) {
	case 0:
		m_SrcEllip=GeoRef::Krassolvsky1990;
		break;
	case 1:
		m_SrcEllip=GeoRef::Clarke1880;
		break;
	case 2:
		m_SrcEllip=GeoRef::WGS84;
		break;
	}	
}
void CDlgCoordTrans::RetrieveDataFromCtrl(const char flag/* =0 */)
{
	CString tmp;
	int dd,mm;float ss;
	if(flag & 0x1){//src
		if (1 == m_SrcCoordType) {
			switch(m_SrcBLUnit) {
			case 0://dd:mm:ss
				m_edtsrc1.GetWindowText(tmp);
				sscanf(tmp,"%d:%d:%f″",&dd,&mm,&ss);
	//			sscanf(tmp,"%d:%m:%f",&dd,&mm,&ss)
				m_src1=(dd+1.0*mm/60+ss/3600)*PI/180;
				m_edtsrc2.GetWindowText(tmp);
				sscanf(tmp,"%d:%d:%f″",&dd,&mm,&ss);
	//			sscanf(tmp,"%d:%m:%f",&dd,&mm,&ss)
				m_src2=(dd+1.0*mm/60+ss/3600)*PI/180;
				break;
			case 1://dd°mm′ss″
				m_edtsrc1.GetWindowText(tmp);
				sscanf(tmp,"%d°%d′%f″",&dd,&mm,&ss);
	//			sscanf(tmp,"%d:%m:%f",&dd,&mm,&ss)
				m_src1=(dd+1.0*mm/60+ss/3600)*PI/180;
				m_edtsrc2.GetWindowText(tmp);
				sscanf(tmp,"%d°%d′%f″",&dd,&mm,&ss);
	//			sscanf(tmp,"%d:%m:%f",&dd,&mm,&ss)
				m_src2=(dd+1.0*mm/60+ss/3600)*PI/180;
				break;
			case 2://degree
				m_edtsrc1.GetWindowText(tmp); m_src1=atof(tmp);m_src1 = m_src1*PI/180;
				m_edtsrc2.GetWindowText(tmp); m_src2=atof(tmp);m_src2 = m_src2*PI/180;
				break;
			case 3://radian
				m_edtsrc1.GetWindowText(tmp); m_src1=atof(tmp);
				m_edtsrc2.GetWindowText(tmp); m_src2=atof(tmp);
				break;
			default://second
				m_edtsrc1.GetWindowText(tmp); m_src1=atof(tmp);m_src1=m_src1/3600*PI/180;
				m_edtsrc2.GetWindowText(tmp); m_src2=atof(tmp);m_src2=m_src2/3600*PI/180;
			}		
		}
		else{
			m_edtsrc1.GetWindowText(tmp); m_src1=atof(tmp);
			m_edtsrc2.GetWindowText(tmp); m_src2=atof(tmp);
		}
		m_edtsrc3.GetWindowText(tmp); m_src3=atof(tmp);
	}
	if(flag & 0x2){//dest
		if (1 == m_DestCoordType) {
			switch(m_DestBLUnit) {
			case 0://dd:mm:ss
				m_edtdest1.GetWindowText(tmp);
				sscanf(tmp,"%d:%d:%f″",&dd,&mm,&ss);
	//			sscanf(tmp,"%d:%m:%f",&dd,&mm,&ss)
				m_dest1=(dd+1.0*mm/60+ss/3600)*PI/180;
				m_edtdest2.GetWindowText(tmp);
				sscanf(tmp,"%d:%d:%f″",&dd,&mm,&ss);
	//			sscanf(tmp,"%d:%m:%f",&dd,&mm,&ss)
				m_dest2=(dd+1.0*mm/60+ss/3600)*PI/180;
				break;
			case 1://dd°mm′ss″
				m_edtdest1.GetWindowText(tmp);
				sscanf(tmp,"%d°%d′%f″",&dd,&mm,&ss);
	//			sscanf(tmp,"%d:%m:%f",&dd,&mm,&ss)
				m_dest1=(dd+1.0*mm/60+ss/3600)*PI/180;
				m_edtdest2.GetWindowText(tmp);
				sscanf(tmp,"%d°%d′%f″",&dd,&mm,&ss);
	//			sscanf(tmp,"%d:%m:%f",&dd,&mm,&ss)
				m_dest2=(dd+1.0*mm/60+ss/3600)*PI/180;
				break;
			case 2://degree
				m_edtdest1.GetWindowText(tmp); m_dest1=atof(tmp);m_dest1 = m_dest1*PI/180;
				m_edtdest2.GetWindowText(tmp); m_dest2=atof(tmp);m_dest2 = m_dest2*PI/180;
				break;
			case 3://radian
				m_edtdest1.GetWindowText(tmp); m_dest1=atof(tmp);
				m_edtdest2.GetWindowText(tmp); m_dest2=atof(tmp);
				break;
			default://second
				m_edtdest1.GetWindowText(tmp); m_dest1=atof(tmp);m_dest1=m_dest1/3600*PI/180;
				m_edtdest2.GetWindowText(tmp); m_dest2=atof(tmp);m_dest2=m_dest2/3600*PI/180;
			}		
		}
		else{
			m_edtdest1.GetWindowText(tmp); m_dest1=atof(tmp);
			m_edtdest2.GetWindowText(tmp); m_dest2=atof(tmp);
		}
		m_edtdest3.GetWindowText(tmp); m_dest3=atof(tmp);
	}


}

void CDlgCoordTrans::InitializeDataToCtrl(const char flag/* =3 */)
{
	CString tmp;
	int dd,mm;float ss;
	if(flag & 0x1){//src
		if (1 == m_SrcCoordType) {//initialize the value of Cedit control
			switch(m_SrcBLUnit) {
			case 0://dd:mm:ss
				m_src1=m_src1*180/PI;	
				dd=(int)m_src1;		mm=(int)((m_src1-dd)*60);
				ss=((m_src1-dd)*60-mm)*60;
				tmp.Format("%d:%d:%f",dd,mm,ss);m_edtsrc1.SetWindowText(tmp);
				
				m_src2=m_src2*180/PI;
				dd=(int)m_src2;		mm=(int)((m_src2-dd)*60);
				ss=((m_src2-dd)*60-mm)*60;
				tmp.Format("%d:%d:%f",dd,mm,ss);m_edtsrc2.SetWindowText(tmp);
				break;
			case 1://dd°mm′ss″
				m_src1=m_src1*180/PI;	
				dd=(int)m_src1;		mm=(int)((m_src1-dd)*60);
				ss=((m_src1-dd)*60-mm)*60;
				tmp.Format("%d°%d′%f″",dd,mm,ss);m_edtsrc1.SetWindowText(tmp);
				
				m_src2=m_src2*180.0/PI;
				dd=(int)m_src2;		mm=(int)((m_src2-dd)*60);
				ss=((m_src2-dd)*60-mm)*60;
				tmp.Format("%d°%d′%f″",dd,mm,ss);m_edtsrc2.SetWindowText(tmp);
				break;
			case 2://degree
				m_src1=m_src1*180.0/PI;tmp.Format("%f",m_src1);m_edtsrc1.SetWindowText(tmp); 
				m_src2=m_src2*180.0/PI;
				tmp.Format("%f",m_src2);m_edtsrc2.SetWindowText(tmp);
				break;
			case 3://radian
				tmp.Format("%f",m_src1);m_edtsrc1.SetWindowText(tmp); 
				tmp.Format("%f",m_src2);m_edtsrc2.SetWindowText(tmp);
				break;
			default://second
				m_src1=m_src1*180.0/PI*3600;tmp.Format("%f",m_src1);m_edtsrc1.SetWindowText(tmp); 
				m_src2=m_src2*180.0/PI*3600;tmp.Format("%f",m_src2);m_edtsrc2.SetWindowText(tmp);
			}
			
			tmp.Format("%f",m_src3);m_edtsrc3.SetWindowText(tmp);
		}
		else
		{
			tmp.Format("%f",m_src1);m_edtsrc1.SetWindowText(tmp);		
			tmp.Format("%f",m_src2);m_edtsrc2.SetWindowText(tmp);
			tmp.Format("%f",m_src3);m_edtsrc3.SetWindowText(tmp);
		}
	}
	if(flag & 0x2){//dest
		if (1 == m_DestCoordType) {//initialize the value of Cedit control
			switch(m_DestBLUnit) {
			case 0://dd:mm:ss
				m_dest1=m_dest1*180.0/PI;	
				dd=m_dest1;		mm=(m_dest1-dd)*60;		ss=((m_dest1-dd)*60-mm)*60;
				tmp.Format("%d:%d:%f",dd,mm,ss);m_edtdest1.SetWindowText(tmp);
				
				m_dest2=m_dest2*180.0/PI;
				dd=m_dest2;		mm=(m_dest2-dd)*60;		ss=((m_dest2-dd)*60-mm)*60;
				tmp.Format("%d:%d:%f",dd,mm,ss);m_edtdest2.SetWindowText(tmp);
				break;
			case 1://dd°mm′ss″
				m_dest1=m_dest1*180.0/PI;	
				dd=m_dest1;		mm=(m_dest1-dd)*60;		ss=((m_dest1-dd)*60-mm)*60;
				tmp.Format("%d°%d′%f″",dd,mm,ss);m_edtdest1.SetWindowText(tmp);
				
				m_dest2=m_dest2*180.0/PI;
				dd=m_dest2;		mm=(m_dest2-dd)*60;		ss=((m_dest2-dd)*60-mm)*60;
				tmp.Format("%d°%d′%f″",dd,mm,ss);m_edtdest2.SetWindowText(tmp);
				break;
			case 2://degree
				m_dest1=m_dest1*180.0/PI;tmp.Format("%f",m_dest1);m_edtdest1.SetWindowText(tmp); 
				m_dest2=m_dest2*180.0/PI;tmp.Format("%f",m_dest2);m_edtdest2.SetWindowText(tmp);
				break;
			case 3://radian

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -