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

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Oct 22 08:58:54 CEST 2013


yes, and

print(gis.k, digits=7)

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.

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
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAD3A77F1



More information about the R-sig-Geo mailing list