Reputation: 29
I need to be able to create a table and store a few x,y co-ordinates as a geometry and then be able to generate a convex hull for these points.
This is what I have so far
CREATE TABLE global_points (
id SERIAL PRIMARY KEY,
name VARCHAR(64),
location GEOMETRY(POINT,4326));
But I'm not too sure about it. How do I insert my collection x,y co-ordinates to this table and then generate a convex hull for this geometry?
Need to do this using potsgis spatial database extension for postgres
Upvotes: 0
Views: 2561
Reputation: 313
You should give more information about the way you want to add points to your table. Here is an example with some random points.
1) Insert data into your table
--insert points using geographical coordinates
INSERT INTO global_points (name, location) VALUES
('point1', ST_SetSRID(ST_MakePoint(-5, 25), 4326)),
('point2', ST_SetSRID(ST_MakePoint(1.2, -2.3), 4326)),
('point3', ST_SetSRID(ST_MakePoint(5.3, 21), 4326)),
('point4', ST_SetSRID(ST_MakePoint(2, 12), 4326));
2) Compute the convex hull from a collection of points
--get the convex hull
SELECT ST_ConvexHull(ST_Collect(location)) AS convex_hull
FROM global_points;
Upvotes: 3