This will give you the number of separate "rings", but that won't
allow you to differentiate between separate simple polygons, and rings
that represent "holes":

sapply(s...@polygons, function(x) length(slot(x, "Polygons")))

It needs more work to check each individual "Polygon" in "x" to see if
slot(x[[i]], "hole") is TRUE. I think this will do it:

sapply(s...@polygons, function(x) sum( !sapply(slot(x, "Polygons"),
slot, "hole")))

Note that use slot(x, "name") is more verbose that x...@name, but either
is not recommended for normal use and should be bundled into methods,
or helper functions.

I think it's worth delving into the structure of these objects, as
it's fairly simple once you get used to it and writing summary
functions is not hard.

Cheers, Mike.

On Fri, Nov 5, 2010 at 10:50 AM, Craig Mundy <craig.mu...@utas.edu.au> wrote:
>
> Hi All,
>
> I have searched for (but not found), a function for counting polygons within 
> each record of a multi-polygon SpatialPolygonDataFrame class? I had thought 
> of sifting through the slot information, but thought I would check if there 
> was a function I had overlooked before I embarked on that. I can easily do 
> this in SQL Server but would prefer to batch process in R along with some 
> other tasks.
>
> Thanks
>
> Craig
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsum...@gmail.com

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to