STV_Extent
返回一个包含所有输入数据的边界框。
在嵌套查询中使用 STV_Extent 以获得最佳结果。OVER 子句必须为空。
重要
当输入为单点时,STV_Extent 不会返回有效的多边形。行为类型
不可变语法
STV_Extent( g )
参数
g
- 空间对象,类型为 GEOMETRY。
返回
GEOMETRY
支持的数据类型
- 数据类型
- GEOMETRY
- Point
- 是
- Multipoint
- 是
- Linestring
- 是
- Multilinestring
- 是
- Polygon
- 是
- Multipolygon
- 是
- GeometryCollection
- 是
示例
以下示例显示了如何使用 STV_Extent。
返回线串的边界框,并验证它是否是有效的多边形:
=> SELECT ST_AsText(geom) AS bounding_box, ST_IsValid(geom)
FROM (SELECT STV_Extent(ST_GeomFromText('LineString(0 0, 1 1)')) OVER() AS geom) AS g;
bounding_box | ST_IsValid
-------------------------------------+------------
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) | t
(1 row)
返回表中空间对象的边界框:
=> CREATE TABLE misc_geo_shapes (id IDENTITY, geom GEOMETRY);
CREATE TABLE
=> COPY misc_geo_shapes (gx FILLER LONG VARCHAR, geom AS ST_GeomFromText(gx)) FROM STDIN;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> POINT(-71.03 42.37)
>> LINESTRING(-71.058849 42.367501, -71.062240 42.371276, -71.067938 42.371246)
>> POLYGON((-71.066030 42.380617, -71.055827 42.376734, -71.060811 42.376011, -71.066030 42.380617))
>> \\.
=> SELECT ST_AsText(geom_col) AS bounding_box
FROM (SELECT STV_Extent(geom) OVER() AS geom_col FROM misc_geo_shapes) AS g;
bounding_box
------------------------------------------------------------------------------------------------------------------
POLYGON ((-71.067938 42.367501, -71.03 42.367501, -71.03 42.380617, -71.067938 42.380617, -71.067938 42.367501))
(1 row)