[R-sig-Geo] WGS84 conversion to UTM

Roger Bivand Roger.Bivand at nhh.no
Thu Apr 13 14:58:47 CEST 2006


On Thu, 13 Apr 2006, Taylor, RB wrote:

> Dear all,
> 
> I'm a rather new user to R, so please excuse my ignorance. I understand
> in R there are different spatial packages that allow one to do a variety
> of spatial analyses. I have collected GPS in WGS84 in South Africa. I
> have the data in a tab-deliniated txt file (along with attribute data)
> and in .shp files. I want to be able to read the text file (or ascii)
> into R and then batch convert long lat to UTM (34 S), and then do some
> analyses in R. I can across the website
> http://r-spatial.sourceforge.net/xtra/xtra.RHnw.html#spproj, which seems
> quite good. But I don't seem to be able to replicate the same procedure
> with my files. Being fairly new to R, I am not all that familiar with
> the syntax so perhaps this is why I can't do it.

The functionality in spproj has recently been moved to rgdal, so that for 
a target UTM zone 34 S:

library(rgdal)
EPSG <- make_EPSG()
EPSG[grep("UTM zone 34S", EPSG$note), 1:2]

gives five alternatives with different ellipsoids. Assuming WGS 84:

utm34S <- CRS("+init=epsg:32734")
showWKT(CRSargs(utm34S))

shows that the EPSG projection has been picked up (EPSG is a long list of 
projections originally created by frustrated oil companies in Europe, 
mostly in the North Sea, because nothing lined up right when they began 
from the coastal states' national grids, etc.).

If your shapefiles have a *.prj file already, readOGR() will pick it up. 
If not, and for the textfiles, you'll need to assign the input coordinate 
reference system to the Spatial object(s):

my_ll <- CRS("+proj=lonlat +datum=WGS84")
proj4string(my_ll_object) <- my_ll

from there it is simple,

my_utm34S_object <- transform(my_ll_object,  utm34S)

Some documentation is coming before (too) long.

Roger

> 
> Any help is appreciated,
> thanks
> 
> PS I work in a windows environment
> 
> --
> Rob Taylor
> 
> University of York
> Biology Department
> PO Box 373
> York
> YO10 5YW
> United Kingdom
> 
> Mob +00 44 079 01531259
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list