ST_DWithin — 如果两个几何在给定距离内,则返回True
boolean ST_DWithin(
geometry g1, geometry g2, double precision distance_of_srid)
;
boolean ST_DWithin(
geography gg1, geography gg2, double precision distance_meters, boolean use_spheroid = true)
;
如果几何在给定距离内,则返回True
为 几何体 :距离以几何图形的空间参考系定义的单位指定。要使此函数有意义,源几何图形必须位于相同的坐标系中(具有相同的SRID)。
为 地理学 :单位以米为单位,距离测量默认为 use_spheroid
=真。用于更快的评估使用 use_spheroid
=False以在球体上测量。
![]() | |
使用 ST_3DDWithin 用于3D几何图形。 |
![]() | |
此函数调用包括一个边界框比较,它利用几何图形上可用的任何索引。 |
This method implements the OGC Simple Features
Implementation Specification for SQL 1.1.
可用性:引入了1.5.0地理位置支持
增强:2.1.0提高了地理位置的速度。看见 让地理操作更快捷 有关详细信息,请参阅。
增强:2.1.0引入了对曲线几何图形的支持。
在1.3之前, ST_Expand 通常与以下词结合使用 & & 和ST_Distance来测试距离,在1.3.4之前的版本中,此函数使用该逻辑。从1.3.4开始,ST_DWiThin使用更快的短路距离函数。
-- Find the nearest hospital to each school -- that is within 3000 units of the school. -- We do an ST_DWithin search to utilize indexes to limit our search list -- that the non-indexable ST_Distance needs to process -- If the units of the spatial reference is meters then units would be meters SELECT DISTINCT ON (s.gid) s.gid, s.school_name, s.geom, h.hospital_name FROM schools s LEFT JOIN hospitals h ON ST_DWithin(s.geom, h.geom, 3000) ORDER BY s.gid, ST_Distance(s.geom, h.geom); -- The schools with no close hospitals -- Find all schools with no hospital within 3000 units -- away from the school. Units is in units of spatial ref (e.g. meters, feet, degrees) SELECT s.gid, s.school_name FROM schools s LEFT JOIN hospitals h ON ST_DWithin(s.geom, h.geom, 3000) WHERE h.gid IS NULL; -- Find broadcasting towers that receiver with limited range can receive. -- Data is geometry in Spherical Mercator (SRID=3857), ranges are approximate. -- Create geometry index that will check proximity limit of user to tower CREATE INDEX ON broadcasting_towers using gist (geom); -- Create geometry index that will check proximity limit of tower to user CREATE INDEX ON broadcasting_towers using gist (ST_Expand(geom, sending_range)); -- Query towers that 4-kilometer receiver in Minsk Hackerspace can get -- Note: two conditions, because shorter LEAST(b.sending_range, 4000) will not use index. SELECT b.tower_id, b.geom FROM broadcasting_towers b WHERE ST_DWithin(b.geom, 'SRID=3857;POINT(3072163.4 7159374.1)', 4000) AND ST_DWithin(b.geom, 'SRID=3857;POINT(3072163.4 7159374.1)', b.sending_range);