2016-01-29 113 views

回答

1

有很多方法可以從spark中查詢地理空間數據。使用magellan https://github.com/harsha2010/magellan或蜂巢esri地理空間工具包。 https://github.com/Esri/spatial-framework-for-hadoop 我從來沒有嘗試過mongo librairie,但是使用spark數據源api或mongo連接器,我認爲你可以用mongo語法運行geo查詢,然後將它們轉換爲RDD或Dataframe。

+0

麥哲倫此刻不能進行鄰近查詢。 Esri聽起來很有意思。 – Randomize

0

您可以使用此library從Spark SQL查詢MongoDB。 MongoDB允許應用程序對地理空間數據執行以下類型的查詢:包含,交集,鄰近。

顯然,除了地理空間之外,您還可以使用其他所有操作符。現在我們來看一些具體的例子。

以下是一個示例: 查找加利福尼亞州的所有機場。爲此,您需要獲取California位置(Polygon)並在查詢中使用$ geoWithin命令。從貝它看起來就像:

use geo 
var cal = db.states.findOne( {code : "CA"} ); 

db.airports.find( 
    { 
    loc : { $geoWithin : { $geometry : cal.loc } } 
    }, 
    { name : 1 , type : 1, code : 1, _id: 0 } 
); 

結果:

{ 「名」: 「莫德斯托市 - 縣」, 「類型」: 「」, 「代碼」: 「MOD」} ... {「name」:「San Francisco Intl」,「type」:「International」,「code」:「SFO」} {「name」:「San Jose International」,「type」 ,「code」:「SJC」}

如果你想嘗試其他的例子,看看這個博客文章here

+0

你如何使用stratio運行鄰近查詢? – Randomize