I have a database with over 150 000 points in a EPSG 2950 projection. As I wanted to cluster those points in polygons, I used a ConvexHull fonction. The goal was to create clusters where I would find AT LEAST 5 points at a MAX DISTANCE of 75 meters from one to another.

The fonction I used was the following:

Select *
INTO new_table
 FROM (Select ST_ConvexHull
     (ST_ClusterWithin(geom, 75)))
      AS geom from my_table) sq
Where ST_NPoints(geom) >= 5

The fonction worked really well but now I would like to try to have clusters where the perimeter is a bit more representative of the points inside (The convexHull can leave big gaps where there is no points).

To do so I tried replacing the ConvexHull fonction for a ConcaveHull one:

Select *
INTO new_table
 FROM (Select ST_ConcaveHull
    (ST_Collect(unnest(ST_ClusterWithin(geom, 75), 0.70)))
      AS geom my_table) sq 
Where ST_NPoints(geom) >= 5

This specific function returned the following error...

ERROR: the function unnest(geometry[], numeric) doesn't exist LINE 4: (ST_Collect(unnest(ST_ClusterWithin(geom, 75), 0.70)))

I have tried some variants (as using the ConcaveHull function before the FROM clause) but the closest I got was getting 1 ConcaveHull over ALL my points and therefore ignoring the constraint of having AT LEAST 5 points at a MAX DISTANCE of 75 m.

Any ideas to solve my problem?

  • What was the error? – dbaston Jun 21 '16 at 17:51
  • I have edited the question with the error. – Alex Girard Jun 21 '16 at 18:07
  • Try to create triangles from the points (ST_DelaunayTriangles) and unite (ST_Union) along the longest side of the triangles. – Zoltan Jun 21 '16 at 18:12
  • There you go - mismatched parentheses. – dbaston Jun 21 '16 at 18:48
  • Yes you are right, but I tried to correct the said error and can't find the correct way to do so – Alex Girard Jun 22 '16 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.