# [R-sig-Geo] proj4 transform problem (Hungarian EOV CRS)

Roger Bivand Roger.Bivand at nhh.no
Mon Jun 19 19:34:37 CEST 2006

```On Mon, 19 Jun 2006, Bálint Czúcz wrote:

> Dear R-Sig-Geo readers!
>
> I am trying to integrate spatial data given in the Hungarian EOV CRS
> with lonlat data, but I am having problems with the coordinate
> transformations.

Actually, the problem is that you have wgs84 instead of WGS84:

library(rgdal)
EOV <- "+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778
+alpha=90 +k=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 +units=m
+no_defs +towgs84=+57.01,-69.97,-9.29"
test <- matrix(c(5,1,5,2,6,2,6,1,5,1)*100000, ncol=2, byrow=TRUE)
test1 <- SpatialPolygons(list(Polygons(list(Polygon(test)),ID=1)),
proj4string=CRS(EOV))
test2 <- spTransform(test1, CRS("+proj=longlat +datum=WGS84"))
plot(test2, axes=TRUE)

Some of the proj4 names are sometimes case-sensitive, WGS84 is one of them
(contrast your use of WGS84 in cs2cs! I've used the rgdal package here -
it includes spproj - and the transform() methods have become
spTransform(), but otherwise this should now work.

Thanks for an excellent report!

Hope this helps,

Roger

>
> I found this proj4string on the net:
> +proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778
> +alpha=90 +k=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 +units=m
> +no_defs +towgs84=+57.01,-69.97,-9.29
>
> Using this string I get an error message:
> > test <- matrix(c(5,1,5,2,6,2,6,1,5,1)*100000, ncol=2, byrow=TRUE)
> > test <- SpatialPolygons(list(Polygons(list(Polygon(test)),ID=1)))
> > proj4string(test) <- CRS("+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +alpha=90 +k=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 +units=m +no_defs +towgs84=+57.01,-69.97,-9.29")
> > test2 <- transform(test, CRS=CRS("+proj=longlat +datum=wgs84"))
> Error in transform_Polygon(input[[i]], to_args = to_args, from_args =
> from_args) :
> 	no arguments in initialization list
>
> The other direction does not work either:
> > ceu <- map("worldHires", plot = FALSE, xlim = xl, ylim = yl)
> > ceu <- pruneMap(ceu, xlim = xl, ylim = yl)
> > ceu.sp <- map2SpatialLines(ceu, proj4string = CRS("+proj=longlat +datum=wgs84"))
> > ceu2 <- transform(ceu.sp, CRS=CRS("+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +alpha=90 +k=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 +units=m +no_defs +towgs84=+57.01,-69.97,-9.29"))
> Error in transform_Line(input[[i]], to_args = to_args, from_args = from_args) :
> 	unknown elliptical parameter name
>
> In spite of this the proj4string seems to work OK with the same
> projection string and the command line cs2cs utility:
> ba:~\$ cs2cs +proj=somerc +lat_0=47.14439372222222
> +lon_0=19.04857177777778 +alpha=90 +k=0.99993 +x_0=650000 +y_0=200000
> +ellps=GRS67 +units=m +no_defs +towgs84=+57.01,-69.97,-9.29   +to
> +proj=latlong +datum=WGS84
> 0 0
> 10d47'15.654"E  45d2'9.093"N 46.348
> 650000 200000
> 19d2'50.836"E   47d8'38.85"N 36.882
> ...
>
> What can be the problem?
> (NB: EOV is a swiss-type oblique mercator projection: can this cause problems?)
> Have I forgotten about something?
>
> Thank you for your help!
> Bálint
>
>
> > sessionInfo()
> R version 2.2.1, 2005-12-20, i586-uhu-linux-gnu
>
> attached base packages:
> [1] "datasets"  "graphics"  "grDevices" "methods"   "stats"     "utils"
> [7] "base"
>
> other attached packages:
>   spproj   spmaps  mapdata     maps maptools       sp    gstat  foreign
>  "0.3-4"  "0.1-3" "2.0-17" "2.0-31" "0.5-12" "0.8-14" "0.9-23" "0.8-12"
>     ROCR   gplots    gdata   gtools    rpart      JGR   JavaGD    rJava
>  "1.0-1"  "2.2.0"  "2.1.2"  "2.2.3" "3.1-27" "0.1-10"  "0.3-2"  "0.3-4"
>
>
>

--
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

```