1

我有一个任务,我必须在 Google 地图(4 点)上绘制 2 条线,并且在提交事件中我需要显示通过这些点的车辆。我能够在谷歌地图上绘制 2 条线,这给了我 4 个纬度/经度格式的点。

现在的主要问题是如何查询数据库以使车辆通过两条线。我知道我可能必须在 T-SQL 中使用 LineString 函数,但我如何让所有车辆通过这些线路?欢迎任何建议。

4

1 回答 1

1

鉴于我不确定您是如何表示您的“汽车”或您的“线条”并且必须做出假设,这个代码示例可能会为您提供帮助。它将返回一个数据集,指示哪些汽车已经通过了哪些线路。空间查询不是我的强项。也许其他人可以提供优化。

--  This is the first line as describer by 2 points
DECLARE @line1  GEOMETRY = geometry::STGeomFromText('LINESTRING(0 10, 10 10)', 0)
--  This is the second line as describer by another 2 points
DECLARE @line2  GEOMETRY = geometry::STGeomFromText('LINESTRING(0 20, 10 20)', 0)
--  @Car1's path is represented as a line that does NOT intersect the 2 defined lines above
DECLARE @Car1   GEOMETRY = geometry::STGeomFromText('LINESTRING(5 0, 5 11)', 0)
--  @Car2's path is represented as a line that DOES intersect that 2 defined lines above
DECLARE @Car2   GEOMETRY = geometry::STGeomFromText('LINESTRING(5 0, 5 23)', 0)

;WITH Lines (LineID, LineGeom) AS
(
    SELECT 1, @line1    UNION ALL
    SELECT 2, @line2
)
,Cars (CarID, CarGeom) AS
(
    SELECT 1, @Car1 UNION ALL
    SELECT 2, @Car2
)
SELECT   C.CarID
        ,L.LineID
FROM Cars   C
JOIN Lines  L ON L.LineGeom.STIntersects(C.CarGeom) = 1
于 2012-12-31T08:03:17.597 回答