Skip to content
Prev 6635 / 29559 Next

Multiple polygons

On Wed, 14 Oct 2009, Rui Catarino wrote:

            
What do the input data look like? Is there a list of +/-150 data.frame 
objects, or a single data.frame object (read with read.table()). If the 
latter, use split() first to make a list of data.frames, where the list 
components will take the name of the ID column values (assumed all 
identical for coordinates belonging to the same polygon).

Once you've got the list, say lst, you'll use lapply() to build a list of 
Polygons objects, each built of a list with a single Polygon object. This 
needs the coordinates in the right order and closed, so something like:

crds <- cbind(obj$x, obj$y)
crds <- crds[obj$order,]
crds <- rbind(crds, crds[1,])

should get them re-ordered, and then ring-closed. Insert the names as ID 
as appropriate. If this seems obscure, provide a very simple example data 
set on a website - it is actually quite straightforward if the data are 
cleanly organised.

Hope this helps,

Roger