我跟着這個博客[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。我無法知道它爲什麼給我這麼多或者在半徑的一英里裏郵編。
請幫助