张金龙的博客分享 http://blog.sciencenet.cn/u/zjlcas 物种适应性、分布与进化

博文

WGS84坐标和HK80坐标之间的相互转换

已有 7277 次阅读 2020-12-14 09:39 |个人分类:天文地理|系统分类:科研笔记

HK80(Hong Kong 1980 Grid System)是香港的一种坐标系(EPSG:2326),一般用于地图绘制、工程勘测、树木调查等。不过,生态学研究中最常用的坐标系为WGS84(EPSG:4326),例如GPS一般就是直接给出WGS84的经纬度,Google Earth等也用WGS84坐标系。那么HK80坐标如何转换为WGS84坐标呢?

香港地政署测绘处给出了测量基准说明(https://www.geodetic.gov.hk/common/data/pdf/explanatorynotes_c.pdf), 其中有非常详细的转换公式。根据这些公式,本人曾于2014年编写了HK80 R程序包(https://cran.r-project.org/web/packages/HK80/index.html)。

近几年来,也有不少新工具诞生:例如,香港地政署测绘处的HK80坐标在线转换工具(https://www.geodetic.gov.hk/en/services/tform/tform.aspx )公开了API,该API可以根据用户在网址中传入的参数返回json数据。sf程序包也在proj程序包的基础上开发了st_transform函数,让不同坐标系之间的转换变得非常方便。也有人基于pyproj(https://pyproj4.github.io/pyproj/stable/#,https://proj.org/)开发了hk80 python程序包(https://pypi.org/project/hk80/)等。

本文给出在R中进行WGS84和HK80坐标相互转换的三种方法,其中首选为香港地政署的在线转换工具,但是由于服务器可能会有一定的限制,如果有大量数据需要准换,访问会较为频繁,用户IP可能受限。下载到本地的sf和HK80程序包就没有这些限制。sf和HK80的程序包的结果都是可靠的。相比之下,在sf中建立坐标点并进行转换批量转换更为方便。HK80程序包的结果可以作为参考。

地理坐标转换常涉及度、分、秒和十进制的转换,本文也给出两种方法,作为附录,以方便读者。

HK80GRID坐标转换为WGS84坐标

The HK80 R package

library(HK80)
HK1980GRID_TO_WGS84GEO(N = 820359.389, E = 832591.320)
##   latitude longitude
## 1 22.32225  114.1412

The official online conversion tool

the Geodetic Survey Section, Lands Department, Hong Kong SAR Gov.

API example: http://www.geodetic.gov.hk/transform/v2/?inSys=hkgrid&e=832591.320&n=820359.389

library(jsonlite)data1 <- fromJSON(" 
names(data1)
##  [1] "wgsLat"      "wgsLong"     "hkLat"       "hkLong"      "utmGridZone"
##  [6] "utmGridE"    "utmGridN"    "utmRefZone"  "utmRefE"     "utmRefN"
data1$wgsLat
## [1] 22.32224
data1$wgsLong
## [1] 114.1412

The sf package

library(sf)
## Linking to GEOS 3.8.1, GDAL 3.1.1, PROJ 6.3.1
p1 = st_point(c(832591.320, 820359.389))
sfc = st_sfc(p1, crs = 2326)
(st_transform(sfc, 4326))
## Geometry set for 1 feature 
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: 114.1412 ymin: 22.32224 xmax: 114.1412 ymax: 22.32224
## geographic CRS: WGS 84
## POINT (114.1412 22.32224)

WGS84 坐标转换为HK80GRID坐标

The HK80 R package

library(HK80)
WGS84GEO_TO_HK1980GRID(latitude = 22.32224, longitude = 114.14118)
##          N        E
## 1 820358.7 832591.4

The official online conversion tool

from the Geodetic Survey Section, Lands Department, Hong Kong SAR Gov.

# Copy the following URL to browser
#  
# {"hkN": 820358.910,"hkE": 832590.508,"hkpd": 26.009}
library(jsonlite)
data1 <- fromJSON(" 
names(data1)
## [1] "hkN"  "hkE"  "hkpd"
data1$hkN
## [1] 820358.9
data1$hkE
## [1] 832590.5

The sf package

library(sf)
p1 = st_point(c(114.14118, 22.32224))
sfc = st_sfc(p1, crs = 4326)
(ccc <- st_transform(sfc, 2326))
## Geometry set for 1 feature 
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: 832590.5 ymin: 820358.9 xmax: 832590.5 ymax: 820358.9
## projected CRS:  Hong Kong 1980 Grid System
## POINT (832590.5 820358.9)

附录: 度、分、秒和十进制格式的相互转换

Using the sp package

library(sp)
dd2dms(114.14118) 
# decimal to Degree, Minute, Second format
## [1] 114d8'28.248"E
as.numeric(dd2dms(114.14118)) 
#
## [1] 114.1412
char2dms("47d15'6.12\"E")
## [1] 47d15'6.12"E
as.numeric(char2dms("47d15'6.12\"E"))
## [1] 47.2517

Using the biogeo package

library(biogeo)
res <- dms2dd(47,15,6.12,"E") # ns letters (N,S,E,W)
print(res)
## [1] 47.2517
dd2dmslong(114.14118)
##   xdeg xmin xsec EW
## 1  114    8 28.2  E
dd2dmslat(22.32224)
##   ydeg ymin ysec NS
## 1   22   19 20.1  N

进一步阅读

  • Ooms J.  (2014). The jsonlite Package: A Practical and Consistent Mapping Between JSON Data and R Objects. arXiv:1403.2805 [stat.CO] URL https://arxiv.org/abs/1403.2805.

  • Zhang J.  (2016). HK80: Conversion Tools for HK80 Geographical Coordinate System. R package version 0.0.2. https://CRAN.R-project.org/package=HK80

  • Robertson M. (2016). biogeo: Point Data Quality Assessment and Coordinate Conversion. R package version 1.0. https://CRAN.R-project.org/package=biogeo

  • Pebesma, E., (2018). Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal 10 (1), 439-446, https://doi.org/10.32614/RJ-2018-009

  • Roger S. Bivand, Edzer Pebesma, Virgilio Gomez-Rubio,(

  • 2013) Applied spatial data analysis with R, Second edition. Springer, NY. https://asdar-book.org/

  • https://pypi.org/project/hk80/

  • https://spatialreference.org/ref/?search=Hong+Kong

  • https://www.geodetic.gov.hk/en/download.htm




https://wap.sciencenet.cn/blog-255662-1262375.html

上一篇:用plantlist程序包查询和处理植物学名 (plantlist 0.6.5)
下一篇:群落系统发育研究不能脱离理论框架
收藏 IP: 113.28.150.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-3-28 17:15

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部