[R] extracting coordinates from SpatialPolygonsDataFrame using slot functions

Jeff Hamann jeff.hamann at forestinformatics.com
Thu May 6 05:01:25 CEST 2010


In converting some older code:

## builds an OWIN to generate a set of points on a grid within the OWIN object:
bdry <- read.shape( "../../data/boundary.shp" )
outline.verts <- bdry$Shapes[[2]]$verts[1:bdry$Shapes[[2]]$Pstart[2],]
outline.order <- nrow( outline.verts ) : 2
bdry.poly <- vector( 2, mode="list" )
bdry.poly[[1]] <- list( x=outline.verts[outline.order,1], 
                  y=outline.verts[outline.order,2] )
bdry.poly[[2]] <- list( x=bdry$Shapes[[1]]$verts[1:(nrow(bdry$Shapes[[1]]$verts)-1),1], 
                   y=bdry$Shapes[[1]]$verts[1:(nrow(bdry$Shapes[[1]]$verts)-1),2] )
bdry.owin <- owin( poly=bdry.poly )
grid <- gridcentres( bdry.owin, 200, 200 ) 

I've run across the following problem where I now need to use the readShapePoly function in the sp package:

bdry2 <- readShapePoly( "../../data/boundary.shp" )

which requires the elements be accessed using the slot function? 

My question, after trying to find the answer on-line and in some docs, is how?

Help?

Also, I'm not sure I get the r-help digests, so if someone can shed light on the subject, can you please respond directly?



More information about the R-help mailing list