How can I do this Spatial Query in Sql 2008?

百般思念 提交于 2019-12-10 10:38:22

问题


i'm trying to do a spatial query in sql 2008 -> for a given list of POI's (point of interest, long/lat GEOGRAPHY data), which postcodes do they exist in (multipolygon GEOGRAPHY data).

So this is the query i tried, but it's syntactically incorrect:-

SELECT PostCodeId, ShapeFile
FROM Postcodes a
WHERE a.ShapeFile.STIntersects(
    SELECT PointOfInterest
    FROM PointOfInterests
    WHERE PointOfInterestId IN (SELECT Item from dbo.fnSplit(@PoiIdList, ','))

So this means i pass in a csv list of POI Id's and split them. That's not a problem .. it's my subquery in the STIntersects. That's invalid.

So .. any suggestions folks?


回答1:


How about:

SELECT a.PostCodeId, a.ShapeFile
FROM (SELECT Item from dbo.fnSplit(@PoiIdList, ',')) AS POI_IDs
INNER JOIN PointOfInterests
    ON PointOfInterests.PointOfInterestId = POI_IDs.Item
INNER JOIN Postcodes a
    ON a.ShapeFile.STIntersects(PointOfInterests.PointOfInterest) = 1


来源:https://stackoverflow.com/questions/498353/how-can-i-do-this-spatial-query-in-sql-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!