This topic describes the ST_ConcaveHull function. This function returns the concave hull of the input geometry objects.

Syntax

geometry  ST_ConcaveHull(geometry  geomA , float  targetPercent , boolean  allowHoles);

Parameters

Parameter Description
geomA The geometry object that you want to specify.
targetPercent The percent of the area of the concave hull to the area of the convex hull before the ST_ConcaveHull function returns the result.
allowHoles Specifies whether the ST_ConcaveHull function allows a polygon object with holes. Default value: false.

Description

  • The dimension of the returned concave hull is not higher than the dimension of the input polygon object.
  • If you specify point objects, LineString objects, or GeometryCollection objects, use the ST_Collect function. If you specify polygon objects, use the ST_Union function. If you specify invalid geometry objects, the ST_ConcaveHull function fails.
  • A small value of the targetPercent parameter indicates that a long period of time is required to return the concave hull. A small value also increases the possibilities of topology exceptions. However, a small value allows the function to return a more precise concave hull. Suggestions on the configuration of the targetPercent parameter:
    • Set the targetPercent parameter to 0.99. In this case, the ST_ConcaveHull function returns the concave hull in a short period of time. In some scenarios, the function returns the result as fast as calculating the convex hull. In most cases, the proportion of the area of the concave hull to the area of the convex hull is smaller than 99%.
    • Try a value that is smaller than 0.99 to find the most appropriate value. The smaller the value, the longer the response time.
  • If you want to reduce the precision of the return value, you can use the ST_SimplifyPreserveTopology function or the ST_SnapToGrid function to process the results that are returned by the ST_ConcaveHull function. In most cases, the ST_SnapToGrid runs faster than the ST_SimplifyPreserveTopology function because the ST_SimplifyPreserveTopology function needs to verify the validity of the returned results. However, the ST_SnapToGrid function may return invalid geometry objects.
  • In most cases, the ST_ConcaveHull function is used for MULTI and GeometryCollection objects. The ST_ConcaveHull function is not an aggregate function. If you want to obtain the concave hull of a set of point objects, LineString objects, or polygon objects, you can use this function with the ST_Collect function or the ST_Union function. Example: ST_ConcaveHull(ST_Collect(somepointfield),0.80).
  • This function runs faster when it calculates the convex hull of input geometry objects than when it calculates the concave hull. However, the ST_ConcaveHull function encloses all the input geometry objects better and is useful for image recognition.

Examples

Comparison among the original object, the object returned with the targetPercent parameter set to 0.99, and the object returned with the targetPercent parameter set to 0.98:
SELECT g,ST_ConcaveHull(g,0.99),ST_ConcaveHull(g,0.98),g from
    (select 'MULTIPOLYGON(((0 0,1 0,1 1,0 1,0 0)),((0 6,6 3,6 6,0 6)))'::geometry as g) as test
123