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
有什麼建議?
您能否介紹一下關於first()函數的使用。我正在爲與你的問題非常相似的事情而努力,而且你的方法似乎可以解決它。 [http://stackoverflow.com/q/43861961/5013735](http://stackoverflow.com/q/43861961/5013735)試試吧! – Jobel
@jobel嗨,我的理解是,LET $ temp =(SELECT ...)的技巧實際上有$ temp存儲結果列表。我的示例鍵知道$ temp只會有1個條目,因爲Name字段是唯一的,我可以使用first()將第一個條目從列表中拉出並引用它的元素。 – TxAG98