简体   繁体   English

找出空间数据库中两点之间是否有路线

[英]find out if there is a route between two points in spatial database

I am beginner in the matter of spatial databases I am using MS SQL Server 2014 with database structure as follows: 我是spatial databases方面的初学者,我正在使用MS SQL Server 2014 ,其数据库结构如下:

Point {
  id int AI,
  point geometry,
  name text
}
Path{
  id int AI,
  path geometry,
}

column point is created as (x,y) and path as set of start point and end point as linestring (xy, xy) point创建为(x,y)path作为起点和终点的集合作为linestring (xy, xy)

I would like to check if there is connection through many paths from one point to another. 我想检查从一个point到另一point许多paths是否存在连接。 Is there anyway to check it in SQL ? 反正有在SQL检查它吗? I can believe that I can do it at the server side or manually check all connections from first point etc. and in the end I will knew each combination (but I want to knew boolean value yes or no or the number of possible paths). 我可以相信我可以在服务器端做到这一点,也可以手动检查第一个point等的所有连接,最后我将知道每种组合(但是我想知道布尔值是或否或可能的路径数)。

I can't find any good article nor book about spatial database and looking for a path function... 我找不到任何好的文章,也找不到关于空间数据库和寻找路径功能的书...

Use the Geospatial STIntersects method. 使用地理空间STIntersects方法。 Look at MSDN article here 在这里查看MSDN文章

DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 2, 2 0, 4 2)', 0);
SET @h = geometry::STGeomFromText('POINT(1 1)', 0);
SELECT @g.STIntersects(@h);

to use in a select statement: 在select语句中使用:

Select geometryColumn.STIntersects(@g)
from Test

Sarin's answer is right but still not complete. 沙林的答案是正确的,但仍然不完整。

The following query pick point id 1 and checks if is intersect with any path: 以下查询选择点ID 1,并检查是否与任何路径相交:

SELECT Path.path.STIntersects(Point.point)
FROM Point CROSS JOIN dbo.Path
WHERE Point.id=1

I've tested the query with the same values as the ones from sarin's answer: 我已经使用与sarin答案相同的值测试了查询:

INSERT INTO Path (path)
VALUES (geometry::STGeomFromText('LINESTRING(0 2, 2 0, 4 2)', 0)),
       (geometry::STGeomFromText('LINESTRING(0 0, 2 2, 4 4)', 0))
GO
INSERT INTO Point (point, name)
VALUES (geometry::STGeomFromText('POINT(1 1)', 0), 'myPoint');

So the first path returns 0 (does not intersect with 1,1) and the second one returns 1. 因此,第一个路径返回0(不与1,1相交),第二个路径返回1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM