maptools, write.polylistShape

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

maptools, write.polylistShape

Patrick Giraudoux
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?

All the best,

Patrick

--

Department of Environmental Biology
EA3184 usc INRA
University of Franche-Comte
25030 Besancon Cedex
(France)

tel. +33 381 665 745
fax +33 381 665 797
http://lbe.univ-fcomte.fr

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: maptools, write.polylistShape

Roger Bivand
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: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Roger Bivand
Department of Economics
NHH Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway