I have the following table which contains coordinates of fields from a farm. I'm trying to create polygons using points coordinates as edges of those polygons.
CREATE TABLE field_point (
field_id VARCHAR(64) PRIMARY KEY,
point_latitude DOUBLE PRECISION,
point_longitude DOUBLE PRECISION,
point GEOMETRY(Point,4326),
);
I understand that by creating geometry points using latitude and longitude of each point.
I then collect the coordinates to create a point geometry in table field_point as such:
UPDATE field_point SET point = ST_Transform(ST_SetSRID(ST_MakePoint(point_longitude, point_latitude), 4326),4326);
Lastly, I collect the newly created point and run convex_hull function on another table called field to return polygons as such:
INSERT INTO field (polygon) SELECT ST_ConvexHull(ST_Collect(point)) FROM field_point GROUP BY field_id;
I'm now not able to bring the field_id from the first table. Could you help?
Expected resuld should be the following table
CREATE TABLE field (
field_id VARCHAR(64) PRIMARY KEY,
polygon GEOMETRY(polygon,4326),
);
one row should the polygon created from all points defining field_id from the field_point table.
Thanks!
Please use below query,
INSERT INTO field (field_id, polygon)
SELECT field_id, ST_ConvexHull(ST_Collect(point)) FROM field_point;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.