[R-sig-Geo] Does sp::coordinates() behave correct?
Rainer Hurling
rhurlin at gwdg.de
Mon Oct 21 21:41:38 CEST 2013
Hi Sarah,
thanks for clearing this up and the very fast answer.
Greetings from Göttingen in Germany,
Rainer
Am 21.10.2013 21:31, schrieb Sarah Goslee:
> Hi,
>
> It's purely a printing issue; the coordinates are unchanged:
>
>> coordinates(gis.k)
> x y
> [1,] 3469125 5521625
> [2,] 3469375 5521125
> [3,] 3471875 5522875
> [4,] 3472500 5524510
>
> A number of print methods in R round things to 'look nice', which can
> lead to unexpected side-effects, like confused users.
>
> Thanks for the short reproducible example; much appreciated.
>
> Sarah
>
> On Mon, Oct 21, 2013 at 3:27 PM, Rainer Hurling <rhurlin at gwdg.de> wrote:
>> I am using 'coordinates(x) <- ~x+y' to convert data.frames into
>> SpatialPointsDataFrames.
>>
>> It seems, that some coordinates will be rounded(?), when they are
>> transformed by coordinates():
>>
>>
>> library(maptools)
>>
>> # Defining some Datapoints with coordinates
>> gis.k <- data.frame(name=c("K0001","K0002","K0016","K0020"),
>> rsoll=c(3469125,3469375,3471875,3472500),
>> hsoll=c(5521625,5521125,5522875,5524510))
>>
>> # Converting them into a SpatialPointsDataFrame
>> gis.k$x <- gis.k$rsoll
>> gis.k$y <- gis.k$hsoll
>> coordinates(gis.k) <- ~x+y
>>
>> # Show contents of new SpatialPointsDataFrame
>> gis.k
>> coordinates name rsoll hsoll
>> 1 (3469120, 5521620) K0001 3469125 5521625
>> 2 (3469380, 5521120) K0002 3469375 5521125
>> 3 (3471880, 5522880) K0016 3471875 5522875
>> 4 (3472500, 5524510) K0020 3472500 5524510
>>
>>
>> In lines 1 to 3 the coordinates from rsoll and hsoll are rounded, for
>> example 3469125 into 3469120 and 3471875 into 3471880. (In some cases
>> they are rounded up, in others round down?) Only coordinates with last
>> digit =0 are not changed.
>>
>> Is this an expected behaviour and if this is right, why? If not, what
>> would be the correct solution to convert these coordinates? Or do I
>> missunderstand something here.
>>
>> Any help is appreciated. Thanks in advance,
>> Rainer Hurling
>>
>
More information about the R-sig-Geo
mailing list