暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

金仓数据库 KingbaseGIS 使用手册(6.17. 边界框函数)

数据猿 2022-08-12
468

6.17. 边界框函数

6.17.1. Box2D

Box2D — 返回一个几何对象的最大扩展 BOX2D 对象

用法

box2d Box2D(geometry geomA);

描述

返回一个几何对象的最大扩展 BOX2D 对象

  • 该函数支持 CircularString 和 Curve 几何类型对象

  • 该函数支持 Polyhedral Surface 类型几何对象.

  • 该函数支持 Triangles 和 Triangulated Irregular Network Surfaces (TIN) 类型.

样例

SELECT Box2D(ST_GeomFromText('LINESTRING(1 2, 3 4, 5 6)'));

box2d
---------
BOX(1 2,5 6)

SELECT Box2D(ST_GeomFromText('CIRCULARSTRING(220268 150415,220227 150505,220227 150406)'));

box2d
--------
BOX(220186.984375 150406,220288.25 150506.140625)

参考

Box3D, ST_GeomFromText

6.17.2. Box3D

Box3D — 返回一个几何对象的最大扩展 BOX3D 对象

用法

box3d Box3D(geometry geomA);

描述

返回一个几何对象的最大扩展 BOX3D 对象

  • 该函数支持 CircularString 和 Curve 几何类型对象

  • 该函数支持 Polyhedral Surface 类型几何对象.

  • 该函数支持 Triangles 和 Triangulated Irregular Network Surfaces (TIN) 类型.

  • 这个函数支持 3D 对象,并且不会删除 z 坐标

样例

SELECT Box3D(ST_GeomFromEWKT('LINESTRING(1 2 3, 3 4 5, 5 6 5)'));

Box3d
---------
BOX3D(1 2 3,5 6 5)

SELECT Box3D(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 1,220227 150406 1)'));

Box3d
--------
BOX3D(220227 150406 1,220268 150415 1)

参考

Box2D, ST_GeomFromEWKT

6.17.3. ST_EstimatedExtent

ST_EstimatedExtent — 返回一个给定的空间类型的估算 box2d 对象。该估算是基于对几何类型列的统计。如果没有指定 schema,使用当前 current_schema () 对应的值

用法

box2d ST_EstimatedExtent(text schema_name, text table_name, text geocolumn_name);
box2d ST_EstimatedExtent(text table_name, text geocolumn_name);

描述

返回一个给定的空间类型的估算 box2d 对象。该估算是基于对几何类型列的统计。如果没有指定 schema,使用当前 current_schema () 对应的值。

对于 KingbaseES 版本中,该函数统计是基于 VACUUM ANALYZE,统计的长度大概是实际的 95%

注意

如果没有统计(空表或者没有调用 ANALYZE 进程),该函数会返回 NULL,这种情况会抛出一个异常对于 KingbaseES 统计是基于 update_geometry_stats () 的结果,返回的结果是精确的。

  • 该函数支持 CircularString 和 Curve 几何类型对象

样例

SELECT ST_EstimatedExtent('ny', 'edges', 'the_geom');
--result--
BOX(-8877653 4912316,-8010225.5 5589284)

SELECT ST_EstimatedExtent('feature_poly', 'the_geom');
--result--
BOX(-124.659652709961 24.6830825805664,-67.7798080444336 49.0012092590332)

参考

ST_Extent

6.17.4. ST_Expand

ST_Expand — 根据输入几何对象的 bounding box 返回一个向各个方向扩展的 bounding box。输出对象的坐标精度使用双精度

用法

geometry ST_Expand(geometry g1, float units_to_expand);
box2d ST_Expand(box2d g1, float units_to_expand);
box3d ST_Expand(box3d g1, float units_to_expand);

描述

根据输入几何对象的 bounding box 返回一个向各个方向扩展的 bounding box,输出对象的坐标精度使用双精精度。对于距离查询或者 bounding box 查询很有用的,因为它可以添加一个索引来对进行查询过滤。 该函数有 3 种形式。输入对象是 geometry 类型的,会返回一个表示 bounding box 的 POLYGON 类型对象,是最常用的一种形式。 函数 ST_Expand 在概念上和函数 ST_Buffer 很类似,但区别是对几何对象进行各个方向扩展时候,函数 ST_Expand 是扩展 bounding box 所对应的 x,y,z 坐标一个指定的单位。单位按照 SRID 所对应空间参考系所规定的单位.

注意

在 1.3 之前,函数 ST_Expand 通常用于在距离查询中,让索引可用。例如如下查询 the_geom && ST_Expand ('POINT (10 20)', 10) AND ST_Distance (the_geom, 'POINT (10 20)') < 10 Post 1.2,该查询用 ST_DWithin 构建的查询更简单

  • 该函数支持 Polyhedral Surface 类型几何对象.

  • 该函数支持 Triangles 和 Triangulated Irregular Network Surfaces (TIN) 类型.

样例

注意

下面的样例是使用 US National Atlas Equal Area (SRID=2163) 坐标系

--10 meter expanded box around bbox of a linestring
SELECT CAST(ST_Expand(ST_GeomFromText('LINESTRING(2312980 110676,2312923 110701,2312892 110714)', 2163),10) As box2d);

st_expand
------------------------------------
BOX(2312882 110666,2312990 110724)

--10 meter expanded 3d box of a 3d box
SELECT ST_Expand(CAST('BOX3D(778783 2951741 1,794875 2970042.61545891 10)' As box3d),10);

st_expand
-----------------------------------------------------
BOX3D(778773 2951731 -9,794885 2970052.61545891 20)

--10 meter geometry astext rep of a expand box around a point geometry
SELECT ST_AsEWKT(ST_Expand(ST_GeomFromEWKT('SRID=2163;POINT(2312980 110676)'),10));

st_asewkt
-----------------------------------------------------------------------------------------------
SRID=2163;POLYGON((2312970 110666,2312970 110686,2312990 110686,2312990 110666,2312970 110666))

参考

ST_AsEWKT, ST_Buffer, ST_DWithin, ST_GeomFromEWKT, ST_GeomFromText, ST_SRID

6.17.5. ST_Extent

ST_Extent — 一个返回包含多个 geometry 对象的 bounding box 的聚集函数

用法

box2d ST_Extent(geometry set geomfield);

描述

一个返回包含多个 geometry 对象的 bounding box 的聚集函数。该函数是聚合函数意味着,对于多行的数据,该函数的作用方式会像 SQL 里面的聚合函数 SUM () and AVG () 一样。由于该函数返回 bounding box,空间单位以 SRID 对应的参考系所规定的单位 ST_Extent is 函数对应 Oracle Oracle Spatial/Locator 中的函数 SDO_AGGR_MBR

注意

因为函数 ST_3Dextent 返回一个 bounding box,但 SRID 值会被丢掉,使用函数 ST_SetSRID 函数重新把 SRID 值写进该几何对象中去。空间单位以 SRID 对应的参考系所规定的单位。

注意

ST_Extent 函数返回的 bounding box 值包含 x 和 y 坐标,即便输入对象是 (x,y,z) 形式的坐标。如果想返回 x,y,z 形式的 3 维坐标,使用函数 ST_3DExtent instead.

  • 该函数支持 Polyhedral Surface 类型几何对象.

  • 该函数支持 Triangles 和 Triangulated Irregular Network Surfaces (TIN) 类型.

样例

样例 below use Massachusetts State Plane ft (SRID=2249)

SELECT ST_Extent(the_geom) as bextent FROM sometable;

st_bextent
------------------------------------
BOX(739651.875 2908247.25,794875.8125 2970042.75)

--Return extent of each category of geometries
SELECT ST_Extent(the_geom) as bextent
FROM sometable
GROUP BY category ORDER BY category;

bextent                                            |name
---------------------------------------------------+----------------
BOX(778783.5625 2951741.25,794875.8125 2970042.75) | A
BOX(751315.8125 2919164.75,765202.6875 2935417.25) | B
BOX(739651.875 2917394.75,756688.375 2935866)      | C

--Force back into a geometry
-- and render the extended text representation of that geometry
SELECT ST_SetSRID(ST_Extent(the_geom),2249) as bextent
FROM sometable;

bextent
--------------------------------------------------------------------------------------
SRID=2249;POLYGON((739651.875 2908247.25,739651.875 2970042.75,794875.8125 2970042.75,
794875.8125 2908247.25,739651.875 2908247.25))

参考

ST_AsEWKT, ST_3DExtent, ST_SetSRID, ST_SRID

6.17.6. ST_3DExtent

ST_3DExtent — 一个返回包含多个 geometry 对象的 3D bounding box 的聚集函数

用法

box3d ST_3DExtent(geometry set geomfield);

描述

一个返回包含多个 geometry 对象的 3D bounding box(包含 Z 坐标)的聚集函数。该函数是聚合函数意味着,对于多行的数据,该函数的作用方式会像 SQL 里面的聚合函数 SUM () and AVG () 一样。由于该函数返回 bounding box,空间单位以 SRID 对应的参考系所规定的单位

注意

因为函数 ST_3Dextent 返回一个 bounding box,但 SRID 值会被丢掉,使用函数 ST_SetSRID 函数重新把 SRID 值写进该几何对象中去。

空间单位以 SRID 对应的参考系所规定的单位

  • 这个函数支持 3D 对象,并且不会删除 z 坐标

  • 该函数支持 CircularString 和 Curve 几何类型对象

  • 该函数支持 Polyhedral Surface 类型几何对象.

  • 该函数支持 Triangles 和 Triangulated Irregular Network Surfaces (TIN) 类型.

样例

SELECT ST_3DExtent(foo.the_geom) As  b3extent
FROM (SELECT ST_MakePoint(x,y,z) As  the_geom
FROM generate_series(1,3) As x
CROSS JOIN generate_series(1,2) As  y
CROSS JOIN generate_series(0,2)
As Z) As foo;

b3extent
--------------------
BOX3D(1 1 0,3 2 2)

--Get the extent of various elevated circular strings
SELECT ST_3DExtent(foo.the_geom) As b3extent
FROM (SELECT ST_Translate(ST_Force3DZ(ST_LineToCurve(ST_Buffer(ST_MakePoint(x,y),1))),0,0,
z) As the_geom
FROM generate_series(1,3) As x
CROSS JOIN generate_series(1,2) As y
CROSS JOIN generate_series(0,2) As Z) As foo;

b3extent
--------------------
BOX3D(1 0 0,4 2 2)

参考

ST_Extent, ST_Force3DZ

6.17.7. ST_MakeBox2D

ST_MakeBox2D — 根据给定的 point 几何类型创建 BOX2D 对象

用法

box2d ST_MakeBox2D(geometry pointLowLeft, geometry pointUpRight);

描述

根据给定的 point 几何类型创建 BOX2D 对象,该函数对范围查询很有用。

样例

--Return all features that fall reside or partly reside in a US national atlas coordinate bounding box
--It is assumed here that the geometries are stored with SRID = 2163 (US National atlas equal area)
SELECT feature_id, feature_name, the_geom
FROM features
WHERE the_geom && ST_SetSRID(ST_MakeBox2D(ST_Point(-989502.1875, 528439.5625),
  ST_Point(-987121.375 ,529933.1875)),2163)

参考

ST_MakePoint, ST_Point, ST_SetSRID, ST_SRID

6.17.8. ST_3DMakeBox

ST_3DMakeBox — 根据 3D 类型的 point 几何类型创建 BOX3D 对象。

用法

box3d ST_3DMakeBox(geometry point3DLowLeftBottom, geometry point3DUpRightTop);

描述

根据 3D 类型的 point 几何类型创建 BOX3D 对象.

  • 这个函数支持 3D 对象,并且不会删除 z 坐标。

样例

SELECT ST_3DMakeBox(ST_MakePoint(-989502.1875, 528439.5625, 10),
ST_MakePoint(-987121.375 ,529933.1875, 10)) As abb3d

--bb3d--
----------------------------------------------------------------
BOX3D(-989502.1875 528439.5625 10,-987121.375 529933.1875 10)

参考

ST_MakePoint, ST_SetSRID, ST_SRID

6.17.9. ST_XMax

ST_XMax — 返回 2d 或 3d 的 bounding box 或一个几何对象的 X 最大值

用法

float ST_XMax(box3d aGeomorBox2DorBox3D);

描述

返回 2d 或 3d 的 bounding box 或一个几何对象的 X 最大值.

注意

虽然该函数是为 box3d 而定义的,但这个函数也支持 box2d 和 geometry 类型对象,因为这两种对象可以自动转换成 box3d 类型。然而不能用 WKT 表述的 geometry 或 box2d 对象传递进去,因为这种情况下不能做自动转换成 box3d 类型

样例

SELECT ST_XMax('BOX3D(1 2 3, 4 5 6)');

st_xmax
-------
4

SELECT ST_XMax(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'));

st_xmax
-------
5

SELECT ST_XMax(CAST('BOX(-3 2, 3 4)' As box2d));

st_xmax
-------
3

--Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D
SELECT ST_XMax('LINESTRING(1 3, 5 6)');

--ERROR: BOX3D parser - doesnt start with BOX3D(

SELECT ST_XMax(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));

st_xmax
--------
220288.248780547

参考

ST_XMin , ST_YMax , ST_YMin , ST_ZMax , ST_ZMin

6.17.10. ST_XMin

ST_XMin — 返回 bounding box 或者 2d 或 3d 或 geometry 的 X 方向范围的最小值

用法

float ST_XMin(box3d aGeomorBox2DorBox3D);

描述

返回 bounding box 或者 2d 或 3d 或 geometry 的 X 方向范围的最小值.

注意

虽然该函数是为 box3d 而定义的,但这个函数也支持 box2d 和 geometry 类型对象,因为这两种对象可以自动转换成 box3d 类型。然而不能用 WKT 表述的 geometry 或 box2d 对象传递进去,因为这种情况下不能做自动转换成 box3d 类型

  • 这个函数支持 3D 对象,并且不会删除 z 坐标

  • 该函数支持 CircularString 和 Curve 几何类型对象

样例

SELECT ST_XMin('BOX3D(1 2 3, 4 5 6)');

st_xmin
-------
1

SELECT ST_XMin(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'));

st_xmin
------
1

SELECT ST_XMin(CAST('BOX(-3 2, 3 4)' As box2d));

st_xmin
--------
3

--Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D
SELECT ST_XMin('LINESTRING(1 3, 5 6)');

--ERROR: BOX3D parser - doesnt start with BOX3D(

SELECT ST_XMin(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));

st_xmin
--------
220186.995121892

参考

ST_XMax , ST_YMax , ST_YMin , ST_ZMax , ST_ZMin

6.17.11. ST_YMax

ST_YMax — 返回 bounding box 或者 2d 或 3d 或 geometry 的 Y 方向范围的最大值.

用法

float ST_YMax(box3d aGeomorBox2DorBox3D);

描述

返回 bounding box 或者 2d 或 3d 或 geometry 的 Y 方向范围的最大值.

注意

虽然该函数是为 box3d 而定义的,但这个函数也支持 box2d 和 geometry 类型对象,因为这两种对象可以自动转换成 box3d 类型。然而不能用 WKT 表述的 geometry 或 box2d 对象传递进去,因为这种情况下不能做自动转换成 box3d 类型

  • 这个函数支持 3D 对象,并且不会删除 z 坐标

  • 该函数支持 CircularString 和 Curve 几何类型对象

样例

SELECT ST_YMax('BOX3D(1 2 3, 4 5 6)');

st_ymax
-------
5

SELECT ST_YMax(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'));

st_ymax
-------
6

SELECT ST_YMax(CAST('BOX(-3 2, 3 4)' As box2d));

st_ymax
-------
4

--Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D
SELECT ST_YMax('LINESTRING(1 3, 5 6)');

--ERROR: BOX3D parser - doesnt start with BOX3D(

SELECT ST_YMax(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));

st_ymax
--------
150506.126829327

参考

ST_XMin, ST_XMax, ST_YMin, ST_ZMax, ST_ZMin

6.17.12. ST_YMin

ST_YMin — 返回 bounding box 或者 2d 或 3d 或 geometry 的 Y 方向范围的最小值.

用法

float ST_YMin(box3d aGeomorBox2DorBox3D);

描述

返回 bounding box 或者 2d 或 3d 或 geometry 的 Y 方向范围的最小值.

注意

虽然该函数是为 box3d 而定义的,但这个函数也支持 box2d 和 geometry 类型对象,因为这两种对象可以自动转换成 box3d 类型。然而不能用 WKT 表述的 geometry 或 box2d 对象传递进去,因为这种情况下不能做自动转换成 box3d 类型.

  • 这个函数支持 3D 对象,并且不会删除 z 坐标

  • 该函数支持 CircularString 和 Curve 几何类型对象

样例

SELECT ST_YMin('BOX3D(1 2 3, 4 5 6)');

st_ymin
-------
2

SELECT ST_YMin(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'));

st_ymin
-------
3

SELECT ST_YMin(CAST('BOX(-3 2, 3 4)' As box2d));

st_ymin
-------
2

--Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D
SELECT ST_YMin('LINESTRING(1 3, 5 6)');

--ERROR: BOX3D parser - doesnt start with BOX3D(

SELECT ST_YMin(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));

st_ymin
--------
150406

参考

ST_GeomFromEWKT , ST_XMin , ST_XMax , ST_YMax , ST_ZMax , ST_ZMin

6.17.13. ST_ZMax

ST_ZMax — 返回 bounding box 或者 2d 或 3d 或 geometry 的 Z 方向范围的最大值。

用法

float ST_ZMax(box3d aGeomorBox2DorBox3D);

描述

返回 bounding box 或者 2d 或 3d 或 geometry 的 Z 方向范围的最大值.

注意

虽然该函数是为 box3d 而定义的,但这个函数也支持 box2d 和 geometry 类型对象,因为这两种对象可以自动转换成 box3d 类型。然而不能用 WKT 表述的 geometry 或 box2d 对象传递进去,因为这种情况下不能做自动转换成 box3d 类型.

  • 这个函数支持 3D 对象,并且不会删除 z 坐标

  • 该函数支持 CircularString 和 Curve 几何类型对象

样例

SELECT ST_ZMax('BOX3D(1 2 3, 4 5 6)');

st_zmax
-------
6

SELECT ST_ZMax(ST_GeomFromEWKT('LINESTRING(1 3 4, 5 6 7)'));

st_zmax
-------
7

SELECT ST_ZMax('BOX3D(-3 2 1, 3 4 1)' );

st_zmax
-------
1

--Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D

SELECT ST_ZMax('LINESTRING(1 3 4, 5 6 7)');
--ERROR: BOX3D parser - doesnt start with BOX3D(

SELECT ST_ZMax(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));

st_zmax
--------
3

参考

ST_GeomFromEWKT , ST_XMin , ST_XMax , ST_YMax , ST_YMin , ST_ZMax

6.17.14. ST_ZMin

ST_ZMin — 返回 bounding box 或者 2d 或 3d 或 geometry 的 Z 方向范围的最小值

用法

float ST_ZMin(box3d aGeomorBox2DorBox3D);

描述

返回 bounding box 或者 2d 或 3d 或 geometry 的 Z 方向范围的最小值

注意

虽然该函数是为 box3d 而定义的,但这个函数也支持 box2d 和 geometry 类型对象,因为这两种对象可以自动转换成 box3d 类型。然而不能用 WKT 表述的 geometry 或 box2d 对象传递进去,因为这种情况下不能做自动转换成 box3d 类型.

  • 这个函数支持 3D 对象,并且不会删除 z 坐标

  • 该函数支持 CircularString 和 Curve 几何类型对象

样例

SELECT ST_ZMin('BOX3D(1 2 3, 4 5 6)');

st_zmin
-------
3

SELECT ST_ZMin(ST_GeomFromEWKT('LINESTRING(1 3 4, 5 6 7)'));

st_zmin
-------
4

SELECT ST_ZMin('BOX3D(-3 2 1, 3 4 1)' );

st_zmin
-------
1

--Observe THIS DOES NOT WORK because it will try to autocast the string representation to a BOX3D

SELECT ST_ZMin('LINESTRING(1 3 4, 5 6 7)');
--ERROR: BOX3D parser - doesnt start with BOX3D(

SELECT ST_ZMin(ST_GeomFromEWKT('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'));

st_zmin
--------
1

参考

ST_GeomFromEWKT , ST_GeomFromText , ST_XMin , ST_XMax , ST_YMax , ST_YMin , ST_ZMax

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论