钱磊
地理坐标转网格定位码python脚本
2021-7-29 21:48
阅读:1761

import ephem
import numpy as np
import sys

convert_radian2degree=180.0/np.pi

if (len(sys.argv)<3):
    print 'too few input parameters, format:'
    print 'python terr_radec2grid_location.py terr_ra    terra_dec'
    print '                     (degree) (degrees)'
    sys.exit()
else:
    rad=sys.argv[1]
    decd=sys.argv[2]
    rad0=float(ephem.degrees(rad))*convert_radian2degree
    decd0=float(ephem.degrees(decd))*convert_radian2degree

if(rad0<-180 or rad0>180 or decd0<-90 or decd0>90):
    print('Wrong longitude or latitude!')
    sys.exit()

rd = int(abs(rad0))
rm = int((abs(rad0)-rd)*60)
rs = (abs(rad0)-rd-rm/60.0)*3600

dd = int(abs(decd0))
dm = int((abs(decd0)-dd)*60)
ds = (abs(decd0)-dd-dm/60.0)*3600

indexf1=int(rad0+180)/20
indexf2=int(decd0+90)/10

indexs1=int(rad0-(indexf1*20-180))
indexs2=int(decd0-(indexf2*10-90))

indexss1=int((rad0-int(rad0))*60/5)
indexss2=int((decd0-int(decd0))*60/2.5)



string1='ABCDEFGHIJKLMNOPQR'
string2='ABCDEFGHIJKLMNOPQRSTUVWX'


print('The grid location ('+rad+','+decd+') is:')
print(string1[indexf1]+string1[indexf2]+str(indexs1)+str(indexs2)+string2[indexss1]+string2[indexss2])





转载本文请联系原作者获取授权,同时请注明本文来自钱磊科学网博客。

链接地址:https://wap.sciencenet.cn/blog-117333-1297563.html?mobile=1

收藏

分享到:

当前推荐数:0
推荐到博客首页
网友评论0 条评论
确定删除指定的回复吗?
确定删除本博文吗?