文档

ST_DWithin

更新时间:

如果两个对象之间的距离在指定范围之内,则返回True。

语法

boolean ST_DWithin(geometry g1 , geometry g2 , double precision distanceOfSrid);
boolean ST_DWithin(geography gg1 , geography gg2 , double precision distanceMeters);
boolean ST_DWithin(geography gg1 , geography gg2 , double precision distanceMeters , boolean useSpheroid);

参数

参数名称

描述

g1

第一个Geometry对象。

g2

第二个Geometry对象。

distanceOfSrid

在源数据SRID下的距离。

gg1

第一个Geography对象。

gg2

第二个Geography对象。

distanceMeters

单位为米的距离值。

useSpheroid

是否使用椭球参考系。使用椭球参考系会使得结果更精确但稍慢。

描述

  • 对于Geometry对象,两个对象的SRID必须一致才使得函数有意义。

  • 对于Geography对象,默认使用米为单位。

  • 该函数调用时将自动包括外包框比较,该比较将利用Geometry对象上可用的任何索引。

  • 对于3D对象,需要使用ST_3DDWithin

示例

对比ST_DFullyWithin

SELECT ST_DFullyWithin(g1,g2,2), ST_DWithin(g1,g2,2) from (SELECT 'LINESTRING(0 1,1 1)'::geometry as g1,
                                                                           'LINESTRING(0 0,0 -1)'::geometry as g2) as test;
 st_dfullywithin | st_dwithin
-----------------+------------
 f               | t
(1 row)
                
  • 本页导读 (1)
文档反馈