Computational Geometry Part I: Convex Hull

  |   Source

Computational geometry is the study of algorithms which relate to geometry and often serves as the bedrock for many GIS functionalities. On the surface a problems in CG can look quite simple, yet when trying to write code for it can quickly a daunting yet fun challenge. Thankfully many problems in GC have been solved and there are mature libraries full of solutions, CGAL is probably the most promonent. There are Python bindings to it and it is used in applications like QGIS. That being said, being able to solve problems in CG isn't needed to be able to understand and use the existing concepts and solutions.

Common problems in CG can appear as such: Which points are in which polygons? To the human eye such a quesition would seem trivial, yet coding it may not come as intutively. For this intro I'm going to focus on one of the most fundamental concepts in CG- the convex hull. Imagine you had some nails on a board and tied a rubber band around them, that would produce the shape of a convex hull. It is the minimum bounding area for a set of spatial features (points, polygon or line) and it must be convex.

In [2]:
from shapely.geometry import MultiPoint
In [10]:
mp=MultiPoint([(-30, 100), (30, -20), (-30, 2),(-52, 42), (-53,12), (71,-25), (-11, 50) ,(-31, 40)])
mp
Out[10]:
In [11]:
mp.convex_hull
Out[11]:

Any general purpose GIS software (ArcMap, QGIS...) should have support for producing convex hulls. Reasons for using this functionality include converting points to polygons and creating simpler shapes to increase processing speeds. I hope this information is useful, as I plan to continue adding small posts about various algorithms in machine learning and computational geometry.