2016-12-02 17 views
0

我正在嘗試將查詢放在一起以查找位於圖的節點2km內的節點。說我有從納斯卡線痕有些geoglyphs數據集:在OrientDB中使用子選擇的根空間查詢

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 

現在,我想找到的節點中的「手2公里「字形,我可以在此查詢由緯度/經度座標手動輸入推杆:

SELECT Name, Latitude, Longitude, $distance AS Distance 
FROM GeoGlyph 
WHERE [Latitude,Longitude,$spatial] 
NEAR [-14.694459,-75.113884,{"maxDistance":2}] 
ORDER BY Distance 

我得到的結果是:

+----+------+----------+----------+--------------------+ 
|# |Name |Latitude |Longitude |Distance   | 
+----+------+----------+----------+--------------------+ 
|0 |Hands |-14.694459|-75.113884|5.230883384236603E-6| 
|1 |Tree |-14.693897|-75.11446 |0.08836486627516459 | 
|2 |Spider|-14.694363|-75.12358 |1.0442063409276094 | 
|3 |Spiral|-14.688309|-75.12276 |1.1754176535538237 | 
|4 |Condor|-14.698346|-75.128334|1.6149944044266815 | 
+----+------+----------+----------+--------------------+ 

到目前爲止,這麼好。

由於輸入座標有點痛苦,我寧願只使用名稱字段「手」在2公里內尋找字形。

這是我目前卡住的地方。我想我應該能夠使用LET block得到我想要的東西...但到目前爲止,我已經試過不工作:

SELECT *,$distance AS Distance 
FROM GeoGlyph 
LET $temp = (SELECT * FROM GeoGlyph WHERE Name = "Hands") 
WHERE [Latitude,Longitude,$spatial] 
NEAR [$temp.Latitude, $temp.Longitude,{"maxDistance":2}] 
ORDER BY Distance 

有什麼建議?

回答

1

我想通了,做...如果它是安全的假設,該場GeoGlyph.Name是唯一的方式,我可以在NEAR子句中使用first()

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

這似乎這樣的伎倆。

orientdb {db=nazca.orientdb}> SELECT *,$distance AS Distance FROM GeoGlyph LET $temp = (SELECT * FROM GeoGlyph WHERE Name = "Hands") WHERE [Latitude,Longitude,$spatial] NEAR [first($temp).Latitude, first($temp).Longitude,{"maxDistance":2}] ORDER BY Distance 

+----+-----+--------+----------+----------+------+-------------------+ 
|# |@RID |@CLASS |Latitude |Longitude |Name |Distance   | 
+----+-----+--------+----------+----------+------+-------------------+ 
|0 |#25:5|GeoGlyph|-14.694459|-75.113884|Hands |0.0    | 
|1 |#25:6|GeoGlyph|-14.693897|-75.11446 |Tree |0.08836394983673491| 
|2 |#25:3|GeoGlyph|-14.694363|-75.12358 |Spider|1.0442092937404572 | 
|3 |#25:4|GeoGlyph|-14.688309|-75.12276 |Spiral|1.1754175925032648 | 
|4 |#25:2|GeoGlyph|-14.698346|-75.128334|Condor|1.614998440581846 | 
+----+-----+--------+----------+----------+------+-------------------+ 

我仍然不知道到底我應該這樣做,如果我不能依靠Name領域的獨特性,雖然。例如,如果我想計算彼此相距2公里內的所有geoglyphs對...

+0

您能否介紹一下關於first()函數的使用。我正在爲與你的問題非常相似的事情而努力,而且你的方法似乎可以解決它。 [http://stackoverflow.com/q/43861961/5013735](http://stackoverflow.com/q/43861961/5013735)試試吧! – Jobel

+0

@jobel嗨,我的理解是,LET $ temp =(SELECT ...)的技巧實際上有$ temp存儲結果列表。我的示例鍵知道$ temp只會有1個條目,因爲Name字段是唯一的,我可以使用first()將第一個條目從列表中拉出並引用它的元素。 – TxAG98