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

Martin Ivanov martin.ivanov at ifg.uni-tuebingen.de
Fri Aug 24 09:26:53 CEST 2012


Dear Prof. Bivand,

Thank You very much for the support. Now everything works like a charm.
I am happy to have been able to make my small contribution to the 
improvement of the rgdal package.

Best regards,
Martin

On 08/23/2012 07:39 PM, Roger Bivand wrote:
> 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,
>>>>
>>>>
>>>
>>
>>
>>
>


-- 
Dr. Martin Ivanov
Eberhard-Karls-Universität Tübingen
Mathematisch-Naturwissenschaftliche Fakultät
Fachbereich Geowissenschaften
Water & Earth System Science (WESS)
Hölderlinstraße 12, 72074 Tübingen, Deutschland
Tel. +4970712974213



More information about the R-sig-Geo mailing list