Tuesday 12 April 2016

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


Convex Hull


A convex hull of a shape is defined as:



In mathematics, the convex hull or convex envelope for a set of points X in a real vector space V is the minimal convex set containing X (Wikipedia)




Wikipedia visualizes it nicely using a rubber band analogy, and there are some good algorithms to compute it.


Concave Hull


A concave hull is visualized using the red line in the image below (the blue line visualizes the convex hull). Intuitively, it is a polygon which embraces all the points, but has less (minimal?) area compared to the convex hull. As a result, the polygon's boundary length is longer.


A concave hull may be the solution for some real-world problems (e.g. finding the reasonable boundary of a city).


enter image description here


I have failed to find a proper definition, algorithm and practical solution for the notion of a Concave Hull. The Grass Wiki has some descriptions and images, and there is a commercial solution in concavehull.com.


Any ideas, algorithms and links?



Answer



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:



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');


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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...