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

📄 projection_gaussdlg.cpp

📁 用C++中的MFC编程实现高斯投影正算和反算 即已知经纬度求X,Y 已知X,Y求经纬度
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Projection_GaussDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Projection_Gauss.h"
#include "Projection_GaussDlg.h"
#include <math.h>
#include <string>
#include  <iostream>
#include  <vector>
#include  <list>
#include <iomanip>
#include <stdlib.h>
using namespace std;


double a,a0,a2,a4,a6,a8;
double q0,q2,q4,q6,q8;
double p,square_e1,square_e,c;
#define pi 3.14159265358979323846
#define p0 57.2957795130823208767981
int tag=0;
int flag=1;
int daicha;

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
	// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA
	
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL
	
	// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProjection_GaussDlg dialog

CProjection_GaussDlg::CProjection_GaussDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProjection_GaussDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CProjection_GaussDlg)
	m_Ellipse = _T("");
	m_B_degree = 0.0;
	m_B_minute = 0.0;
	m_B_second = 0.0;
	m_L_degree = 115.0;
	m_L_minute = 0.0;
	m_L_second = 0.0;
	m_L0_degree = 114.0;
	m_L0_minute = 0.0;
	m_L0_second = 0.0;
	m_radio = 0;
	m_x = 0.0;
	m_y = 0.0;
	m_touyingdai = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CProjection_GaussDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProjection_GaussDlg)
	DDX_Control(pDX, IDC_EDIT_y, m_fansuanControl2);
	DDX_Control(pDX, IDC_BUTTON_fansuan, m_fansuanControl3);
	DDX_Control(pDX, IDC_BUTTON_zhengsuan, m_zhengsuanControl7);
	DDX_Control(pDX, IDC_EDIT_x, m_fansuanControl1);
	DDX_Control(pDX, IDC_EDIT_L_minute, m_zhengsuanControl5);
	DDX_Control(pDX, IDC_EDIT_L_second, m_zhengsuanControl6);
	DDX_Control(pDX, IDC_EDIT_L_degree, m_zhengsuanControl4);
	DDX_Control(pDX, IDC_EDIT_B_second, m_zhengsuanControl3);
	DDX_Control(pDX, IDC_EDIT_B_minute, m_zhengsuanControl2);
	DDX_Control(pDX, IDC_EDIT_B_degree, m_zhengsuanControl1);
	DDX_Control(pDX, IDC_LIST, m_List);
	DDX_CBString(pDX, IDC_COMBO_Ellipse, m_Ellipse);
	DDX_Text(pDX, IDC_EDIT_B_degree, m_B_degree);
	DDX_Text(pDX, IDC_EDIT_B_minute, m_B_minute);
	DDX_Text(pDX, IDC_EDIT_B_second, m_B_second);
	DDX_Text(pDX, IDC_EDIT_L_degree, m_L_degree);
	DDX_Text(pDX, IDC_EDIT_L_minute, m_L_minute);
	DDX_Text(pDX, IDC_EDIT_L_second, m_L_second);
	DDX_Text(pDX, IDC_EDIT_L0_degree, m_L0_degree);
	DDX_Text(pDX, IDC_EDIT_L0_minute, m_L0_minute);
	DDX_Text(pDX, IDC_EDIT_L0_second, m_L0_second);
	DDX_Radio(pDX, IDC_RADIO1, m_radio);
	DDX_Text(pDX, IDC_EDIT_x, m_x);
	DDX_Text(pDX, IDC_EDIT_y, m_y);
	DDX_CBString(pDX, IDC_COMBO_touyingdai, m_touyingdai);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CProjection_GaussDlg, CDialog)
//{{AFX_MSG_MAP(CProjection_GaussDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_Help, OnBUTTONHelp)
ON_BN_CLICKED(IDC_BUTTON_zhengsuan, OnBUTTONzhengsuan)
ON_BN_CLICKED(IDC_BUTTON_fansuan, OnBUTTONfansuan)
ON_BN_CLICKED(IDC_RADIO1, OnRadio_zhengsuan)
ON_BN_CLICKED(IDC_RADIO2, OnRadio_fansuan)
	ON_BN_CLICKED(IDC_BUTTON_Save, OnBUTTONSave)
	ON_BN_CLICKED(IDC_BUTTON_Open, OnBUTTONOpen)
	ON_BN_CLICKED(IDC_BUTTON_Clear, OnBUTTONClear)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProjection_GaussDlg message handlers

BOOL CProjection_GaussDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	// Add "About..." menu item to system menu.
	
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	//初始化输出表单LIST
	char* color[] = {"编号No","纬度B/角度","经度L/角度","横坐标x/cm","纵坐标y/cm"};
	CRect cd;
	m_List.GetClientRect(cd);
	this->m_List.GetDlgItem(IDC_LIST);
	DWORD dwStyle;
	dwStyle = m_List.GetStyle();
	dwStyle = LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS ;
	m_List.SetExtendedStyle(dwStyle);
	m_List.SetBkColor(RGB(0xec,0xf1,0xfd));
	m_List.SetTextBkColor(RGB(0xfe,0xFF,0xc6));
	for(int i = 0;i<5;i++){
		this->m_List.InsertColumn(i,color[i],LVCFMT_CENTER,cd.Width()/5);
	}
	
	//默认情况下用正算计算
	m_zhengsuanControl1.EnableWindow(true);
	m_zhengsuanControl2.EnableWindow(true);
	m_zhengsuanControl3.EnableWindow(true);
	m_zhengsuanControl4.EnableWindow(true);
	m_zhengsuanControl5.EnableWindow(true);
	m_zhengsuanControl6.EnableWindow(true);
	m_zhengsuanControl7.EnableWindow(true);
	m_fansuanControl1.EnableWindow(false);
	m_fansuanControl2.EnableWindow(false);
	m_fansuanControl3.EnableWindow(false);
	
	((CComboBox*)GetDlgItem(IDC_COMBO_Ellipse))->AddString("克氏椭球(北京54坐标系)");
	((CComboBox*)GetDlgItem(IDC_COMBO_Ellipse))->AddString("1975年椭球(西安80坐标系)");
	((CComboBox*)GetDlgItem(IDC_COMBO_Ellipse))->AddString("WGS-84椭球(WGS84坐标系)");
	((CComboBox*)GetDlgItem(IDC_COMBO_Ellipse))->SetCurSel(0);
	((CComboBox*)GetDlgItem(IDC_COMBO_touyingdai))->AddString("3°带");
	((CComboBox*)GetDlgItem(IDC_COMBO_touyingdai))->AddString("6°带");
	((CComboBox*)GetDlgItem(IDC_COMBO_touyingdai))->SetCurSel(0);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CProjection_GaussDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CProjection_GaussDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting
		
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
		
		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		
		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CProjection_GaussDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CProjection_GaussDlg::OnBUTTONHelp() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();
	
}

void CProjection_GaussDlg::OnBUTTONzhengsuan() 
{
	if(flag==0)
		this->m_List.DeleteAllItems();
	this->ChooseEllipse();
	double angle_to_radian=pi/180;
	double t,k,V,N,p,dL,B,L,L0,X;
	B=m_B_degree+m_B_minute/60+m_B_second/3600;
	L=m_L_degree+m_L_minute/60+m_L_second/3600;
	L0=m_L0_degree+m_L0_minute/60+m_L0_second/3600;
	
	if(L0>=0 && L0<=180 && B>=0 && B<=90 && L>=L0-(double)daicha/2 && L<=L0+(double)daicha/2)
	{
		t=tan( B*angle_to_radian);
		k=square_e1*cos( B*angle_to_radian)*cos( B*angle_to_radian);
		V= sqrt(1+k);
		N=c/V;
		dL=L-L0;
		p=cos( B*angle_to_radian)*dL/p0;
		X=a0*B+a2*sin(2* B*angle_to_radian)+a4*sin(4*B*angle_to_radian)+a6*sin(6*B*angle_to_radian)+a8*sin(8*B*angle_to_radian);
		m_x=X+N*t*(1+((5-t*t+(9+4*k)*k)+((61+(t*t-58)*t*t+(9-11*t*t)*30*k)+(1385+(-3111+(543-t*t)*t*t)*t*t)*p*p/56)*p*p/30)*p*p/12)*p*p/2;
		m_y=500000+N*(1+((1-t*t+k)+((5+t*t*(t*t-18-58*k)+14*k)+(61+(-479+(179-t*t)*t*t)*t*t)*p*p/42)*p*p/20)*p*p/6)*p;
		
		CString buf[5];
		buf[0].Format("%d",++tag);
		buf[1].Format("%lf",B);
		buf[2].Format("%lf",L);
		buf[3].Format("%lf",m_x);
		buf[4].Format("%lf",m_y);
		mylist.push_back(B);
		mylist.push_back(L);
		mylist.push_back(m_x);

⌨️ 快捷键说明

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