Python根据站点列表绘制站坐标全球分布图的示例

 更新时间:2021年12月15日 12:11:08   作者:LZ_CUMT  
这篇文章主要介绍了Python根据站点列表绘制站坐标全球分布图,输入站点列表文件、snx全球站点坐标文件,本文通过示例代码给大家介绍的非常详细,需要的朋友可以参考下

根据站点列表绘制站坐标全球分布图
输入:站点列表文件、SNX全球站点坐标文件
站点列表文件示例(可手动创建):

SNX全球站点坐标文件下载地址:
ftp://igs.gnsswhu.cn/pub/whu/pub/gps/products/YYYY/igsyyPwwww.snx.Z
结果输出:

代码:

# coding=utf-8
# !/usr/bin/env python
'''
 Program:plot_global_sitemap.py 
 Function:根据站点列表绘制站坐标全球分布图
 Author:LZ_CUMT
 Version:1.0
 Date:2021/12/10
 '''
from math import pi, sqrt, atan, atan2, sin, cos
import matplotlib.pyplot as plt
import matplotlib as mpl
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter

# xyz转换为llh(经纬度)
def xyz2llh(ecef, site):
    aell = 6378137.0
    fell = 1.0 / 298.257223563
    deg = pi / 180
    u = ecef[0]
    v = ecef[1]
    w = ecef[2]
    esq = 2*fell-fell*fell
    lat = 0
    N = 0
    if w == 0:
        lat = 0
    else:
        lat0 = atan(w/(1-esq)*sqrt(u*u+v*v))
        j = 0
        delta = 10 ^ 6
        limit = 0.000001/3600*deg
        while delta > limit:
            N = aell / sqrt(1 - esq * sin(lat0)*sin(lat0))
            lat = atan((w / sqrt(u*u + v*v)) * (1 + (esq * N * sin(lat0) / w)))
            delta = abs(lat0 - lat)
            lat0 = lat
            j = j + 1
            if j > 10:
                break
    long = atan2(v, u)
    h = (sqrt(u*u+v*v)/cos(lat))-N
    llh = [site, long * 180 / pi, lat * 180 / pi, h]
    return llh

# 由站点文件获取站点列表存入sitelist
def getSite(listfile):
    sitelist = []
    f = open(listfile)
    ln = f.readline()
    while ln:
        sitelist.append(ln[0:4].upper())
        ln = f.readline()
    return sitelist

# 根据站点名在snx文件中搜索XYZ坐标转化为经纬度并输出
def getBLH_single(site,snxlines):
    xyz = [0, 0, 0]
    for ln in snxlines:
        if site in ln:
            if 'STAX   ' in ln:
                xyz[0] = float(ln[47:68])
            if 'STAY   ' in ln:
                xyz[1] = float(ln[47:68])
            if 'STAZ   ' in ln:
                xyz[2] = float(ln[47:68])
    blh = xyz2llh(xyz, site)
    if len(blh) != 4:
        print('[INFO] Sitecrd for', site, 'is not found in the snxfile')
    return blh

def getBLH(listfile, snxfile):
    siteBLH = []
    sitelist = getSite(listfile)
    f = open(snxfile)
    lns = f.readlines()
    for site in sitelist:
        siteBLH.append(getBLH_single(site, lns))
    return siteBLH

def plotsite(siteBLH):
    # mpl.rcParams['font.sans-serif'] = ['Helvetical']
    mpl.rcParams['axes.unicode_minus'] = False
    mpl.rc('xtick', labelsize=9)
    mpl.rc('ytick', labelsize=9)
    mpl.rcParams['xtick.direction'] = 'in'
    mpl.rcParams['ytick.direction'] = 'in'

    fig = plt.figure(figsize=(14, 7))
    ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=150))
    ax.set_extent([-180, 180, -90, 90], crs=ccrs.PlateCarree())
    ax.set_xticks([0, 60, 120, 180, 240, 300, 360], crs=ccrs.PlateCarree())
    ax.set_yticks([-90, -60, -30, 0, 30, 60, 90], crs=ccrs.PlateCarree())
    ax.add_feature(cfeature.LAND)
    ax.add_feature(cfeature.OCEAN)
    ax.add_feature(cfeature.COASTLINE, linewidth=0.1)

    for site in siteBLH:
        ax.plot(site[1], site[2], 'o', color='r', mec='k', mew=0.5, transform=ccrs.Geodetic(), ms=13.0)
        plt.text(site[1] + 1.5, site[2] + 1.5, site[0], transform=ccrs.Geodetic(),fontsize='x-large')  # 添加站名标注
    plt.xticks(fontsize='x-large')
    plt.yticks(fontsize='x-large')
    lon_formatter = LongitudeFormatter(zero_direction_label=True)
    lat_formatter = LatitudeFormatter()
    ax.xaxis.set_major_formatter(lon_formatter)
    ax.yaxis.set_major_formatter(lat_formatter)

    fig.savefig('global_sitemap.png', bbox_inches='tight', dpi=400)
    plt.show()


if __name__ == '__main__':
    listfile = r'site.info'               # 输入要画的站点列表文件
    snxfile = r'igs21P2177.snx'              # 输入IGS站坐标文件
    siteBLH = getBLH(listfile, snxfile)   # 获取所有站点的经纬度
    plotsite(siteBLH)           # 画图
    print('[INFO] Plot complete!')        # 完成

到此这篇关于Python根据站点列表绘制站坐标全球分布图的文章就介绍到这了,更多相关python绘制站坐标全球分布图内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • 使用Pandas对数据进行筛选和排序的实现

    使用Pandas对数据进行筛选和排序的实现

    这篇文章主要介绍了使用Pandas对数据进行筛选和排序的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-07-07
  • Python爬虫入门案例之爬取去哪儿旅游景点攻略以及可视化分析

    Python爬虫入门案例之爬取去哪儿旅游景点攻略以及可视化分析

    读万卷书不如行万里路,学的扎不扎实要通过实战才能看出来,本篇文章手把手带你爬取去哪儿平台的旅游景点攻略并进行可视化分析,大家可以在过程中查缺补漏,看看自己掌握程度怎么样
    2021-10-10
  • Python实现csv文件(点表和线表)转换为shapefile文件的方法

    Python实现csv文件(点表和线表)转换为shapefile文件的方法

    这篇文章主要介绍了Python实现csv文件(点表和线表)转换为shapefile文件的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-10-10
  • python高手之路python处理excel文件(方法汇总)

    python高手之路python处理excel文件(方法汇总)

    用python来自动生成excel数据文件。python处理excel文件主要是第三方模块库xlrd、xlwt、xluntils和pyExcelerator,除此之外,python处理excel还可以用win32com和openpyxl模块
    2016-01-01
  • python实现指定字符串补全空格的方法

    python实现指定字符串补全空格的方法

    这篇文章主要介绍了python实现指定字符串补全空格的方法,涉及Python中rjust,ljust和center方法的使用技巧,非常具有实用价值,需要的朋友可以参考下
    2015-04-04
  • Python 常用的print输出函数和input输入函数

    Python 常用的print输出函数和input输入函数

    这篇文章主要介绍了Python 常用的print输出函数和input输入函数,今天主要学习一下Python中的输入输出流,会对标准输入输出流、文件输入输出流展开介绍,需要的朋友可以参考一下
    2022-02-02
  • PyCharm利用pydevd-pycharm实现Python远程调试的详细过程

    PyCharm利用pydevd-pycharm实现Python远程调试的详细过程

    这篇文章主要介绍了PyCharm利用pydevd-pycharm实现Python远程调试,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-09-09
  • python之信息加密题目详解

    python之信息加密题目详解

    这篇文章主要介绍了python之信息加密题目详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,,需要的朋友可以参考下
    2019-06-06
  • python训练数据时打乱训练数据与标签的两种方法小结

    python训练数据时打乱训练数据与标签的两种方法小结

    今天小编就为大家分享一篇python训练数据时打乱训练数据与标签的两种方法小结,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-11-11
  • python cookielib 登录人人网的实现代码

    python cookielib 登录人人网的实现代码

    今天晚上不是很忙,所以早早的就在电脑的旁边开始写东西了。我今天给大家分享一个我自己用python写的自动登录 人人网的脚本,没办法就是懒!懒的输入帐号和密码,让python给我们减少工作量
    2012-12-12

最新评论