[R-sig-Geo] Does sp::coordinates() behave correct?

Rainer Hurling rhurlin at gwdg.de
Tue Oct 22 10:04:33 CEST 2013


Am 22.10.2013 08:58 (UTC+1) schrieb Edzer Pebesma:
> yes, and
> 
> print(gis.k, digits=7)

After Sarah's answer I remembered, that this is only a printing issue.
Thanks for your further example to print exact coordinates.

> 
> gives:
> 
>> print(gis.k, digits=7)
>          coordinates  name   rsoll   hsoll
> 1 (3469125, 5521625) K0001 3469125 5521625
> 2 (3469375, 5521125) K0002 3469375 5521125
> 3 (3471875, 5522875) K0016 3471875 5522875
> 4 (3472500, 5524510) K0020 3472500 5524510
> 
> I will update the print methods for Spatial objects in sp to use
> 
>> getOption("digits")
> [1] 7
> 
> as a default for digits, instead of 6.

That would be very nice! Until now we always have to remember, when
print spatial objects directly [= print(gis.k)], that there could be
some 'pretty printing at work' ;)

Just a small thought: Do 7 digits will fit all usual cases of coordinate
types? Or would it be better to calculate the longest value (number of
digits) before printing coordinates? But I fear, this would slow down
printing to much ...

Thanks for your very good and important sp package. We almost daily use
it heavily,
Rainer

> 
> On 10/21/2013 09:41 PM, Rainer Hurling wrote:
>> 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
>>>>
>>>
>>
>> _______________________________________________ R-sig-Geo mailing 
>> list R-sig-Geo at r-project.org 
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>



More information about the R-sig-Geo mailing list