[R-sig-Geo] coordinates

Roger Bivand Roger.Bivand at nhh.no
Fri Jun 19 11:22:34 CEST 2009


On Fri, 19 Jun 2009, Agustin Lobo wrote:

> Hi!
>
> When using
>
>> coordinates(VEGPROimas20090409punts) <- c("xc","yc")
>
> where VEGPROimas20090409punts is a dataframe and xc, yc
> column variables in the dataframe,
> xc and yc are deleted from the @data table of the resultinf spdf.

This is by design - they get re-instated when you coerce to data.frame. 
The obvious alternative is:

library(sp)
data(meuse)
meuse[1,]
meuse <- SpatialPointsDataFrame(SpatialPoints(cbind(meuse$x, meuse$y)),
   data=meuse)
meuse[1,]

which you could can as a function with 3 or more arguments if you like.

Roger


> I mean:
>
>> VEGPROimas20090409punts[1,]
>  site           image     xc      yc        g    h       hg    v     N  Z
> 1    1 SDIM0380_L1.TIF 444088 4624897 1166.573 1340 173.4269 39.5 307.6 66
>      Qh   Qv1   Qv2
> 1 13.182 1.415 0.667
>
>> coordinates(VEGPROimas20090409punts) <- c("xc","yc")
>
>> VEGPROimas20090409punts at data[1,]
>  site           image        g    h       hg    v     N  Z     Qh   Qv1 
> Qv2
> 1    1 SDIM0380_L1.TIF 1166.573 1340 173.4269 39.5 307.6 66 13.182 1.415 
> 0.667
>
> Is there any way
> to keep xc and yc in the @data table of the resulting spdf?
> I know I can put them back, but often forget. An option might be
> useful.
>
> Thanks
>
> Agus
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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