Skip to content

Instantly share code, notes, and snippets.

@cblanc
Created August 4, 2017 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cblanc/266c4eebc9c0722453dda07d6e7c3d48 to your computer and use it in GitHub Desktop.
Save cblanc/266c4eebc9c0722453dda07d6e7c3d48 to your computer and use it in GitHub Desktop.
Computing Hulls from a List of Geometries
-- Compute Convex Hull for a list of geolocations matching the outcode 'SW1A'
SELECT
ST_AsText(ST_ConvexHull(ST_Collect(location::geometry))) AS hull
FROM
postcodes
WHERE
outcode = 'SW1A';
-- Compute Concave Hull for a list of geolocations matching the outcode 'SW1A'
-- Little bit more expensive but the polygons are a "tighter fit", the more you increase the second parameter the "tightness" increases but so does computational work required
SELECT
ST_AsText(ST_ConcaveHull(ST_Collect(location::geometry), 0.99)) AS hull
FROM
postcodes
WHERE
outcode = 'AB10';
-- Create a table of outcode and associated convex hulls
CREATE TABLE outcode_hulls
AS SELECT
outcode,
ST_ConvexHull(ST_Collect(location::geometry)) AS convex_hull
FROM
postcodes
GROUP BY
postcodes.outcode;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment