I'm trying to create convex hull for about 25000 points stored in the table. ST_ConvexHull run successfully, but resulting geometry does not covers some points.

What could be a reason?

And it is not problem of points falling exactly on boundary. The example shows the problem in GIS viewer for two specific points quite far away from the hull.

select ST_ConvexHull(ST_Collect(ARRAY(select st_setsrid(point(stop_lon,stop_lat)::geometry, 4326)
                                      from gtfs_stops
select st_setsrid(point(stop_lon,stop_lat)::geometry, 4326)
from gtfs_stops
where stop_code in ('10798', '10498')


  • 2
    On a side note, use ST_MakePoint instead of point (which is not a Postgis type, but rather the native Posgres geometric type) – JGH May 13 at 13:24
  • Doesn't cast to ::geometry take care of the conversion? But yes, certainly easier to debug by using direct PostGIS geometries. – user30184 May 13 at 14:56
  • You may well need to convert to a "flat" projection or use Geography points instead of treating epsg:4326 as a flat plane – Ian Turton May 13 at 16:39

ST_ConvexHull is a geometry calcul. It works on a plan. By giving it 4326 data you will certainly have unexpected results, for example your 2 points must be inside your polygon if you display your points and your polygon in a cartesian plan, they are outside because the 4326 spheroïde is definitely not a plan. The larger your area is, and the highest latitude it is, the more problems you will have, especially with oblique lines and if your area is vertically big.

You should first project (using ST_Transform) your points using a suitable local projection, like the country's official projection for example, or a local UTM, or at least if your area is really large the 3857 projection. Be sure to use the same projection for all your points. You can project back in 4326 your result after.

| improve this answer | |

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.