在了解了新旧图幅号的基础之后,就可以开始图幅号的计算了,本文是用C++编写。
在知道比例尺后,经度和维度的差值是确定的,如下表所示:
比例尺 | 1:100万 | 1:5万 | 1:25万 | 1:10万 | 1:5万 | 1:2.5万 | 1:1万 | 1:5千 |
经差 | 6.0 | 3.0 | 1.5 | 0.5 | 0.25 | 0.125 | 0.0625 | 0.03125 |
纬差 | 4.0 | 2.0 | 1.0 | 1.0/3.0 | 1.0/6.0 | 1.0/12.0 | 1.0/24.0 | 1.0/48.0 |
经纬差及对应的比例尺关系:
detlon[0]=6.0;
detlon[1]=3.0;
detlon[2]=1.5;
detlon[3]=0.5;
detlon[4]=0.25;
detlon[5]=0.125;
detlon[6]=0.0625;
detlon[7]=0.03125;
detlat[0]=4.0;
detlat[1]=2.0;
detlat[2]=1.0;
detlat[3]=1.0/3.0;
detlat[4]=1.0/6.0;
detlat[5]=1.0/12.0;
detlat[6]=1.0/24.0;
detlat[7]=1.0/48.0;
nsubblock[0]=1;
nsubblock[1]=2;
nsubblock[2]=4;
nsubblock[3]=12;
nsubblock[4]=24;
nsubblock[5]=48;
nsubblock[6]=96;
nsubblock[7]=192;
1.由经纬度、比例尺计算图幅号
stMapNumber CMapSubdivision::MapNumbering(double lon, double lat, int scale)
{
int a,b,c,d;
double dlat,dlon;
stMapNumber mapnumber;
dlat=detlat[scale];
dlon=detlon[scale];
a=INT(lat/4.0)+1;
b=INT(lon/6.0)+31;
c=4.0/dlat-INT(RES(lat,4.0)/dlat);
d=INT(RES(lon,6.0)/dlon)+1;
mapnumber.nlat=a;
mapnumber.nlon=b;
mapnumber.scale=scale;
mapnumber.nsublat=c;
mapnumber.nsublon=d;
return mapnumber;
}
CString CMapSubdivision::MapNumber2String(stMapNumber mapnumber)
{
CString sa,sc,sb,sd,sscale,sresult;
int a,b,c,d,scale;
char ctemp;
a=mapnumber.nlat;
b=mapnumber.nlon;
c=mapnumber.nsublat;
d=mapnumber.nsublon;
scale=mapnumber.scale;
ctemp='A'+a-1;
sa=ctemp;
if(b<10)
sb.Format(_T("0%d"),b);
else
sb.Format(_T("%d"),b);
ctemp='A'+scale;
sscale=ctemp;
if(c<10)
sc.Format(_T("00%d"),c);
else if(c<100)
sc.Format(_T("0%d"),c);
else
sc.Format(_T("%d"),c);
if(d<10)
sd.Format(_T("00%d"),d);
else if(d<100)
sd.Format(_T("0%d"),d);
else
sd.Format(_T("%d"),d);
if(scale>0)
sresult=sa+sb+sscale+sc+sd;
else
sresult=sa+sb;
return sresult;
}
2.计算四角点坐标
bool CMapSubdivision::MapNumber2Val(stMapNumber mapnumber, double lon[2], double lat[2])
{
int a,b,c,d,scale;
double dlon,dlat;
if(mapnumber.scale==0)
{
a=mapnumber.nlat;
b=mapnumber.nlon;
lat[0]=(a-1)*4.0;
lon[0]=(b-31)*6.0;
lat[1]=lat[0]+4.0;
lon[1]=lon[0]+6.0;
}
else if(mapnumber.scale>0&&mapnumber.scale<8)
{
a=mapnumber.nlat;
b=mapnumber.nlon;
scale=mapnumber.scale;
c=mapnumber.nsublat;
d=mapnumber.nsublon;
dlat=detlat[scale];
dlon=detlon[scale];
lat[0]=(a-1)*4.0+(4.0/dlat-c)*dlat;
lon[0]=(b-31)*6.0+(d-1)*dlon;
lat[1]=lat[0]+dlat;
lon[1]=lon[0]+dlon;
}
else
{
smartlog<<"mapnumber.scale取值有误!";
return false;
}
return true;
}
bool CMapSubdivision::MapString2Val(CString mapstring, double lon[2], double lat[2])//将地图分幅号转化为地图四个角点的坐标
{
stMapNumber mapnumber;
mapnumber=String2MapNumber(mapstring);//将图幅号字符串转化为自定义的地图结构体
return MapNumber2Val(mapnumber, lon, lat);//将地图结构体转化为四个角点坐标
}