3

I am looking for a way in R to project WGS84 latitudes and longitudes to a UTM grid and then convert the UTM coordinates back to the WGS84 latitudes and longitudes. I have found a number of ways to project to a UTM grid (mapproj::mapproject, rgdal::spTransform), but going from the grid back to latitudes and longitudes seems to be more complicated. Is there a projection function that offers the inverse?

I would like to use find the reverse of this:

newdata <-mapproject(dataset$lon, dataset$lat, projection = "lambert", parameters = c(mean(dataset$lon), mean(dataset$lat)))
4
  • 2
    What have you researched so far? There are plenty of places with the generic algorithm for this as well as code snippets of the transformation in various languages.
    – ed.hank
    Jan 6, 2016 at 20:04
  • Can you please point me to a place that shows how to do this in R? I am obviously not looking the right way as I haven't found the answer. Jan 6, 2016 at 21:12
  • When I get back to the office I can go through my bookmarks, I am pretty sure I have something in there.
    – ed.hank
    Jan 6, 2016 at 21:45
  • are you looking for something like that spTransform(x, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")) ?
    – MLavoie
    Jan 7, 2016 at 0:15

1 Answer 1

1

You can move from any CRS to another CRS, below R code will work. Make sure you know the EPSG code for CRS which you are using. This is a reproducible example for converting from BNG to WGS. Vice versa is also possible.

library(raster)
t<-as.data.frame(matrix(c(531366.2,531325.7,259349.5,249798),nrow=2)) #sample coordinates
colnames(t) = c("x", "y")
t_wgs<-spTransform(SpatialPointsDataFrame(t[,c(1,2)],data = t,proj4string = crs("+init=epsg:27700")) , crs("+init=epsg:4326"))
t_wgs$lon<-t_wgs@coords[,1]
t_wgs$lat<-t_wgs@coords[,2]
View(t_wgs@data)

EPSG code for BNG is 27000 and WGS84 is 4326

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.