ST_ConvexHull
What is ST_ConvexHull?
ST_ConvexHull is a PostGIS function that returns the smallest convex geometry enclosing every point of its input. Conceptually it is the shape made by stretching a rubber band around the geometry — every interior angle of the result is at most 180 degrees.
ST_ConvexHull(geometry geomA) → geometryThe result is a Polygon for 2D inputs with three or more non-collinear points, a LineString for collinear points, or a Point for a single point or duplicates.
When would you use ST_ConvexHull?
Use ST_ConvexHull for quick "extent" polygons around feature clusters — bounding a project area from survey points, computing an approximate territory from delivery stops, or generating a simplified polygon for a spatial index filter. It is also a useful preprocessing step before more expensive operations, as the hull tends to have far fewer vertices than the original input.
1SELECT region_id, ST_ConvexHull(ST_Collect(geom)) AS territory
2FROM customer_points
3GROUP BY region_id;FAQs
When should I prefer ST_ConvexHull over ST_ConcaveHull?
ST_ConvexHull is deterministic, fast, and mathematically well-defined. Use it when you need a guaranteed convex shape — for bounding, for indexing, or as a quick visual envelope. Prefer ST_ConcaveHull only when the input has an obvious non-convex distribution and you are willing to tune a parameter.
Is ST_ConvexHull the same as ST_Envelope?
No. ST_Envelope returns the axis-aligned bounding box (four right-angle corners), while ST_ConvexHull returns the tightest enclosing convex polygon, which can have many vertices and any orientation. Envelope is far cheaper; convex hull is tighter.
How does ST_ConvexHull handle collinear input?
If all input points lie on a line, the result is a LineString, not a polygon. For a single point or duplicate points, it returns a Point. Always check the output geometry type with ST_GeometryType if downstream code expects a polygon.
Does ST_ConvexHull respect the CRS?
It operates in the input's Cartesian coordinate space. For lat/lon data spanning large areas the result is only an approximation of the true geodesic hull — for global analyses, reproject to a suitable projected CRS or use geography functions where available.