For a little more Background information: I have a set of coordinates in Lat/Lon and wish to add the respective UTM coordinates to the data frame or SpatialPointsDataFrame. To this end, I have so far written a function that does that by first converting the df to a SpatialPointsDataFrame, reprojects to UTM and writes the coordinates to the input DF.
WGS2UTM <- function(df, WGS_coords){
temp <- sp::SpatialPointsDataFrame(coords = WGS_coords, data = df,
proj4string = CRS("+proj=longlat
+ellps=WGS84 +datum=WGS84 +no_defs"))
temp <- spTransform(temp, CRS(as.character(unique(temp@data$EPSG_UTM))))
df$UTM_E <- sp::coordinates(temp)[,"x"]
df$UTM_N <- sp::coordinates(temp)[,"y"]
return(df)
}
The EPSG code used to reproject in the function is contained in the DF as a Factor.
Now to my question: Since we frequently deal with locations spread across multiple different UTM Zones, I'd like to be able to apply the function above to the factor levels of the EPSG_UTM column. I am aware that the apply family is best used for this kind of operation but I can't figure it out. Any pointers?