2016-12-05 36 views
0

我測試了orientdb spatial module。我已經把一個簡單的數據集座標幾geoglyphs在納斯卡線(nazca_lines.csv):OrientDB空間查詢找到彼此X公里內的所有對

Name,Latitude,Longitude 
Hummingbird,-14.692131,-75.148892 
Monkey,-14.706940,-75.138532 
Condor,-14.697444,-75.126208 
Spider,-14.694145,-75.122381 
Spiral,-14.688277,-75.122746 
Hands,-14.694459,-75.113881 
Tree,-14.693898,-75.114520 
Astronaut,-14.745222,-75.079755 
Dog,-14.706401,-75.130788 
Wing,-14.680309,-75.100385 
Parrot,-14.689463,-75.107498 

我創建一個使用空間索引:

CREATE INDEX GeoGlyph.index.Location 
ON GeoGlyph(Latitude,Longitude) SPATIAL ENGINE LUCENE 

我可以生成列表這給了我這樣的結果

SELECT $temp.Name AS SourceName, Name AS TargetName, $distance.format("%.4f") AS Distance 
FROM GeoGlyph 
LET $temp = first((SELECT * FROM GeoGlyph WHERE Name = "Tree")) 
WHERE [Latitude,Longitude,$spatial] 
NEAR [$temp.Latitude, $temp.Longitude,{"maxDistance":2}] 
ORDER BY Distance 

:節點內,使用像我在this stack-overflow question生成一個查詢說2KM,具體geoglyph的

+----+----------+----------+--------+ 
|# |SourceName|TargetName|Distance| 
+----+----------+----------+--------+ 
|0 |Tree  |Tree  |0.0000 | 
|1 |Tree  |Hands  |0.0884 | 
|2 |Tree  |Spider |0.9831 | 
|3 |Tree  |Spiral |1.0883 | 
|4 |Tree  |Condor |1.5735 | 
+----+----------+----------+--------+ 

這很好,但我只能找到相對於特定節點的節點。我想擴大這個範圍,要求所有對彼此相距2公里以內的節點。

,我很感興趣的一個結果會是這個樣子:

+----+-----------+-----------+--------+ 
|# |SourceName |TargetName |Distance| 
+----+-----------+-----------+--------+ 
|1 |Hummingbird|Monkey  |1.6314 | 
|2 |Monkey  |Dog  |1.8035 | 
|3 |Dog  |Condor  |0.9349 | 
|4 |Dog  |Spider  |1.5487 | 
|5 |Condor  |Spider  |0.6772 | 
|6 |Condor  |Spiral  |1.2685 | 
|7 |Condor  |Tree  |1.5735 | 
|8 |Condor  |Hands  |1.6150 | 
|9 |Spider  |Spiral  |0.6797 | 
... 

任何想法?

回答

0

你應該OPoint類型使用新的空間模塊功能

,並使用ST_Distance_Sphere功能

http://orientdb.com/docs/2.2/Spatial-Index.html#stdistancesphere-from-orientdb-224

+0

謝謝,我能看個明白。我沒有使用WKT方法,因爲我們的數據沒有使用WKT。也許在未來。這仍然不能真正幫助我的主要問題:目前,我得到這個工作的唯一方法是對具有2km特定節點的節點進行根的搜索。我想找到兩對距離在2公里以內的節點。我可以很容易地用javascript或Java來完成,但我正在尋找一個基於查詢的解決方案。 – TxAG98