UltipaDocs
Try Playground
  • Introduction
  • Terminologies
    • Reserved Words
    • Data Types
    • Alias
    • Operators
    • Expression
    • Filter
    • Prefix
    • Node and Edge Templates
    • Homologous and Heterologous Data
    • Clause Execution Times
    • Graphset
    • Schema
    • Property
    • Insert
    • Overwrite
    • Upsert
    • Update
    • Delete
    • Find Nodes
    • Find Edges
      • AB
      • Autonet
      • Spread
      • Path Template
      • K-Hop
      • K-Hop Template
    • Find Subgraphs
    • GROUP BY
    • ORDER BY
    • SKIP
    • LIMIT
    • WHERE
    • RETURN
    • WITH
    • UNCOLLECT
    • UNION
    • UNION ALL
    • CALL
    • BATCH
      • Schema Checker
      • Equal
      • Not Equal
      • Less Than
      • Greater Than
      • Less Than or Equal
      • Greater Than or Equal
      • Between
      • Between or Equal
      • Beong to
      • Not Belong To
      • CONTAINS | String
      • CONTAINS | Full-Text
      • Regular Match
      • IS NULL
      • IS NOT NULL
      • And
      • Or
      • Not
      • Exclusive OR
      • DISTINCT
      • toString()
      • toInteger()
      • toFloat()
      • toDouble()
      • toDecimal()
      • toSet()
      • castToRaw()
      • now()
      • dateAdd()
      • dateDiff()
      • year()
      • month()
      • day()
      • dayOfWeek()
      • dateFormat()
      • point()
      • distance()
      • pointInPolygon()
      • lower()
      • upper()
      • reverse()
      • startsWith()
      • endsWith()
      • JSON_decode()
      • JSON_merge()
      • trim()
      • ltrim()
      • rtrim()
      • left()
      • right()
      • substring()
      • replace()
      • split()
      • intersection()
      • difference()
      • listUnion()
      • size()
      • head()
      • reduce()
      • listContains()
      • append()
      • pi()
      • pow()
      • sqrt()
      • abs()
      • floor()
      • ceil()
      • round()
      • sin()
      • cos()
      • tan()
      • cot()
      • asin()
      • acos()
      • atan()
      • length()
      • pnodes()
      • pedges()
      • count()
      • sum()
      • max()
      • min()
      • avg()
      • stddev()
      • collect()
      • dedup()
      • CASE
      • table()
      • coalesce()
      • ifnull()
    • Acceleration
    • Index
    • Full-text
    • LTE
    • Real-time Process
    • Backend Task
    • Analytics Node
    • Server Statistics
    • Server Backup
    • Privilege
    • Policy
    • User
  • Trigger
  1. Docs
  2. /
  3. UQL
  4. /
  5. Spatial Functions

distance()

Function distance() returns the direct distance of two geographical coordinates in meters.

Arguments:

  • Geographical coordinates1 <point>
  • Geographical coordinates2 <point>

Returns:

  • Distance <number>

Sample graph: (to be used for the following examples)

Run below UQLs one by one in an empty graphset to create graph data:
UQL
create().node_property(@default, "name").node_property(@default, "lat_long", point)
insert().into(@default).nodes([{_id:"L001", _uuid:1, name:"New York", lat_long:point({latitude:40.7, longitude:-74.0})}, {_id:"L002", _uuid:2, name:"Paris", lat_long:point({latitude:48.5, longitude:2.2})}, {_id:"L003", _uuid:3, name:"Sydney", lat_long:point({latitude:-33.9, longitude:150.9})}, {_id:"L004", _uuid:4, name:"Beijing", lat_long:point({latitude:39.9, longitude:116.3})}])

Common Usage

Exalmple: Direct calculate, return in kilometers

UQL
find().nodes({name in ["New York", "Paris"]}) as a
find().nodes({name in ["Sydney", "Beijing"]}) as b
return table(a.name, b.name, distance(a.lat_long, b.lat_long)/1000)
Result
|  a.name  | b.name  | distance(a.point, b.point)/1000 |
|----------|---------|---------------------------------|
| New York | Sydney  | 16017.5939640978                |
| Paris    | Beijing | 8247.41966611293                |

Exalmple: Multiply and calculate, return in kilometers

UQL
find().nodes({name in ["New York", "Paris"]}) as a
find().nodes({name in ["Sydney", "Beijing"]}) as b
with distance(a.lat_long, b.lat_long)/1000 as c
return table(a.name, b.name, c)
Result
|  a.name  | b.name  |         c        |
|----------|---------|------------------|
| New York | Sydney  | 16017.5939640978 |
| New York | Beijing | 10992.9752060986 |
| Paris    | Sydney  | 16967.299225946  |
| Paris    | Beijing | 8247.41966611293 |