I have an Object of class 'SpatialPolygonsDataFrame' with the structure shown below.
What's the secret to getting to the @area slot? Ultimately, I'm trying to filter this file so that I'm only left with polygons >= 64m^2. The resultant shapefile will be imported to OCAD (orienteering mapping software), in an attempt to semi-automatically map a class of vegetation.
I thought I had some understanding of S4 classes, but clearly I have a gap.
among many similar failed attempts:
> xfile@polygons$Polygons@Polygons$Polygon
Error: trying to get slot "Polygons" from an object of a basic class ("NULL") with no slots
> xfile@polygons$Polygons@Polygons
Error: trying to get slot "Polygons" from an object of a basic class ("NULL") with no slots
> xfile@polygons@Polygons
Error: trying to get slot "Polygons" from an object of a basic class ("list") with no slots
> xfile@polygons$Polygons
NULL
> xfile@polygons$'Polygons'@Polygons$'Polygon'@area
Error: trying to get slot "Polygons" from an object of a basic class ("NULL") with no slots
> xfile@polygons$'Polygons'@Polygons
Error: trying to get slot "Polygons" from an object of a basic class ("NULL") with no slots
> xfile@polygons$'Polygons'
NULL
> xfile@polygons$area
NULL
> xfile$polygons
NULL
> xfile@polygons
( the whole file )
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
..@ data :'data.frame': 1 obs. of 1 variable:
.. ..$ layer: num 1
..@ polygons :List of 1
.. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
.. .. .. ..@ Polygons :List of 191
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 513021 4319805
.. .. .. .. .. .. ..@ area : num 9.64
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:19, 1:2] 513018 513025 513025 513024 513024 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 513053 4319805
.. .. .. .. .. .. ..@ area : num 1.85
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:5, 1:2] 513051 513054 513054 513051 513051 ...
......
.. .. .. .. .. [list output truncated]
.. .. .. ..@ plotOrder: int [1:191] 18 118 101 168 110 148 61 135 166 90 ...
.. .. .. ..@ labpt : num [1:2] 513181 4319787
.. .. .. ..@ ID : chr "0"
.. .. .. ..@ area : num 38206
..@ plotOrder : int 1
..@ bbox : num [1:2, 1:2] 512793 4319369 513380 4319807
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr "+proj=utm +zone=13 +datum=WGS84 +units=m +no_defs"
sf
by usingx <-st_read("myshapefile.shp")
? Perhaps it might be easier that way.gArea
from the rgeos package to return area for each polygon on a sp class object.