Skip to main content
Given a shape A, ST_ConvexHull(A) returns another shape B that is the convex hull of A. The convex hull of a shape is the smallest convex set of points that every point in the set that comprises that shape. In other words, given a set of points A in the plane, the convex hull is the shape B created by stretching an imaginary rubber band around the outermost points in A. ST_ConvexHull works on the following data types:
ST_ConvexHull is not an aggregate function. It operates on a single GEOMETRY object. This means that in practice it is most often used in combination with an aggregate function such as .

Examples

In this example, we will generate the convex hull of a single geometry. The geometry is made from many individual points using .
  1. Create a temporary table to hold all the points, which will be in format:
  2. Insert the points with the following statement:
  3. Run the query below, which gathers the points into a single geometry using that can be operated on by ST_ConvexHull, and converts the output to so that we can view it with geojson.io:
  4. Paste the JSON emitted in the previous step into geojson.io and you should see an image like the following, which shows the convex hull surrounding the locations of most of the independent bookstores in New York State: ST_ConvexHull example
  5. Finally, drop the temporary table if you no longer need it:

See also