How to convert UTM coordinates to lat and long in R

Caroline4 picture Caroline4 · May 3, 2015 · Viewed 19.3k times · Source

I am trying to run a species distribution model and need to create background points to run my logistic regression model. I have just created 500 randomPoints but they are in UTM coordinates and I need lat and long. Is there a way to convert them to lat and long in R? If so, can you share the code with me? I am fairly new to R. Thanks!

Answer

Robert Hijmans picture Robert Hijmans · May 3, 2015

If you need long/lat you should probably generate the random points using that coordinate reference system. But otherwise, create a SpatialPoints object and use spTransform. That is, do something like this (replace the ???):

  library(rgdal)
  sputm <- SpatialPoints(randompoints, proj4string=CRS("+proj=utm +zone=??? +datum=WGS84")) 
  spgeo <- spTransform(sputm, CRS("+proj=longlat +datum=WGS84"))