Created
August 4, 2017 13:55
-
-
Save cblanc/266c4eebc9c0722453dda07d6e7c3d48 to your computer and use it in GitHub Desktop.
Computing Hulls from a List of Geometries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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