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

📄 coorchannedlg.cpp

📁 能够实现一些常用的地图转换
💻 CPP
字号:
// CoorChanneDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CalSurBase.h"
#include "CoorChanneDlg.h"
#include "Survey.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCoorChanneDlg dialog


CCoorChanneDlg::CCoorChanneDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCoorChanneDlg::IDD, pParent)
{
	bfselcal=0;
	//{{AFX_DATA_INIT(CCoorChanneDlg)
	m_strip = -1;
	m_zbx = -1;
	//}}AFX_DATA_INIT
}


void CCoorChanneDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCoorChanneDlg)
	DDX_Control(pDX, IDC_STATIC_OLD, m_textold);
	DDX_Control(pDX, IDC_STATIC_NEW, m_textnew);
	DDX_Control(pDX, IDC_MSFLEXGRID_NEW, m_gridnew);
	DDX_Control(pDX, IDC_MSFLEXGRID_OLD, m_gridold);
	DDX_Radio(pDX, IDC_RADIO_STRIPA, m_strip);
	DDX_Radio(pDX, IDC_RADIO_ZBXA, m_zbx);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCoorChanneDlg, CDialog)
	//{{AFX_MSG_MAP(CCoorChanneDlg)
	ON_BN_CLICKED(ID_INPUT, OnInput)
	ON_BN_CLICKED(ID_SAVEDATA, OnSavedata)
	ON_BN_CLICKED(ID_CLEARDATA, OnCleardata)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCoorChanneDlg message handlers

BOOL CCoorChanneDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
    if(bfselcal==1)
	{
		CString StrTxt;
		m_gridold.SetCol(0);
		m_gridold.SetRow(0);
		m_textold.SetWindowText("高 斯 坐 标(X,Y)");
		StrTxt = "< 点号 >|<   北坐标(X)   >|<  东坐标(Y)   >";
		m_gridold.SetFormatString(StrTxt);
		m_gridold.Refresh();	//m_gridold

		m_gridnew.SetCol(0);
		m_gridnew.SetRow(0);
		m_textnew.SetWindowText("大 地 坐 标(B,L)");
		StrTxt = "< 点号 >|<北坐标(纬度)|<东坐标(经度)";
		m_gridnew.SetFormatString(StrTxt);
		m_gridnew.Refresh();	//m_gridold
	}
	else if(bfselcal==2)
	{
		CString StrTxt;
		m_gridold.SetCol(0);
		m_gridold.SetRow(0);
		m_textnew.SetWindowText("大 地 坐 标(B,L)");
		StrTxt = "< 点号 >|<北坐标(纬度)|<东坐标(经度)";
		
		m_gridold.SetFormatString(StrTxt);
		m_gridold.Refresh();	//m_gridold

		m_gridnew.SetCol(0);
		m_gridnew.SetRow(0);
		m_textold.SetWindowText("高 斯 坐 标(X,Y)");
		StrTxt = "< 点号 >|<   北坐标(X)   >|<  东坐标(Y)   >";
		m_gridnew.SetFormatString(StrTxt);
		m_gridnew.Refresh();	//m_gridold
	}
	else
	{
		AfxMessageBox("错误!");
	}
	m_strip=0;
	m_zbx=0;
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BEGIN_EVENTSINK_MAP(CCoorChanneDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CCoorChanneDlg)
	ON_EVENT(CCoorChanneDlg, IDC_MSFLEXGRID_OLD, -603 /* KeyPress */, OnKeyPressMsflexgridOld, VTS_PI2)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CCoorChanneDlg::OnKeyPressMsflexgridOld(short FAR* KeyAscii) 
{
	CString getdata;CString strport;
	getdata=m_gridold.GetText();
	getdata.TrimLeft();
    getdata.TrimRight();
	if(*KeyAscii==8)
	{
        strport=getdata.Left(getdata.GetLength()-1);
		m_gridold.SetText(strport);
	}
    else if(*KeyAscii==32)
	{
		long scol=0;
		scol=m_gridold.GetCol();
		if(scol>=2)
		{
            m_gridold.SetRow(m_gridold.GetRow()+1);
			m_gridold.SetCol(0);
		}
		else
		{
		    m_gridold.SetCol(scol+1);
		}
	}
	else
	{
		strport.Format("%c",*KeyAscii);
		getdata=getdata+strport;
		m_gridold.SetText(getdata);
	}		
}

int CCoorChanneDlg::CheckFile(CString strline)  //检查文件是否有高程   0 文件错误  1无高程  2有高程
{
	CString strgd;
	if(strline.GetLength()>3)
	{
		strgd=strline.Left(4);
        strgd.TrimRight();
		if(strgd=="@XYZ")
			return 2;
		else
			return 1;
	}
	else
	{   return 0;}
}

void CCoorChanneDlg::OnInput() 
{
    CString strfilename;
	CStdioFile n_File;
	CFileDialog gldOpenFile(true,"*.*",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|",NULL);
	gldOpenFile.DoModal();
    strfilename=gldOpenFile.GetPathName();
	//-------------------------------------------
	CFileException e;
	if(!n_File.Open(strfilename,CFile::modeRead,&e)) 
	{		return;	}
	CString cstrLine;
	CString strgd;
	n_File.ReadString(cstrLine);
	//strgd=cstrLine.Left(4);
	//strgd.TrimLeft();strgd.TrimRight();
	int setj=0;
	int colnum=0;
	cstrLine.TrimLeft();cstrLine.TrimRight();
	int chj=CheckFile(cstrLine);  //检查文件格式
	if(chj==0)  
	{
		AfxMessageBox("文件错误!");
		return;	
	}
	if(chj==2)
	{
		AfxMessageBox("数据不提供该文件格式,文件错误!");
		return;	
	}
	while(n_File.ReadString(cstrLine)!=false)
	{
		cstrLine.TrimLeft(); cstrLine.TrimRight();
		if(cstrLine.IsEmpty())  {  continue; }
		colnum=colnum+1;
		if(colnum>=m_gridold.GetRows())
		{
			m_gridold.SetRows(colnum+100);
			m_gridnew.SetRows(colnum+100);
		}
		setj=cstrLine.Find(' ');
		strgd=cstrLine.Left(setj);
		strgd.TrimLeft();strgd.TrimRight();
		m_gridold.SetRow(colnum);
		m_gridold.SetCol(0);
		m_gridold.SetText(strgd);
		strgd=cstrLine.Right(cstrLine.GetLength()-setj);
		strgd.TrimLeft();strgd.TrimRight();
		cstrLine=strgd;
		setj=cstrLine.Find(' ');
		strgd=cstrLine.Left(setj);
		strgd.TrimLeft();strgd.TrimRight();
		m_gridold.SetCol(1);
		m_gridold.SetText(strgd);
		strgd=cstrLine.Right(cstrLine.GetLength()-setj);
		strgd.TrimLeft();strgd.TrimRight();
		m_gridold.SetCol(2);
		m_gridold.SetText(strgd);
	}
}

void CCoorChanneDlg::OnOK() 
{
	CSurvey survey;
	double meri=0,dh=0;
	CString strport;
	UpdateData(true);
	survey.GetSysDat(m_zbx+1);
	if(m_strip==0)
	{  survey.dudai=3;}
	else
	{  survey.dudai=6;}
	if(bfselcal==1)
	{   //已知坐标为大地坐标
		for(int j=1;j<m_gridold.GetRows();j++)
		{
			m_gridold.SetRow(j);
			m_gridold.SetCol(1);
			strport=m_gridold.GetText();
			strport.TrimLeft();  strport.TrimRight();
			if(strport.IsEmpty())
			{    continue; }
			survey.dsetx=atof(m_gridold.GetText());
			m_gridold.SetCol(2);
			survey.dsety=atof(m_gridold.GetText());
			survey.GetFdh();   //计算中央子午线和代号
			survey.dsety = survey.dsety-survey.fdh*1000000;
			survey.XyToBl();
			m_gridnew.SetRow(j);
			m_gridnew.SetCol(1);
			strport.Format("%.6f",survey.dgetbl_b);
			m_gridnew.SetText(strport);
			//m_gridnew.SetRow(j);
			m_gridnew.SetCol(2);
			strport.Format("%.6f",survey.dgetbl_l);
			m_gridnew.SetText(strport);
			m_gridold.SetCol(0);
			m_gridnew.SetCol(0);
			m_gridnew.SetText(m_gridold.GetText());
			//m_outnorth=survey.dgetbl_b;
		}
	}
	else if(bfselcal==2)
	{   //已知坐标为地理坐标
		for(int j=1;j<m_gridold.GetRows();j++)
		{
			m_gridold.SetRow(j);
			m_gridold.SetCol(1);
			strport=m_gridold.GetText();
			strport.TrimLeft();  strport.TrimRight();
			if(strport.IsEmpty())
			{    continue; }

			survey.dgetbl_b=atof(m_gridold.GetText());
			m_gridold.SetCol(2);
			survey.dgetbl_l=atof(m_gridold.GetText());
			survey.BCalMeri(survey.dgetbl_l,survey.dgetbl_l,survey.dudai,&meri,&dh);
			survey.dmeil_last = (int)meri;
			survey.fdh_last = (int)dh;
			survey.BlToXy();
			m_gridnew.SetRow(j);
			m_gridnew.SetCol(2);
			strport.Format("%.3f",survey.dgety+survey.fdh_last*1000000);
			m_gridnew.SetText(strport);
			m_gridnew.SetCol(1);
			strport.Format("%.3f",survey.dgetx);
			m_gridnew.SetText(strport);
            
			m_gridold.SetCol(0);
			m_gridnew.SetCol(0);
			m_gridnew.SetText(m_gridold.GetText());
			//m_outnorth=survey.dgetx;
		}
	}
	else
	{
		AfxMessageBox("错误!");
	}
	//CDialog::OnOK();	
	
	UpdateData(false);
}

void CCoorChanneDlg::OnSavedata() 
{
	UpdateData(true);
	CString strport;
	CString strgd;
    CString strfilename;
	CStdioFile n_File;
	CFileDialog gldOpenFile(true,"*.*",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|",NULL);
	gldOpenFile.DoModal();
    strfilename=gldOpenFile.GetPathName();
	//-------------------------------------------
	CFileException e;
	if(!n_File.Open(strfilename,CFile::modeCreate | CFile::modeWrite,&e)) 
	{
		return;
	}

	for(long k=1;k<m_gridnew.GetRows();k++)
	{
		m_gridnew.SetRow(k);
		m_gridnew.SetCol(0);
		
		strport.Format("%10s",m_gridnew.GetText());
		if(m_gridnew.GetText().IsEmpty()) {break;}
        strgd=strport;
		for(long j=1;j<m_gridnew.GetCols();j++)
		{
			m_gridnew.SetCol(j);
			strport.Format("%15s",m_gridnew.GetText());
			strgd=strgd+strport;
		}
		strgd+="\n";
		n_File.WriteString(strgd);
		//break;
	}
	n_File.Close();
    ShellExecute(::GetDesktopWindow(), _T("open"), strfilename, NULL, NULL, SW_NORMAL);		
}

void CCoorChanneDlg::OnCleardata() 
{
	m_gridold.Clear();
	m_gridnew.Clear();
    if(bfselcal==1)
	{
		CString StrTxt;
		m_gridold.SetCol(0);
		m_gridold.SetRow(0);
		m_textold.SetWindowText("高 斯 坐 标(X,Y)");
		StrTxt = "< 点号 >|<   北坐标(X)   >|<  东坐标(Y)   >";
		m_gridold.SetFormatString(StrTxt);
		m_gridold.Refresh();	//m_gridold

		m_gridnew.SetCol(0);
		m_gridnew.SetRow(0);
		m_textnew.SetWindowText("大 地 坐 标(B,L)");
		StrTxt = "< 点号 >|<北坐标(纬度)|<东坐标(经度)";
		m_gridnew.SetFormatString(StrTxt);
		m_gridnew.Refresh();	//m_gridold
	}
	else if(bfselcal==2)
	{
		CString StrTxt;
		m_gridold.SetCol(0);
		m_gridold.SetRow(0);
		m_textnew.SetWindowText("大 地 坐 标(B,L)");
		StrTxt = "< 点号 >|<北坐标(纬度)|<东坐标(经度)";
		
		m_gridold.SetFormatString(StrTxt);
		m_gridold.Refresh();	//m_gridold

		m_gridnew.SetCol(0);
		m_gridnew.SetRow(0);
		m_textold.SetWindowText("高 斯 坐 标(X,Y)");
		StrTxt = "< 点号 >|<   北坐标(X)   >|<  东坐标(Y)   >";
		m_gridnew.SetFormatString(StrTxt);
		m_gridnew.Refresh();	//m_gridold
	}
	else
	{
		AfxMessageBox("错误!");
	}
}

⌨️ 快捷键说明

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