r - 在 R 中将 UTM 转换为纬度/经度

标签 r latitude-longitude utm rgooglemaps

我有一个包含 9,000 多个 UTM 坐标的 .csv 文件,我想将其转换为十进制度数,但遇到了一些麻烦。我已经搜索了在这里和其他地方发布的几篇文章,但似乎找不到将我的 UTM 集转换为可用且准确的经纬度的解决方案。

我基本上有两个问题:1) 有没有人看到我的代码有任何问题;和 2) 是否有人熟悉放弃将 UTM 转换为纬度/经度而仅在 Rgooglemaps 包中使用 UTM?

以下是我的代码和数据的一些示例:

数据:

>head(utm)
-Northing Easting
1  4236576  615805
2  4236576  615805
3  4236576  615805
4  4236576  615805
5  4236576  615805
6  4236576  615805

到目前为止的代码:
utm <- read.csv(file="utm.csv", header=TRUE, sep=",")
library(rgdal)
utm <- utm[complete.cases(utm),]
utm1 <- data.frame(x=utm$Northing,y=utm$Easting) 
coordinates(utm1) <- ~x+y 
class(utm1)
proj4string(utm1) <- CRS("+proj=utm +zone=10 +datum=WGS84 +units=m +ellps=WGS84") 
utm2 <- spTransform(utm1,CRS("+proj=longlat +datum=WGS84"))

结果
> head(utm2)
SpatialPoints:
             x        y
[1,] -91.08516 4.727323
[2,] -91.08516 4.727323
[3,] -91.08516 4.727323
[4,] -91.08516 4.727323
[5,] -91.08516 4.727323
[6,] -91.08516 4.727323
Coordinate Reference System (CRS) arguments: +proj=longlat +datum=WGS84 +ellps=WGS84
+towgs84=0,0,0 

所以,我得到了一些输出,但我没有得到合理的输出。有什么我在这里想念的吗?此外,对于它的值(value),我计划使用“Rgooglemaps”包来创建一些热图和内核密度图。

最佳答案

我正在使用以下代码从 UTM 转换为纬度/经度。它适用于伦敦地区

wgs84 = "+init=epsg:4326"
bng = '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 
+ellps=airy +datum=OSGB36 +units=m +no_defs'

ConvertCoordinates <- function(easting,northing) {
out = cbind(easting,northing)
mask = !is.na(easting)
sp <-  sp::spTransform(sp::SpatialPoints(list(easting[mask],northing[mask]),proj4string=sp::CRS(bng)),sp::CRS(wgs84))
out[mask,]=sp@coords
out
}

关于r - 在 R 中将 UTM 转换为纬度/经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36520915/

相关文章:

r - R:遍历向量时使用元素的位置信息。

R错误: some group is too small for 'qda'

google-analytics - 如何跟踪所有页面中的 UTM 参数?

javascript - 当值未定义时,如何为 UTM 参数填充默认值?

r - 有没有办法计算数据框每一列中 NA 的百分比,但将 df 分成不同的组?

r - 使用 ggplot 绘制深度剖面

mapping - 在(墨卡托投影)SVG map 上绘制纬度

python - 根据纬度和经度过滤数据 - Numpy

r - 计算不同数据框中点之间的距离

iphone - iOS : How to convert MKMapPoint or CLLocationCoordinate2D to UTM?