On Sat, 7 Jan 2006, Patrick Giraudoux wrote:
> Dear Roger,
>
> I am trying to use the write.polylistShape() function of maptools for
> the first time and realize that it handles list of polygons of class
> 'polylist'. However, it seems that no as.polylist() function exist
in
> the package. The question behind that is: in your opinion, which would
> be the best way to convert a list of matrix of polygon nodes
> coordinates into an object of class polylist?
Certainly through sp classes - construct a list of Polygons objects each
with one (or more) Polygon objects, raise to SpatialPolygons, then back
out through writePolyShape(). Assuming each list member matrix is the
perimeter of a single polygon, and each Polygons object only has one
Polygon:
n <- length(list_of_matrices)
list_of_polygons <- vector(mode="list", length=n)
for (i in 1:n) {
Pl <- Polygon(list_of_matrices[[i]])
list_of_polygons[[i]] <- Polygons(list(Pl), ID=as.character(i))
}
# could be done with lapply too
SPs <- SpatialPolygons(list_of_polygons)
rownames(mydata) <- as.character(1:n)
SPDF <- SpatialPolygonsDataFrame(SPs, mydata)
writePolyShape(SPDF, "outfile")
(untried - but close enough).
Best wishes,
Roger
>
> All the best,
>
> Patrick
>
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no