<#> — 返回 A 和 B 边界框之间的二维距离。
double precision <#>(
geometry A , geometry B )
;
<#>
运算符返回两个浮点边界框之间的距离,可能从空间索引中读取(需要 PostgreSQL 9.1+)。对于执行最近邻 近似 距离排序很有用。
此操作数将利用几何体上可能存在的任何索引。它与使用空间索引的其他运算符不同,因为空间索引仅在运算符位于 ORDER BY 子句中时使用。 |
索引仅在其中一个几何体是常量时才生效,例如 ORDER BY (ST_GeomFromText('POINT(1 2)') <#> geom) 而不是 g1.geom <#>。 |
可用性:2.0.0 -- KNN 仅适用于 PostgreSQL 9.1+
SELECT * FROM ( SELECT b.tlid, b.mtfcc, b.geom <#> ST_GeomFromText('LINESTRING(746149 2948672,745954 2948576, 745787 2948499,745740 2948468,745712 2948438, 745690 2948384,745677 2948319)',2249) As b_dist, ST_Distance(b.geom, ST_GeomFromText('LINESTRING(746149 2948672,745954 2948576, 745787 2948499,745740 2948468,745712 2948438, 745690 2948384,745677 2948319)',2249)) As act_dist FROM bos_roads As b ORDER BY b_dist, b.tlid LIMIT 100) As foo ORDER BY act_dist, tlid LIMIT 10; tlid | mtfcc | b_dist | act_dist -----------+-------+------------------+------------------ 85732027 | S1400 | 0 | 0 85732029 | S1400 | 0 | 0 85732031 | S1400 | 0 | 0 85734335 | S1400 | 0 | 0 85736037 | S1400 | 0 | 0 624683742 | S1400 | 0 | 128.528874268666 85719343 | S1400 | 260.839270432962 | 260.839270432962 85741826 | S1400 | 164.759294123275 | 260.839270432962 85732032 | S1400 | 277.75 | 311.830282365264 85735592 | S1400 | 222.25 | 311.830282365264 (10 rows)