I'm trying to convert vectors that contain northing and easting data into decimal degrees using R. So far I have been able to the package rgdal to perform a projection, but I am running into a problem. The argument for the UTM zone must be a single character string, but I have multiple UTM zones in my data. Is there a way to use the rgdal::SpatialPoints() function to set multiple UTM zones? I tried inputting set character strings and using a vector in the CRS() function, but I received a warning message that only the first zone was used.
df<- data.frame(X = c(774869, 771437, 1051883, 524468),
Y = c(414498, 403790, 184967, 779682),
WGS.1984.UTM.Zone = c("57N", "57N", "54N", "59N"))
library(rgdal)
sputm <- SpatialPoints(df[c("X", "Y")], proj4string=CRS("+proj=utm +zone=57N +datum=WGS84"))
spgeo <- spTransform(sputm, CRS("+proj=longlat +datum=WGS84"))
#resultant coordinates are all transformed relative to UTM zone 57N
df$projargs<- paste("+proj=utm +zone=", df$WGS.1984.UTM.Zone, " +datum=WGS84", sep = "")
#trying again with set projargs character strings
spUTM<- SpatialPoints(df[c("X", "Y")], proj4string=CRS(df$projargs))
Warning messages:
1: In if (!is.na(projargs)) { : the condition has length > 1 and only the first element will be used
2: In if (!is.na(projargs)) { : the condition has length > 1 and only the first element will be used
3: In if (is.na(projargs)) uprojargs <- projargs else uprojargs <- paste(unique(unlist(strsplit(projargs, : the condition has length > 1 and only the first element will be used