姚博文 图幅号计算

// 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


 }

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值