[R-sig-Geo] extending sp classes

Katarzyna Adamczyk Katarzyna.Adamczyk at jouy.inra.fr
Fri Oct 6 13:29:29 CEST 2006


Dear members of r-sig-geo,

I discovered "sp" library and I found
it very usefull  for switching
between different classes of R spatial
libraries.

I  defined my own class, extending
SpatialPolygonsDataFrame.
When I try to apply "spplot" function to
the extended class, it doesn't work :
I have a coercion problem error message,
but I don't know what it means.

I proceeded as follows:

I considered SpatialPolygonsDataFrame help example :

grd <- GridTopology(c(1,1), c(1,1), c(10,10))
polys <- as.SpatialPolygons.GridTopology(grd)
centroids <- getSpPPolygonsLabptSlots(polys)
x <- centroids[,1]
y <- centroids[,2]
z <- 1.4 + 0.1*x + 0.2*y + 0.002*x*x
ex_1.7 <- SpatialPolygonsDataFrame(polys, data=data.frame(x=x, y=y, z=z, row.names=getSpPPolygonsIDSlots(polys)))
spplot(ex_1.7)


I defined my own class :

 > setClass("myclass",contains="SpatialPolygonsDataFrame")
[1] "myclass"
 > ex<-ex_1.7
 > class(ex) = "myclass"
 > is(ex)
[1] "myclass"                  "SpatialPolygonsDataFrame"
[3] "SpatialPolygons"          "Spatial"
 > spplot(ex)
Erreur dans as.data.frame.default(obj) : cannot coerce class "myclass" 
into a data.frame

Did anyone of you encounter a similar problem and can help me?

Thank you in advance.

Katarzyna




More information about the R-sig-Geo mailing list