Skip to main content

GEO func

(this is a ref to the udemy course which has a guide how to setup the data set)

GEO funcs docs

Assume we have a data structure like: { lat: 1, long: 23,state:"STRING"}. We want to locate all docs where state == "TX" (texas) The GEO_POINT func will return a struct see below. Which then can be used to work with that data on the database level.

FOR doc in airports
FILTER doc.state == "TX"
RETURN GEO_POINT(doc.long,doc.lat)
return of query
[
{
"type": "Point",
"coordinates": [
-95.01792778,
30.68586111
]
},
{
"type": "Point",
"coordinates": [
-97.79696778,
31.42127556
]
}
]

Now if we wanted to get all airports in a specific range of a lat long point. Here in this example i use 50km. Either return the point OR the whole doc to get the information... GEO_DISTANCE first array is will not change in the iteration but the second on will change for each doc.

FOR doc in airports
FILTER GEO_DISTANCE([-95.01792778, 30.68586111],[doc.long,doc.lat]) <= 50000
RETURN GEO_POINT(doc.long,doc.lat)
FOR doc in airports
FILTER GEO_DISTANCE([-95.01792778, 30.68586111],[doc.long,doc.lat]) <= 50000
RETURN doc
[
{
"_key": "00R",
"_id": "airports/00R",
"_rev": "_ecuTAJe---",
"name": "Livingston Municipal",
"city": "Livingston",
"state": "TX",
"country": "USA",
"lat": 30.68586111,
"long": -95.01792778,
"vip": false
},
{
"_key": "6R3",
"_id": "airports/6R3",
"_rev": "_ecuTALS--R",
"name": "Cleveland Municipal",
"city": "Cleveland",
"state": "TX",
"country": "USA",
"lat": 30.35643,
"long": -95.00801472,
"vip": false
}
]