Skip to content
Prev 343179 / 398513 Next

Generating a polygon around points

I have been using a process like the following to create polygons that
(closely) surround a non-convex set of points.

  buf1 <- gBuffer(tmpb.ne, width=bstart, byid=TRUE)
  buf2 <- gUnaryUnion(buf1)
  buf <-  gBuffer(buf2, width=bshrink)

These functions are from the rgeos package. In my case, tmpb.ne is a
SpatialPointsDataFrame (sp package) whose coordinates slot has the
coordinates of interest. You would have to tinker with the values for the
two width arguments.


The first gBuffer() puts a buffer (a circle) around each individual point.

The gUnaryUnion() joins those circles into one or more polygons, depending
on how they overlap.

The second gBuffer() shrinks the polygons to make the polygon(s) surround
the points more closely.


It will even respect holes, for example if all your points are on land,
but there?s a lake in the middle somewhere.

I use it with projected coordinates, and the width parameters are in the
same units as the projection. I have never tried it with lat/long.

R-sig-geo would be a good place to follow-up. I think that was where I
found the above solution (I didn?t figure out by myself!)


-Don