Converting latitude and longitude points to UTM

前端 未结 5 1469
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 08:52

I found a fairly simple example of how to do this but I cant get it to work for me. I\'m pretty new to R

library(rgdal) 
xy <- cbind(c(118, 119), c(10, 50         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 09:24

    Converting latitude and longitude points to UTM

    library(sp)
    library(rgdal)
    
    #Function
    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))
    }
    
    # Example
    x<-c( -94.99729,-94.99726,-94.99457,-94.99458,-94.99729)
    y<-c( 29.17112, 29.17107, 29.17273, 29.17278, 29.17112)
    LongLatToUTM(x,y,15)
    

提交回复
热议问题