I am trying to put together a query to find nodes that are within 2km of a node in my graph. Say I have a dataset that marks some geoglyphs from the nazca lines:
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
I have a spatial index created using:
CREATE INDEX GeoGlyph.index.Location
ON GeoGlyph(Latitude,Longitude) SPATIAL ENGINE LUCENE
Now, I want to find the nodes within 2km of the "Hands" glyph, I can enter in this query by manually putting in the Lat/Long coordinates:
SELECT Name, Latitude, Longitude, $distance AS Distance
FROM GeoGlyph
WHERE [Latitude,Longitude,$spatial]
NEAR [-14.694459,-75.113884,{"maxDistance":2}]
ORDER BY Distance
I get the result:
+----+------+----------+----------+--------------------+
|# |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 |
+----+------+----------+----------+--------------------+
So far, so good.
Since it's a bit of a pain to type in the coordinates, I'd much rather just look for glyphs within 2km using the Name field "Hands".
This is where I'm currently stuck. I think I should be able to use LET block to get what I want... but what I've tried so far isn't working:
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
Any suggestions?