inconsistent as.data.frame(SpatialPointsDF)
Edzer - Look like we posted at the same time. In my example my coordinates are named, no? I tried your example in my R environment and can replicate the behavior I mentioned.
df = data.frame(x=1:2, y=2:1, z = 3:4) df1 = df library(sp) coordinates(df1) = ~x+y as.data.frame(df1)
x y z 1 1 2 3 2 2 1 4
coordnames(df1)
[1] "x" "y"
coordnames(df1)=c('long','lat')
str(df1)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots ..@ data :'data.frame': 2 obs. of 1 variable: .. ..$ z: int [1:2] 3 4 ..@ coords.nrs : int [1:2] 1 2 ..@ coords : num [1:2, 1:2] 1 2 2 1 .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : NULL .. .. ..$ : chr [1:2] "long" "lat" ..@ bbox : num [1:2, 1:2] 1 1 2 2 .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : chr [1:2] "long" "lat" .. .. ..$ : chr [1:2] "min" "max" ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot .. .. ..@ projargs: chr NA
as.data.frame(df1)
x y z 1 1 2 3 2 2 1 4 Interestingly, when I open a new R instance and without loading all the packages associated with my project, the names are *not* converted. So it seems that one of the packages I have loaded is conflicting with sp and causing the names to change... my sessionInfo() was attached in the other post. -- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/inconsistent-as-data-frame-SpatialPointsDF-tp7587920p7587929.html Sent from the R-sig-geo mailing list archive at Nabble.com.