[R-sig-Geo] Acessing slot information in spatialPolygon class
jon.skoien at jrc.ec.europa.eu
jon.skoien at jrc.ec.europa.eu
Tue Dec 13 14:25:33 CET 2011
Hi Rui,
I think the following should give you what you are looking for:
res$area2 = sapply(slot(res,"polygons"), function(x) slot(x, "area"))
Cheers,
Jon
On 13-Dec-11 13:50, Rui Catarino wrote:
> Dear all,
>
>
>
> This may seem a very obvious question but I'm suck and for the past 2h I
> haven't been able of solving the problem. So for the sake of
> productivity I'll ask for some help:
>
>
>
> I have a SpatialPolygon Class that looks like(see bellow) in the example
> below I have only 2 polygons but they will be thousands. What I'm trying
> to achieve is a list with the total area of each polygon.
>
>
>
> Thanks in advance
>
>
>
>> str(res)
> Formal class 'SpatialPolygons' [package "sp"] with 4 slots
>
> ..@ polygons :List of 2
>
> .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
>
> .. .. .. ..@ Polygons :List of 9
>
> .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
>
> .. .. .. .. .. .. ..@ labpt : num [1:2] 3.19 51.68
>
> .. .. .. .. .. .. ..@ area : num 8.96e-05
>
> .. .. .. .. .. .. ..@ hole : logi FALSE
>
> .. .. .. .. .. .. ..@ ringDir: int 1
>
> .. .. .. .. .. .. ..@ coords : num [1:5, 1:2] 3.18 3.18 3.19 3.2 3.18
> ...
>
> .
>
> .
>
> .
>
>
>
> .. .. .. ..@ plotOrder: int [1:9] 9 8 2 3 1 4 7 5 6
>
> .. .. .. ..@ labpt : num [1:2] 3.14 51.67
>
> .. .. .. ..@ ID : chr "2"
>
> .. .. .. ..@ area : num 0.000993
>
> ..@ plotOrder : int [1:2] 2 1
>
> ..@ bbox : num [1:2, 1:2] 3.09 51.66 3.26 51.73
>
> .. ..- attr(*, "dimnames")=List of 2
>
> .. .. ..$ : chr [1:2] "x" "y"
>
> .. .. ..$ : chr [1:2] "min" "max"
>
> ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
>
> .. .. ..@ projargs: chr NA
>
>
>
>
>
>
>
>
>
>
>
> Rui Catarino
>
> Scientific Officer
>
> Fishery Systems Group
>
> Marine Scotland - Science
>
>
>
> Scottish Government | 36 |B |Marine Laboratory, PO Box 101| 375,
> Victoria Road | Aberdeen AB11 9DB
>
>
>
> Tel: +44 (0)1224 295572
>
> Mob:+44 (0)7530 240666
>
> Fax: +44 (0)1224 295511
>
> e: r.catarino at marlab.ac.uk
>
> w: http://www.scotland.gov.uk/marinescotland
> <http://www.scotland.gov.uk/marinescotland>
>
>
>
>
> ______________________________________________________________________
> This email has been scanned by the Symantec Email Security.cloud service.
> For more information please visit http://www.symanteccloud.com
> ______________________________________________________________________
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Global Environment Monitoring Unit
Via Fermi 2749, TP 440, I-21027 Ispra (VA), ITALY
jon.skoien at jrc.ec.europa.eu
Tel: +39 0332 789206
Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission.
More information about the R-sig-Geo
mailing list