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 packagelibrary(HK80)
HK1980GRID_TO_WGS84GEO(N = 820359.389, E = 832591.320)
## latitude longitude
## 1 22.32225 114.1412
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("http://www.geodetic.gov.hk/transform/v2/?inSys=hkgrid&e=832591.320&n=820359.389")
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 packagelibrary(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 packagelibrary(HK80)
WGS84GEO_TO_HK1980GRID(latitude = 22.32224, longitude = 114.14118)
## N E
## 1 820358.7 832591.4
from the Geodetic Survey Section, Lands Department, Hong Kong SAR Gov.
# Copy the following URL to browser
# http://www.geodetic.gov.hk/transform/v2/?inSys=wgsgeog&outSys=hkgrid&lat=22.32224&long=114.14118&h=23.128
# {"hkN": 820358.910,"hkE": 832590.508,"hkpd": 26.009}
library(jsonlite)
data1 <- fromJSON("http://www.geodetic.gov.hk/transform/v2/?inSys=wgsgeog&outSys=hkgrid&lat=22.32224&long=114.14118&h=23.128")
names(data1)
## [1] "hkN" "hkE" "hkpd"
data1$hkN
## [1] 820358.9
data1$hkE
## [1] 832590.5
The sf packagelibrary(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 packagelibrary(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 packagelibrary(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