2016-04-09 76 views
2

我有一個.csv文件,其中包含9,000多個UTM座標,我想將其轉換爲十進制度並且我遇到了一些麻煩。我已經搜索了幾篇帖子,這些帖子已經發布在這裏和其他地方,我似乎無法找到一個解決方案,將我的一套UTM轉換爲可用的和準確的緯度/經度。我基本上有兩個問題:1)有沒有人看到我的代碼的任何問題;和2)是否有人熟悉將UTM轉換爲lat/long並僅在Rgooglemaps包中使用UTM?將UTM轉換爲Lat/Long在R

這裏是我的代碼和數據的一些例子:

數據:

>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 

所以,我得到一些輸出,但是我沒有得到明智的輸出。有什麼我在這裏失蹤?另外,爲了實現它的價值,我打算使用「Rgooglemaps」包創建一些熱圖和內核密度圖。

+0

你確定你的utm區?區= 10是正確的嗎? – MLavoie

回答

1

我正在使用以下代碼將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,][email protected] 
out 
} 
+0

如果你想計算UTM區域,並且如果你知道緯度/經度,那麼以下鏈接可以幫助你:http://stackoverflow.com/questions/9186496/determining-utm-zone-to-convert-from-longitude-latitude –