使用 STContains 查找县到道路
Finding county to a road using STContains
运行 SQL 服务器 2014 标准版
我有大约 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
包含多边形县,它们的几何列也是 [shape]。
有更快的方法吗?我错过了什么吗?
创建县代码查找主键只需 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
然后根据table更新即可。
运行 SQL 服务器 2014 标准版
我有大约 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
包含多边形县,它们的几何列也是 [shape]。
有更快的方法吗?我错过了什么吗?
创建县代码查找主键只需 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
然后根据table更新即可。