地图分幅编号实验
课程: 地图学
班级: ******
学号: ******
姓名: ******
实验目的及要求:
1.利用计算机编程实现地图图幅编号的计算。
2.深化对地图图幅编号计算的原理,地图图幅编号的计算的理解,并掌握其计算步骤。
3.提高自己的计算机语言编程能力。
4.实验完成后提交报告,实验总结,编写代码,要独立编程,程序稳定可行。
工具:
Visual C++ 6.0
实验感悟:
此次实验,首先认真学习了
中对地图分幅编号的计算。 首先在数据输入的编辑框中添加了判断语句,以确保编辑框中输入数据的可用性。在旧的比例尺分幅计算中,有时W计算完成后需要转换成英文大写或小写字母,此处运用了ASCII码进行了转换。最后根据课件
对程序进行了调试、验证。通过这次试验,熟悉了新旧两种地图分幅编号的计算。
1
程序运行结果:
2
3
4
5
程序代码:
//地图分幅的计算
void CMyDlg::OnCal()
{
// TODO: Add your control notification handler code here
UpdateData();
//字符转换
int LDeg = atoi(m_LDeg.Right(m_LDeg.GetLength()-1));
double LMin = strtod(m_LSec,NULL);
int BDeg = atoi(m_BDeg);
double BMin = strtod(m_BSec,NULL);
int index;
index = ((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCurSel()+1;
int i,j,c,d,W,V,n;//W所求比例尺图幅代号 n代表划分为该比例尺后的列数 c列号 d行号
CString C,D;
double l,b;//l,b分别表示经差和纬差
i = (int)(BDeg/4.0)+1;
CString s = m_LDeg.Left(1);
CString s1;
//判断东经西经
if(s == "E" || s == "e")
{
j = (int) (floor(LDeg/6.0))+31;
}
else if(s == "W" || s == "w")
{
j = 31-(int)(floor(LDeg/6.0));
}
else
{
MessageBox("输入经度错误", "Error", MB_ICONERROR );
}
//1:100万基本比例尺图幅计算
s = "";
s.Format(_T("-%d"),j);
Old = (int)(i+64);
Old+=s;
New = (int)(i+64);
s.Format(_T(" %d"),j);
New+=s;
6
//1:10万基本比例尺计算
V=133;
l=30.0*60;
b=20.0*60;
n=12;
W = V-(int)((((int)(BDeg*3600+BMin*60))%(4*3600))/((int)b))*n
+(int)((((int)(LDeg*3600+LMin*60))%(6*3600))/((int)l));
s1.Format(_T("-%d"),W);
Old1=Old+s1;
switch(index)
{
case 1://1:100万
m_Old=Old;
m_New=New;
break;
case 2://1:50万
V=3;
l=3*3600.0;
b=2*3600.0;
n=2;
//旧的分幅编号
W = V-(int)((((int)(BDeg*3600+BMin*60))%(4*3600))/((int)b))*n
+(int)((((int)(LDeg*3600+LMin*60))%(6*3600))/((int)l));
s = (int)(W+64);
Old += "-";
m_Old=Old+s;
//新的分幅编号
c=(int)(4*3600/b)-(int)(((int)(BDeg*3600+BMin*60)%(4*3600))/b);
d=(int)(((int)(LDeg*3600+LMin*60)/(6*3600))/l)+1;
C.Format(_T("%.3d"),c);
D.Format(_T("%.3d"),d);
m_New = New + " B"+C+D;
break;
case 3://1:25万
V=13;
l=1.5*3600;
b=1.0*3600;
n=4;
//旧的分幅编号
W = V-(int)((((int)(BDeg*3600+BMin*60))%(4*3600))/((int)b))*n
+(int)((((int)(LDeg*3600+LMin*60))%(6*3600))/((int)l));
7
s.Format(_T("-[%d]"),W);
m_Old=Old+s;
//新的分幅编号
c=(int)(4*3600/b)-(int)(((int)(BDeg*3600+BMin*60)%(4*3600))/b);
d=(int)(((int)(LDeg*3600+LMin*60)%(6*3600))/l)+1;
C.Format(_T("%.3d"),c);
D.Format(_T("%.3d"),d);
m_New=New+" C"+C+D;
break;
case 4://1:10万
m_Old=Old1;
//新的分幅编号
c=(int)(4*3600/b)-(int)(((int)(BDeg*3600+BMin*60)%(4*3600))/b);
d=(int)(((int)(LDeg*3600+LMin*60)%(6*3600))/l)+1;
C.Format(_T("%.3d"),c);
D.Format(_T("%.3d"),d);
m_New=New+" C"+C+D;
break;
case 5://1:5万
V=3;
l=15.0*60;
b=10.0*60;
n=2;
//旧的分幅编号
W = V-(int)((((int)(BDeg*3600+BMin*60))%(20*60))/((int)b))*n
+(int)((((int)(LDeg*3600+LMin*60))%(30*60))/((int)l));
s=(int)(W+64);
m_Old=Old1+"-"+s;
//新的分幅编号
c=(int)(4*3600/b)-(int)(((int)(BDeg*3600+BMin*60)%(4*3600))/b);
d=(int)(((int)(LDeg*3600+LMin*60)%(6*3600))/l)+1;
C.Format(_T("%.3d"),c);
D.Format(_T("%.3d"),d);
m_New=New+" D"+C+D;
break;
case 6://1:2.5万
//1:5万编号计算
8
V=3;
l=15.0*60;
b=10.0*60;
n=2;
W = V-(int)((((int)(BDeg*3600+BMin*60))%(20*60))/((int)b))*n
+(int)((((int)(LDeg*3600+LMin*60))%(30*60))/((int)l));
s=(int)(W+64);
m_Old=Old1+"-"+s;
V=3;
l=7.5*60;
b=5*60;
n=2;
//旧的分幅编号
W = V-(int)((((int)(BDeg*3600+BMin*60))%(10*60))/((int)b))*n
+(int)((((int)(LDeg*3600+LMin*60))%(15*60))/((int)l));
s.Format(_T("-%d"),W);
m_Old+=s;
//新的分幅编号
c=(int)(4*3600/b)-(int)(((int)(BDeg*3600+BMin*60)%(4*3600))/b);
d=(int)(((int)(LDeg*3600+LMin*60)%(6*3600))/l)+1;
C.Format(_T("%.3d"),c);
D.Format(_T("%.3d"),d);
m_New=New+" F"+C+D;
break;
case 7://1:1万
V=57;
l=3.75*60;
b=2.5*60;
n=8;
//旧的分幅编号
W = V-(int)((((int)(BDeg*3600+BMin*60))%(20*60))/((int)b))*n
+(int)((((int)(LDeg*3600+LMin*60))%(30*60))/((int)l));
s.Format(_T("-(%d)"),W);
m_Old = Old1+s;
//新的分幅编号
c=(int)(4*3600/b)-(int)(((int)(BDeg*3600+BMin*60)%(4*3600))/b);
d=(int)(((int)(LDeg*3600+LMin*60)%(6*3600))/l)+1;
C.Format(_T("%.3d"),c);
D.Format(_T("%.3d"),d);
m_New=New+" G"+C+D;
9
break;
case 8://1:5000
//1:1万基本比例尺计算
V=57;
l=3.75*60;
b=2.5*60;
n=8;
W = V-(int)((((int)(BDeg*3600+BMin*60))%(20*60))/((int)b))*n
+(int)((((int)(LDeg*3600+LMin*60))%(30*60))/((int)l));
s.Format(_T("-(%d)"),W);
m_Old = Old1+s;
V=3;
l=1.875*60;
b=1.25*60;
n=2;
//旧的分幅编号
W = V-(int)((((int)(BDeg*3600+BMin*60))%150)/((int)b))*n
+(int)((((int)(LDeg*3600*60+LMin*60*60))%(225*60))/((int)(l*60)));
s=(int)(W+96);
m_Old+="-"+s;
//新的分幅编号
c=(int)(4*3600/b)-(int)(((int)(BDeg*3600+BMin*60)%(4*3600))/b);
d=(int)(((int)(LDeg*3600+LMin*60)%(6*3600))/l)+1;
C.Format(_T("%.3d"),c);
D.Format(_T("%.3d"),d);
m_New=New+" H"+C+D;
break;
}
if(m_BDeg == "" || m_BSec == "" || m_LSec == "" || m_LDeg == "")
{
if (m_BDeg == "" && m_BSec == "" && m_LSec == "" &&
(m_LDeg == "E" || m_LDeg == "W"))
{
MessageBox("请输入经度、纬度","错误",MB_ICONERROR);
m_Old = "";
m_New = "";
}
else
10
{
MessageBox("系统将空白处自动赋值为0","提示
",MB_ICONEXCLAMATION);
}
}
UpdateData(false);
}
//对话框的初始设置
BOOL CMyDlg::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
GetDlgItem(IDC_EDIT5)->EnableWindow(false);
GetDlgItem(IDC_EDIT6)->EnableWindow(false);
//设置图标
11
m_hIcons[0] =
LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON1));
m_hIcons[1] =
LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON2));
m_hIcons[2] =
LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON3));
m_hIcons[3] =
LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON4));
m_hIcons[4] =
LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON5));
m_hIcons[5] =
LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON6));
m_hIcons[6] =
LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON7));
SetClassLong(m_hWnd,GCL_HICON,(long)m_hIcons[0]);
SetTimer(1,1000,NULL);
//列表框
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1:100万");
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1:50万");
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1:25万");
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1:10万");
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1:5万");
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1:2.5万");
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1:1万");
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1:5000");
((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);
//设置字体
CFont * f;
f = new CFont;
f->CreateFont(18, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_BOLD, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
12
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("宋体")); // lpszFac
GetDlgItem(IDC_STATIC1)->SetFont(f);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::OnQuit()
{
// TODO: Add your control notification handler code here
this->DestroyWindow();
}
void CMyDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
static int index=1;
SetClassLong(m_hWnd,GCL_HICON,(long)m_hIcons[index]);
index = ++index%7;
CDialog::OnTimer(nIDEvent);
}
void CMyDlg::OnHelp()
{
// TODO: Add your control notification handler code here
CAboutDlg dlgAbout;
dlgAbout.DoModal();
// GotoDlgCtrl((CEdit*)GetDlgItem(IDC_LDeg)); }
void CMyDlg::OnClear()
{
// TODO: Add your control notification handler code here
m_BDeg = "";
m_BSec = "";
m_LSec = "";
m_LDeg = "E";
m_Old = "";
m_New = "";
((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);
13
GotoDlgCtrl((CEdit*)GetDlgItem(IDC_LDeg));
}
void CMyDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
static int index=1;
SetClassLong(m_hWnd,GCL_HICON,(long)m_hIcons[index]);
index = ++index%7;
CDialog::OnTimer(nIDEvent);
}
void CMyDlg::OnHelp()
{
// TODO: Add your control notification handler code here
CAboutDlg dlgAbout;
dlgAbout.DoModal();
// GotoDlgCtrl((CEdit*)GetDlgItem(IDC_LDeg)); }
void CMyDlg::OnClear()
{
// TODO: Add your control notification handler code here
m_BDeg = "";
m_BSec = "";
m_LSec = "";
m_LDeg = "E";
m_Old = "";
m_New = "";
((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);
GotoDlgCtrl((CEdit*)GetDlgItem(IDC_LDeg));
}
14