[R] extracting slot "coords" from a Polygons class object

Monica Pisica pisicandru at hotmail.com
Wed Apr 8 23:07:59 CEST 2015



I am struggling to extract the polygon vertices from a list of an object class "Polygons", specifically the slot "coords".


 I have a point, and i "draw" a buffer around with gBuffer, i am "extracting" the polygon form the SpatialPolygons class and i end up with a list of 1 one object Polygons class that seems to have slots, but if i try to extract them i get an error. 


So here it goes after i load the respective libraries: sp, maptools, rgdal, rgeos

pt1 <- data.frame(x=217680.2, y = 3817555)

coordinates(pt1) <- c("x", "y")

crs = "+proj=utm +zone=11 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"


proj4string(pt1) <- CRS(crs)

pt1.cpoly <- gBuffer(pt1, width = 100, byid = TRUE)



class       : SpatialPolygons 

features    : 1 

extent      : 217580.2, 217780.2, 3817455, 3817655  (xmin, xmax, ymin, ymax)

coord. ref. : +proj=utm +zone=11 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0


pt1.poly <- pt1.cpoly at polygons




An object of class "Polygons"

Slot "Polygons":


An object of class "Polygon"

Slot "labpt":

[1]  217680.2 3817554.7


Slot "area":

[1] 30901.7


Slot "hole":



Slot "ringDir":

[1] 1


Slot "coords":

             x       y

 [1,] 217780.2 3817555

 [2,] 217775.3 3817524

 [3,] 217761.1 3817496

 [4,] 217739.0 3817474

Etc. …..


pt1.crd <- pt1.poly[[1]]@coords

Error: no slot of name "coords" for this object of class "Polygons"


So my question is: How do i access the "coords" slot i clearly see when i print pt1.poly on the screen? 

Thanks for any help,


More information about the R-help mailing list