Skip to content
Prev 15939 / 29559 Next

spTransform: unable to convert coordinates

Dear Prof. Bivand,

Here is a minimal working example with SpatialLines and SpatialPolygons. 
With both objects spTransform does not
multiply the transformed coordinates by 180/pi:

crds1 <- matrix(data=c(7, 51, 8, 52, 9, 52, 10, 51), ncol=2, byrow=TRUE, 
dimnames=list(NULL, c("lon", "lat")));
crds2 <- matrix(data=c(8, 48, 9, 49, 11, 49, 9, 48), ncol=2, byrow=TRUE, 
dimnames=list(NULL, c("lon", "lat")));
crds3 <- matrix(data=c(6, 47, 6, 55, 15, 55, 15, 47), ncol=2, 
byrow=TRUE, dimnames=list(NULL, c("lon", "lat")));
spLines <- SpatialLines(list(Lines(list(Line(crds1), Line(crds2), 
Line(crds3)), ID="a")));
spLines at proj4string <- CRS("+proj=longlat +ellps=sphere +no_defs");
bbox(spLines);
spLines_tr <- spTransform(spLines, CRS("+proj=ob_tran +o_proj=longlat 
+o_lon_p=-162 +o_lat_p=39.25 +lon_0=180 +ellps=sphere +no_defs"), 
use_ob_tran=TRUE);
bbox(spLines_tr)
bbox(spLines_tr)*180/pi

crds1 <- matrix(data=c(7, 51, 8, 52, 9, 52, 10, 51, 7, 51), ncol=2, 
byrow=TRUE, dimnames=list(NULL, c("lon", "lat")));
crds2 <- matrix(data=c(8, 48, 9, 49, 11, 49, 9, 48, 8, 48), ncol=2, 
byrow=TRUE, dimnames=list(NULL, c("lon", "lat")));
crds3 <- matrix(data=c(6, 47, 6, 55, 15, 55, 15, 47, 6, 47), ncol=2, 
byrow=TRUE, dimnames=list(NULL, c("lon", "lat")));
spPolygons <- SpatialPolygons(list(Polygons(list(Polygon(crds1), 
Polygon(crds2), Polygon(crds3)), ID="a")));
spPolygons at proj4string <- CRS("+proj=longlat +ellps=sphere +no_defs");
bbox(spPolygons);
spPolygons_tr <- spTransform(spPolygons, CRS("+proj=ob_tran 
+o_proj=longlat +o_lon_p=-162 +o_lat_p=39.25 +lon_0=180 +ellps=sphere 
+no_defs"), use_ob_tran=TRUE);
bbox(spPolygons_tr)
bbox(spPolygons_tr)*180/pi


The correct bounding boxes are the second ones. Hence the coordinates 
have also got to be multiplied by 180/pi.

Best regards,

Martin
On 08/23/2012 02:37 PM, Roger Bivand wrote: