在bng grid refs(例如nt123456)和osgb36(epsg:27700)坐标之间转换
bng的Python项目详细描述
bng
Convert between BNG grid refs (e.g. NT123456) and OSGB36 (EPSG:27700) coords
Ordnance Survey National Grid或英国国家网格中的坐标通常由引用网格正方形的字母数字网格引用定义。
它们基于osgb36
(epsg:27700)坐标参考系,但大多数gis软件并不理解。
此模块包含python函数,用于将4、6、8或10位数的字母数字网格引用转换为纯osgb36
坐标。
这段代码最初发布在一篇博客文章中:Easily change coordinate projection systems in Python with pyproj。 博客文章包含了使用python在坐标系之间转换的更多信息和说明。
安装
可以使用pip:
为python 2.7或python 3安装bngpip install bng
说明
函数to_osbg36
和from_osbg36
用于在osgb36(x,y)坐标和字母数字网格引用的元组之间进行转换。
至OSBG36
bng网格引用可以转换为osbg36
坐标,如下所示。
单个值:
importbngbng.to_osgb36('NT2755072950')# (327550, 672950)
坐标对应于网格参照所描述的网格正方形的西南角。
对于多个值,请使用python的zip函数和列表理解:
importbnggridrefs=['HU431392','SJ637560','TV374354']x,y=zip(*[bng.to_osgb36(g)forgingridrefs])x# (443100, 363700, 537400)y# (1139200, 356000, 35400)
从U OSBG36
bng网格引用可以从osbg36
坐标创建,如下所示。
单个值:
importbngbng.from_osgb36((327550,672950),figs=6)# 'NT275729'
可以指定网格引用中的图形数。 坐标对应于包含(x,y)坐标的网格正方形的西南角。
对于多个值,请使用python的zip函数和列表理解:
importbngx=[443143,363723,537395]y=[1139158,356004,35394][bng.from_osgb36(coords,figs=4)forcoordsinzip(x,y)]# ['HU4339', 'SJ6356', 'TV3735']
将栅格参考转换为GPS坐标
BNG
可以与pyproj
组合(参见blog post)将网格引用转换为许多不同的坐标系。
BNG网格参考可以转换为GPS系统使用的纬度/经度(EPSG:4326),如下所示:
importbngimportpyproj# Define coordinate systemswgs84=pyproj.Proj("+init=EPSG:4326")# LatLon with WGS84 datum used by GPS units and Google Earthosgb36=pyproj.Proj("+init=EPSG:27700")# UK Ordnance Survey, 1936 datum# Transformx,y=bng.to_osgb36('NT2755072950')pyproj.transform(osgb36,wgs84,x,y)# (-3.1615548588213667, 55.944109545140932)
GPS坐标可以转换为BNG网格参考,如下所示:
importbngimportpyproj# Define coordinate systemswgs84=pyproj.Proj("+init=EPSG:4326")# LatLon with WGS84 datum used by GPS units and Google Earthosgb36=pyproj.Proj("+init=EPSG:27700")# UK Ordnance Survey, 1936 datum# Transformlon=-3.1615548588213667lat=55.944109545140932x,y=pyproj.transform(wgs84,osgb36,lon,lat)bng.from_osgb36((x,y))# 'NT275729'
请注意,对于测量工作(即1米精度),有必要进行大地水准面校正。 projuses以ntv2格式的网格更正文件进行此更正。 军械测量局提供了这些文件(ostn2转换模型)on their website。
对于开发人员
安装开发人员依赖项:
pip install -r requirements.txt
运行测试:
pytest -vs test_bng.py