PostGis 从距离线一定距离的多个表中查找点

PostGis find points from multiple tables in certain distance from line

我有三个 table 几何 "lines"、"points_a"、"points_b"。 我想要做的是从 "lines"

的 1.5 m 范围内的两个 table 中找到所有点

从一个 table 中找到点是没有问题的:

SELECT * from lines l 
JOIN points_a a ON (ST_DWithin(l.geom, a.geom, 1.5)

但我不知道如何添加第二个 table 点数。 当我添加 next Join 时,我得到:都在同一行缓冲区中的点,当只有其中一个是缓冲区时,我没有得到它们

这些行中的内容可以解决问题:

SELECT * from (select * from lines union all select * from lines2) l
JOIN points_a a ON (ST_DWithin(l.geom, a.geom, 1.5)

SELECT * from lines l1
JOIN points_a a ON (ST_DWithin(l1.geom, a.geom, 1.5)
union all
SELECT * from lines l2
JOIN points_a a ON (ST_DWithin(l2.geom, a.geom, 1.5)

此致,
比亚尼

只有当它们在两个缓冲区中时才获取它们的原因是您正在使用内部联接来创建此查询 - 这将排除任何 ON 子句为假的行。

您可以聚合 CTE(或子查询)中的点,并在其上加入:

WITH points AS (
  SELECT geom FROM points_a
  UNION ALL
  SELECT geom FROM points_b
)
SELECT
  *
FROM
  lines l 
JOIN
  points p ON ST_DWithin(l.geom, p.geom, 1.5)