使用STContains查找县道路

时间:2016-01-29 22:03:43

标签: sql-server performance optimization spatial spatial-index

运行SQL Server 2014 Standard

我有大约100万个线串(代表道路)和98个多边形(县)。我想更新道路所属的县。我的问题:

UPDATE RAW_HERE
SET COUNTY = RAW_HERE_COUNTY.POLYGON_NM
FROM [dbo].[RAW_HERE_PROCESSED_SINGLE] AS RAW_HERE
INNER JOIN [RAW_HERE_D91_COUNTY] as RAW_HERE_COUNTY ON (RAW_HERE_COUNTY.[Shape].STContains(RAW_HERE.[Shape]) = 1)

这个查询已经运行了3个小时并且正在计算,我已经验证它正在使用RAW_HERE_D91_COUNTY上的空间索引

RAW_HERE_PROCESSED_SINGLE包含线串(其几何列为[shape])RAW_HERE_D91_COUNTY包含多边形县,其几何列也是[形状]。

有更快的方法吗?我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

只需5分钟即可完成县级代码查找的主键,因此加入县而不是在道路上加入县似乎还有很长的路要走

CREATE TABLE [dbo].[#OBJECTCOUNTY](
    OBJECTID int PRIMARY KEY,
    [County] [nvarchar](105) NOT NULL
) ON [PRIMARY] 

INSERT INTO [#OBJECTCOUNTY]
SELECT RAW_HERE.OBJECTID, RAW_HERE_COUNTY.POLYGON_NM as County
FROM [RAW_HERE_D93_COUNTY] as RAW_HERE_COUNTY
LEFT JOIN [RAW_HERE_D93] as RAW_HERE ON (RAW_HERE_COUNTY.[Shape].STContains(RAW_HERE.[Shape]) = 1)
WHERE RAW_HERE.[Shape] IS NOT NULL

然后根据表格进行更新。