I am working with lat long coordinates in R
. First I need to transform my coordinates to zone 17 and then add some buffer to them. For that I used next code (the data used is in orig_coords
):
library(sp)
library(rgdal)
library(rgeos)
orig_coords <- data.frame(lat=-0.1848787,lon=-78.48179)
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 +south=T +zone=",zone," ellps=WGS84",sep='')))
#return(as.data.frame(res))
return(res)
}
#Res
res <- LongLatToUTM(orig_coords$lon,orig_coords$lat,17)
#Add buffer
pc2km <- gBuffer( res, width=2000, byid=TRUE )
#Bounding box
bb <- pc2km@bbox
With that I got the bounding box which contains the projected coordinates with the buffer added to them:
bb
min max
x 778303.1 782303.1
y 9977545.5 9981545.5
My question is how can I transform the min and max coordinates from bb
back to latitude and longitude? Many thanks.
pc2km_WGS84 <- spTransform(pc2km, CRS("+proj=longlat +datum=WGS84"))
and thenbb <- pc2km_WGS84@bbox
. Not sure if that syntax is correct as I have not really used those packages much, but the workflow seems logical. – Nostoc