I use the method from Stanislav in this topic of Forum, which is a question about "converting latitude and longitude points to UTM". I edited the function reversely to change points from UTM to WGS84, which is:
library(sp); library(rgdal)
#Function
UTMToLongLat<-function(x,y,zone){
xy <- data.frame(ID = 1:length(x), X = x, Y = y)
coordinates(xy) <- c("X", "Y")
proj4string(xy) <- CRS(paste("+proj=utm +zone=",zone," ellps=WGS84",sep=''))
res <- spTransform(xy, CRS("+proj=longlat +datum=WGS84"))
return(as.data.frame(res))
}
The example in the previous question mentioned above is tried, that is:
x2 <- c(-48636.65, 1109577); y2 <- c(213372.05, 5546301)
What is expected is (118, 10), (119, 50) in WGS84. Colin's example is in UTM51.
So, the following sentence is used:
done2 <- UTMToLongLat(x2,y2,51)
However, it produced: (118.0729, 1.92326), (131.4686, 49.75866).
What is wrong? By the way, how to control the decimal digits of the output?