I have a database of around 100,000 postcodes each with lat/lon which I have converted to geom type in PostGIS. Each postcode also has one of 5 "regions". I wish to generate an accurate bounding polygon for each region, and have attempted to query it as so: select region, count(*), ST_AsGeoJSON(ST_ConvexHull(ST_Collect(geom))) from postcode group by region;

Despite the counts all being above 10,000 each, the resulting polygons are disappointingly simple and broad (e.g. around 10 sides only), with lots of overlaps.

Is there any way in PostGIS or other where I can achieve this goal of extracting highly detailed polygons? I need to do this because unfortunately the government body in question does not publish open data for these respective regions they have defined.

1 Answer 1


You may instead want to produce a Concave Hull (that is, replace ST_ConvexHull with ST_ConcaveHull as well as possibly experimenting with tweaking the second and third optional target_percent and allow_holes parameters). It may still be disappointingly simple depending on the target_percent you set, but it will most likely be closer to the ideal shape you are really looking to produce.

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.