使用T-Sql指向多边形

时间:2013-11-13 09:34:50

标签: polygon

我正在创建一个地图应用程序,用户可以在Google地图上以交互方式绘制多边形。

我需要将此多边形数据发送回Sql Server,并根据多边形内数据库中的LatLng位置确定要返回的记录。

是否有人知道如何执行此操作或可用的例程。 提前致谢

1 个答案:

答案 0 :(得分:0)

如果您的地理列与记录相关联,则可以使用该列来查询多边形内的项目。 Link让你入门这是一个例子:

--What Items are within the Bermuda Triangle? 
---Note that Well-Known Text representation of a polygon is composed of points defined by Longitude then Latitude.
---Note that the points are defined in a counter-clockwise order so that the polygon is the interior of the triangle.  
DECLARE @BermudaTriangle geography = geography::STPolyFromText
('POLYGON((
    -80.190262  25.774252,
    -66.118292 18.466465,
    -64.75737 32.321384,
    -80.190262 25.774252
))', 4326)

SELECT ItemID, ReportedGPSPoint.Lat, ReportedGPSPoint.Long
FROM Items
WHERE ReportedGPSPoint.STIntersects(@BermudaTriangle) = 1