[R] Gauss-Krüger coordinates system

Roger Bivand Roger.Bivand at nhh.no
Wed Feb 1 13:04:02 CET 2006


On Wed, 1 Feb 2006, Giannitrapani, Marco GSUK-GSSC wrote:

> Dear All, 
> 
> I need to convert some Northing-Easting coordinates from the
> Gauss-Krüger system into latitude-longitude.
> 
> Any suggestions on how to do it?

(The "Spatial" Task View on CRAN and/or the R-sig-geo mailing lists might 
have helped).

Yes, the off-CRAN package spproj using classes from the sp package and the 
underlying PROJ.4 projection library should be able to do it:

rSpatial <- "http://r-spatial.sourceforge.net/R"
install.packages("spproj", repos=rSpatial)

# if you don't have it already; on Mac OSX and Linux/Unix, you need to 
# install PROJ.4 first; on Windows the binary package should install OK

library(spproj)

lon <- 2*runif(20)+9
lat <- 2*runif(20)+50
coords <- cbind(lon, lat)

# generate some coordinates

coords_sp <- SpatialPoints(coords,
 proj4string=CRS("+proj=longlat +ellps=WGS84"))
plot(coords_sp, axes=TRUE)

coords_sp_GK <- transform(coords_sp, CRS("+init=epsg:2166"))
plot(coords_sp_GK, axes=TRUE)

#
# and make them Pulkovo 1942(83) / Gauss Kruger zone 3 (see 
# system.file("proj/epsg", package="spproj")[1]
# for PROJ.4 definitions of thousands of projections
#
# EPSG was founded and funded by oil companies fed up with
# projection metadata being treated as top secret, and it seems to
# be well-maintained
#
# The first argument to transform() must be a "Spatial" class object
# with its proj4string slot set to the appropriate projection.
# If you set it wrong, you may be surprised/disappointed
#

coords_sp_LL <- transform(coords_sp_GK, CRS("+proj=longlat +ellps=WGS84"))

# and back again (your question) for your choice of datum and/or ellipsoid

all.equal(slot(coords_sp_LL, "coords"), slot(coords_sp, "coords"))

Roger

> 
> Regards,
> 
> Marco
> 
> Marco Giannitrapani
> Statistical Consultant

-- 
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-help mailing list