简体   繁体   English

将 NZMG 坐标转换为纬度/经度

[英]Convert NZMG coordinates to lat/long

I have a bunch of NZ Map Grid coordinates, which I want convert to lat/long.我有一堆 NZ Map 网格坐标,我想将其转换为纬度/经度。 Based on this question , here is what I tried. 基于这个问题,这是我尝试过的。

library(sp)
options(digits = 11) # to display to greater d.p.

Attempt 1:尝试1:

proj4string <- "+proj=nzmg +lat_0=-41.0 +lon_0=173.0 +x_0=2510000.0 
+y_0=6023150.0 +ellps=intl +units=m"
p <- proj4::project(c(2373200, 5718800), proj = proj4string, inverse=T)

Attempt 2尝试 2

dat <- data.frame(id = c(1), x = c(2373200) , y = c(5718800))
sp::coordinates(dat) = ~x+y

sp::proj4string(dat) = CRS('+init=epsg:27200') 
data_wgs84 <- spTransform(dat, CRS('+init=epsg:4326'))
print(data_wgs84)

If I run my coordinates through the linz coordinate conversion tool I get a slightly different result, which is the "true" result.如果我通过linz 坐标转换工具运行我的坐标,我会得到一个稍微不同的结果,这是“真实”的结果。

Results:
171.30179199  -43.72743909  # attempt 1 - ~200m off linz 
171.30190004, -43.72577765  # attempt 2 - a few meters off linz
171.30189464, -43.72576664  # linz

Based on Mike T's answer I should be using a "distortion grid transformation method" and he links to a "nzgd2kgrid0005.gsb grid shift file".根据Mike T 的回答,我应该使用“失真网格变换方法”,他链接到“nzgd2kgrid0005.gsb 网格移位文件”。

My Question: Is it possible to do this conversion using R without downloading additional files (nzgd2kgrid0005.gsb)?我的问题:是否可以在不下载其他文件 (nzgd2kgrid0005.gsb) 的情况下使用 R 进行此转换? I want to share my code with others without them having to download any additional files.我想与其他人共享我的代码,而无需他们下载任何其他文件。

Any advice much appreciated.非常感谢任何建议。

Turns out it is pretty simple, if you have the rgdal package installed, the required nzgd2kgrid0005.gsb file is included and you don't need to download anything extra.事实证明这很简单,如果您安装了rgdal package,则包含所需的nzgd2kgrid0005.gsb文件,您无需下载任何额外内容。

You just need to use the full PROJ.4 string as outlined in Mike T 's answer.您只需要使用Mike T的回答中概述的完整 PROJ.4 字符串。

dat <- data.frame(id = c(1), x = c(2373200) , y = c(5718800))
sp::coordinates(dat) = ~x+y

proj4string <- "+proj=nzmg +lat_0=-41 +lon_0=173 +x_0=2510000 +y_0=6023150 
+ellps=intl +datum=nzgd49 +units=m +towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993 
+nadgrids=nzgd2kgrid0005.gsb +no_defs"

sp::proj4string(dat) = sp::CRS(proj4string) 
data_wgs84 <- sp::spTransform(dat, sp::CRS('+init=epsg:4326'))
as.data.frame(data_wgs84)

id          x            y
1 171.3018946 -43.72576664

Which is the same as the output from the LINZ coordinate conversion tool.与LINZ坐标转换工具中的output相同。 Hopefully this saves someone else a bit of time.希望这可以节省其他人一些时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM