rooted spatial query with sub-select in OrientDB

后端 未结 1 1679
孤街浪徒
孤街浪徒 2021-01-29 02:41

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:



        
1条回答
  •  醉梦人生
    2021-01-29 03:04

    I figured out the way to do it... if it's safe to assume that the field GeoGlyph.Name is unique, I can use first() in the NEAR clause:

    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
    

    This seemed to do the trick.

    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  |
    +----+-----+--------+----------+----------+------+-------------------+
    

    I'm still not sure exactly how I'd do this if I couldn't rely on uniqueness of the Name field though. For example if I wanted to compute all the pairs of geoglyphs within 2km of each other...

    0 讨论(0)
提交回复
热议问题