我们有一个空间表(dbo.Map),其中11个多边形代表11个区域。此表具有唯一的ID,名称和与其关联的其他元数据,以及名为geo的地理数据类型列。我们还有一个单独的表(dbo.points),其中列表中的纬度/长度位于第一个表定义的区域中。除非我们能够将lat / long连接到地理列,否则这两个表没有任何东西可以加入它们。我们如何返回给定区域中所有点的列表?
答案 0 :(得分:0)
以下是我的表现:
首先,我必须推断你的架构。我会选择这样的东西:
create table dbo.Map (
MapID int identity not null,
geo geography not null
);
create table dbo.Points (
PointID int identity not null,
Latitude decimal(9, 7),
Longitude decimal(10, 7),
geo as geography::Point(Latitude, Longitude, 4236) persisted
);
接下来,选择:
select PointID, MapID
from dbo.Points as p
left join dbo.Map as m
on p.geo.STIntersects(m.geo) = 1
你可能想要添加某种where子句,但这只是一块骨头"我怎样才能找到我的观点所在的区域?"。
另请注意,points表有一个持久计算列,它是一个地理实例,表示经度和纬度列给定的点。这有几个原因:
abs(Latitude) > 90
)数据放入纬度和经度。