0

I want to transform lat/long coordinates into the UTM (zone 47) system using R. I have finally managed to get a result without error messages by using the last post on the bottom. But the result is not as expected. Here an example:

    LongLatToUTM<-function(x,y,zone){
  xy <- data.frame(ID = 1:length(x), X = x, Y = y)
  coordinates(xy) <- c("X", "Y")
  proj4string(xy) <- CRS("+proj=longlat +datum=WGS84")  ## for example
  res <- spTransform(xy, CRS(paste("+proj=utm +zone=",zone," ellps=WGS84",sep='')))
  return(as.data.frame(res))
}

# Execute
x<-100.4605
y=21.568216
res.1<-LongLatToUTM(x,y,47)

I get the following result: x=646172.7 y=2876501 with R, but I'm expecting x=651218 y=2385744. What did I do wrong?

Community
  • 1
  • 1
Lukas
  • 223
  • 3
  • 12
  • 1
    running your code gives me `x=651218.2 y=2385744 ` which is what you stated you were expecting – user5219763 Apr 22 '16 at 15:12
  • Hey! thanks for pointing that out! Because of that I tried the code with a different computer and strangely enough the unexpected results only occur on the first computer, for all the others it works. I'll see what I can do, thanks! – Lukas Apr 23 '16 at 21:03

0 Answers0