// char *MapNo:图幅号
// int lon_deg:经度-度
// lon_min:经度-分
// lon_sec:经度-秒
// lat_deg:纬度-度
// lat_min:纬度-分
// lat_sec:纬度-秒
// long lscale:比例尺
// 传入秒单位的经纬度值
public static String getMeshId(double dLongitude, double dLatitude, long lscale) {
int ScaleID;
char S[] = "ABCDEFGHIJKLMNOPQRSTUV".toCharArray(); // 1:1000000地形图图幅所在纬度带字符码
long Scale[] = { 1000000, 500000, 250000, 100000, 50000, 25000, 10000,5000 }; // 图幅比例尺
double df[] = { 14400, 7200, 3600, 1200, 600, 300, 150, 75 }; // 图幅纬差,单位秒
double dr[] = { 21600, 10800, 5400, 1800, 900, 450, 225, 112.5 }; // 图幅经差单位秒
for (ScaleID = 0; ScaleID < 8; ScaleID++) {
if (Scale[ScaleID] == lscale) {
// System.out.println(ScaleID);
break;
}
}
System.out.println(ScaleID);
if (ScaleID == 8) {
return "";
}
System.out.println(df[ScaleID]/3600);
dLongitude = dLongitude / (double) 3600;
dLatitude = dLatitude / (double) 3600;
int nMapRow = (int) ((dLatitude / 4) + 1); /* 得到地形图图幅行号 */
int nMapLine = (int) (dLongitude / 6) + 31; /* 得到地形图图幅列号 */
char cMapRow = (char) ('A' + nMapRow - 1); /* 得到地形图图幅行号字符码 */
int nRow = (int) (4*3600d / df[ScaleID]) - (int) ((dLatitude % 4*3600) / df[ScaleID]);/* 得到图幅行号 */
int nLine = (int) ((dLongitude % 6 * 3600d) / dr[ScaleID]) + 1;/* 得到图幅列号 */
System.out.println("nRow " + nRow);
System.out.println("nLine " + nLine);
String strRow = getStringFromInt(nRow);
String strLine = getStringFromInt(nLine);
return cMapRow + "" + nMapLine + S[ScaleID] + strRow + strLine;
}
private static String getStringFromInt(int n) {
String strReturn = Integer.toString(n, 10);
// 0 代表前面补充0
// 3 代表长度为4
// d 代表参数为正数型
strReturn = String.format("%03d", Integer.parseInt(strReturn));
return strReturn;
}
public static void main(String[] args) {
// System.out.println(Integer.toString(125, 10));
// char[] nos = new char[10];
// 经度为 114° 33′ 45″,纬度为 39° 22′ 30″
System.out.println(getMeshId(418483.646000d,144723.020000d,25000));
// System.out.println(nos);
// System.out.println((char) ('A' + 6 - 1));
// String str = String.format("%03d", 1);
// System.out.println(str); // 0001
}