[R-sig-Geo] Put polygon points in correct order

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Fri Oct 2 09:27:06 CEST 2009


On Fri, Oct 2, 2009 at 5:52 AM, Don MacQueen <macq at llnl.gov> wrote:
> I have a set of points that form a polygon, except that they are in the
> wrong order. For example, source into R the object "tmpsub" given below.
> Then do
>
> plot(tmpsub)
> polygon(tmpsub)
>
> You will see that although the points define a polygon, they are in the
> wrong order.
>
> I need an algorithm to put them in the correct order. It's not obvious to me
> how to do this.
> (They will then be used to build a SpatialPolygons object.)
>
> Suggestions, or pointers to algorithms, would be much appreciated.

 For the points you gave us I can see several ways of making a
non-self-intersecting polygon. Along the top, for example, you could
either have squares or triangles. Do you have any other constraints?
It looks to me like you only want horizontal and vertical lines in
your polygons. Is that so? That might make a unique  solution
possible...

Barry



More information about the R-sig-Geo mailing list