2010-04-28 50 views
0

要在谷歌地圖顯示數據,我在SQL服務器2005> 50,000列數據的以下的(簡化的)結構確保地理數據的良好擴散從SQL數據庫

PointID 
Latitude 
Longitude 
TypeID 

我可以選擇一個小的子集邊界框之內,以確保類型的這樣一個體面組合:

..... 
(
@NELat float, 
@NELong float, 
@SWLat float, 
@SWLong float 
) 
as 
select top 100 PointID, Latitude, Longitude, 
rank() over (partition by PointTable.TypeID order by newid()) as NewRank 
from PointTable 
where 
(
CONVERT(float, PointTable.Latitude) >= @SWLat and CONVERT(float, PointTable.Latitude) <= @NELat and 
CONVERT(float, PointTable.Longitude) >= @SWLong and CONVERT(float, PointTable.Longitude) <= @NELong 
) 
order by NewRank 

不幸的是初始數據被朝向一個特定地理位置偏置。

什麼是確保檢索到的數據具有良好地理分佈的最有效/計算最快的方法?

我不想對數據進行聚類,只是爲了在邊界框中顯示更均勻的數據傳播。 我可能創建邊界框網格的一個子集,並對它們進行分區? 任何建議將是一個很大的幫助!

我一直在尋找可用於SQL sever 2008的地理數據類型,但它看起來不像2005年的可用。我也知道float不是用於存儲座標的最佳數據類型,但這不是最好的對我來說。

回答

0

我最終什麼事做的是以下幾點:

擴展我的表,包括Hierarchical Triangular Mesh ID爲給定的緯度/經度。使用在空間數據庫中的函數從「Using Table Valued Functions in SQL Server 2005 to Implement a Spatial Data Library」生成

PointID 
Latitude 
Longitude 
TypeID 
HTMID 

HTMID,與源代碼下載從Codeplex(注意我不得不生成新sampleKey.snk構建示例項目。我跟着these instructions

然後HTMID可以被四捨五入並用於將附近的點組合在一起。

..... 
(
@NELat float, 
@NELong float, 
@SWLat float, 
@SWLong float 
) 
as 
select top 100 PointID, Latitude, Longitude, 
rank() over (partition by PointTable.TypeID order by newid()) as NewRank, 
rank() over (partition by round(PointTable.HTMID,-7) order by newid()) as HTMRank 
from PointTable 
where 
(
CONVERT(float, PointTable.Latitude) >= @SWLat and CONVERT(float, PointTable.Latitude) <= @NELat and 
CONVERT(float, PointTable.Longitude) >= @SWLong and CONVERT(float, PointTable.Longitude) <= @NELong 
) 
order by HTMRank, NewRank 

這可能不完全準確,我也不會用這個HTMID來計算任何更精確,而不深入到技術細節更深入地 - 但它確實達到了我想要它。