I'm using Postgres 9.4 with PostGIS 2.1. I have a table with the following columns:

    Column    |          Type                 
 ogc_fid      | integer                
 wkb_geometry | geometry(Polygon,4326) 
 plot_id      | integer               
 org          | character varying      

I want to get all the polygons relating to a particular organisation, draw the convex hull around them, then calculate the area of that convex hull.

I've tried this query:

 SUM(ST_AREA(ST_CONCAVEHULL(wkb_geometry, 0.1)::geography)) AS area
 FROM mytable
 WHERE org='myorg'

But it seems to be first finding the convex hull of each individual polygon, then adding together the areas. This is not what I want.

How can I edit this query to first find the convex hull of the entire polygon set, and only then calculate the area?


You are missing a union call and also 0.1 is pretty low for a concave hull, try something like 0.7. (that is really the shrink parameter so 0.1 would be like target to 10% of convexhull area. The smaller the value the longer the processing and more likely you'll run into invalid geometry)

  SUM(ST_AREA(ST_CONCAVEHULL(ST_Union(wkb_geometry), 0.7)::geography)) AS area
FROM mytable
WHERE org='myorg';
  • 1
    I suppose that there is only one concave hull because of UNION so SUM is unnecessary, but it does not make any harm. – user30184 Apr 17 '16 at 21:25
  • correct you can get rid of the sum. Also did you want ST_ConcaveHull or ST_ConvexHull? ST_ConvexHull is a much faster process. – LR1234567 Apr 17 '16 at 21:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.