我遇到一个空间(Oracle)查询问题。 简要概述了问题:
我有两张桌子:
CREATE TABLE thin_lines (
id NUMBER PRIMARY KEY,
geom SDO_GEOMETRY),
color VARCHAR2(32);
CREATE TABLE thick_lines (
id NUMBER PRIMARY KEY,
geom SDO_GEOMETRY),
color VARCHAR2(32);
两个表都包含2D线。 示例图片:
问题:
我想创建SQL查询或PL / SQL程序来查找连接到粗绿线的所有蓝色细线(包括蓝线的整个蓝色分支)的ID。
感谢您的协助。
答案 0 :(得分:0)
您应该查看Oracle Spatial Data Type和SDO_INTERSECTION。
我没有对此进行测试,但可能无效;但它应该是一个有用的起点:
DECLARE
type intersecting_blue_line is table of NUMBER;
RT_GL thick_lines%ROWTYPE;
CURSOR get_GreenLines IS
SELECT *
FROM thick_lines TKL
WHERE TKL.color = 'Green';
BEGIN
OPEN get_GreenLines;
LOOP
FETCH get_GreenLines INTO RT_GL;
for x in (SELECT TNL.id,
FROM thin_lines TNL
WHERE TNL.color = 'Blue'
AND SDO_GEOM.SDO_INTERSECTION(RT_GL.geom, TNL.geom, 0.005) IS NOT NULL;)
LOOP
intersecting_blue_line := x.id;
END LOOP;
END LOOP;
CLOSE get_tables;
END;
SELECT * FROM intersecting_blue_line;
答案 1 :(得分:0)
我找到了一个使用一个查询(Oracle 11.2)执行此操作的解决方案:
WITH recursive (p1, p2) AS (
SELECT thin.connection_id, thin.geom FROM thin_lines thin, thick_lines thick
WHERE sdo_touch(thin.geom, thick.geom) = 'TRUE' AND thick.color = 'green' AND thin.color = 'blue'
UNION ALL
SELECT thin.connection_id, thin.geom FROM thin_lines thin, recursive r
WHERE sdo_touch(thin.geom, r.p2) = 'TRUE' and thin.color='blue'
)
CYCLE p1 SET is_cycle TO 1 DEFAULT 0
SELECT distinct p1 FROM recursive order by p1;
它可以工作,但适用于细小的粗线条。对于巨大的设置,它对我来说无法使用。