On Wed, 14 Oct 2009, Rui Catarino wrote:
Hello to all,
This is my first attempt to use GIS tools in R so I'm sorry if my
question is to na?ve, but the truth is that I've spent several hours
looking in forum's and packages for a solution with no joy.
What I'm trying to achieve is to create multiple polygons (around 150)
based in a table with (x,y) coordinates. This table also as two extra
fields one which will be the code (numeric value) for each polygon. The
second field is the numeric order in which the points in each polygon
should be joined.
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
Thanks in advance
Rui
[[alternative HTML version deleted]]
--
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.biv...@nhh.no
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo