[英]How to check if point geometry from table 1 exist to line geometry from table 2 in spatial sql query
I have two tables, table 1 is valve - POINT geometry我有两张表,表 1 是阀门 - POINT 几何
table 2 is tbline - LINE geometry.表 2 是 tbline - LINE 几何。 I need to get the valve_id from valve if valve.geometry exists in tbline.geometry and I need to identify which point do valve_id positioned its either startpoint or EndPoint?
如果 tbline.geometry 中存在 Valve.geometry,我需要从 Valve 获取 Valve_id,并且我需要确定 Valve_id 定位其起点或终点的哪个点?
Any help is much appreciated.任何帮助深表感谢。 Currently, this is my query, I'm stuck here:
目前,这是我的查询,我被困在这里:
;WITH CTE_A AS (
select a.valve_id, a.elevation,geometry from valve a
)
Select
b.valve_id as startnode,B.elevation from tblline C INNER JOIN CTE_A B ON c.geometry.STStartPoint().STTouches(B.geometry) = 1
union
SELECT b.valve_id as endnode,b.elevation from tblline d INNER JOIN CTE_A B ON d.geometry.STEndPoint().STTouches(B.geometry) = 1
table - valve表 - 阀门
valve_id![]() |
PointX![]() |
PointY![]() |
---|---|---|
VLV873 ![]() |
533726.788191639 ![]() |
1030389.94089809 ![]() |
VLV289 ![]() |
533726.403676326 ![]() |
1030390.12088887 ![]() |
table - tblline表 - tblline
StartX![]() |
StartY![]() |
EndX ![]() |
EndY![]() |
---|---|---|---|
533726.788191639 ![]() |
1030389.94089809 ![]() |
533726.403676326 ![]() |
1030390.12088887 ![]() |
below is my expected result in which I need to update this to tblline start_node and end_node column:下面是我的预期结果,我需要将其更新为 tblline start_node 和 end_node 列:
startnode![]() |
endnode![]() |
---|---|
VLV873 ![]() |
VLV289 ![]() |
Since the coordinates are stored with limited precision it's often impractical to determine of two shapes "touch".由于坐标以有限的精度存储,因此确定两个“触摸”形状通常是不切实际的。 Instead select a small buffer distance and test if they overlap.
取而代之的是 select 一个小的缓冲距离并测试它们是否重叠。 So "touching" is replaced by "within 0.001 units" or somesuch.
所以“接触”被“0.001单位以内”或类似的东西代替。 eg
例如
use tempdb
drop table if exists valve
drop table if exists tblline
go
create table valve(valve_id varchar(20) primary key, elevation float default 0, geometry geometry)
create table tblline (id int identity primary key, geometry geometry)
insert into valve(valve_id, geometry)
values ('VLV873', geometry::Point(533726.788191639, 1030389.94089809,0))
insert into valve(valve_id, geometry)
values ('VLV289', geometry::Point(533726.403676326, 1030390.12088887,0))
insert into tblline(geometry)
values (geometry::STLineFromText('LINESTRING (533726.788191639 1030389.94089809, 533726.403676326 1030390.12088887)',0))
--visualize the results
select geometry.STBuffer(0.001) from tblline
union all
select geometry.STBuffer(0.02) from valve
go
;WITH CTE_A AS (
select a.valve_id, a.elevation,geometry from valve a
)
Select b.valve_id as startnode,B.elevation
from tblline C
INNER JOIN CTE_A B
ON c.geometry.STStartPoint().STBuffer(0.001).STIntersects(B.geometry) = 1
union
SELECT b.valve_id as endnode,b.elevation
from tblline d
INNER JOIN CTE_A B
ON d.geometry.STEndPoint().STBuffer(0.001).STIntersects(B.geometry) = 1
outputs输出
and和
startnode elevation
-------------------- ----------------------
VLV289 0
VLV873 0
(2 rows affected)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.