多边形
由一组封闭的线串标识的对象。多边形可能包含一个或多个由内部边界定义的孔,但所有点都必须保持连接状态。以下是两个多边形的示例:
包含性和独占性多边形
如果多边形以顺时针顺序将其点包括在内,则包含多边形边内的所有空间,排除边外的所有空间。如果多边形以逆时针顺序将其点包括在内,则排除多边形边内的所有空间,包含边外的所有空间。
示例
下面的示例使用 GEOMETRY 类型创建表,使用复制将多边形加载到表,然后查询表来查看多边形:
=> CREATE TABLE polygon_geom (gid int, geom GEOMETRY(1000));
CREATE TABLE
=> COPY polygon_geom(gid, gx filler LONG VARCHAR, geom AS ST_GeomFromText(gx)) FROM stdin delimiter '|';
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>>1|POLYGON(( 2 6, 2 9, 6 9, 7 7, 4 6, 2 6))
>>\.
=> SELECT gid, ST_AsText(geom) FROM polygon_geom;
gid | ST_AsText
-----+------------------------------------------
1 | POLYGON((2 6, 2 9, 6 9, 7 7, 4 6, 2 6))
(1 row)
下面的示例使用 GEOGRAPHY 类型创建表,使用 COPY 将多边形加载到表,然后查询表以查看多边形:
=> CREATE TABLE polygon_geog (gid int, geog GEOGRAPHY(1000));
CREATE TABLE
=> COPY polygon_geog(gid, gx filler LONG VARCHAR, geog AS ST_GeographyFromText(gx)) FROM stdin delimiter '|';
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>>1|POLYGON((42.1 71, 41.4 70, 41.3 72.9, 44.47 73.21, 42.99 71.46, 42.1 71))
>>\.
=> SELECT gid, ST_AsText(geog) FROM polygon_geog;
gid | ST_AsText
-----+---------------------------------------------------------------------------
1 | POLYGON((42.1 71, 41.4 70, 41.3 72.9, 44.47 73.21, 42.99 71.46, 42.1 71))
(1 row)