[R-sig-Geo] spTransform: unable to convert coordinates

Roger Bivand Roger.Bivand at nhh.no
Thu Aug 23 19:39:59 CEST 2012


On Thu, 23 Aug 2012, Martin Ivanov wrote:

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

Please check R-forge revision 360 - the argument reversal was done 
correctly for points (so for pixels and grids), but the wrong way round 
for the other two cases. Test now in help page example.

Thanks for your patience,

Roger

>
> Best regards,
>
> Martin
>
>
>
>
>
>
> On 08/23/2012 02:37 PM, Roger Bivand wrote:
>> On Thu, 23 Aug 2012, Martin Ivanov wrote:
>> 
>>> Dear Prof. Bivand,
>>> 
>>> I tested spTransform with a SpatialLines object and it still does not 
>>> multiply the coordinates by 180/pi. With SpatialPixels, SpatialPoints and 
>>> SpatialGrids it works perfectly though. If necessary, I will provide a 
>>> minimal working example.
>> 
>> Please do - I may have left something out. I'm travelling now, so an 
>> example would help. What about SpatialPolygons objects?
>> 
>> Roger
>> 
>>> 
>>> Best regards,
>>> 
>>> 
>> 
>
>
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
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