Hi,
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)
pt1.cpoly
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
pt1.poly
[[1]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 217680.2 3817554.7
Slot "area":
[1] 30901.7
Slot "hole":
[1] FALSE
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,
Monica
extracting slot "coords" from a Polygons class object
5 messages · MacQueen, Don, Sarah Goslee, Monica Pisica +1 more
It would be better to ask this question on r-sig-geo. More people there
are more familiar with the structure of Spatial{*} classes.
-Don
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 4/8/15, 2:07 PM, "Monica Pisica" <pisicandru at hotmail.com> wrote:
>
>Hi,
>
>
>
>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)
>
>
>
>pt1.cpoly
>
>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
>
>
>
>pt1.poly
>
>[[1]]
>
>An object of class "Polygons"
>
>Slot "Polygons":
>
>[[1]]
>
>An object of class "Polygon"
>
>Slot "labpt":
>
>[1] 217680.2 3817554.7
>
>
>
>Slot "area":
>
>[1] 30901.7
>
>
>
>Slot "hole":
>
>[1] FALSE
>
>
>
>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,
>
>
>
>Monica
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
You didn't parse the output you pasted in correctly: pt1.cpoly at polygons[[1]]@Polygons[[1]]@coords or coordinates(pt1.cpoly at polygons[[1]]@Polygons[[1]])
class(pt1.cpoly)
[1] "SpatialPolygons" attr(,"package") [1] "sp" So see ?"SpatialPolygons-class" for details. Sarah
On Wed, Apr 8, 2015 at 5:07 PM, Monica Pisica <pisicandru at hotmail.com> wrote:
Hi,
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)
pt1.cpoly
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
pt1.poly
[[1]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 217680.2 3817554.7
Slot "area":
[1] 30901.7
Slot "hole":
[1] FALSE
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,
Monica
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Sarah Goslee http://www.functionaldiversity.org
Hi Sarah, Thank you so much. This is exactly what i need it. I was wondering if my parsing was totally wrong. I read the SpatialPolygons-class help, but obviously i didn't understand it. Again, thanks so much, Monica ----------------------------------------
Date: Wed, 8 Apr 2015 20:42:56 -0400 Subject: Re: [R] extracting slot "coords" from a Polygons class object From: sarah.goslee at gmail.com To: pisicandru at hotmail.com CC: r-help at r-project.org You didn't parse the output you pasted in correctly: pt1.cpoly at polygons[[1]]@Polygons[[1]]@coords or coordinates(pt1.cpoly at polygons[[1]]@Polygons[[1]])
class(pt1.cpoly)
[1] "SpatialPolygons" attr(,"package") [1] "sp" So see ?"SpatialPolygons-class" for details. Sarah On Wed, Apr 8, 2015 at 5:07 PM, Monica Pisica <pisicandru at hotmail.com> wrote:
Hi,
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)
pt1.cpoly
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
pt1.poly
[[1]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 217680.2 3817554.7
Slot "area":
[1] 30901.7
Slot "hole":
[1] FALSE
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,
Monica
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Sarah Goslee http://www.functionaldiversity.org
Note that you can get everything (without recording its structure) with coordinates(as(as(x, "SpatialLines"), "SpatialPoints")) - also ggplot2 uses fortify methods to turn these objects into tables. Cheers, Mike.
On Thu, 9 Apr 2015 at 22:57 Monica Pisica <pisicandru at hotmail.com> wrote:
Hi Sarah, Thank you so much. This is exactly what i need it. I was wondering if my parsing was totally wrong. I read the SpatialPolygons-class help, but obviously i didn't understand it. Again, thanks so much, Monica ----------------------------------------
Date: Wed, 8 Apr 2015 20:42:56 -0400 Subject: Re: [R] extracting slot "coords" from a Polygons class object From: sarah.goslee at gmail.com To: pisicandru at hotmail.com CC: r-help at r-project.org You didn't parse the output you pasted in correctly: pt1.cpoly at polygons[[1]]@Polygons[[1]]@coords or coordinates(pt1.cpoly at polygons[[1]]@Polygons[[1]])
class(pt1.cpoly)
[1] "SpatialPolygons" attr(,"package") [1] "sp" So see ?"SpatialPolygons-class" for details. Sarah On Wed, Apr 8, 2015 at 5:07 PM, Monica Pisica <pisicandru at hotmail.com>
wrote:
Hi, 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) pt1.cpoly 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 pt1.poly [[1]] An object of class "Polygons" Slot "Polygons": [[1]] An object of class "Polygon" Slot "labpt": [1] 217680.2 3817554.7 Slot "area": [1] 30901.7 Slot "hole": [1] FALSE 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, Monica
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posti
ng-guide.html
and provide commented, minimal, self-contained, reproducible code.
-- Sarah Goslee http://www.functionaldiversity.org
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posti ng-guide.html and provide commented, minimal, self-contained, reproducible code.