Can anyone please help me figure out how to convert locations that are in lat/long (decimal degrees) to UTM NAD83 Zone 13 using program R?
I have this written so far:
install.packages("sp")
install.packages("rgdal")
library(sp)
library(rgdal)
setwd("I:/R/latlong_utm/")
locs=read.table("Location_Database.txt", head=TRUE)
locs=subset(locs, select=c(number, LongWGS84, LatWGS84))
head(locs)
LongLatToUTM <- function(x, y, ID, zone){
xy <- data.frame(ID=ID, X=x, Y=y)
coordinates(xy) <- c("X", "Y")
proj4string(xy) <- CRS("+ proj=longlat + datum=WGS84")
res <- spTransform(xy, CRS(paste("+ proj=utm + zone=", zone, " ellps=WGS84",
sep='')))
return(as.data.frame(res))
}
x=LongLatToUTM(locs$LongWGS84, locs$LatWGS84, ID=locs$number, 13)
x$number = x$ID
locs=merge(locs, x, by="number")
head(locs)
plot(locs$X, locs$Y)
I also tried a different code:
require("PBSmapping") || install.packages("PBSmapping", dependencies=TRUE)
&& require("PBSmapping")
setwd("I:/R/latlong_utm/")
locs <- read.csv("Location_Database.csv", head=TRUE)
Location_Database.csv <- commandArgs(TRUE)[1]
coord <- read.csv("Location_Database.csv", head=TRUE)
attr(coord, "projection") <- "LL"
attr(coord, "zone") <- 13
coord.utm <- convUL(coord)
output <- sub(pattern = "Location_Database.csv", replacement = ".utm.csv",
x = "Location_Database.csv")
write.csv(coord.utm, file =
"C:/Users/utmoutput.csv",
row.names = FALSE)
tail(meter.data)
)
Neither of these work. Keep in mind this would be for batch locations (e.g., 75k + locations). Any help is much appreciated!