What are Definition, Algorithms and Practical Solutions for Concave Hull?

As scw points out, you want an implementation of α-shapes.

Alpha shapes can be considered a generalisation of the convex hull. They were first described in 1981 in:

Edelsbrunner, H.; Kirkpatrick, D.; Seidel, R.; , "On the shape of a set of points in the plane," Information Theory, IEEE Transactions on , vol.29, no.4, pp. 551- 559, Jul 1983

Open source implementations exist for the environments you are interested in:

PostGIS

If you are using the PostGIS stack, pgRouting's optional Driving Distance extension exposes an alpha shape implementation. I'm not sure if you can vary the alpha parameter, however.

Usage is below:

SELECT the_geom AS alpha_shape 
FROM 
  points_as_polygon(
    'SELECT id, ST_X(your_geom) AS x, ST_Y(your_geom) AS y FROM your_table');

Python

There are probably many python modules you could use. I have heard good things about CGAL, a C++ computational geometry library. Python wrappers exist for parts of CGAL, including exposing CGAL's alpha shape implementation to Python.

Be aware that parts of CGAL are licensed under the QPL, which means that if you distribute your program, linked to CGAL, you may need to release it under the QPL. It is fine to keep your code proprietary if you do not redistribute your program code or binaries.


Here is what you are looking for.

You can download and test the program: (in java, under GPL license)

alt text

The paper presenting the algorithm is there:

Duckham, M., Kulik, L., Worboys, M.F., Galton, A. (2008) Efficient generation of simple polygons for characterizing the shape of a set of points in the plane. Pattern Recognition v41, 3224-3236


This seems to be a specific application of alpha shapes, which are from my reading a more general form of this problem. R has the alphahull module, which has excellent documentation on computing alpha shapes. Also check this detailed background on alpha shapes. If you only want to compute convex/concave hulls, check out lasboundary, part of lastools, it scales well and can handle millions of input points.

Finally, this interesting application of alpha shapes by Flickr made the rounds a while ago, showing their utility for aggregating user generated point content:

alpha hull of texas from flickr