[R-sig-Geo] Multiple polygons
Rui Catarino
R.Catarino at MARLAB.AC.UK
Wed Oct 14 16:54:56 CEST 2009
Hello again,
Thank you for such a quick reply.
You were right, it seems a bit obscure so following your suggestion I
attach a small example of what looks like my table. The list is in excel
format and I usually use the package xlsReadWrite to read the excel
files.
Once again thank you for your trouble
Rui
-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no]
Sent: 14 October 2009 14:30
To: Rui Catarino
Cc: r-sig-geo at stat.math.ethz.ch
Subject: Re: [R-sig-Geo] Multiple polygons
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.Bivand at nhh.no
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Example.xls
Type: application/vnd.ms-excel
Size: 16384 bytes
Desc: Example.xls
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20091014/2149d2de/attachment.xls>
More information about the R-sig-Geo
mailing list