我跟着这个博客[http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/sql-server-2008-proximity-search-with-th]并做了所有的指导,我很高兴事情进展顺利,我的表定义在下面提到,我正在执行的查询也在下面提到。PostCode使用sql server 2008在Radius中搜索GeoGraphy
我使用CodePointData数据是从https://www.ordnancesurvey.co.uk/opendatadownload/products.html下载
USE [TESTDB] GO
/****** Object: Table [dbo].[PostCode] Script Date: 08/23/2012 05:32:05 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[PostCode]( [PostCode] [nvarchar](10) NOT NULL, [Coordinates] [geography] NOT NULL, [Coordinates1] [geography] NULL, CONSTRAINT [PK_PostCode] PRIMARY KEY CLUSTERED ( [PostCode] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY] )ON [PRIMARY]
GO SELECT distinct(left(h.postcode,4)) from postcode g join postcode h on g.postcode <> h.postcode and g.postcode ='IG1 4LF' and h.postcode <> 'IG1 4LF' Where g.coordinates.STDistance(h.coordinates)<=(1*1609.344) order by left(h.postcode,4)
当我跑步时上面的查询提供了很多不属于该Radius的邮编。我正在验证我的结果与另一个网站http://www.freemaptools.com/find-uk-postcodes-inside-radius.htm,这个网站是说,1英里的半径包含邮政编码IG1,IG2,IG3,但是当我运行上述查询时,我的结果来了E12,IG1,IG2,IG3,IG4, IG5,IG6。我无法知道它为什么给我这么多或者在半径的一英里里邮编。
请帮助