我们有一个空间表(dbo.Map),其中11个多边形代表11个区域。该表具有唯一的ID、名称和与其关联的其他元数据,以及名为geo的地理数据类型列。我们还有一个单独的表(dbo.points),其中包含在第一个表定义的区域中的具有lat/longs的点的列表。除非我们能够将lat/long连接到地理列,否则这两个表没有任何可连接的内容。我们如何返回给定区域中所有点的列表?
发布于 2015-05-23 00:48:13
我是这样做的:
首先,我必须推断出您的模式。我会选择这样的东西:
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子句,但这是最基本的:“我如何找到我的观点所在的区域?”
还请注意,point表有一个持久化计算列,它是一个地理实例,表示经度和纬度列所给出的点。这样做有以下几个原因:
abs(Latitude) > 90)放进纬度和经度。https://stackoverflow.com/questions/30406220
复制相似问题