简体   繁体   English

如何在空间 sql 查询中检查表 1 中的点几何是否存在于表 2 中的线几何

[英]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 

Here's my expected output: [expected result][1] 这是我预期的 output:[预期结果][1]

table - valve表 - 阀门

valve_id阀门标识 PointX点X PointY点Y
VLV873 VLV873 533726.788191639 533726.788191639 1030389.94089809 1030389.94089809
VLV289 VLV289 533726.403676326 533726.403676326 1030390.12088887 1030390.12088887

table - tblline表 - tblline

StartX开始X StartY开始 EndX EndX EndY结束
533726.788191639 533726.788191639 1030389.94089809 1030389.94089809 533726.403676326 533726.403676326 1030390.12088887 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 VLV873 VLV289 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.

相关问题 如何在SQL Server 2012空间表中将列从几何转换为地理? - How to convert a column from Geometry to Geography in SQL Server 2012 Spatial table? 如何在 postgis 中从包含 field_ID 和 lat long point 的另一个表中创建具有几何多边形和 field_ID 的表 - How to create a table with geometry polygons and field_ID from another table containing field_ID and lat long point in postgis PostGIS 查询 Select 多边形表中的所有多边形,这些多边形具有相交的几何图形,在传递的地理坐标列表中具有一个或多个点 - PostGIS query to Select all Polygons from Polygon table having an intersecting geometry with one or more point in passed list of GeoCoordinates 在同一张表上使用Postgis几何编写SQL查询 - Writing a SQL query using postgis geometry on the same table Oracle(空间几何)查询问题 - Problem with Oracle (Spatial Geometry) query 另一个表中不存在的独特几何 - Distinct geometry that don't exist in another table SQL将新几何插入到新表中,该表使用相交和差的空间函数计算 - SQL Inserting new geometry into a new table that is calculated using spatial functions for intersections and difference SQL:如果表B上存在表A,如何逐一检查? - SQL: How to check one by one from table A if it exist on table B? SQL Server几何-从线串创建半圆 - SQL Server Geometry - Create a half circle from a line string 将坐标划分为SQL Server 2012中具有几何数据的表中的X和Y坐标 - Divide the coordinates into X and Y coordinates from a table having geometry data in SQL Server 2012
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM