I want to create a polygon table using PostGIS. Each row in table 'point
' has three-point ID.
Table 'point_location
' has the location information of points. I googled this question but did not find the answer. What's wrong with the following code?
SELECT ST_GeomFromText('POLYGON((' || b.x || ' ' || b.y || ',' || c.x || ' ' || c.y || ',' || d.x || ' ' || d.y || ',' || b.x || ' ' || b.y'))',4326)
AS polygon
FROM point a, point_location b, point_location c, point_location d
WHERE a.p1=b.point_id AND a.p2=c.point_id AND a.p3=d.point_id
geometry. Polygon to simply convert to line string to a polygon. It will connect the first and last coordinates. Try Polygon([(0, 0), (1, 1), (1, 2), (0, 1)]) or Polygon(s1) to produce POLYGON ((0 0, 1 1, 1 2, 0 1, 0 0)).
Well-Known Text (WKT)
A MULTIPOLYGON is a collection of Polygons. MultiPolygons are useful for gathering a group of Polygons into one geometry. For example, you may want to gather the Polygons denoting a group of properties in a particular municipality.
An SRID indicates coordinates of data. For example: Supported SRIDs can be queried from PostGIS, such as query coordinates related to Beijing and China. postgres=# select * from spatial_ref_sys where srtext ~* 'beijing'; postgres=# select * from spatial_ref_sys where srtext ~* 'china';
A better way to construct a polygon from points is to use PostGIS' geometry constructors. This way, you avoid the need to convert binary → text → binary (WKB → WKT → WKB), which is slower, lossy, and is prone to text formatting distractions as evidenced by the missing ||
. For example, try:
SELECT ST_MakePolygon(ST_MakeLine(ARRAY[b, c, d, b]))
FROM point a, point_location b, point_location c, point_location d
WHERE a.p1=b.point_id and a.p2=c.point_id and a.p3=d.point_id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With